Skip to content

Commit 75ca6ad

Browse files
riteshharjanitytso
authored andcommitted
ext4: fix loff_t overflow in ext4_max_bitmap_size()
We should use unsigned long long rather than loff_t to avoid overflow in ext4_max_bitmap_size() for comparison before returning. w/o this patch sbi->s_bitmap_maxbytes was becoming a negative value due to overflow of upper_limit (with has_huge_files as true) Below is a quick test to trigger it on a 64KB pagesize system. sudo mkfs.ext4 -b 65536 -O ^has_extents,^64bit /dev/loop2 sudo mount /dev/loop2 /mnt sudo echo "hello" > /mnt/hello -> This will error out with "echo: write error: File too large" Signed-off-by: Ritesh Harjani <[email protected]> Reviewed-by: Jan Kara <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/594f409e2c543e90fd836b78188dfa5c575065ba.1622867594.git.riteshh@linux.ibm.com Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 6fed839 commit 75ca6ad

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

fs/ext4/super.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,17 +3030,17 @@ static loff_t ext4_max_size(int blkbits, int has_huge_files)
30303030
*/
30313031
static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
30323032
{
3033-
loff_t res = EXT4_NDIR_BLOCKS;
3033+
unsigned long long upper_limit, res = EXT4_NDIR_BLOCKS;
30343034
int meta_blocks;
3035-
loff_t upper_limit;
3036-
/* This is calculated to be the largest file size for a dense, block
3035+
3036+
/*
3037+
* This is calculated to be the largest file size for a dense, block
30373038
* mapped file such that the file's total number of 512-byte sectors,
30383039
* including data and all indirect blocks, does not exceed (2^48 - 1).
30393040
*
30403041
* __u32 i_blocks_lo and _u16 i_blocks_high represent the total
30413042
* number of 512-byte sectors of the file.
30423043
*/
3043-
30443044
if (!has_huge_files) {
30453045
/*
30463046
* !has_huge_files or implies that the inode i_block field
@@ -3083,7 +3083,7 @@ static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
30833083
if (res > MAX_LFS_FILESIZE)
30843084
res = MAX_LFS_FILESIZE;
30853085

3086-
return res;
3086+
return (loff_t)res;
30873087
}
30883088

30893089
static ext4_fsblk_t descriptor_loc(struct super_block *sb,

0 commit comments

Comments
 (0)