Skip to content

Commit 025497e

Browse files
committed
erofs: reject inodes with negative i_size
Negative i_size is never supported, although crafted images with inodes having negative i_size will NOT lead to security issues in our current codebase: The following image can verify this (gzip+base64 encoded): H4sICCmk4mYAA3Rlc3QuaW1nAGNgGAWjYBSMVPDo4dcH3jP2aTED2TwMKgxMUHHNJY/SQDQX LxcDIw3tZwXit44MDNpQ/n8gQJZ/vxjijosPuSyZ0DUDgQqcZoKzVYFsDShbHeh6PT29ktTi Eqz2g/y2pBFiLxDMh4lhs5+W4TAKRsEoGAWjYBSMglEwCkYBPQAAS2DbowAQAAA= Mark as bad inodes for such corrupted inodes explicitly. Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 7c3ca18 commit 025497e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fs/erofs/inode.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* Copyright (C) 2021, Alibaba Cloud
66
*/
77
#include "xattr.h"
8-
98
#include <trace/events/erofs.h>
109

1110
static int erofs_fill_symlink(struct inode *inode, void *kaddr,
@@ -16,7 +15,7 @@ static int erofs_fill_symlink(struct inode *inode, void *kaddr,
1615

1716
m_pofs += vi->xattr_isize;
1817
/* check if it cannot be handled with fast symlink scheme */
19-
if (vi->datalayout != EROFS_INODE_FLAT_INLINE || inode->i_size < 0 ||
18+
if (vi->datalayout != EROFS_INODE_FLAT_INLINE ||
2019
check_add_overflow(m_pofs, inode->i_size, &off) ||
2120
off > i_blocksize(inode))
2221
return 0;
@@ -131,6 +130,11 @@ static int erofs_read_inode(struct inode *inode)
131130
goto err_out;
132131
}
133132

133+
if (unlikely(inode->i_size < 0)) {
134+
erofs_err(sb, "negative i_size @ nid %llu", vi->nid);
135+
err = -EFSCORRUPTED;
136+
goto err_out;
137+
}
134138
switch (inode->i_mode & S_IFMT) {
135139
case S_IFREG:
136140
case S_IFDIR:
@@ -186,7 +190,6 @@ static int erofs_read_inode(struct inode *inode)
186190
inode->i_blocks = round_up(inode->i_size, sb->s_blocksize) >> 9;
187191
else
188192
inode->i_blocks = nblks << (sb->s_blocksize_bits - 9);
189-
190193
err_out:
191194
DBG_BUGON(err);
192195
erofs_put_metabuf(&buf);

0 commit comments

Comments
 (0)