* [PATCH net-next] net: use RCU_INIT_POINTER() to clear sk->sk_wq in sock_orphan()
@ 2026-12-02 18:03 Jiayi Zhang
2026-12-03 18:05 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Jiayi Zhang @ 2026-12-02 18:03 UTC (permalink / raw)
To: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
David S. Miller, Jakub Kicinski, Simon Horman
Cc: netdev, syzbot+c2e012bd497ee37068b0, syzkaller-bugs
sk->sk_wq is an RCU pointer: sock_graft() sets it with
rcu_assign_pointer() and readers such as unix_write_space() load it with
rcu_dereference(), possibly while the socket is being closed. When an
AF_UNIX socket is closed while its peer frees skbs charged to it,
sock_orphan() clears the pointer with a plain store and KCSAN reports:
BUG: KCSAN: data-race in unix_release_sock / unix_write_space
read (marked) to 0xffff888137738100 of 8 bytes by task 20918 on cpu 0:
unix_write_space+0xa6/0x170 net/unix/af_unix.c:603
sock_wfree+0x282/0x400 net/core/sock.c:2749
unix_wfree+0x1d/0x30 net/unix/af_unix.c:2019
skb_release_head_state+0x27b/0x280 net/core/skbuff.c:1167
skb_release_all net/core/skbuff.c:1187 [inline]
__kfree_skb+0x18/0x180 net/core/skbuff.c:1203
sk_skb_reason_drop+0xd6/0x270 net/core/skbuff.c:1242
kfree_skb_reason include/linux/skbuff.h:1330 [inline]
unix_release_sock+0x66f/0x790 net/unix/af_unix.c:759
write to 0xffff888137738100 of 8 bytes by task 20919 on cpu 1:
sock_orphan include/net/sock.h:2145 [inline]
unix_release_sock+0x238/0x790 net/unix/af_unix.c:711
The race has no functional effect. Readers handle a NULL sk_wq
(skwq_has_sleeper() and sock_wake_async() check for it), and a reader
that still sees the old pointer is safe because the socket_wq is part
of the socket inode, which is freed after an RCU grace period. The
plain store still lets the compiler tear it, and KCSAN reports it.
Clear the pointer with RCU_INIT_POINTER(), which stores it with
WRITE_ONCE(), as sk_clone() and sock_init_data_uid() already do.
Fixes: 43815482370c ("net: sock_def_readable() and friends RCU conversion")
Reported-by: syzbot+c2e012bd497ee37068b0@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=c2e012bd497ee37068b0
Signed-off-by: Jiayi Zhang <zhangjiayi1014@gmail.com>
---
The syzbot report is in syzbot's moderation queue and was not sent to
the lists; the Closes: link shows it.
Tested in QEMU with a test program that closes both ends of AF_UNIX
socket pairs at the same time after queueing messages (KCSAN report
filter set to these functions): without the patch 5 of 5 instances
reported this race on sk->sk_wq within 10 minutes; with the patch none
of 5 did. The net selftests were not run.
With the patch, 3 of the 5 instances reported another pair of accesses
under the same title: sock_set_flag(sk, SOCK_DEAD) in sock_orphan(),
a non-atomic __set_bit() on sk->sk_flags, against the test of
SOCK_FASYNC in sk_wake_async_rcu(). syzbot shows that pair in 3 of the
35 crashes of this bug; the other 32 are the sk->sk_wq race fixed here.
This patch does not change it.
mptcp has the same plain store of sk_wq in net/mptcp/protocol.c; that
would be a separate patch.
AI tools assisted with the analysis, the code and the changelog.
include/net/sock.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 3144efa..669608d 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2142,7 +2142,7 @@ static inline void sock_orphan(struct sock *sk)
write_lock_bh(&sk->sk_callback_lock);
sock_set_flag(sk, SOCK_DEAD);
sk_set_socket(sk, NULL);
- sk->sk_wq = NULL;
+ RCU_INIT_POINTER(sk->sk_wq, NULL);
write_unlock_bh(&sk->sk_callback_lock);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net-next] net: use RCU_INIT_POINTER() to clear sk->sk_wq in sock_orphan()
2026-12-02 18:03 [PATCH net-next] net: use RCU_INIT_POINTER() to clear sk->sk_wq in sock_orphan() Jiayi Zhang
@ 2026-12-03 18:05 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-03 18:05 UTC (permalink / raw)
To: zhangjiayi1014
Cc: edumazet, kuniyu, pabeni, willemb, davem, kuba, horms, netdev,
syzbot+c2e012bd497ee37068b0, syzkaller-bugs
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The patch carries `Closes:` for the syzbot bug titled "data-
race in unix_release_sock / unix_write_space", but one of the access…
--
net: use RCU_INIT_POINTER() to clear sk->sk_wq in sock_orphan()
This patch changes the plain store that clears sk->sk_wq in sock_orphan()
to RCU_INIT_POINTER(), so the store is done with WRITE_ONCE(). The goal is
to silence a KCSAN data-race report between unix_release_sock() and
unix_write_space() that syzbot found.
Closes: https://syzkaller.appspot.com/bug?extid=c2e012bd497ee37068b0
> diff --git a/include/net/sock.h b/include/net/sock.h
> index 5a203809218aa..9d22ccd91838d 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -2168,7 +2168,7 @@ static inline void sock_orphan(struct sock *sk)
> write_lock_bh(&sk->sk_callback_lock);
> sock_set_flag(sk, SOCK_DEAD);
[Severity: Medium]
Will the syzbot bug in the Closes: tag still be reported after this patch?
sock_set_flag() is a plain non-atomic read-modify-write of the whole
sk_flags word:
include/net/sock.h:sock_set_flag() {
__set_bit(flag, &sk->sk_flags);
}
On the peer side, the skb free path reads the same word without holding
sk_callback_lock:
unix_release_sock()->kfree_skb_reason()->unix_wfree()->sock_wfree()
->unix_write_space()->sk_wake_async_rcu()
include/net/sock.h:sk_wake_async_rcu() {
if (unlikely(sock_flag(sk, SOCK_FASYNC)))
sock_wake_async(rcu_dereference(sk->sk_wq), how, band);
}
unix_write_space() only holds rcu_read_lock(), so no lock is shared with
sock_orphan(). KCSAN can still report this pair under the same title,
"data-race in unix_release_sock / unix_write_space".
The notes below the changelog say this pair shows up in 3 of the 35 syzbot
crashes and in 3 of 5 local runs with the patch applied. Once this is
merged, syzbot would close the bug and then report it again from the same
reproducer.
Should the sk_flags access be handled too? One option is an atomic
set_bit() for SOCK_DEAD in sock_orphan(). Another is data_race() on the
reader side. If that is out of scope, could the Closes: tag be changed so
it does not claim the whole syzbot report is fixed?
> sk_set_socket(sk, NULL);
> - sk->sk_wq = NULL;
> + RCU_INIT_POINTER(sk->sk_wq, NULL);
> write_unlock_bh(&sk->sk_callback_lock);
> }
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261202180315.4144359-1-zhangjiayi1014%40gmail.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 18:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 18:03 [PATCH net-next] net: use RCU_INIT_POINTER() to clear sk->sk_wq in sock_orphan() Jiayi Zhang
2026-12-03 18:05 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox