提交 9614189c 编写于 作者: R Ritesh Harjani 提交者: Zheng Zengkai

ext4: fix loff_t overflow in ext4_max_bitmap_size()

stable inclusion
from stable-5.10.71
commit d11502fa26913f84883438c55fab0a8cb0d11474
bugzilla: 182981 https://gitee.com/openeuler/kernel/issues/I4I3KD

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=d11502fa26913f84883438c55fab0a8cb0d11474

--------------------------------

commit 75ca6ad4 upstream.

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: NRitesh Harjani <riteshh@linux.ibm.com>
Reviewed-by: NJan Kara <jack@suse.cz>
Signed-off-by: NTheodore Ts'o <tytso@mit.edu>
Cc: stable@kernel.org
Link: https://lore.kernel.org/r/594f409e2c543e90fd836b78188dfa5c575065ba.1622867594.git.riteshh@linux.ibm.comSigned-off-by: NTheodore Ts'o <tytso@mit.edu>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Acked-by: NWeilong Chen <chenweilong@huawei.com>
Signed-off-by: NChen Jun <chenjun102@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 31bb8500
...@@ -3165,17 +3165,17 @@ static loff_t ext4_max_size(int blkbits, int has_huge_files) ...@@ -3165,17 +3165,17 @@ static loff_t ext4_max_size(int blkbits, int has_huge_files)
*/ */
static loff_t ext4_max_bitmap_size(int bits, int has_huge_files) static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
{ {
loff_t res = EXT4_NDIR_BLOCKS; unsigned long long upper_limit, res = EXT4_NDIR_BLOCKS;
int meta_blocks; int meta_blocks;
loff_t upper_limit;
/* This is calculated to be the largest file size for a dense, block /*
* This is calculated to be the largest file size for a dense, block
* mapped file such that the file's total number of 512-byte sectors, * mapped file such that the file's total number of 512-byte sectors,
* including data and all indirect blocks, does not exceed (2^48 - 1). * including data and all indirect blocks, does not exceed (2^48 - 1).
* *
* __u32 i_blocks_lo and _u16 i_blocks_high represent the total * __u32 i_blocks_lo and _u16 i_blocks_high represent the total
* number of 512-byte sectors of the file. * number of 512-byte sectors of the file.
*/ */
if (!has_huge_files) { if (!has_huge_files) {
/* /*
* !has_huge_files or implies that the inode i_block field * !has_huge_files or implies that the inode i_block field
...@@ -3218,7 +3218,7 @@ static loff_t ext4_max_bitmap_size(int bits, int has_huge_files) ...@@ -3218,7 +3218,7 @@ static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)
if (res > MAX_LFS_FILESIZE) if (res > MAX_LFS_FILESIZE)
res = MAX_LFS_FILESIZE; res = MAX_LFS_FILESIZE;
return res; return (loff_t)res;
} }
static ext4_fsblk_t descriptor_loc(struct super_block *sb, static ext4_fsblk_t descriptor_loc(struct super_block *sb,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册