๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10949

Re: [PATCH net v3] tcp: free saved_syn after an RCU grace period

#10949
From: Eric Dumazet
Date: Wed, 04 Nov 2026 12:40
111 lines
14157 bytes
Le mer. 4 nov. 2026 ร  13:32, Yingjie Wang <x-professor@outlook.com> a รฉcrit :
>
> tcp_reqsk_record_syn() allocates saved_syn separately from its request
> socket. bpf_sock_ops_get_syn() can load that pointer while processing a
> retransmitted SYN under RCU.
>
> There are two ownership transfers which can let another CPU reclaim the
> allocation while such a reader is still using it.
>
> First, tcp_move_syn() transfers req->saved_syn to a newly created child
> socket. The child can be closed and tcp_saved_syn_free() can reclaim the
> allocation before a reader of the old request finishes.
>
> Second, inet_reqsk_clone() shallow-copies request_sock during request
> migration. After reqsk_migrate_reset() clears the old request pointer, the
> migrated clone owns it. However, a reader which already loaded the pointer
> from the old request can still be using it when the clone is released.
>
> I found this through LLM-assisted concurrency fuzzing.
>
> Mark the request-socket saved_syn pointer as RCU protected and use RCU
> accessors for its reads and updates. Keep the full-socket pointer plain
> because all of its accesses hold the socket lock. Embed an rcu_head in
> struct saved_syn and use kfree_rcu() in both teardown paths. This lets a
> request-side reader which loaded the object before an ownership transfer
> finish.
>
> This follows commit e3f33b0a1d89 ("ipv4: free inet_opt and ireq_opt
> after an RCU grace period"), which fixed the same ownership-transfer
> pattern for IPv4 options.
>
> The issue was confirmed with KASAN on v7.3-16007-g36aad21d50d1 using
> temporary kernel instrumentation to widen the reader and request-migration
> window. KASAN reported a slab-use-after-free read in
> bpf_sock_ops_get_syn(), with the allocation freed by __reqsk_free() from
> reqsk_timer_handler(). The same explicit migration test completed without
> a report with deferred reclamation. A patched kernel without the delay
> instrumentation also completed a successful migration and seven saved-SYN
> reads without a KASAN report.
>
> Fixes: 0813a841566f ("bpf: tcp: Allow bpf prog to write and parse TCP header option")
> Fixes: c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.")
> Cc: stable@vger.kernel.org
> Signed-off-by: Yingjie Wang <x-professor@outlook.com>
> ---
> Changes in v3:
> - Keep tcp_sock::saved_syn under the socket lock and apply RCU protection
>   only to request_sock::saved_syn, as suggested by Eric Dumazet.
> - Use unrcu_pointer() when transferring or reclaiming the request-side
>   pointer.
> - Describe the discovery as LLM-assisted concurrency fuzzing.
> - Rebase onto net/main commit 241dec6f9ab7.
>
> v2: https://lore.kernel.org/r/3dd45a687afdd0213ee82685c52777e5b0855e20.1793704772.git.x-professor@outlook.com
> - Add RCU annotations and accessors following Kuniyuki Iwashima's review.
>
> v1: https://lore.kernel.org/r/34f32e63b803f9f7faf0b0a5754219e48a986136.1793616950.git.x-professor@outlook.com
>
>  include/linux/tcp.h             | 6 +++---
>  include/net/request_sock.h      | 4 +++-
>  net/core/filter.c               | 2 +-
>  net/ipv4/inet_connection_sock.c | 6 +++---
>  net/ipv4/tcp_input.c            | 2 +-
>  5 files changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/include/linux/tcp.h b/include/linux/tcp.h
> index d18f7bc1e5d0..3ae57ae65ec4 100644
> --- a/include/linux/tcp.h
> +++ b/include/linux/tcp.h
> @@ -618,13 +618,13 @@ static inline void fastopen_queue_tune(struct sock *sk, int backlog)
>  static inline void tcp_move_syn(struct tcp_sock *tp,
>                                 struct request_sock *req)
>  {
> -       tp->saved_syn = req->saved_syn;
> -       req->saved_syn = NULL;
> +       tp->saved_syn = unrcu_pointer(req->saved_syn);
> +       RCU_INIT_POINTER(req->saved_syn, NULL);
>  }
>
>  static inline void tcp_saved_syn_free(struct tcp_sock *tp)
>  {
> -       kfree(tp->saved_syn);
> +       kfree_rcu(tp->saved_syn, rcu);
>         tp->saved_syn = NULL;
>  }
>
> diff --git a/include/net/request_sock.h b/include/net/request_sock.h
> index 5a9c826a7092..ddc134f1d15d 100644
> --- a/include/net/request_sock.h
> +++ b/include/net/request_sock.h
> @@ -16,6 +16,7 @@
>  #include <linux/types.h>
>  #include <linux/bug.h>
>  #include <linux/refcount.h>
> +#include <linux/rcupdate.h>

nit: this include is not needed.

Not worth a new version though.

Reviewed-by: Eric Dumazet <edumazet@kernel.org>
Technical Details
Message-ID: <CAL4Wiiqen5n7i2Wa_YxJLYOr32aj4dgknPnjbVpi-xPOcMAd7Q@mail.gmail.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356419-linux-kernel-netdev=dewy.ru
References: <38fa9f2cc476502e9b1c1fef09ebba1df5dd5901.1793795528.git.x-professor@outlook.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-356419-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3] tcp: free saved_syn after an RCU grace period
Date: Wed, 4 Nov 2026 13:40:35 +0100
Organization: Usenet Network
Message-ID: <CAL4Wiiqen5n7i2Wa_YxJLYOr32aj4dgknPnjbVpi-xPOcMAd7Q@mail.gmail.com>
References: <38fa9f2cc476502e9b1c1fef09ebba1df5dd5901.1793795528.git.x-professor@outlook.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="3389975"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:pkdYcIrQ2iw/CRrPZtCTvhKUe1I= sha256:xFSiDTxlbJGXGvD2PuJM6vQyhrBM5E21zbEX1bDSgVk=
	sha1:wpE8fFz0XH1NLvkxQaUwwbwnazE= sha256:tcXlzQJtgiB2bBb1h+lcAc8ECjXxkpjykXUsiV9wq2w=
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 1A2E0112BC0; Wed,  4 Nov 2026 15:42:36 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 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] 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 fC77AhBMXvmR;
	Wed,  4 Nov 2026 15:42:31 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-356419-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 6D308112BBA; Wed,  4 Nov 2026 15:42:23 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 9F76433A08; Wed,  4 Nov 2026 12:40:50 +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=1793796050;
	b=Paiy4XN59abGSTDRsAI36TT2s69NvEDvsWeIcbxi/a+ZDdwL1kwi1reJ9etXgvI03qk9
	 /UWdB6v42kidKnuN8MqVNwNPgYvRKbGxaQE5PqlyDGGG+l47x7l2u9woddjzNgmPH35qU
	 xAgcLKS1COwP8RCsewQ5Mj12HlGdJYGJXbR7kRdc7SdpBirhLTs8NbHIlSy0OQOi5gW02
	 2ZdEGVzPy4zjTjeY+xcplQOdVrrEK0oySxi9Va04GDDcu7WC1iQzKECtbFK29YQA3pc4w
	 Btp/YPX2UpV1GhydVeOIghNoyrxC6LXjhgDIg/Ei1QANwC9n659QtaVwENSUP/fOkVA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793796050;
	h=X-Original-To:Received:Received:DKIM-Signature:Received:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:References:In-Reply-To:From:Date:
	 X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:Subject:To:Cc:
	 Content-Type:Content-Transfer-Encoding;
	bh=alfWwL6/FuueZbwen1V8hepkvtjYNfPuDnxUgf69IeQ=;
	b=aDq/OYzg4fzvheVlBSIHTr44E7YIaJrl+NYSik7Zq9Wes2J5RBOutf3sMHOzSMVkv/Wh
	 9IDfgpLTeuVDs+b2oT/hrK403Nljlg3b8NTbmRlxpLfknah0Vc/7fR7F+/M5mY9m67lfn
	 v/n2AoLPp7VECs6bM3BQTjjyIEVAF91Vh1CCY1YIYPmKOU8z36tyGpmGkg2+zBb9/XHG8
	 Jqfg9yZkl+U8a6uL0HWrVrq9pB2qtlrhrlrZWLsQmGJilcKxqh6AxmN3A36eUDcL/oPWm
	 4XSsrMn209IzbEIaxB4nvaW/4ZuWoTrU1Scg55m52IeqkQavA2Npjyr4GxFnBTmHyOA==
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=gySUN7DJ;
	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 E607E606D80D;
	Wed,  4 Nov 2026 12:40:49 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gySUN7DJ
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=1793796049;
	b=2yWw/nV3YlbpbDESRRFsZHOWrik2LbWwC+F0GHSgXuOxhUFn0h7cKzChZxMwW6ZCnLkl
	 ETe2sl33mVV1DdC6ZfVQYGfAf8hG4Et8NtQ7Ieu9p5OuMAHL01YwZLMvtq9wjCDk3hoaj
	 mX1ShGDHO7AYzuwV5DpEf9nBCFE6GAzj9/Jefr9EAau8XhXw4WlReqAOUGl5XxPvBiYfg
	 Esa7CsawGFzufRvLhbmLN9AUExris9Bgu8KcS/hTWucVr/Bd9hjRP1RQKe5EtDpbksgQA
	 kx0ilzr1VlugPm4SEHMBKKq3tWEQPqYFxdaKzJcVz9RHbtw+wFtd6C2c27QNU8NAdCg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793796049;
	h=Received:DKIM-Signature:Received:X-Forwarded-Encrypted:
	 X-Gm-Message-State:X-Received:MIME-Version:References:In-Reply-To:
	 From:Date:X-Gmail-Original-Message-ID:X-Gm-Features:Message-ID:
	 Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
	bh=alfWwL6/FuueZbwen1V8hepkvtjYNfPuDnxUgf69IeQ=;
	b=DOSw4+knsevLmzndgGkk81HVgvIZMwLgY1Xzbr5I7lHTRa3704cyWM+jcVfziqoDbtzv
	 8LcVYJFp6/f7qjUc0Dh/EMWqhOSqZ0zQ4FGDCu92XRsHsx4CIjRbqj5pungMj4ULBGfIz
	 DCQocnjk3+lvRk1MvppPrPZ57v0cyMWN1ENkhvAIqB2B0xDMf5sJ+fZ5+eQRF23IUOlz4
	 h7aEM8UwfCmeIlCDpCUAatNpVRAmHcUMiJ/hRmhod5wpDYlk5aRrOB02LqgUF/Fcl4MFo
	 7ePTl9yj0MT2xYhhTHiydeYC4+iYOSu5XXgBllF1wL4lunA7bEW++vmlQ1jYQXLebZA==
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=gySUN7DJ;
	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 58266606A335
	for <netdev@vger.kernel.org>; Wed,  4 Nov 2026 12:40:48 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 113E11F00A1D
	for <netdev@vger.kernel.org>; Wed,  4 Nov 2026 12:40:48 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793796048;
	bh=alfWwL6/FuueZbwen1V8hepkvtjYNfPuDnxUgf69IeQ=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc;
	b=gySUN7DJaGHHwlysYEGpIJF47dle3J4s3We53JvzRKIDu50gj5a2wkGJPwbEx3KbN
	 IolmNtz1cKv7hu/lS9yd/VIv00HU/99J6FN9TsvQYw+RaR/BtNAWRh7Bk3A/jITpFQ
	 LAhrZAU4d/9wTkkWUQlC+kp0c+J0rfZAE/BbDjZyXfZtUe8qeeCnX4TdGiq47gbBn9
	 kREQQfm2F5xX7pCSvnulapabG89v1ZJqZxwn6RlDM/FE+D42KVOaN8mQtxZm/gFRy/
	 jupooXjF333Ngy3s9Iful/ZC4eLNa/SpQae1jkG5FEhWTY2xARIL7ztxwwWP8Ewoll
	 /ffreyaOzjyhA==
X-Received: by mail-oa1-f48.google.com with SMTP id 586e51a60fabf-486f013db83so228292fac.0
        for <netdev@vger.kernel.org>; Wed, 04 Nov 2026 04:40:48 -0800 (PST)
X-Forwarded-Encrypted: i=1; AKwUvBylac0gW3oUr7+FkCQy1LNBuh+3bJ3wTK7LbK/3Yb/nrI7X1ijBZFE2pCuLZfQyO7/DwbtgsHw=@vger.kernel.org
X-Gm-Message-State: APuU4Z/w0DiqD5Dn+v1k9SeLJZK0dfdmHMHJYbiYdvbOfb010yGWpBet
	6dCrYPFHXdpvyrMK/aPyAZUhrXF0vajOb1QRrbBvbVokJhj8eIrvTEFFa3WHtBQbPsjMW4jCGXP
	V+/zkZH9oMfrwHmpTOTgryjllquZGF9c=
X-Received: by 2002:a05:6870:d609:b0:49e:d4c:e6f0 with SMTP id
 586e51a60fabf-4a90772c1b0mr10331737fac.46.1793796047403; Wed, 04 Nov 2026
 04:40:47 -0800 (PST)
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
X-In-Reply-To: <38fa9f2cc476502e9b1c1fef09ebba1df5dd5901.1793795528.git.x-professor@outlook.com>
X-Gmail-Original-Message-ID: <CAL4Wiiqen5n7i2Wa_YxJLYOr32aj4dgknPnjbVpi-xPOcMAd7Q@mail.gmail.com>
X-Gm-Features: AclHuK8GZXD43O-lNJEKnJiywNAx6AQFktc6lK1CpovXsWvfdozbKRYapn5LGpk
X-Cc: Neal Cardwell <ncardwell@google.com>, Kuniyuki Iwashima <kuniyu@google.com>, 
	"David S . Miller" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, 
	Simon Horman <horms@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, 
	John Fastabend <john.fastabend@gmail.com>, Stanislav Fomichev <sdf@fomichev.me>, 
	Martin KaFai Lau <martin.lau@linux.dev>, Alexei Starovoitov <ast@kernel.org>, 
	Andrii Nakryiko <andrii@kernel.org>, Eduard Zingerman <eddyz87@gmail.com>, 
	Kumar Kartikeya Dwivedi <memxor@gmail.com>, Song Liu <song@kernel.org>, 
	Yonghong Song <yonghong.song@linux.dev>, Jiri Olsa <jolsa@kernel.org>, 
	Emil Tsalapatis <emil@etsalapatis.com>, Ihor Solodrai <ihor.solodrai@linux.dev>, 
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>, "bpf@vger.kernel.org" <bpf@vger.kernel.org>, 
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, 
	"stable@vger.kernel.org" <stable@vger.kernel.org>