KCSAN: data-race in unix_release_sock / unix_write_space (2)

Status: moderation: reported on 2026/11/17 16:53
Subsystems: net
Labels: prio:low race:benign
[Documentation on labels]
Reported-by: syzbot+c2e012bd497ee37068b0@syzkaller.appspotmail.com
First crash: 13h41m, last: 2h24m
✨ AI cause bisection: introduced by (AI job) :
commit 43815482370c510c569fd18edb57afcb0fa8cab6
Author: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu Apr 29 11:01:49 2010 +0000

  net: sock_def_readable() and friends RCU conversion

  
✨ AI-generated root cause summary:

In sock_orphan() (include/net/sock.h), sk->sk_wq is cleared using a plain, unmarked C store (sk->sk_wq = NULL) instead of RCU_INIT_POINTER(sk->sk_wq, NULL). Although sock_orphan() holds sk->sk_callback_lock, socket wakeup callbacks such as unix_write_space() read sk->sk_wq locklessly under rcu_read_lock() using rcu_dereference(). When one task releases an AF_UNIX socket and purges inflight skbs, invoking unix_wfree() -> sock_wfree() -> unix_write_space() on the sender socket concurrently with another task orphaning that sender socket in unix_release_sock(), KCSAN reports a data race between the unmarked store and the marked RCU read.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 666539eecdf4:

Technical Root Cause Analysis

1. Functions, Structs, and Fields Involved


2. Root Cause & Concurrency Mechanism

In struct sock, the wait queue pointer sk_wq is declared with the __rcu attribute:

union {
    struct socket_wq __rcu *sk_wq;
    /* private: */
    struct socket_wq       *sk_wq_raw;
    /* public: */
};

Socket wakeup callbacks (such as unix_write_space(), sock_def_write_space(), sock_def_readable(), and sock_def_wakeup()) access sk->sk_wq locklessly under rcu_read_lock() using rcu_dereference(sk->sk_wq) without acquiring sk->sk_callback_lock.

In sock_orphan() (include/net/sock.h):

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;
    write_unlock_bh(&sk->sk_callback_lock);
}

sock_orphan() updates sk->sk_wq using a plain, unmarked C store (sk->sk_wq = NULL;). While sk_set_socket() immediately preceding it explicitly uses WRITE_ONCE(), and other socket initialization/grafting helpers (sock_graft(), sock_init_data_uid(), sk_clone()) use rcu_assign_pointer() or RCU_INIT_POINTER(), sock_orphan() fails to use RCU_INIT_POINTER(sk->sk_wq, NULL).

Holding write_lock_bh(&sk->sk_callback_lock) does not protect against concurrent readers because RCU readers of sk->sk_wq do not take sk_callback_lock. Consequently, under the Linux Kernel Memory Model (LKMM), an unmarked write races with a marked read (rcu_dereference()).


3. Trigger Flow

  1. CPU 0 (Task 8407):

    • Closes an AF_UNIX socket (Socket B) via sys_close() -> sock_close() -> __sock_release() -> unix_release() -> unix_release_sock().
    • At af_unix.c:678, it calls sock_orphan(sk) on Socket B.
    • Inside sock_orphan(), it performs the plain write sk->sk_wq = NULL; at sock.h:2145.
  2. CPU 1 (Task 8405):

    • Closes peer AF_UNIX socket (Socket A) in unix_release_sock().
    • While purging remaining unread buffers from Socket A's sk_receive_queue at af_unix.c:726, it calls kfree_skb_reason(skb, SKB_DROP_REASON_SOCKET_CLOSE).
    • The queued skb was sent by Socket B, so dropping the packet triggers its destructor unix_wfree() -> sock_wfree() on Socket B.
    • sock_wfree() calls sk_write_space(sk) -> unix_write_space(sk) on Socket B.
    • In unix_write_space(), line 603 dereferences sk->sk_wq with wq = rcu_dereference(sk->sk_wq);.
  3. Sanitizer Detection: KCSAN detects a concurrent marked read (rcu_dereference() -> READ_ONCE()) on CPU 1 and an unmarked write (sk->sk_wq = NULL) on CPU 0 to the exact same pointer address (sk->sk_wq).


4. Remediation

In sock_orphan() (include/net/sock.h), sk->sk_wq = NULL; should be replaced with:

RCU_INIT_POINTER(sk->sk_wq, NULL);

This applies WRITE_ONCE() to the assignment, preventing compiler store-tearing and ensuring consistency with RCU reader expectations and LKMM concurrency rules.

▶ ▼ ✨ AI Jobs (3)
ID Workflow Result Correct Bug Created Started Finished Revision
35c0f0e0 bisect-cause ❓ KCSAN: data-race in unix_release_sock / unix_write_space (2) 2026/11/17 16:47 2026/11/17 16:47 2026/11/17 16:54 ca622473
2b34268d assessment-kcsan Benign: ✅ ❓ KCSAN: data-race in unix_release_sock / unix_write_space (2) 2026/11/17 16:45 2026/11/17 16:45 2026/11/17 17:39 ca622473
a676b7e8 assessment-security DenialOfService: ❌ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ✅ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KCSAN: data-race in unix_release_sock / unix_write_space (2) 2026/11/17 16:42 2026/11/17 16:42 2026/11/17 16:52 ca622473
▶ ▼ Similar bugs (1)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream KCSAN: data-race in unix_release_sock / unix_write_space net 6 47 2349d 2579d 0/29 closed as invalid on 2020/06/18 14:24

Sample crash report:
==================================================================
BUG: KCSAN: data-race in unix_release_sock / unix_write_space

read (marked) to 0xffff888129b56500 of 8 bytes by task 8405 on cpu 1:
 unix_write_space+0xa6/0x170 net/unix/af_unix.c:603
 sock_wfree+0x282/0x400 net/core/sock.c:2746
 unix_wfree+0x1d/0x30 net/unix/af_unix.c:1986
 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:1329 [inline]
 unix_release_sock+0x66f/0x790 net/unix/af_unix.c:726
 unix_release+0x58/0x80 net/unix/af_unix.c:1193
 __sock_release+0x65/0x150 net/socket.c:735
 sock_close+0x19/0x30 net/socket.c:1529
 __fput+0x292/0x660 fs/file_table.c:512
 fput_close_sync+0xd5/0x1d0 fs/file_table.c:618
 filp_close_sync+0x27/0x40 fs/open.c:1574
 __range_close fs/file.c:919 [inline]
 __do_sys_close_range fs/file.c:1003 [inline]
 __se_sys_close_range+0x765/0x880 fs/file.c:954
 __x64_sys_close_range+0x43/0x50 fs/file.c:954
 x64_sys_call+0x2198/0x2550 arch/x86/include/generated/asm/syscalls_64.h:437
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

write to 0xffff888129b56500 of 8 bytes by task 8407 on cpu 0:
 sock_orphan include/net/sock.h:2145 [inline]
 unix_release_sock+0x238/0x790 net/unix/af_unix.c:678
 unix_release+0x58/0x80 net/unix/af_unix.c:1193
 __sock_release+0x65/0x150 net/socket.c:735
 sock_close+0x19/0x30 net/socket.c:1529
 __fput+0x292/0x660 fs/file_table.c:512
 ____fput+0x1c/0x30 fs/file_table.c:541
 task_work_run+0x145/0x1a0 kernel/task_work.c:233
 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
 __exit_to_user_mode_loop kernel/entry/common.c:70 [inline]
 exit_to_user_mode_loop+0x1fa/0x940 kernel/entry/common.c:101
 __exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
 syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline]
 syscall_exit_to_user_mode include/linux/entry-common.h:343 [inline]
 do_syscall_64+0x23b/0x3a0 arch/x86/entry/syscall_64.c:107
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 8407 Comm: syz.1.7185 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/17 15:25 upstream 666539eecdf4 43af6cac .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in unix_release_sock / unix_write_space
2026/11/17 04:09 upstream 666539eecdf4 a3e64cfc .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-kcsan-gce KCSAN: data-race in unix_release_sock / unix_write_space
* Struck through repros no longer work on HEAD.