From bd1d15a44e9c05939a278997c856a5b688553b10 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 12 Jun 2024 16:50:19 +0200 Subject: [PATCH] 6.1-stable patches added patches: f2fs-fix-to-do-sanity-check-on-i_xattr_nid-in-sanity_check_inode.patch media-lgdt3306a-add-a-check-against-null-pointer-def.patch --- ...on-i_xattr_nid-in-sanity_check_inode.patch | 69 +++++++++++++++++++ ...add-a-check-against-null-pointer-def.patch | 51 ++++++++++++++ queue-6.1/series | 2 + 3 files changed, 122 insertions(+) create mode 100644 queue-6.1/f2fs-fix-to-do-sanity-check-on-i_xattr_nid-in-sanity_check_inode.patch create mode 100644 queue-6.1/media-lgdt3306a-add-a-check-against-null-pointer-def.patch diff --git a/queue-6.1/f2fs-fix-to-do-sanity-check-on-i_xattr_nid-in-sanity_check_inode.patch b/queue-6.1/f2fs-fix-to-do-sanity-check-on-i_xattr_nid-in-sanity_check_inode.patch new file mode 100644 index 00000000000..02a4c34a4ae --- /dev/null +++ b/queue-6.1/f2fs-fix-to-do-sanity-check-on-i_xattr_nid-in-sanity_check_inode.patch @@ -0,0 +1,69 @@ +From 20faaf30e55522bba2b56d9c46689233205d7717 Mon Sep 17 00:00:00 2001 +From: Chao Yu +Date: Thu, 25 Apr 2024 16:58:38 +0800 +Subject: f2fs: fix to do sanity check on i_xattr_nid in sanity_check_inode() + +From: Chao Yu + +commit 20faaf30e55522bba2b56d9c46689233205d7717 upstream. + +syzbot reports a kernel bug as below: + +F2FS-fs (loop0): Mounted with checkpoint version = 48b305e4 +================================================================== +BUG: KASAN: slab-out-of-bounds in f2fs_test_bit fs/f2fs/f2fs.h:2933 [inline] +BUG: KASAN: slab-out-of-bounds in current_nat_addr fs/f2fs/node.h:213 [inline] +BUG: KASAN: slab-out-of-bounds in f2fs_get_node_info+0xece/0x1200 fs/f2fs/node.c:600 +Read of size 1 at addr ffff88807a58c76c by task syz-executor280/5076 + +CPU: 1 PID: 5076 Comm: syz-executor280 Not tainted 6.9.0-rc5-syzkaller #0 +Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024 +Call Trace: + + __dump_stack lib/dump_stack.c:88 [inline] + dump_stack_lvl+0x241/0x360 lib/dump_stack.c:114 + print_address_description mm/kasan/report.c:377 [inline] + print_report+0x169/0x550 mm/kasan/report.c:488 + kasan_report+0x143/0x180 mm/kasan/report.c:601 + f2fs_test_bit fs/f2fs/f2fs.h:2933 [inline] + current_nat_addr fs/f2fs/node.h:213 [inline] + f2fs_get_node_info+0xece/0x1200 fs/f2fs/node.c:600 + f2fs_xattr_fiemap fs/f2fs/data.c:1848 [inline] + f2fs_fiemap+0x55d/0x1ee0 fs/f2fs/data.c:1925 + ioctl_fiemap fs/ioctl.c:220 [inline] + do_vfs_ioctl+0x1c07/0x2e50 fs/ioctl.c:838 + __do_sys_ioctl fs/ioctl.c:902 [inline] + __se_sys_ioctl+0x81/0x170 fs/ioctl.c:890 + do_syscall_x64 arch/x86/entry/common.c:52 [inline] + do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83 + entry_SYSCALL_64_after_hwframe+0x77/0x7f + +The root cause is we missed to do sanity check on i_xattr_nid during +f2fs_iget(), so that in fiemap() path, current_nat_addr() will access +nat_bitmap w/ offset from invalid i_xattr_nid, result in triggering +kasan bug report, fix it. + +Reported-and-tested-by: syzbot+3694e283cf5c40df6d14@syzkaller.appspotmail.com +Closes: https://lore.kernel.org/linux-f2fs-devel/00000000000094036c0616e72a1d@google.com +Signed-off-by: Chao Yu +Signed-off-by: Jaegeuk Kim +Signed-off-by: Greg Kroah-Hartman +--- + fs/f2fs/inode.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +--- a/fs/f2fs/inode.c ++++ b/fs/f2fs/inode.c +@@ -298,6 +298,12 @@ static bool sanity_check_inode(struct in + } + } + ++ if (fi->i_xattr_nid && f2fs_check_nid_range(sbi, fi->i_xattr_nid)) { ++ f2fs_warn(sbi, "%s: inode (ino=%lx) has corrupted i_xattr_nid: %u, run fsck to fix.", ++ __func__, inode->i_ino, fi->i_xattr_nid); ++ return false; ++ } ++ + return true; + } + diff --git a/queue-6.1/media-lgdt3306a-add-a-check-against-null-pointer-def.patch b/queue-6.1/media-lgdt3306a-add-a-check-against-null-pointer-def.patch new file mode 100644 index 00000000000..18eec74fac8 --- /dev/null +++ b/queue-6.1/media-lgdt3306a-add-a-check-against-null-pointer-def.patch @@ -0,0 +1,51 @@ +From c1115ddbda9c930fba0fdd062e7a8873ebaf898d Mon Sep 17 00:00:00 2001 +From: Zheyu Ma +Date: Tue, 5 Apr 2022 10:50:18 +0100 +Subject: media: lgdt3306a: Add a check against null-pointer-def + +From: Zheyu Ma + +commit c1115ddbda9c930fba0fdd062e7a8873ebaf898d upstream. + +The driver should check whether the client provides the platform_data. + +The following log reveals it: + +[ 29.610324] BUG: KASAN: null-ptr-deref in kmemdup+0x30/0x40 +[ 29.610730] Read of size 40 at addr 0000000000000000 by task bash/414 +[ 29.612820] Call Trace: +[ 29.613030] +[ 29.613201] dump_stack_lvl+0x56/0x6f +[ 29.613496] ? kmemdup+0x30/0x40 +[ 29.613754] print_report.cold+0x494/0x6b7 +[ 29.614082] ? kmemdup+0x30/0x40 +[ 29.614340] kasan_report+0x8a/0x190 +[ 29.614628] ? kmemdup+0x30/0x40 +[ 29.614888] kasan_check_range+0x14d/0x1d0 +[ 29.615213] memcpy+0x20/0x60 +[ 29.615454] kmemdup+0x30/0x40 +[ 29.615700] lgdt3306a_probe+0x52/0x310 +[ 29.616339] i2c_device_probe+0x951/0xa90 + +Link: https://lore.kernel.org/linux-media/20220405095018.3993578-1-zheyuma97@gmail.com +Signed-off-by: Zheyu Ma +Signed-off-by: Mauro Carvalho Chehab +Signed-off-by: Greg Kroah-Hartman +--- + drivers/media/dvb-frontends/lgdt3306a.c | 5 +++++ + 1 file changed, 5 insertions(+) + +--- a/drivers/media/dvb-frontends/lgdt3306a.c ++++ b/drivers/media/dvb-frontends/lgdt3306a.c +@@ -2177,6 +2177,11 @@ static int lgdt3306a_probe(struct i2c_cl + struct dvb_frontend *fe; + int ret; + ++ if (!client->dev.platform_data) { ++ dev_err(&client->dev, "platform data is mandatory\n"); ++ return -EINVAL; ++ } ++ + config = kmemdup(client->dev.platform_data, + sizeof(struct lgdt3306a_config), GFP_KERNEL); + if (config == NULL) { diff --git a/queue-6.1/series b/queue-6.1/series index fd661f82b56..94815ed9e27 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -13,3 +13,5 @@ mptcp-cleanup-sol_tcp-handling.patch mptcp-fix-full-tcp-keep-alive-support.patch vxlan-fix-regression-when-dropping-packets-due-to-invalid-src-addresses.patch scripts-gdb-fix-sb_-constants-parsing.patch +f2fs-fix-to-do-sanity-check-on-i_xattr_nid-in-sanity_check_inode.patch +media-lgdt3306a-add-a-check-against-null-pointer-def.patch -- 2.47.3