🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #15672

Re: [PATCH net v2] tcp: fix NULL pointer dereference when restarting a Fast Open listener

#15672
From: Eric Dumazet
Date: Fri, 13 Nov 2026 08:59
147 lines
14471 bytes
Le jeu. 12 nov. 2026 à 18:05, <netdev-bot+sashiko@kernel.org> a écrit :
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 1 · Medium: 0 · Low: 0
>
> 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 patch is meant to stop request_socks from being stranded in
>   rskq_rst_head while they hold a listener reference, but another path…
>
> --
>
> tcp: fix NULL pointer dereference when restarting a Fast Open listener
>
> This patch makes inet_csk_listen_stop() always take fastopenq.lock and
> detach rskq_rst_head while holding it. That serializes the drain against
> reqsk_fastopen_remove() adding entries to the RST list. The goal is to
> stop request_socks from being stranded on rskq_rst_head while holding a
> listener reference, and to avoid the NULL rskq_rst_tail dereference seen
> when listen() is called again.
>
> > diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
> > index 37cc8606d6835..9ca59dca5d184 100644
> > --- a/net/ipv4/inet_connection_sock.c
> > +++ b/net/ipv4/inet_connection_sock.c
> > @@ -1533,17 +1533,15 @@ void inet_csk_listen_stop(struct sock *sk)
>
> [ ... ]
>
> > +     /* Free all the reqs queued in rskq_rst_head. */
> > +     spin_lock_bh(&queue->fastopenq.lock);
> > +     req = queue->fastopenq.rskq_rst_head;
> > +     queue->fastopenq.rskq_rst_head = NULL;
> > +     spin_unlock_bh(&queue->fastopenq.lock);
> > +     while (req != NULL) {
> > +             next = req->dl_next;
> > +             reqsk_put(req);
> > +             req = next;
> >       }
> >       WARN_ON_ONCE(sk->sk_ack_backlog);
> >  }
>
> [Severity: High]
> Is this fix complete? The commit message says:
>
>     With this synchronization, reqsk_fastopen_remove() either inserts the
>     request_sock before inet_csk_listen_stop() acquires the lock, in which
>     case inet_csk_listen_stop() reclaims it, or sees that the listener is
>     not in TCP_LISTEN and does not insert anything.
>
> That argument only holds if every exit from TCP_LISTEN goes through
> inet_csk_listen_stop(). The failure path in inet_csk_listen_start()
> does not:
>
> net/ipv4/inet_connection_sock.c:inet_csk_listen_start() {
>     ...
>         reqsk_queue_alloc(&icsk->icsk_accept_queue);
>     ...
>         inet_sk_state_store(sk, TCP_LISTEN);
>         err = sk->sk_prot->get_port(sk, inet->inet_num);
>         if (!err) {
>                 ...
>                 err = sk->sk_prot->hash(sk);
>
>                 if (likely(!err))
>                         return 0;
>         }
>
>         inet_sk_set_state(sk, TCP_CLOSE);
>         return err;
> }
>
> Take a listener that went through shutdown(SHUT_RD) or connect(AF_UNSPEC)
> while an accepted Fast Open child was still in SYN_RECV. Then listen() is
> called on it again. If an RST for that child arrives after TCP_LISTEN is
> stored, reqsk_fastopen_remove() passes this check under fastopenq->lock:
>
>         if (!reset || lsk->sk_state != TCP_LISTEN) {
>
> It then links req onto rskq_rst_head/rskq_rst_tail without calling
> reqsk_put().
>
> Now suppose get_port() fails afterwards, for example with EADDRINUSE
> because another SO_REUSEADDR socket started listening on the port, or
> hash() fails. The socket goes back to TCP_CLOSE and rskq_rst_head is never
> drained.
>
> A later close() will not reclaim the list, because __tcp_close() only
> calls inet_csk_listen_stop() when sk_state == TCP_LISTEN. A later
> successful listen() just overwrites the list in reqsk_queue_alloc():
>
>         queue->fastopenq.rskq_rst_head = NULL;
>         queue->fastopenq.rskq_rst_tail = NULL;
>
> Does this leak the request_sock? If so, it also leaks the listener
> reference taken in reqsk_alloc_noprof(), which only
> sock_put(req->rsk_listener) in __reqsk_free() drops. That would pin the
> listener sock and its netns reference too.
>
> This looks like the same leak the commit message describes, reached
> through a different TCP_LISTEN -> TCP_CLOSE transition.
>
> Should the inet_csk_listen_start() error path also drain fastopenq under
> fastopenq.lock? Alternatively, could the drain move to a place that covers
> both paths?
>
> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/avMkfJrXhCFXn8M_%40v4bel

This looks legitimate, but it is a separate and pre-existing issue,
not something added or made worse by this patch.

inet_csk_listen_start() sets TCP_LISTEN before get_port()/hash() and
goes back to TCP_CLOSE on failure without purging rskq_rst_head, so an
RST for a Fast Open child accepted in a previous life of the listener
can queue a request there during that window. Nothing reclaims it
afterwards.

It needs listen() to fail (e.g. -EADDRINUSE because another
SO_REUSEADDR socket started listening on the port) with the RST
landing while get_port() runs, so the window is quite small.

Hyunwoo, no need to respin, your v2 is fine as is for the
inet_csk_listen_stop() side.

Reviewed-by: Eric Dumazet <edumazet@kernel.org>

I will send a follow-up on top of it, moving the purge to a helper
that is also called from the inet_csk_listen_start() error path.

Thanks.
Technical Details
Message-ID: <CAL4WiioP-25nYs19MiNAjnzbvi-H870uem1W+jY5jTJb=DKn+g@mail.gmail.com>
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-362513-linux-kernel-netdev=dewy.ru
References: <avMkfJrXhCFXn8M_@v4bel> <179450310167.2199510.18107423940014989443@kernel.org>

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-362513-linux-kernel-netdev=dewy.ru
From: edumazet@kernel.org (Eric Dumazet)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] tcp: fix NULL pointer dereference when restarting
 a Fast Open listener
