]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
5.15-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Feb 2024 20:03:42 +0000 (21:03 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Feb 2024 20:03:42 +0000 (21:03 +0100)
added patches:
af_unix-fix-task-hung-while-purging-oob_skb-in-gc.patch
tracing-inform-kmemleak-of-saved_cmdlines-allocation.patch

queue-5.15/af_unix-fix-task-hung-while-purging-oob_skb-in-gc.patch [new file with mode: 0644]
queue-5.15/series
queue-5.15/tracing-inform-kmemleak-of-saved_cmdlines-allocation.patch [new file with mode: 0644]

diff --git a/queue-5.15/af_unix-fix-task-hung-while-purging-oob_skb-in-gc.patch b/queue-5.15/af_unix-fix-task-hung-while-purging-oob_skb-in-gc.patch
new file mode 100644 (file)
index 0000000..2fc92b4
--- /dev/null
@@ -0,0 +1,103 @@
+From 25236c91b5ab4a26a56ba2e79b8060cf4e047839 Mon Sep 17 00:00:00 2001
+From: Kuniyuki Iwashima <kuniyu@amazon.com>
+Date: Fri, 9 Feb 2024 14:04:53 -0800
+Subject: af_unix: Fix task hung while purging oob_skb in GC.
+
+From: Kuniyuki Iwashima <kuniyu@amazon.com>
+
+commit 25236c91b5ab4a26a56ba2e79b8060cf4e047839 upstream.
+
+syzbot reported a task hung; at the same time, GC was looping infinitely
+in list_for_each_entry_safe() for OOB skb.  [0]
+
+syzbot demonstrated that the list_for_each_entry_safe() was not actually
+safe in this case.
+
+A single skb could have references for multiple sockets.  If we free such
+a skb in the list_for_each_entry_safe(), the current and next sockets could
+be unlinked in a single iteration.
+
+unix_notinflight() uses list_del_init() to unlink the socket, so the
+prefetched next socket forms a loop itself and list_for_each_entry_safe()
+never stops.
+
+Here, we must use while() and make sure we always fetch the first socket.
+
+[0]:
+Sending NMI from CPU 0 to CPUs 1:
+NMI backtrace for cpu 1
+CPU: 1 PID: 5065 Comm: syz-executor236 Not tainted 6.8.0-rc3-syzkaller-00136-g1f719a2f3fa6 #0
+Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/25/2024
+RIP: 0010:preempt_count arch/x86/include/asm/preempt.h:26 [inline]
+RIP: 0010:check_kcov_mode kernel/kcov.c:173 [inline]
+RIP: 0010:__sanitizer_cov_trace_pc+0xd/0x60 kernel/kcov.c:207
+Code: cc cc cc cc 66 0f 1f 84 00 00 00 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa 65 48 8b 14 25 40 c2 03 00 <65> 8b 05 b4 7c 78 7e a9 00 01 ff 00 48 8b 34 24 74 0f f6 c4 01 74
+RSP: 0018:ffffc900033efa58 EFLAGS: 00000283
+RAX: ffff88807b077800 RBX: ffff88807b077800 RCX: 1ffffffff27b1189
+RDX: ffff88802a5a3b80 RSI: ffffffff8968488d RDI: ffff88807b077f70
+RBP: ffffc900033efbb0 R08: 0000000000000001 R09: fffffbfff27a900c
+R10: ffffffff93d48067 R11: ffffffff8ae000eb R12: ffff88807b077800
+R13: dffffc0000000000 R14: ffff88807b077e40 R15: 0000000000000001
+FS:  0000000000000000(0000) GS:ffff8880b9500000(0000) knlGS:0000000000000000
+CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
+CR2: 0000564f4fc1e3a8 CR3: 000000000d57a000 CR4: 00000000003506f0
+DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
+DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
+Call Trace:
+ <NMI>
+ </NMI>
+ <TASK>
+ unix_gc+0x563/0x13b0 net/unix/garbage.c:319
+ unix_release_sock+0xa93/0xf80 net/unix/af_unix.c:683
+ unix_release+0x91/0xf0 net/unix/af_unix.c:1064
+ __sock_release+0xb0/0x270 net/socket.c:659
+ sock_close+0x1c/0x30 net/socket.c:1421
+ __fput+0x270/0xb80 fs/file_table.c:376
+ task_work_run+0x14f/0x250 kernel/task_work.c:180
+ exit_task_work include/linux/task_work.h:38 [inline]
+ do_exit+0xa8a/0x2ad0 kernel/exit.c:871
+ do_group_exit+0xd4/0x2a0 kernel/exit.c:1020
+ __do_sys_exit_group kernel/exit.c:1031 [inline]
+ __se_sys_exit_group kernel/exit.c:1029 [inline]
+ __x64_sys_exit_group+0x3e/0x50 kernel/exit.c:1029
+ do_syscall_x64 arch/x86/entry/common.c:52 [inline]
+ do_syscall_64+0xd5/0x270 arch/x86/entry/common.c:83
+ entry_SYSCALL_64_after_hwframe+0x6f/0x77
+RIP: 0033:0x7f9d6cbdac09
+Code: Unable to access opcode bytes at 0x7f9d6cbdabdf.
+RSP: 002b:00007fff5952feb8 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
+RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f9d6cbdac09
+RDX: 000000000000003c RSI: 00000000000000e7 RDI: 0000000000000000
+RBP: 00007f9d6cc552b0 R08: ffffffffffffffb8 R09: 0000000000000006
+R10: 0000000000000006 R11: 0000000000000246 R12: 00007f9d6cc552b0
+R13: 0000000000000000 R14: 00007f9d6cc55d00 R15: 00007f9d6cbabe70
+ </TASK>
+
+Reported-by: syzbot+4fa4a2d1f5a5ee06f006@syzkaller.appspotmail.com
+Closes: https://syzkaller.appspot.com/bug?extid=4fa4a2d1f5a5ee06f006
+Fixes: 1279f9d9dec2 ("af_unix: Call kfree_skb() for dead unix_(sk)->oob_skb in GC.")
+Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
+Link: https://lore.kernel.org/r/20240209220453.96053-1-kuniyu@amazon.com
+Signed-off-by: Paolo Abeni <pabeni@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ net/unix/garbage.c |    7 ++++---
+ 1 file changed, 4 insertions(+), 3 deletions(-)
+
+--- a/net/unix/garbage.c
++++ b/net/unix/garbage.c
+@@ -315,10 +315,11 @@ void unix_gc(void)
+       __skb_queue_purge(&hitlist);
+ #if IS_ENABLED(CONFIG_AF_UNIX_OOB)
+-      list_for_each_entry_safe(u, next, &gc_candidates, link) {
+-              struct sk_buff *skb = u->oob_skb;
++      while (!list_empty(&gc_candidates)) {
++              u = list_entry(gc_candidates.next, struct unix_sock, link);
++              if (u->oob_skb) {
++                      struct sk_buff *skb = u->oob_skb;
+-              if (skb) {
+                       u->oob_skb = NULL;
+                       kfree_skb(skb);
+               }
index aba77c34a1f6c3d67793b9eac497415775e4089e..52ed0540a7eb0a42e1500f7e41b935dcc7119d0c 100644 (file)
@@ -432,3 +432,5 @@ of-property-fix-typo-in-io-channels.patch
 can-j1939-prevent-deadlock-by-changing-j1939_socks_lock-to-rwlock.patch
 can-j1939-fix-uaf-in-j1939_sk_match_filter-during-setsockopt-so_j1939_filter.patch
 pmdomain-core-move-the-unused-cleanup-to-a-_sync-initcall.patch
+tracing-inform-kmemleak-of-saved_cmdlines-allocation.patch
+af_unix-fix-task-hung-while-purging-oob_skb-in-gc.patch
diff --git a/queue-5.15/tracing-inform-kmemleak-of-saved_cmdlines-allocation.patch b/queue-5.15/tracing-inform-kmemleak-of-saved_cmdlines-allocation.patch
new file mode 100644 (file)
index 0000000..ec6dcf0
--- /dev/null
@@ -0,0 +1,94 @@
+From 2394ac4145ea91b92271e675a09af2a9ea6840b7 Mon Sep 17 00:00:00 2001
+From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
+Date: Wed, 14 Feb 2024 11:20:46 -0500
+Subject: tracing: Inform kmemleak of saved_cmdlines allocation
+
+From: Steven Rostedt (Google) <rostedt@goodmis.org>
+
+commit 2394ac4145ea91b92271e675a09af2a9ea6840b7 upstream.
+
+The allocation of the struct saved_cmdlines_buffer structure changed from:
+
+        s = kmalloc(sizeof(*s), GFP_KERNEL);
+       s->saved_cmdlines = kmalloc_array(TASK_COMM_LEN, val, GFP_KERNEL);
+
+to:
+
+       orig_size = sizeof(*s) + val * TASK_COMM_LEN;
+       order = get_order(orig_size);
+       size = 1 << (order + PAGE_SHIFT);
+       page = alloc_pages(GFP_KERNEL, order);
+       if (!page)
+               return NULL;
+
+       s = page_address(page);
+       memset(s, 0, sizeof(*s));
+
+       s->saved_cmdlines = kmalloc_array(TASK_COMM_LEN, val, GFP_KERNEL);
+
+Where that s->saved_cmdlines allocation looks to be a dangling allocation
+to kmemleak. That's because kmemleak only keeps track of kmalloc()
+allocations. For allocations that use page_alloc() directly, the kmemleak
+needs to be explicitly informed about it.
+
+Add kmemleak_alloc() and kmemleak_free() around the page allocation so
+that it doesn't give the following false positive:
+
+unreferenced object 0xffff8881010c8000 (size 32760):
+  comm "swapper", pid 0, jiffies 4294667296
+  hex dump (first 32 bytes):
+    ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
+    ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff  ................
+  backtrace (crc ae6ec1b9):
+    [<ffffffff86722405>] kmemleak_alloc+0x45/0x80
+    [<ffffffff8414028d>] __kmalloc_large_node+0x10d/0x190
+    [<ffffffff84146ab1>] __kmalloc+0x3b1/0x4c0
+    [<ffffffff83ed7103>] allocate_cmdlines_buffer+0x113/0x230
+    [<ffffffff88649c34>] tracer_alloc_buffers.isra.0+0x124/0x460
+    [<ffffffff8864a174>] early_trace_init+0x14/0xa0
+    [<ffffffff885dd5ae>] start_kernel+0x12e/0x3c0
+    [<ffffffff885f5758>] x86_64_start_reservations+0x18/0x30
+    [<ffffffff885f582b>] x86_64_start_kernel+0x7b/0x80
+    [<ffffffff83a001c3>] secondary_startup_64_no_verify+0x15e/0x16b
+
+Link: https://lore.kernel.org/linux-trace-kernel/87r0hfnr9r.fsf@kernel.org/
+Link: https://lore.kernel.org/linux-trace-kernel/20240214112046.09a322d6@gandalf.local.home
+
+Cc: Masami Hiramatsu <mhiramat@kernel.org>
+Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+Cc: Catalin Marinas <catalin.marinas@arm.com>
+Fixes: 44dc5c41b5b1 ("tracing: Fix wasted memory in saved_cmdlines logic")
+Reported-by: Kalle Valo <kvalo@kernel.org>
+Tested-by: Kalle Valo <kvalo@kernel.org>
+Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ kernel/trace/trace.c |    3 +++
+ 1 file changed, 3 insertions(+)
+
+--- a/kernel/trace/trace.c
++++ b/kernel/trace/trace.c
+@@ -40,6 +40,7 @@
+ #include <linux/ctype.h>
+ #include <linux/init.h>
+ #include <linux/panic_notifier.h>
++#include <linux/kmemleak.h>
+ #include <linux/poll.h>
+ #include <linux/nmi.h>
+ #include <linux/fs.h>
+@@ -2255,6 +2256,7 @@ static void free_saved_cmdlines_buffer(s
+       int order = get_order(sizeof(*s) + s->cmdline_num * TASK_COMM_LEN);
+       kfree(s->map_cmdline_to_pid);
++      kmemleak_free(s);
+       free_pages((unsigned long)s, order);
+ }
+@@ -2274,6 +2276,7 @@ static struct saved_cmdlines_buffer *all
+               return NULL;
+       s = page_address(page);
++      kmemleak_alloc(s, size, 1, GFP_KERNEL);
+       memset(s, 0, sizeof(*s));
+       /* Round up to actual allocation */