From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 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== 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== 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 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 ; Thu, 5 Nov 2026 16:48:36 +0000 (UTC) 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 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 047CC1F000C1; Thu, 5 Nov 2026 16:48:33 +0000 (UTC) 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== From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima , Willem de Bruijn Cc: Simon Horman , netdev@vger.kernel.org, Eric Dumazet , Kyle Zeng 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 Message-ID: <20261105164830.1682714-1-edumazet@kernel.org> X-Mailer: git-send-email 2.53.0 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Eric Dumazet --- 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 #include #include #include @@ -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