Date: Fri, 13 Nov 2026 09:59:54 +0100
Organization: Usenet Network
Message-ID: <CAL4WiioP-25nYs19MiNAjnzbvi-H870uem1W+jY5jTJb=DKn+g@mail.gmail.com>
References: <avMkfJrXhCFXn8M_@v4bel> <179450310167.2199510.18107423940014989443@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="1321215"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:DgFwB10VfzvkSZYqlpbwEiQnVA4= sha256:wJz9/jw34xtM/C5Gwqv5OjxBdFnIin2rUPuq+N4eEjQ=
	sha1:SdKaFrfqchqRWqSBOGbCS+SC0iQ= sha256:32Lb5gm+su08/lqga/32fUofB+tKTaAHM2ftg5+GE0c=
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 1E34A1144EE; Fri, 13 Nov 2026 13:57:27 +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 ath-xNZAa-OS;
	Fri, 13 Nov 2026 13:57:23 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-362513-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 6A4631144E1; Fri, 13 Nov 2026 13:57:13 +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 78FB56C5F1C; Fri, 13 Nov 2026 09:00:15 +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=1794560408;
	b=3Ga12vIgNoAo4wdreVKWGvgjQ66GvldmUtLQPKJi1wSmNJbDZQ/6cm6OF+jb39NNDMIt
	 PFDxv/nk7V+kIE6Uj1U+zUKM4/ba0qDzmxtwNBeocfiqfZnAX1wO6bjqJ8THDKvuPCaa+
	 z+xDhTczHGeJTajd4dli2oW2HcIzr+mlR/iFVjuEl96hbrSjXElta++dCeJ7xFtOh7r3X
	 b62TMi6Fyd/BmmwcBY++y7hfVsKHu85uMOaBehrzpy1JealYnE+VV5Feq8P1T6Ry1lGzt
	 ey3z1pmFU0X654nyb2XyK/nY4KYeXbRqHXEXrpH+hTzzrouAR+yjS2AZ2ivDy9CDklA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794560408;
	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=nDmZz/9Lu+rwI73C7kuZiJ5O7j/5N39qJGbbT04Ep/k=;
	b=WRJzVmW2BEkV6lnS9cd/u+46P898/UDBouxnX2HFQVWOP/0ZucK2w4Y3eiknsfn7sYhF
	 qqyMVBqqxYco+b2HZmqUw0kQZ6uVspK/cDo/6O62DrXFQRRiFQKslBdNh9XLTW/pjq3zY
	 DtWvCizTBhvhv8AYF7sOS+hdOeI4WbSBzCeODZ57Kyet9UK9jeFiIAEZo/VZoQYHlAGCG
	 PK4lA4yYb3H7K8qTeVU7RmhVBKUBeevWDeyVyQQH3tO0DhNWwgZ/jMjIo6gpvPvUFeG92
	 c4XHBU5Tzl6Jw0hgQiXYJuzRO57o+oLOQ6+DmJHWpEsCwaZktchqDKCtmkG74qj1+Ug==
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="LfSwP/kq";
	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 1D0AF606A33D;
	Fri, 13 Nov 2026 09:00:08 +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=LfSwP/kq
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=1794560407;
	b=lNKpaTtLOp6onS5wemfy6zdqZRuZCmxWgI5qwnr5jf67+ISl8ecExMiT4AGpcjltTiiI
	 hKL3uNEnlAPpaw2ZjMvpwtzsK4ObNm+BMRi+IYfpY9d75TmWN51PfSZzW41SYsUggo/p4
	 GSB+oq+/gYKwWhxo0diP1aoDg+PJxRTLe7K9SEsWcH6WzK7lY7eYACufT3+4TEVI1I0P6
	 fUrLNrREIQKDMTl5HL9OO2Nzb+srgPFlpKSBCg26k4ouuD1MZo+KAFIp4pREdGLN7H/L/
	 XO4eF8RmsbIIhbf6mOw3HQ149q4/z3rKtcx8t/5CI1tbT5MVnEWBk69s30EYRGIhNuw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794560407;
	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=nDmZz/9Lu+rwI73C7kuZiJ5O7j/5N39qJGbbT04Ep/k=;
	b=1V49UhAgbyHLom7uaP+7+q9IYIAAWWWeGjG+G/rbUTqZRZ+OLYieFr27tyf9ftRL5awB
	 aUoRD98zlzs7JnlTSTOJVoa80ipM5thgDrNH01qAHyQUUrBvKcPAgqd0tftgmp8698Ls9
	 5/SViwiUR94CFkn8p9CuY2jqsP2iLoyJ6Y+K4wBk5pCcGzPBcdxL2g13zVcUSp8/JN4hf
	 /kTXKt0gH3bh2RgplckenHM8WsCfDybMXvlFfzCLiiYvWXR19owLd7P7ZDRLhoEBWOGY0
	 wQrNh5i3oBErKDSs005VrQ4i0WzpX3L6jjY7O2qJOXeiyCgtBhntD7mgiPYD1TvyMcw==
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="LfSwP/kq";
	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 38DCD606A32E
	for <netdev@vger.kernel.org>; Fri, 13 Nov 2026 09:00:07 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 170BE1F000CC
	for <netdev@vger.kernel.org>; Fri, 13 Nov 2026 09:00:07 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794560407;
	bh=nDmZz/9Lu+rwI73C7kuZiJ5O7j/5N39qJGbbT04Ep/k=;
	h=References:In-Reply-To:From:Date:Subject:To:Cc;
	b=LfSwP/kqup8ZV1V5xTHwhz73bxZLsYinXaPWO/+z7CnpWPuuuK4n9XIYAMiJ6hoDG
	 nMarxgh7j+Y0rEQJNBn+K0xjzwGcftlXNrWn+LKMYJJOWXdSXyqcc21QisiOfJZCMq
	 end+/zcXMDJFvMAXke36CuIp5g5DtWHMU1Z+WIMLqX/IZI7Vso3GZUfWCu9v427J0W
	 WeINJ0WzQIKpm+oGv9rPA8ZJ5yQo5eOyGrHJV/R+w0y+PJZlarNtCqp7KDCmf6+EK8
	 xOCM3wB3zvYfAkBZ1DQC6+LPub+BnwpgdW1cwmLVzGftC35j1PbEqk/43kxf9pQcQb
	 Qo6+FOWwEtn3A==
