From 4391970158ef76565374c4f8d093ef5f62e65f73 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 12 Jun 2023 11:17:42 +0200 Subject: [PATCH] 5.15-stable patches added patches: revert-debugobject-ensure-pool-refill-again.patch xfs-verify-buffer-contents-when-we-skip-log-replay.patch --- ...debugobject-ensure-pool-refill-again.patch | 73 ++++++++++++ queue-5.15/series | 2 + ...fer-contents-when-we-skip-log-replay.patch | 110 ++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 queue-5.15/revert-debugobject-ensure-pool-refill-again.patch create mode 100644 queue-5.15/xfs-verify-buffer-contents-when-we-skip-log-replay.patch diff --git a/queue-5.15/revert-debugobject-ensure-pool-refill-again.patch b/queue-5.15/revert-debugobject-ensure-pool-refill-again.patch new file mode 100644 index 00000000000..c297cda4d2d --- /dev/null +++ b/queue-5.15/revert-debugobject-ensure-pool-refill-again.patch @@ -0,0 +1,73 @@ +From b9d78a89428def5450797ad58705973b9dfeeefd Mon Sep 17 00:00:00 2001 +From: Greg Kroah-Hartman +Date: Mon, 12 Jun 2023 10:56:09 +0200 +Subject: Revert "debugobject: Ensure pool refill (again)" + +From: Greg Kroah-Hartman + +This reverts commit 503e554782c916aec553f790298564a530cf1778 which is +commit 0af462f19e635ad522f28981238334620881badc upstream. + +Guenter reports problems with it, and it's not quite obvious why, so +revert it for now. + +Link: https://lore.kernel.org/r/d35b1ff1-e198-481c-b1be-9e22445efe06@roeck-us.net +Cc: Ido Schimmel +Cc: Thomas Gleixner +Cc: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman +--- + lib/debugobjects.c | 21 ++++++--------------- + 1 file changed, 6 insertions(+), 15 deletions(-) + +--- a/lib/debugobjects.c ++++ b/lib/debugobjects.c +@@ -590,16 +590,6 @@ static struct debug_obj *lookup_object_o + return NULL; + } + +-static void debug_objects_fill_pool(void) +-{ +- /* +- * On RT enabled kernels the pool refill must happen in preemptible +- * context: +- */ +- if (!IS_ENABLED(CONFIG_PREEMPT_RT) || preemptible()) +- fill_pool(); +-} +- + static void + __debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstack) + { +@@ -608,7 +598,12 @@ __debug_object_init(void *addr, const st + struct debug_obj *obj; + unsigned long flags; + +- debug_objects_fill_pool(); ++ /* ++ * On RT enabled kernels the pool refill must happen in preemptible ++ * context: ++ */ ++ if (!IS_ENABLED(CONFIG_PREEMPT_RT) || preemptible()) ++ fill_pool(); + + db = get_bucket((unsigned long) addr); + +@@ -693,8 +688,6 @@ int debug_object_activate(void *addr, co + if (!debug_objects_enabled) + return 0; + +- debug_objects_fill_pool(); +- + db = get_bucket((unsigned long) addr); + + raw_spin_lock_irqsave(&db->lock, flags); +@@ -904,8 +897,6 @@ void debug_object_assert_init(void *addr + if (!debug_objects_enabled) + return; + +- debug_objects_fill_pool(); +- + db = get_bucket((unsigned long) addr); + + raw_spin_lock_irqsave(&db->lock, flags); diff --git a/queue-5.15/series b/queue-5.15/series index a96c4e91763..18d8712ae2e 100644 --- a/queue-5.15/series +++ b/queue-5.15/series @@ -86,3 +86,5 @@ vhost-support-packed-when-setting-getting-vring_base.patch vhost_vdpa-support-packed-when-setting-getting-vring.patch revert-ext4-don-t-clear-sb_rdonly-when-remounting-r-w-until-quota-is-re-enabled.patch ext4-only-check-dquot_initialize_needed-when-debugging.patch +revert-debugobject-ensure-pool-refill-again.patch +xfs-verify-buffer-contents-when-we-skip-log-replay.patch diff --git a/queue-5.15/xfs-verify-buffer-contents-when-we-skip-log-replay.patch b/queue-5.15/xfs-verify-buffer-contents-when-we-skip-log-replay.patch new file mode 100644 index 00000000000..8d41b3b26cf --- /dev/null +++ b/queue-5.15/xfs-verify-buffer-contents-when-we-skip-log-replay.patch @@ -0,0 +1,110 @@ +From 22ed903eee23a5b174e240f1cdfa9acf393a5210 Mon Sep 17 00:00:00 2001 +From: "Darrick J. Wong" +Date: Wed, 12 Apr 2023 15:49:23 +1000 +Subject: xfs: verify buffer contents when we skip log replay + +From: Darrick J. Wong + +commit 22ed903eee23a5b174e240f1cdfa9acf393a5210 upstream. + +syzbot detected a crash during log recovery: + +XFS (loop0): Mounting V5 Filesystem bfdc47fc-10d8-4eed-a562-11a831b3f791 +XFS (loop0): Torn write (CRC failure) detected at log block 0x180. Truncating head block from 0x200. +XFS (loop0): Starting recovery (logdev: internal) +================================================================== +BUG: KASAN: slab-out-of-bounds in xfs_btree_lookup_get_block+0x15c/0x6d0 fs/xfs/libxfs/xfs_btree.c:1813 +Read of size 8 at addr ffff88807e89f258 by task syz-executor132/5074 + +CPU: 0 PID: 5074 Comm: syz-executor132 Not tainted 6.2.0-rc1-syzkaller #0 +Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022 +Call Trace: + + __dump_stack lib/dump_stack.c:88 [inline] + dump_stack_lvl+0x1b1/0x290 lib/dump_stack.c:106 + print_address_description+0x74/0x340 mm/kasan/report.c:306 + print_report+0x107/0x1f0 mm/kasan/report.c:417 + kasan_report+0xcd/0x100 mm/kasan/report.c:517 + xfs_btree_lookup_get_block+0x15c/0x6d0 fs/xfs/libxfs/xfs_btree.c:1813 + xfs_btree_lookup+0x346/0x12c0 fs/xfs/libxfs/xfs_btree.c:1913 + xfs_btree_simple_query_range+0xde/0x6a0 fs/xfs/libxfs/xfs_btree.c:4713 + xfs_btree_query_range+0x2db/0x380 fs/xfs/libxfs/xfs_btree.c:4953 + xfs_refcount_recover_cow_leftovers+0x2d1/0xa60 fs/xfs/libxfs/xfs_refcount.c:1946 + xfs_reflink_recover_cow+0xab/0x1b0 fs/xfs/xfs_reflink.c:930 + xlog_recover_finish+0x824/0x920 fs/xfs/xfs_log_recover.c:3493 + xfs_log_mount_finish+0x1ec/0x3d0 fs/xfs/xfs_log.c:829 + xfs_mountfs+0x146a/0x1ef0 fs/xfs/xfs_mount.c:933 + xfs_fs_fill_super+0xf95/0x11f0 fs/xfs/xfs_super.c:1666 + get_tree_bdev+0x400/0x620 fs/super.c:1282 + vfs_get_tree+0x88/0x270 fs/super.c:1489 + do_new_mount+0x289/0xad0 fs/namespace.c:3145 + do_mount fs/namespace.c:3488 [inline] + __do_sys_mount fs/namespace.c:3697 [inline] + __se_sys_mount+0x2d3/0x3c0 fs/namespace.c:3674 + do_syscall_x64 arch/x86/entry/common.c:50 [inline] + do_syscall_64+0x3d/0xb0 arch/x86/entry/common.c:80 + entry_SYSCALL_64_after_hwframe+0x63/0xcd +RIP: 0033:0x7f89fa3f4aca +Code: 83 c4 08 5b 5d c3 66 2e 0f 1f 84 00 00 00 00 00 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 49 89 ca b8 a5 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48 +RSP: 002b:00007fffd5fb5ef8 EFLAGS: 00000206 ORIG_RAX: 00000000000000a5 +RAX: ffffffffffffffda RBX: 00646975756f6e2c RCX: 00007f89fa3f4aca +RDX: 0000000020000100 RSI: 0000000020009640 RDI: 00007fffd5fb5f10 +RBP: 00007fffd5fb5f10 R08: 00007fffd5fb5f50 R09: 000000000000970d +R10: 0000000000200800 R11: 0000000000000206 R12: 0000000000000004 +R13: 0000555556c6b2c0 R14: 0000000000200800 R15: 00007fffd5fb5f50 + + +The fuzzed image contains an AGF with an obviously garbage +agf_refcount_level value of 32, and a dirty log with a buffer log item +for that AGF. The ondisk AGF has a higher LSN than the recovered log +item. xlog_recover_buf_commit_pass2 reads the buffer, compares the +LSNs, and decides to skip replay because the ondisk buffer appears to be +newer. + +Unfortunately, the ondisk buffer is corrupt, but recovery just read the +buffer with no buffer ops specified: + + error = xfs_buf_read(mp->m_ddev_targp, buf_f->blf_blkno, + buf_f->blf_len, buf_flags, &bp, NULL); + +Skipping the buffer leaves its contents in memory unverified. This sets +us up for a kernel crash because xfs_refcount_recover_cow_leftovers +reads the buffer (which is still around in XBF_DONE state, so no read +verification) and creates a refcountbt cursor of height 32. This is +impossible so we run off the end of the cursor object and crash. + +Fix this by invoking the verifier on all skipped buffers and aborting +log recovery if the ondisk buffer is corrupt. It might be smarter to +force replay the log item atop the buffer and then see if it'll pass the +write verifier (like ext4 does) but for now let's go with the +conservative option where we stop immediately. + +Link: https://syzkaller.appspot.com/bug?extid=7e9494b8b399902e994e +Signed-off-by: Darrick J. Wong +Reviewed-by: Dave Chinner +Signed-off-by: Dave Chinner +Signed-off-by: Leah Rumancik +Signed-off-by: Greg Kroah-Hartman +--- + fs/xfs/xfs_buf_item_recover.c | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +--- a/fs/xfs/xfs_buf_item_recover.c ++++ b/fs/xfs/xfs_buf_item_recover.c +@@ -934,6 +934,16 @@ xlog_recover_buf_commit_pass2( + if (lsn && lsn != -1 && XFS_LSN_CMP(lsn, current_lsn) >= 0) { + trace_xfs_log_recover_buf_skip(log, buf_f); + xlog_recover_validate_buf_type(mp, bp, buf_f, NULLCOMMITLSN); ++ ++ /* ++ * We're skipping replay of this buffer log item due to the log ++ * item LSN being behind the ondisk buffer. Verify the buffer ++ * contents since we aren't going to run the write verifier. ++ */ ++ if (bp->b_ops) { ++ bp->b_ops->verify_read(bp); ++ error = bp->b_error; ++ } + goto out_release; + } + -- 2.47.2