Article View: linux.kernel.netdev
Article #11809[PATCH net] tcp: do not resurrect a former listener with SO_ATTACH_REUSEPORT_[CE]BPF
From: Eric Dumazet
Date: Thu, 05 Nov 2026 16:48
Date: Thu, 05 Nov 2026 16:48
62 lines
9776 bytes
9776 bytes
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;
+
err = reuseport_alloc(sk, false);
if (err)
return err;
--
2.53.0
Technical Details
Message-ID:
<20261105164830.1682714-1-edumazet@kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-357509-linux-kernel-netdev=dewy.ruShow 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-357509-linux-kernel-netdev=dewy.ru From: edumazet@kernel.org (Eric Dumazet) Newsgroups: linux.kernel.netdev Subject: [PATCH net] tcp: do not resurrect a former listener with SO_ATTACH_REUSEPORT_[CE]BPF Date: Thu, 5 Nov 2026 17:48:30 +0100 Organization: Usenet Network Message-ID: <20261105164830.1682714-1-edumazet@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="3684600"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:+luzRp85T/iBBXRhkp+NK9FmPCE= sha256:UEPD/yavWfHBTQ/BQMGMJckvo3NVrRXpcKyM83XOYUc= sha1:JI0RY9ERTDgtaFwk5Z1E1Ts3JUY= sha256:L4xn3Jbk2MxRyg3RlBAitmjXCGCIOAimeiUcSGjdTgg= 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 C021D11302D; Thu, 5 Nov 2026 20:03:15 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.501 X-Spam-Status: No, score=-3.501 tagged_above=-9999 required=6.31 tests=[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 gJ6Ub2lvvISP; Thu, 5 Nov 2026 20:03:09 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-357509-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 sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id D149C11302A; Thu, 5 Nov 2026 20:02:52 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id 0C01D613AB9; Thu, 5 Nov 2026 16:48:46 +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=1793897317; b=hAZNL7dG4mRBSYlrxKYNVez8Edv25INjJuf6DS+0xNwoWqUIo9hmkFRvRwtvenAsqTSq u+54Ky137SIEHhp5nHq4GEAllTgxY/CQbc2JqLIgqcHw0xH/ZkbOi/b/Nr2oRiYC8Ms6Z ND+I3jmGLXZ+HDXdEtpxecM9EzQiDsH3TLdQq119Frcqtq1BsMrRFxWbh141zYwLex1HT uiQZYMdQ4uAnOOL+LsjkrKTWhEbwORGkoQsBasBr4zGsOF5jIMALKYEYpCma0UOyjlvDZ QdWU4XALmprb1zQVCHAvnuwGuvPfrioMHXDTyYuO7Bo3obtp9fibXK4TvVhTZV7cIhQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793897317; h=X-Original-To:Received:Received:DKIM-Signature: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=ufeqZ6OrxWy/uS8N9+yHglk0bsq8gg6HXoz25xjhh6g=; b=nhpQs7eKOmKwSeNLCtjuWGvUPCjYB4TnhDePocZ0X0Tw4JDNy+bDiZoWtMaxlWN2podf 6jMJB8AeMsCus6W9l0uyl4Ck0RXpymuSBtAUayY7RE+crACabV84iq9LFOIB6AaUujgqo shHs7OY6iGRM+Ociws+TPkeiNbDvjpMo1z+Lo512aFx/lMnenBNXqr/Ki8vWgLKWfN+HU SPGCK2GJgfEMvCOAmFLhwbfHETIPx8YzGmu/+WPb7K6SJTcoYLHqdCZfrKAuJJzf/yV4H 7v6GMS1a4723gn5ZAv/fRfmoxUO9gnkTZZu9yxHr3OYkU3P9+DZynPWM35+rThvwC6Q== 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=hjf+kF3s; 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 BCFC9606D813; Thu, 5 Nov 2026 16:48:37 +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=hjf+kF3s 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=1793897316; b=wdWLzWujP13jfYxe/7eJ9FBT+nQaafU2P/HavzhTuj4GOsVw5yFwgxF05xzt28NVONuV Ctv3rIO1ciFjElglHi05qaJZikynImlyIELUYRXHjXOqpFqniLR/URz7XCb7mpCDFVmAZ AmMUJwxXs4042YUPDz+yzxEAxbuZX/dgXtM1jRUI0GlWYxgCVI4WPQ3uVDLEFkxPfS+LE SuXxG5YHmPyvwxKxZMbGvB503csxW8jM86Dlg9zOad9YzIWwg9un8Yfou6RU0STPjMmM9 G6T+j+0thfX4+1x8mUjiy376ZNTBYLi4iM5/lagNB8s7VXyxT3nSh9PSHIA9sbnY9EQ== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793897316; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=ufeqZ6OrxWy/uS8N9+yHglk0bsq8gg6HXoz25xjhh6g=; b=eADeKTD7FaAl3Xrra9n3zcipXon76crDM4IVsKChTDo9vaDWifjyemJXlDpwAJSR55fb yzktRaSVvCH7S2fAXLotoQnDZeohm8tIsIlHAu9kOQB4Z3W++ULyVuhaAhy3ADAWU/1gc PZxmtTiC38mLakmR2LZ1wCOrAv4W6NmPmhs60kqhbfjmwrXrfAHI4arRAAido+B+X4jmp oISw4ECY93z/K9Pph9KBhgPSRhfpjDY0oXEzLgMC+GNxb1k4xZf1cCh9lB1NQT9Nlkm2o H9C6FKIcUROqvFKfY/gIvm1kF4v/l/C7dUfCc/InnBNBtg/z9M0JL2ON9i47HdqrB2w== 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=hjf+kF3s; 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 A2A67606A336 for <netdev@vger.kernel.org>; Thu, 5 Nov 2026 16:48:36 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 047CC1F000C1; Thu, 5 Nov 2026 16:48:33 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793897316; bh=ufeqZ6OrxWy/uS8N9+yHglk0bsq8gg6HXoz25xjhh6g=; h=From:To:Cc:Subject:Date; b=hjf+kF3sbYbv9uDNgf3PJvxR/b1LTcneFpF/9O/UDYefqGIvjegtrr8x6yZ+Bb4xu N12+yYdwasTb/QVK3g40beLo/biqZgZk95b5Vbef/7tPzdEOhXWXEZLHdUXeisfhOo DhJDJMZMsnkCzD7A5Zg1SbVJsywSNVHr/51miGMhwqgmQsZbyWdPNndtZ2PjUGAGkb LYnT+IyWzsyNxpxwd3blfbm5RGePRvH2zTdNXSitYkAOS1UBr/yNK4EdN/ebKX6oSi kuuCFCyUAmtBoJaVmb+X6T3AtXyfP65fP6gHf21CLFiT/iA0Hw782bOoi1Xb/L5P0C wmQVH4CWY3sZg== X-Cc: Simon Horman <horms@kernel.org>, netdev@vger.kernel.org, Eric Dumazet <edumazet@kernel.org>, Kyle Zeng <kylebot@openai.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