Skip to content

Commit ec134c1

Browse files
hsiangkaogregkh
authored andcommitted
erofs: fix incorrect symlink detection in fast symlink
commit 9ed50b8 upstream. Fast symlink can be used if the on-disk symlink data is stored in the same block as the on-disk inode, so we don’t need to trigger another I/O for symlink data. However, currently fs correction could be reported _incorrectly_ if inode xattrs are too large. In fact, these should be valid images although they cannot be handled as fast symlinks. Many thanks to Colin for reporting this! Reported-by: Colin Walters <[email protected]> Reported-by: https://honggfuzz.dev/ Link: https://lore.kernel.org/r/[email protected] Fixes: 431339b ("staging: erofs: add inode operations") [ Note that it's a runtime misbehavior instead of a security issue. ] Signed-off-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 38c5618 commit ec134c1

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

fs/erofs/inode.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,14 @@ static int erofs_fill_symlink(struct inode *inode, void *kaddr,
212212
unsigned int m_pofs)
213213
{
214214
struct erofs_inode *vi = EROFS_I(inode);
215-
unsigned int bsz = i_blocksize(inode);
215+
loff_t off;
216216
char *lnk;
217217

218-
/* if it cannot be handled with fast symlink scheme */
219-
if (vi->datalayout != EROFS_INODE_FLAT_INLINE ||
220-
inode->i_size >= bsz || inode->i_size < 0) {
218+
m_pofs += vi->xattr_isize;
219+
/* check if it cannot be handled with fast symlink scheme */
220+
if (vi->datalayout != EROFS_INODE_FLAT_INLINE || inode->i_size < 0 ||
221+
check_add_overflow(m_pofs, inode->i_size, &off) ||
222+
off > i_blocksize(inode)) {
221223
inode->i_op = &erofs_symlink_iops;
222224
return 0;
223225
}
@@ -226,16 +228,6 @@ static int erofs_fill_symlink(struct inode *inode, void *kaddr,
226228
if (!lnk)
227229
return -ENOMEM;
228230

229-
m_pofs += vi->xattr_isize;
230-
/* inline symlink data shouldn't cross block boundary */
231-
if (m_pofs + inode->i_size > bsz) {
232-
kfree(lnk);
233-
erofs_err(inode->i_sb,
234-
"inline data cross block boundary @ nid %llu",
235-
vi->nid);
236-
DBG_BUGON(1);
237-
return -EFSCORRUPTED;
238-
}
239231
memcpy(lnk, kaddr + m_pofs, inode->i_size);
240232
lnk[inode->i_size] = '\0';
241233

0 commit comments

Comments
 (0)