Article View: linux.kernel.netdev
Article #26754[PATCH net-next v2] net: use RCU_INIT_POINTER() to clear sk->sk_wq in sock_orphan()
From: Jiayi Zhang
Date: Fri, 04 Dec 2026 05:47
Date: Fri, 04 Dec 2026 05:47
83 lines
13968 bytes
13968 bytes
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
(found by syzbot):
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")
Link: https://syzkaller.appspot.com/bug?extid=c2e012bd497ee37068b0
Signed-off-by: Jiayi Zhang <zhangjiayi1014@gmail.com>
---
v2:
- Replace Reported-by:/Closes: with Link:. The syzbot bug also covers
another pair of accesses (below) that this patch does not change, so
the patch should not close it (Sashiko review of v1).
v1: https://lore.kernel.org/all/20261202180315.4144359-1-zhangjiayi1014@gmail.com/
The syzbot report is in syzbot's moderation queue and was not sent to
the lists; the 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 de23cdc..b26e8e3 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2143,7 +2143,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
Technical Details
Message-ID:
<20261204054709.1889367-1-zhangjiayi1014@gmail.com>Path:
mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377086-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377086-linux-kernel-netdev=dewy.ru
From: zhangjiayi1014@gmail.com (Jiayi Zhang)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v2] net: use RCU_INIT_POINTER() to clear sk->sk_wq in sock_orphan()
Date: Fri, 4 Dec 2026 05:47:09 +0000
Organization: Usenet Network
Message-ID: <20261204054709.1889367-1-zhangjiayi1014@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="2685606"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:DHyBG5HDd6uGyvLsU+8MhAg/ThY= sha256:nPTClC1O0I6dN6XDbdxP7QOIpxRrQTSs5grqSCbUqBk=
sha1:K+5ryTjiamCHBoNOoYCexioysmA= sha256:qEfX6FbYXuOnqppzSPfaaHK8WcW91NhPeU7oBDqke/0=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id CB02A117B15; Fri, 4 Dec 2026 08:47:41 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.396
X-Spam-Status: No, score=-3.396 tagged_above=-9999 required=6.31
tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
HEADER_FROM_DIFFERENT_DOMAINS=0.001, MAILING_LIST_MULTI=-1,
RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id MUjWszWEOMeb;
Fri, 4 Dec 2026 08:47:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-377086-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id C245B116D9F; Fri, 4 Dec 2026 08:47:25 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 4C008223F6; Fri, 4 Dec 2026 05:47:24 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796363242;
b=eF8JGRzEI0ojMKOtHLHqs5kTMYzKxTYohyArvbRhfVlEmM2jS9LDySr6SUjJ5QXhO0Ky
KmNVNEacwdqccLR4krZ4ADEpFc7M9kQDx+Ucsm4Dr5/bevnQzOnfh0Hg9nSVEwLxA+o9Z
0A5w2JLY/rgkuxdCUlkKiInBa/qoI5dn08O1ZBSTnjM3jmyfX9N852VVDH4jvIeJoOUUT
21rCUA2PbQx+z1NiMwDzaOA0BzO+1NcZzVmaQrVlwFfGyfHKwcZqXoaa7iVxUSNUOWQig
HZPBGbq0Axg4smCS+v7bRpWmEdMntCaVpezxyUyZrFhP4yIljR9X/hJ4CFtssEnQCVQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796363242;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:X-Mailing-List:
List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
List-Owner:Precedence:MIME-Version:Content-Transfer-Encoding;
bh=i52CjKinboaP0HpGEYCrTw1KU3mYGt6aGldmF8cIpN4=;
b=h3vPvYyy5tOqoaGPdTYk+pkr84zDRzhT3vPJNo3qlt2tkF1mWTBNAcws7AzZ6S8YC3Tt
ZYdzZU13tTl3NlSuOIU0u0HlCyb8jmCTpw+wcDms7jAutlj5wiJ7HhZhzSxagqQPqc7PN
4X3rn6c8v0IWWw1pZCkbIPygVeIexp6gRtJSNIiYlsIz8B3ooc/fSY86xFOyuh/Aq5ky8
6qeP8N4f5HS+2AkdfAVTVFCw57FQydObdJmbgqmPWrlrtCQB7X9kPZgA/x8fNcOJOb5VM
H0GlMNj75M0fCBVAw/dHz+GliTIqLkXmGrt5txqkCiXPGn0ox8xOPa/4voKEiHtyDrA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=i1M07GKq;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 1731A606A333;
Fri, 4 Dec 2026 05:47:22 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=i1M07GKq
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.229.9
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1796363241;
b=JZLascvfHf69g1t2JKZCwBrVKeZ3/Wj42HZUTnSmgqD27yVouWP1ONUJa06obVfRs3MQ
q7HEAp7knLlh42jMbJ/nKAYTgEORSnCDDewIqakB0ez6Z0V/zZ9/jiqp0CHjcYVnpvEKv
cq6Yj4ykPqVwhahdj3slCsWMuOUzxiTQSf/GIpDpzRqmxcE3XxWS6IEB2XDHdCsQGEv68
vzk+DKyOUx5mR6asz1RrJ3QsV9N0KGxQ6t9gS3ot69RFtz0McFmFgxULgh3jxL7wJDWRe
SWmgqdCsGiN3nVgP9UQGF3i6yKRbFs4an6LUttDeK4ART0SImVFKOH9UdzrXfWoH83Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796363241;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding;
bh=i52CjKinboaP0HpGEYCrTw1KU3mYGt6aGldmF8cIpN4=;
b=0NNx1Fhxyq7kVm+WapLsc+LFmPgEj0tWj2rkj7nZRqgYMNxZ9Fp/4o1DB33sURuZZZik
luEWyMIVwrXdJiAce3EnJEDONHwEtxamEYBSgFtUXYS8vuxdA2MiAfdo07f4I9D/7RuJu
L3LYQL4gYennG6nX9n4eZtKf0kNSECLXILMSsqANugC2iNVz3LvBAbidBtm7QestUdFr6
yWQVcnZVlDroJANpRd3cdTLNjLeWSGhmDcz+mlYYy8bzq5Unw/egV9luhv8hmKEasJgPr
u1pQE0TH3FVI6FaVNF7StUeY34lBcpzKUCY0QMkqx0ihy1+RO0X2e5mIA9BHcdKrSvw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=i1M07GKq;
arc=none smtp.remote-ip=74.125.229.9
X-Received: from mail-dy2-f9.google.com (mail-dy2-f9.google.com [74.125.229.9])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5AC6606A322
for <netdev@vger.kernel.org>; Fri, 4 Dec 2026 05:47:20 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D5AC6606A322
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-dy2-f9.google.com with SMTP id 5a478bee46e88-3678f64d078so417819eec.1
for <netdev@vger.kernel.org>; Thu, 03 Dec 2026 21:47:20 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796363240; x=1796968040; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=i52CjKinboaP0HpGEYCrTw1KU3mYGt6aGldmF8cIpN4=;
b=i1M07GKqS0SYnnPFDatl5LDsxocjqiETL7KNzfJgKxTEC4Iqn/ARuRCc9eswTswl44
M3q27ffY8XjELNlv94FhB/taBmTC2ATNmUnjnmOYNjoni/XJ0f9qhsHHXTeEWZ7BjMIR
9z2tuKZlVYxSL1IDUv3sWt8zz8w30rfVb60u2BMQTTzyWtJEfp4tugOiK3UiRtA0x4EM
Z/wuAIcU1iLY0i0y3w+gnWeiUKC3Bx3Py+BL+8GPLj5g6Djt0FP90C1d7HIuuvLm46iV
9SRTN3ktOnBSLOdkr6OEEQ1qP3GOGzFvqe6O5uedQC3F/p/9nLPbGPhsQ1Lo935QXqrR
+OkQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796363240; x=1796968040;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;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gScgJ8VV4c6rV/G1NIGVVdJC6tsUXnRTxCsxz2U/LHoTcODxavXGZTNsurWmP22
a71YnjBBXcgOYk8pbwacBbFKwsRF1Q3pzvQbYKam/nzI7St0lpOMOiMq
X-Received: by 2002:a05:693c:23ca:b0:386:a915:8b97 with SMTP id 5a478bee46e88-387521537c9mr1045476eec.27.1796363239538;
Thu, 03 Dec 2026 21:47:19 -0800 (PST)
X-Received: from jiayi-vm-sprl-server17.local ([155.69.195.24])
by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387522491dasm3676830eec.28.2026.12.03.21.47.17
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Thu, 03 Dec 2026 21:47:19 -0800 (PST)
X-Cc: netdev@vger.kernel.org,
syzbot+c2e012bd497ee37068b0@syzkaller.appspotmail.com,
syzkaller-bugs@googlegroups.com
X-Mailer: git-send-email 2.53.0
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list