X-Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-6dde81a6820so887137eaf.2
        for <netdev@vger.kernel.org>; Fri, 13 Nov 2026 01:00:07 -0800 (PST)
X-Forwarded-Encrypted: i=1; AL+hErEMonkgkYcHAyR+56UTiNNdxAOwdlQLQqkRA9NhS001MlIhs7gc+OKGofb0a5c93o4hB5sCVJ4=@vger.kernel.org
X-Gm-Message-State: APuU4Z+vE7WeKlry6T9Ow7+nWnxSE7iqoX/bDTbO3gOzhSoDZKUekLy3
	Y7rGiehJkaHoeVEzqUJXDb70QbIuFJVB0uJg8trz3s8G1C04Apsv13BvkyWjj7upbLLAwliq0z1
	17j41IJmDqu498i2sefXBxjXX2+Tc9NQ=
X-Received: by 2002:a05:6820:1608:b0:719:1627:6c0b with SMTP id
 006d021491bc7-71ab4f0c1d5mr1095396eaf.15.1794560406139; Fri, 13 Nov 2026
 01:00:06 -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: <179450310167.2199510.18107423940014989443@kernel.org>
X-Gmail-Original-Message-ID: <CAL4WiioP-25nYs19MiNAjnzbvi-H870uem1W+jY5jTJb=DKn+g@mail.gmail.com>
X-Gm-Features: AclHuK9NNSpFmdpVPLO-9WPIlgqsMexzOEss1wg0JOnZXh8zBeNfDDnJO3kSg4I
X-Cc: imv4bel@gmail.com, ncardwell@google.com, kuniyu@google.com, 
	davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, 
	netdev@vger.kernel.org