Skip to content

Commit 9a0ec04

Browse files
reedrileyKent Overstreet
authored andcommitted
bcachefs: fix overflow in fiemap
filefrag (and potentially other utilities that call fiemap) sometimes pass ULONG_MAX as the length. fiemap_prep clamps excessively large lengths - but the calculation of end can overflow if it occurs before calling fiemap_prep. When this happens, filefrag assumes it has read to the end and exits. Signed-off-by: Reed Riley <reed@riley.engineer> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent db42549 commit 9a0ec04

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/bcachefs/fs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,6 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
964964
struct btree_iter iter;
965965
struct bkey_s_c k;
966966
struct bkey_buf cur, prev;
967-
struct bpos end = POS(ei->v.i_ino, (start + len) >> 9);
968967
unsigned offset_into_extent, sectors;
969968
bool have_extent = false;
970969
u32 snapshot;
@@ -974,6 +973,7 @@ static int bch2_fiemap(struct inode *vinode, struct fiemap_extent_info *info,
974973
if (ret)
975974
return ret;
976975

976+
struct bpos end = POS(ei->v.i_ino, (start + len) >> 9);
977977
if (start + len < start)
978978
return -EINVAL;
979979

0 commit comments

Comments
 (0)