jfs: Fix shift-out-of-bounds in jfs_statfs
PATCH 1/1 jfs: Fix shift-out-of-bounds in jfs_statfs
Syzkaller report issue as follows:
UBSAN: shift-out-of-bounds in fs/jfs/super.c:140:14 shift exponent -236023038 is negative CPU: 0 PID: 3985 Comm: syz-executor.4 Not tainted 6.1.0-rc2-syzkaller #0 Hardware name: Google Compute Engine, BIOS Google 10/11/2022 Call Trace: <TASK> __dump_stack lib/dump_stack.c:88 dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106 ubsan_epilogue lib/ubsan.c:151 __ubsan_handle_shift_out_of_bounds+0x33d/0x3b0 lib/ubsan.c:322 jfs_statfs+0x503/0x510 fs/jfs/super.c:140 statfs_by_dentry fs/statfs.c:66 vfs_statfs+0x136/0x310 fs/statfs.c:90 user_statfs fs/statfs.c:105 __ubsan_handle_shift_out_of_bounds __do_sys_statfs fs/statfs.c:195 __se_sys_statfs fs/statfs.c:192 __x64_sys_statfs+0x120/0x230 fs/statfs.c:192 do_syscall_x64 arch/x86/entry/common.c:50 do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd </TASK>
The on-disk inode map control structure contains a number indicates the log2 number of blocks per inode extent, which will be used as the shift to calculate the number of free blocks in jfs_statfs, so it needs to ensure the on-disk log2 number is positive and less than 64 on JFS mount.
Reported-by [email protected]
Signed-off-by Liao Chang <[email protected]>
--- fs/jfs/jfs_imap.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/jfs/jfs_imap.c +6 -0
@@ -124,6 +124,12 @@ int diMount(struct inode *ipimap)atomic_set (&imap->im_numfree,le32_to_cpu (dinom_le->in_numfree)); imap->im_nbperiext =le32_to_cpu (dinom_le->in_nbperiext); imap->im_l2nbperiext =le32_to_cpu (dinom_le->in_l2nbperiext); +if (imap->im_l2nbperiext <0 || + imap->im_l2nbperiext >=sizeof (s64) *8 ) { +kfree (imap); +return -EINVAL ; + } +for (index =0 ; index <MAXAG ; index++) { imap->im_agctl[index].inofree =le32_to_cpu (dinom_le->in_agctl[index].inofree);
Signature · 1 line
2.17.1