๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12073

Re: [PATCH net] tcp: do not resurrect a former listener with SO_ATTACH_REUSEPORT_[CE]BPF

#12073
From: Eric Dumazet
Date: Fri, 06 Nov 2026 08:10
80 lines
12156 bytes
Le ven. 6 nov. 2026 ร  07:44, Jiayuan Chen <jiayuan.chen@linux.dev> a รฉcrit :
>
>
> On 11/6/26 12:48 AM, Eric Dumazet wrote:
> > After listen() + shutdown(), a TCP socket is moved to the closed
> > section of its reuseport group, while TCP_NEW_SYN_RECV requests
> > can still reference it as rsk_listener.
> >
> > If SO_ATTACH_REUSEPORT_[CE]BPF is then used on this socket,
> > reuseport_attach_prog() calls reuseport_alloc(), which resurrects
> > it into the listening section of a new group, even though the
> > socket is still in TCP_CLOSE.
> >
> > After close(), the socket stays in that group and the pending
> > requests keep it allocated. When the final ACK arrives,
> > reuseport_migrate_sock() can select this dead socket and
> > inet_csk_clone_lock() clones it. With a ULP like espintcp installed
> > while in TCP_CLOSE, the child inherits icsk_ulp_data and sk_destruct
> > after tcp_cleanup_ulp() cleared icsk_ulp_ops, leading to a
> > use-after-free in espintcp_destruct().
> >
> > As done in commit 8cc3aef0cb19 ("tcp: Do not allow buggy transitions
> > between ehash and lhash2."), deny this transition instead of adding
> > checks to the fast path.
> >
> > Only an unhashed former listener is affected. Applications can still
> > attach a reuseport prog to a socket that never listened, or to a
> > listener (including one that called listen() again after shutdown()).
> >
> > Fixes: 333bb73f620e ("tcp: Keep TCP_CLOSE sockets in the reuseport group.")
> > Reported-by: Kyle Zeng <kylebot@openai.com>
> > Signed-off-by: Eric Dumazet <edumazet@kernel.org>
> > ---
> >  net/core/sock_reuseport.c | 9 +++++++++
> >  1 file changed, 9 insertions(+)
> >
> > diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
> > index fccbdd0430b05984e82c19b17b6b723b0a3a03a1..41a25be1bfff6aa486f33ed563a093a264c49344 100644
> > --- a/net/core/sock_reuseport.c
> > +++ b/net/core/sock_reuseport.c
> > @@ -6,6 +6,7 @@
> >   * selecting the socket index from the array of available sockets.
> >   */
> >
> > +#include <net/inet_connection_sock.h>
> >  #include <net/ip.h>
> >  #include <net/sock_reuseport.h>
> >  #include <linux/bpf.h>
> > @@ -692,6 +693,14 @@ int reuseport_attach_prog(struct sock *sk, struct bpf_prog *prog)
> >               if (!sk->sk_reuseport)
> >                       return -EINVAL;
> >
> > +             /* Do not put a shutdown()ed TCP listener back into the
> > +              * listening section of a reuseport group while it is in
> > +              * TCP_CLOSE: requests can still migrate to it.
> > +              */
> > +             if (sk->sk_protocol == IPPROTO_TCP &&
> > +                 inet_csk(sk)->unhashed_state == TCP_LISTEN)
> > +                     return -EINVAL;
> > +
>
>
> I think sk_is_tcp() is better. raw socket still can reach here and inet_csk(sk) is invalid.

Yes sashiko reported that. And had the same 'suggestion'.

https://sashiko.dev/#/patchset/20261105164830.1682714-1-edumazet%40kernel.org

SO_ATTACH_REUSEPORT_[CE]BPF does not make any sense for anything other
than TCP or UDP.

I can switch to sk_is_tcp() for net tree, and perform the real fix in net-next.
Technical Details
Message-ID: <CAL4WiiqxeZSZWSKkK6qcA=U1haTCoCakEKYatYf0i7mB-CdXTA@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-357834-linux-kernel-netdev=dewy.ru
References: <20261105164830.1682714-1-edumazet@kernel.org> <af79b34f-a941-4d0d-adbf-fe30a09c20d7@linux.dev>

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-357834-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] tcp: do not resurrect a former listener with SO_ATTACH_REUSEPORT_[CE]BPF
Date: Fri, 6 Nov 2026 09:10:44 +0100
Organization: Usenet Network
Message-ID: <CAL4WiiqxeZSZWSKkK6qcA=U1haTCoCakEKYatYf0i7mB-CdXTA@mail.gmail.com>
References: <20261105164830.1682714-1-edumazet@kernel.org> <af79b34f-a941-4d0d-adbf-fe30a09c20d7@linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="3825681"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:DZ1xF6krfcblFXXlEuE2Q1I7oLI= sha256:erdbb8kHrfrjJyKl2H+JFqUw2BIkn86HTN6Ljh9tgPI=
	sha1:6y3IjQ1SZsW4WFkqg2niB5StOF4= sha256:/SLME42sj/6zjNyQcBOhpp6rv2Gq6MQkhdGjYSoWntA=
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 6560D1131B1; Fri,  6 Nov 2026 11:11:25 +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 zO-MYFFYpeih;
	Fri,  6 Nov 2026 11:11:20 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-357834-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 5722311317B; Fri,  6 Nov 2026 11:11:11 +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 098EE2F72F; Fri,  6 Nov 2026 08:10:58 +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=1793952657;
	b=zkk82b9dP4HlUNBegXrLvNGpSygjxvnSdGbt823cBnfzJNux9G3n6dCt3oBnffOyERWq
	 6AzBXoc+br7S1vF+XXC6P/0m+psoEDCRenAbbGNtfAfswrjIn8qOXBi0U908Q89KOLAxy
	 LkeOPabJknk4ycDiYNDqTGP1YlhhKWd8h4s0xekKkxsuzXRo38ka+OF1Ska0HYmrYCLrw
	 df4iMcwTkF970Z36Dh4dnQaR/1LRgHw1LJEdPtRtMJWUN544jjTnHwEeI1oJfhtNnkj5G
	 PZhS6FU+01GWhw1iJL3WqMUj00mJWUcUs/3QJYoj2SMjYzbISjyF0uHy4WqzTvbVHAA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793952657;
	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=S9xvJ1NaU4Zk/xPNNDyUuI5WsSyAExyNgvNFDuRo824=;
	b=gOOUCRZx9WyvcJDphq9goULUhlQZorM4ZsKDrgr0byPizV5iq/gBH+mLVmMQWIVShdh3
	 hVACSe4UR/gbgTSXNJ6vZ3nRTEAdXM0kyNTDcDSpgs2DLZnaKyDuISn56VSvFtqlv8RTJ
	 dV353x/FLDwou5Q1JkSWaTaJBincpH6SapB/KIGFSYJbyeH3Zp7RPRpKIjCTU+pQ2M33W
	 8MChggFKKBeNEq40JZ4i71eZiHuEu1eUgS4YiqMaokgXK05PjqRYaB0pK7z+mhq+kXanY
	 UJKZNwgBqxAPWaWYgW9TGjew1zjoV9TmSBTNxobxNKX4sh4Mjtd3rtuzxs5sTn70JYA==
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=JsDAj3eR;
	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 D3296606A32F;
	Fri,  6 Nov 2026 08:10:57 +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=JsDAj3eR
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=1793952657;
	b=Clx0QsMTshFgOJBZm6nLpxOOEROt9BeK+v7/VIZfNUCX6dHSTi1lhEZyPPwkGVTx/FQ/
	 vdLlQvn1FbKdRklJP7rnbHBVG8J8O4/spQGHbdPDaZbT2xPvd4MqK8NHX7DVI18UMHJbA
	 bBxUm4QpwrgTy0SjS0QG9IHauPoqcmaPSy2ZSIvvuvORsteYcGDpt+x9XlaNVPnJ7RgOu
	 rmzVEKuYpyfSG1w7xD5poyaPGD/KE6l2oUj85VLRi1/nNdYsEst2ATX90qPu5XyryHrFj
	 1zNvsDKPtsUAN5nZ5ISB/t3Oj8E0aqrnQ1rzJfG5TeUY/HVaNwbGIonjTfuERe7M9jQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793952657;
	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=S9xvJ1NaU4Zk/xPNNDyUuI5WsSyAExyNgvNFDuRo824=;
	b=O1kqS0YBwNimD9h4oC6plHIrl9tSCcFy/9dlLPxYeVmFssoYp6P/4XRwebwMlXO50pAb
	 GUl1C5+sq4tquvp+uVoHGfgLRV598VMuOMJXozSHPswRuYVhIf2EpFbq8bQpW7xKC6dV9
	 jSMVGt0+guETYkvtTe15vAy17+kolT+CoZAJwIJRs3IZ7exHQXUlyJZ2io/eAhmIwEbDK
	 9RQ5PoYrJ//63TTB4IphWOvzLsD2MbufYQ+LHqV7hQf6GS+M3qQ6++8Av3JoekvRke7ap
	 7krZIpMaQ7y94KLvxuMn8yroo3+cwDW/zqNg7DUGM77PaiyGrDzEcAvCLXKEw0eJhYA==
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=JsDAj3eR;
	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 B03A6606A328
	for <netdev@vger.kernel.org>; Fri,  6 Nov 2026 08:10:56 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41EBF1F008A2
	for <netdev@vger.kernel.org>; Fri,  6 Nov 2026 08:10:56 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793952656;
	bh=S9xvJ1NaU4Zk/xPNNDyUuI5WsSyAExyNgvNFDuRo824=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc;
	b=JsDAj3eRpYVeftt8/G/kKkhbqtHjQlogL301UIb8+aa6p0erq+yx5Xapul/cxzsPZ
	 Rtyo9AXSVS4eXqCOXVDN8Pm+Dw3mNpBYFeXovFb8/63HMKF9LLCVNf4hXzuc9ydN0k
	 F7o4IRJ2Og0tBZMBFnzvn+io1wRvZJ+id0MxLia7LSvimuhyHUoVPq9nM7LeGZ53r1
	 fnndZKwqjmfCQdMqYVUBHcledZ9NyDWFyCCBYeLTJP2/k7c2o0sKm+2cyt2lePVCRL
	 hZm607N2ssnrSjo7MEv6ww3MYY+ApUT93OZFaKSF1mdvdfahHULgPQZjcl0BTeeMKD
	 xrOm5Q1I+X64g==
X-Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-8451a619da7so270910a34.1
        for <netdev@vger.kernel.org>; Fri, 06 Nov 2026 00:10:56 -0800 (PST)
X-Forwarded-Encrypted: i=1; AKwUvBxh3VaByl4HXXstpoSM00lDKY63m0mG/HAdD2nXJ6TvwP8k4y/M5VppNyQeKbqiozKSj1aoQfE=@vger.kernel.org
X-Gm-Message-State: APuU4Z+z9j7UqcfSKFIeQ+ZX8rHrGyZw7sV2jdxRZiE9jlqpEGgj8sTg
	oJvQJemWzkh2W0ljzI2hMTVIVtJDRYmOQ+gjbblQsKopX3f/iCCfXj8/UkzHo/SqF2H7R/zy4TS
	OVCSokDUdl+6EKZARkwg6who+rnfvTcw=
X-Received: by 2002:a05:6830:310b:b0:829:10c4:2c11 with SMTP id
 46e09a7af769-85f1cb65e44mr2173404a34.0.1793952655401; Fri, 06 Nov 2026
 00:10:55 -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: <af79b34f-a941-4d0d-adbf-fe30a09c20d7@linux.dev>
X-Gmail-Original-Message-ID: <CAL4WiiqxeZSZWSKkK6qcA=U1haTCoCakEKYatYf0i7mB-CdXTA@mail.gmail.com>
X-Gm-Features: AclHuK_dki4Pgn8VVhk8z1fjYLjsARhKpZyckE54dKfXi3IEUlCv_TH1XfBb3J0
X-Cc: "David S . Miller" <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>, 
	Paolo Abeni <pabeni@redhat.com>, Kuniyuki Iwashima <kuniyu@google.com>, 
	Willem de Bruijn <willemb@google.com>, Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, 
	Kyle Zeng <kylebot@openai.com>