From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <syoshida@redhat.com>
Cc: <davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<kuniyu@amazon.com>, <linux-kernel@vger.kernel.org>,
<netdev@vger.kernel.org>, <pabeni@redhat.com>,
<syzkaller@googlegroups.com>
Subject: Re: [PATCH net 1/2] af_unix: Fix uninit-value in __unix_walk_scc()
Date: Tue, 2 Jul 2024 19:42:48 -0700 [thread overview]
Message-ID: <20240703024248.99131-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20240702160428.10153-1-syoshida@redhat.com>
From: Shigeru Yoshida <syoshida@redhat.com>
Date: Wed, 3 Jul 2024 01:04:27 +0900
> KMSAN reported uninit-value access in __unix_walk_scc() [1].
>
> In the list_for_each_entry_reverse() loop, when the vertex's index
> equals it's scc_index, the loop uses the variable vertex as a
> temporary variable that points to a vertex in scc. And when the loop
> is finished, the variable vertex points to the list head, in this case
> scc, which is a local variable on the stack (more precisely, it's not
> even scc and might underflow the call stack of __unix_walk_scc():
> container_of(&scc, struct unix_vertex, scc_entry)).
>
> However, the variable vertex is used under the label prev_vertex. So
> if the edge_stack is not empty and the function jumps to the
> prev_vertex label, the function will access invalid data on the
> stack. This causes the uninit-value access issue.
>
> Fix this by introducing a new temporary variable for the loop.
>
> [1]
> BUG: KMSAN: uninit-value in __unix_walk_scc net/unix/garbage.c:478 [inline]
> BUG: KMSAN: uninit-value in unix_walk_scc net/unix/garbage.c:526 [inline]
> BUG: KMSAN: uninit-value in __unix_gc+0x2589/0x3c20 net/unix/garbage.c:584
> __unix_walk_scc net/unix/garbage.c:478 [inline]
> unix_walk_scc net/unix/garbage.c:526 [inline]
> __unix_gc+0x2589/0x3c20 net/unix/garbage.c:584
> process_one_work kernel/workqueue.c:3231 [inline]
> process_scheduled_works+0xade/0x1bf0 kernel/workqueue.c:3312
> worker_thread+0xeb6/0x15b0 kernel/workqueue.c:3393
> kthread+0x3c4/0x530 kernel/kthread.c:389
> ret_from_fork+0x6e/0x90 arch/x86/kernel/process.c:147
> ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
>
> Uninit was stored to memory at:
> unix_walk_scc net/unix/garbage.c:526 [inline]
> __unix_gc+0x2adf/0x3c20 net/unix/garbage.c:584
> process_one_work kernel/workqueue.c:3231 [inline]
> process_scheduled_works+0xade/0x1bf0 kernel/workqueue.c:3312
> worker_thread+0xeb6/0x15b0 kernel/workqueue.c:3393
> kthread+0x3c4/0x530 kernel/kthread.c:389
> ret_from_fork+0x6e/0x90 arch/x86/kernel/process.c:147
> ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244
>
> Local variable entries created at:
> ref_tracker_free+0x48/0xf30 lib/ref_tracker.c:222
> netdev_tracker_free include/linux/netdevice.h:4058 [inline]
> netdev_put include/linux/netdevice.h:4075 [inline]
> dev_put include/linux/netdevice.h:4101 [inline]
> update_gid_event_work_handler+0xaa/0x1b0 drivers/infiniband/core/roce_gid_mgmt.c:813
>
> CPU: 1 PID: 12763 Comm: kworker/u8:31 Not tainted 6.10.0-rc4-00217-g35bb670d65fc #32
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-2.fc40 04/01/2014
> Workqueue: events_unbound __unix_gc
>
> Fixes: 3484f063172d ("af_unix: Detect Strongly Connected Components.")
> Reported-by: syzkaller <syzkaller@googlegroups.com>
> Signed-off-by: Shigeru Yoshida <syoshida@redhat.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Thanks!
next prev parent reply other threads:[~2024-07-03 2:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-02 16:04 [PATCH net 1/2] af_unix: Fix uninit-value in __unix_walk_scc() Shigeru Yoshida
2024-07-02 16:04 ` [PATCH net 2/2] selftest: af_unix: Add test case for backtrack after finalising SCC Shigeru Yoshida
2024-07-03 2:42 ` Kuniyuki Iwashima [this message]
2024-07-04 2:50 ` [PATCH net 1/2] af_unix: Fix uninit-value in __unix_walk_scc() patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240703024248.99131-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=syoshida@redhat.com \
--cc=syzkaller@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox