Article View: linux.kernel.netdev
Article #19469Re: [PATCH] net: initialize sk_peer_lock in cloned sockets
From: netdev-bot+sashiko
Date: Thu, 19 Nov 2026 23:50
Date: Thu, 19 Nov 2026 23:50
141 lines
12581 bytes
12581 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 ยท High: 1 ยท Medium: 0 ยท Low: 1
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).
- [High] The fix is incomplete: on 32-bit kernels, sk_clone() still
inherits sk->sk_stamp_seq in a held state.
- [Low] The commit message says sock_copy() clones a struct sock 'with
two memcpys that both include sk_peer_lock'.
--
Here is the LKML reply:
net: initialize sk_peer_lock in cloned sockets
This commit adds a spin_lock_init() of sk_peer_lock in sk_clone(). Without
it, a clone made while the parent's sk_peer_lock is held starts with the
lock already locked, and the first getsockopt(SO_PEERCRED) on the child
hangs.
> sock_copy() clones a struct sock with two memcpys that both include
> sk_peer_lock. sk_clone() re-initializes sk_lock, but nothing resets
[Severity: Low]
Is the "two memcpys that both include sk_peer_lock" part accurate? The
first copy in sock_copy() stops at sk_dontcopy_begin, which sits inside
__sk_common:
net/core/sock.c:sock_copy() {
...
memcpy(nsk, osk, offsetof(struct sock, sk_dontcopy_begin));
unsafe_memcpy(&nsk->sk_dontcopy_end, &osk->sk_dontcopy_end,
prot->obj_size - offsetof(struct sock, sk_dontcopy_end),
/* alloc is larger than struct, see sk_prot_alloc() */);
...
}
sk_peer_lock is a field in the struct sock body, well after __sk_common.
So only the second unsafe_memcpy() copies it.
The conclusion that the lock is copied verbatim still holds. Could the
commit message describe the mechanism more precisely?
> diff --git a/net/core/sock.c b/net/core/sock.c
> index ad414878dc5ba..b5e2a2a7741cd 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -2545,6 +2545,10 @@ struct sock *sk_clone(const struct sock *sk, const gfp_t priority,
>
> sk_node_init(&newsk->sk_node);
> sock_lock_init(newsk);
> + /* sock_copy() copies the parent's sk_peer_lock verbatim, including a
> + * held state, so the clone must start with a fresh lock.
> + */
> + spin_lock_init(&newsk->sk_peer_lock);
[Severity: High]
Does the same problem remain for sk_stamp_seq on 32-bit kernels?
sk_stamp_seq is a seqlock_t (a spinlock plus a seqcount) declared under
BITS_PER_LONG==32 in struct sock:
include/net/sock.h:
#if BITS_PER_LONG==32
seqlock_t sk_stamp_seq;
#endif
It lies outside the sk_dontcopy range, so sock_copy() copies it along with
sk_peer_lock. It is only initialized by seqlock_init() in
sock_init_data_uid(), which the clone path never runs. Neither sk_clone()
nor sk_init_common() resets it.
The writer takes the spinlock and leaves the sequence count odd:
include/net/sock.h:sock_write_timestamp() {
write_seqlock(&sk->sk_stamp_seq);
sk->sk_stamp = kt;
write_sequnlock(&sk->sk_stamp_seq);
}
sock_gettstamp() (ioctl SIOCGSTAMP) calls that writer without lock_sock
whenever sk_stamp is 0:
net/core/sock.c:sock_gettstamp() {
...
if (ts.tv_sec == 0) {
ktime_t kt = ktime_get_real();
sock_write_timestamp(sk, kt);
...
}
On an SCTP one-to-many socket, sk_stamp becomes 0 after the first
sctp_recvmsg()->sock_recv_cmsgs(). With that state, can the following
happen?
CPU0
ioctl(SIOCGSTAMP)
sock_gettstamp()
sock_write_timestamp()
write_seqlock(&parent->sk_stamp_seq)
CPU1
getsockopt(SCTP_SOCKOPT_PEELOFF)
sctp_getsockopt() /* lock_sock() held */
sctp_do_peeloff()
sctp_clone_sock()
sk_clone()
sock_copy()
The lock_sock() taken on CPU1 does not exclude CPU0's lockless write. The
child would then get a locked spinlock and an odd seqcount.
After that, sock_read_timestamp() on the child would spin forever in
read_seqbegin(). That covers SIOCGSTAMP, and recvmsg via
sock_recv_cmsgs(). On PREEMPT_RT it would block on the copied held lock
instead.
Any sock_write_timestamp() on the child would spin forever in spin_lock()
with preemption disabled. That is the same RCU-stall hang the commit
message describes for sk_peer_lock.
Two threads of an unprivileged user could trigger this. Would it make
sense to also add a seqlock_init(&newsk->sk_stamp_seq) under
BITS_PER_LONG==32 next to the new spin_lock_init()? Another option is to
move all lock re-initialization for clones into one helper.
>
> if (lock)
> bh_lock_sock(newsk);
--
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118084927.1756747-1-bsdhenrymartin%40gmail.com
Technical Details
Message-ID:
<179513221226.3136.10545319024086149359@kernel.org>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367428-linux-kernel-netdev=dewy.ruReferences:
<20261118084927.1756747-1-bsdhenrymartin@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367428-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH] net: initialize sk_peer_lock in cloned sockets Date: Thu, 19 Nov 2026 23:50:12 +0000 Organization: Usenet Network Message-ID: <179513221226.3136.10545319024086149359@kernel.org> References: <20261118084927.1756747-1-bsdhenrymartin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3013652"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:nixsHyiYoAamgh6+3GErUSFgx98= sha256:HWp0/0QWbjqXQ9Y69Dql/0pdSSfA5xCu4ECbyutLpAw= sha1:U4ymStUYdj11QPHghZtjMy8IZRI= sha256:b77RVAQJbkylLzP44SEUnCer/JDKiBMKY7F4acgfHZw= 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 53EC811580A; Fri, 20 Nov 2026 02:50:29 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.4 X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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=kernel.org 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 atSYnalKT6k3; Fri, 20 Nov 2026 02:50:25 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-367428-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 3F58611580B; Fri, 20 Nov 2026 02:50:16 +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 C21F26820A; Thu, 19 Nov 2026 23:50:14 +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=1795132214; b=i9wIAAp66OKJnUdF1ehKRkWkHTyP5PnynhXKTYNVnpL6Z/Cy1f+g1d3W5P6oM9k+dROO FxcYuUeKaBZkiPo0OPHdIt3at2eFC494h+9Mjv+ZJe1MwKGGN1boXKh/d4ml2ojcJLNZy sn3CpgTuVme64TEXJ0sCbK/Wa4aouYGaP8exycTuw0/gqJA+xB199EOHoxiu7WU55CCzR wTq8vIMtNxaO9RarXiuuIFstAasf7vVXaYzmzftQF72XU79Pevwmop0hubg41tiakYfdK PrwvDc+UdHzuychwA/tvcgc7NmDhqoibRCYWrKlubWrsAP9f0LDcJ4e2HhFT0FcTCvg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795132214; h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc: Date:Message-ID:In-Reply-To:References:X-sashiko-severity: Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id: List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner: Precedence:MIME-Version; bh=o1b6XXG9QMuEtUFsFeAjrs4YtDdCD4bIxlLFk9Mv7hU=; b=XY1yJP9rmyhqY87T7j7FYeP+60jGl5USqg8zdtmkTHuIiYLr/EiK9+6tmk3gUi75M7HR jXc8VAmMBRUUd+gTv2F9FoV7qqSzp/iZAHJEaG387woYyjzpk8hkoKv6TRfQ4ZHBNmf/Z A05fJJxwnnhHerj36TGy0yzBVmuKdtbZjrbDEmCRrqpnhHPLmSd6po8SXTmawuuYe6Y0J nbuBQWJQ/lCcIzCpEHX8HsTRWUp4TQ+sja0wASzLrul83P/X4O142s65hFJt/7k081UrM R+K4Q5NoNKh5T9CNI/TqApPmCPtmseO1+nSo9vi6tmMG/AS+1uBQcBWSZHCar+6GeXQ== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jcjiQ0uk; 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 8711B606A32C; Thu, 19 Nov 2026 23:50:14 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jcjiQ0uk X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795132213; b=h/pMiyg5XmZfBcpAOIyvCZAwTzfALihKT8WiwSY/MCqveJo5jIHaFF2EmOXK15bq6ZHS eSag5DyJprxqLLFsWDdjR27G21fwxkGMOJLuHVorAESyv5SdHhbpQ5Ry/fQdiCw0tomsS bxziqV9nUrzG9426dyfWGfj6zdlz5wniE4seX7cBd94RsCYRWtkklmWyrTJkwOhVkS9jc o5Rj/mwB8ugtPT33wwUNEIgoj4Kl9w9ZAQSnTW4504r2kietJy7pkc6hTXD0uvCjnl1Nj mZikeLdFQfS8txGPbXNhRbTWVwgucSZGGOdesWXZtPS+J6U69bgzxJoqinSthbJ76fw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795132213; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=o1b6XXG9QMuEtUFsFeAjrs4YtDdCD4bIxlLFk9Mv7hU=; b=F/MtRu12yDYrgEOd8cAQIMxRayx27tXsSgpL280vi+wI4HC8v7wNuAjpcUO71i60bTze rJBjyx3cWMcmWMxMdXJRNsxhnyEbiOyKtT5VS0KOI3+YoVpVVLRLnNkwVa9mAI6qPUpTn tJE7l3rfrlkErLToaprCUYebY3Q0fPxOd03P7j/7umehqKE0rlgdKLgNmZiyU2l+vGLbm PWFEQABcqaN+Zftq44kXKtyoLc/G+SUoyluabUfF+otBPbi1fZlVjscJzmS7qr90IDda6 P5aPMna1uAyxIvYsqP9O/Owm5+SaaFH011vX4slP+mcYpWSKGHAe3LHb5JPZstRs8vw== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jcjiQ0uk; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0C61606A326; Thu, 19 Nov 2026 23:50:13 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id ADFFD1F000CF; Thu, 19 Nov 2026 23:50:12 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795132213; bh=o1b6XXG9QMuEtUFsFeAjrs4YtDdCD4bIxlLFk9Mv7hU=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=jcjiQ0ukTo1DYmaKQHSBSGnwTZ0hRS2j5A2ym1lb/o9vwEphuvyHEvlwEOOqvTSH2 ucUVDjZsW5wp2dqcPDkg8Ll9E8mbYMv15HgGz5Ecpb+v53wBCXEPOIGdsfAPFrDv8n YrcRIYeN+WpRa0oKeb++Albg89p5plCZdX6q42h/CpIbfENsEP5ZjN6sNbWfhGJ4L9 okiBJC296xaxkZVkbYPTgyIwZG5dpkIQfszV1/TXX/JWMtt3ySeqOojb/HuU0CIiJV MnMu5k6EPxz/XniqWVHN95pClOE6JjYqy3Lt5WBkr/wtAeJMj4NLvDNjMypeLIg3tb XXwuqqod+rCxw== X-Cc: edumazet@kernel.org, kuniyu@google.com, pabeni@redhat.com, willemb@google.com, davem@davemloft.net, kuba@kernel.org, horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org X-In-Reply-To: <20261118084927.1756747-1-bsdhenrymartin@gmail.com> X-sashiko-severity: High 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