fs: Fix UBSAN detected shift-out-bounds error for bad superblock
PATCH 1/1 fs: Fix UBSAN detected shift-out-bounds error for bad superblock
UBSAN: shift-out-of-bounds in fs/minix/bitmap.c:103:3 shift exponent 8192 is too large for 32-bit type 'unsigned int' CPU: 1 PID: 32273 Comm: syz-executor.0 Tainted: G W 6.1.0-rc4-dirty #11 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xcd/0x134 ubsan_epilogue+0xb/0x50 __ubsan_handle_shift_out_of_bounds.cold+0xb1/0x18d minix_count_free_blocks.cold+0x16/0x1b minix_statfs+0x22a/0x490 statfs_by_dentry+0x133/0x210 user_statfs+0xa9/0x160 __do_sys_statfs+0x7a/0xf0 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd
The superblock stores on disk contains the size of a data zone, which is too large to used as the shift when kernel try to calculate the total size of zones, so it needs to check the superblock when kernel mounts MINIX-FS.
--- fs/minix/inode.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/minix/inode.c +6 -0
@@ -166,6 +166,12 @@ static bool minix_check_superblock(struct super_block *sb) sb->s_maxbytes > (7 + 512 + 512*512) * BLOCK_SIZE)return false; +/* the total size of zones must no exceed the limitation of U32_MAX. */ +if (sbi->s_log_zone_size && (sbi->s_nzones - sbi->s_firstdatazone) && + (__builtin_clzl ((__u32)(sbi->s_nzones - sbi->s_firstdatazone)) <= + sbi->s_log_zone_size)) +return false; +return true; }
Signature · 1 line
2.17.1
Quoted 19 lines · Liao Chang
UBSAN: shift-out-of-bounds in fs/minix/bitmap.c:103:3 shift exponent 8192 is too large for 32-bit type 'unsigned int' CPU: 1 PID: 32273 Comm: syz-executor.0 Tainted: G W 6.1.0-rc4-dirty #11 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xcd/0x134 ubsan_epilogue+0xb/0x50 __ubsan_handle_shift_out_of_bounds.cold+0xb1/0x18d minix_count_free_blocks.cold+0x16/0x1b minix_statfs+0x22a/0x490 statfs_by_dentry+0x133/0x210 user_statfs+0xa9/0x160 __do_sys_statfs+0x7a/0xf0 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcd
Quoted 6 lines
The superblock stores on disk contains the size of a data zone, which is too large to used as the shift when kernel try to calculate the total size of zones, so it needs to check the superblock when kernel mounts MINIX-FS.
Signed-off-by Liao Chang <[email protected]>
Thanks for the patch. Just one nit:
fs/minix/inode.c static bool minix_check_superblock(struct super_block *sb) · line 171
Quoted 11 lines
fs/minix/inode.c +3
-0@@ -166,6 +166,12 @@ static bool minix_check_superblock(struct super_block *sb) sb->s_maxbytes > (7 + 512 + 512*512) * BLOCK_SIZE)return false; +/* the total size of zones must no exceed the limitation of U32_MAX. */ + if (sbi->s_log_zone_size && (sbi->s_nzones - sbi->s_firstdatazone) && + (__builtin_clzl((__u32)(sbi->s_nzones - sbi->s_firstdatazone)) <=
Why this strange __builtin_clzl() function? We have a ffs() function in the kernel for this :)
Honza
Quoted 9 lines
fs/minix/inode.c +3
-0+ sbi->s_log_zone_size)) +return false; +return true; }Signature · 1 line
2.17.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 37 lines · Jan Kara
Quoted 19 lines · Liao Chang
UBSAN: shift-out-of-bounds in fs/minix/bitmap.c:103:3 shift exponent 8192 is too large for 32-bit type 'unsigned int' CPU: 1 PID: 32273 Comm: syz-executor.0 Tainted: G W 6.1.0-rc4-dirty #11 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xcd/0x134 ubsan_epilogue+0xb/0x50 __ubsan_handle_shift_out_of_bounds.cold+0xb1/0x18d minix_count_free_blocks.cold+0x16/0x1b minix_statfs+0x22a/0x490 statfs_by_dentry+0x133/0x210 user_statfs+0xa9/0x160 __do_sys_statfs+0x7a/0xf0 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcdQuoted 6 lines
The superblock stores on disk contains the size of a data zone, which is too large to used as the shift when kernel try to calculate the total size of zones, so it needs to check the superblock when kernel mounts MINIX-FS.
Signed-off-by Liao Chang <[email protected]>Thanks for the patch. Just one nit:
Quoted 8 lines
fs/minix/inode.c +0
-0@@ -166,6 +166,12 @@ static bool minix_check_superblock(struct super_block *sb) sb->s_maxbytes > (7 + 512 + 512*512) * BLOCK_SIZE)return false;
Quoted 6 lines
fs/minix/inode.c static bool minix_check_superblock(struct super_block *sb) · line 171
Quoted 3 lines
fs/minix/inode.c +3
-0+/* the total size of zones must no exceed the limitation of U32_MAX. */ + if (sbi->s_log_zone_size && (sbi->s_nzones - sbi->s_firstdatazone) && + (__builtin_clzl((__u32)(sbi->s_nzones - sbi->s_firstdatazone)) <=Why this strange
__builtin_clzl()function? We have affs()function in the kernel for this :)
Great suggestion, i should use a compiler neutral API to caclulate leading zero count, what about count_leading_zeros()?
Thanks.
Quoted 12 lines
Honza
Quoted 9 lines
fs/minix/inode.c +3
-0+ sbi->s_log_zone_size)) +return false; +return true; }Signature · 1 line
2.17.1
Signature · 2 lines
BR, Liao, Chang
Quoted 47 lines · liaochang (A)
Quoted 37 lines · Jan Kara
Quoted 19 lines · Liao Chang
UBSAN: shift-out-of-bounds in fs/minix/bitmap.c:103:3 shift exponent 8192 is too large for 32-bit type 'unsigned int' CPU: 1 PID: 32273 Comm: syz-executor.0 Tainted: G W 6.1.0-rc4-dirty #11 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xcd/0x134 ubsan_epilogue+0xb/0x50 __ubsan_handle_shift_out_of_bounds.cold+0xb1/0x18d minix_count_free_blocks.cold+0x16/0x1b minix_statfs+0x22a/0x490 statfs_by_dentry+0x133/0x210 user_statfs+0xa9/0x160 __do_sys_statfs+0x7a/0xf0 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcdQuoted 6 lines
The superblock stores on disk contains the size of a data zone, which is too large to used as the shift when kernel try to calculate the total size of zones, so it needs to check the superblock when kernel mounts MINIX-FS.
Signed-off-by Liao Chang <[email protected]>Thanks for the patch. Just one nit:
Quoted 8 lines
fs/minix/inode.c +0
-0@@ -166,6 +166,12 @@ static bool minix_check_superblock(struct super_block *sb) sb->s_maxbytes > (7 + 512 + 512*512) * BLOCK_SIZE)return false;Quoted 6 lines
fs/minix/inode.c static bool minix_check_superblock(struct super_block *sb) · line 171
Quoted 3 lines
fs/minix/inode.c +3
-0+/* the total size of zones must no exceed the limitation of U32_MAX. */ + if (sbi->s_log_zone_size && (sbi->s_nzones - sbi->s_firstdatazone) && + (__builtin_clzl((__u32)(sbi->s_nzones - sbi->s_firstdatazone)) <=Why this strange
__builtin_clzl()function? We have affs()function in the kernel for this :)
Quoted 2 lines
Great suggestion, i should use a compiler neutral API to caclulate leading zero count, what about
count_leading_zeros()?
Yeah, that would work as well.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 34 lines · Liao Chang
UBSAN: shift-out-of-bounds in fs/minix/bitmap.c:103:3 shift exponent 8192 is too large for 32-bit type 'unsigned int' CPU: 1 PID: 32273 Comm: syz-executor.0 Tainted: G W 6.1.0-rc4-dirty #11 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xcd/0x134 ubsan_epilogue+0xb/0x50 __ubsan_handle_shift_out_of_bounds.cold+0xb1/0x18d minix_count_free_blocks.cold+0x16/0x1b minix_statfs+0x22a/0x490 statfs_by_dentry+0x133/0x210 user_statfs+0xa9/0x160 __do_sys_statfs+0x7a/0xf0 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcdThe superblock stores on disk contains the size of a data zone, which is too large to used as the shift when kernel try to calculate the total size of zones, so it needs to check the superblock when kernel mounts MINIX-FS.
Signed-off-by Liao Chang <[email protected]>--- fs/minix/inode.c | 6 ++++++ 1 file changed, 6 insertions(+)fs/minix/inode.c +0
-0
fs/minix/inode.c static bool minix_check_superblock(struct super_block *sb) · line 169
Quoted 4 lines
fs/minix/inode.c +1
-0@@ -166,6 +166,12 @@ static bool minix_check_superblock(struct super_block *sb) sb->s_maxbytes > (7 + 512 + 512*512) * BLOCK_SIZE)return false; +/* the total size of zones must no exceed the limitation of U32_MAX. */
must not exceed
Quoted 8 lines
fs/minix/inode.c +5
-0+if (sbi->s_log_zone_size && (sbi->s_nzones - sbi->s_firstdatazone) && + (__builtin_clzl ((__u32)(sbi->s_nzones - sbi->s_firstdatazone)) <= + sbi->s_log_zone_size)) +return false; +return true; }
Signature · 1 line
~Randy
Quoted 40 lines · Randy Dunlap
Quoted 37 lines · Liao Chang
UBSAN: shift-out-of-bounds in fs/minix/bitmap.c:103:3 shift exponent 8192 is too large for 32-bit type 'unsigned int' CPU: 1 PID: 32273 Comm: syz-executor.0 Tainted: G W 6.1.0-rc4-dirty #11 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.15.0-0-g2dd4b9b3f840-prebuilt.qemu.org 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xcd/0x134 ubsan_epilogue+0xb/0x50 __ubsan_handle_shift_out_of_bounds.cold+0xb1/0x18d minix_count_free_blocks.cold+0x16/0x1b minix_statfs+0x22a/0x490 statfs_by_dentry+0x133/0x210 user_statfs+0xa9/0x160 __do_sys_statfs+0x7a/0xf0 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x63/0xcdThe superblock stores on disk contains the size of a data zone, which is too large to used as the shift when kernel try to calculate the total size of zones, so it needs to check the superblock when kernel mounts MINIX-FS.
Signed-off-by Liao Chang <[email protected]>--- fs/minix/inode.c | 6 ++++++ 1 file changed, 6 insertions(+)fs/minix/inode.c +0
-0@@ -166,6 +166,12 @@ static bool minix_check_superblock(struct super_block *sb) sb->s_maxbytes > (7 + 512 + 512*512) * BLOCK_SIZE)return false;
Quoted 3 lines
fs/minix/inode.c static bool minix_check_superblock(struct super_block *sb) · line 169
Quoted 1 line
fs/minix/inode.c +1
-0+/* the total size of zones must no exceed the limitation of U32_MAX. */ must not exceed
Thanks, i will correct it in next revision.
Quoted 10 lines
Quoted 9 lines
fs/minix/inode.c +5
-0+if (sbi->s_log_zone_size && (sbi->s_nzones - sbi->s_firstdatazone) && + (__builtin_clzl ((__u32)(sbi->s_nzones - sbi->s_firstdatazone)) <= + sbi->s_log_zone_size)) +return false; +return true; }
Signature · 2 lines
BR, Liao, Chang