🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13135

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

#13135
From: Hyunwoo Kim
Date: Mon, 09 Nov 2026 11:08
110 lines
14292 bytes
When a valid RST is received for a Fast Open child accepted before the
three-way handshake completes, reqsk_fastopen_remove() adds the
request_sock to the listener's RST list if the listener is in TCP_LISTEN.

An application can call shutdown(SHUT_RD) and then listen() on the same
listener socket. inet_csk_listen_stop() checks rskq_rst_head without
holding fastopenq.lock. If rskq_rst_head is NULL, it does not acquire the
lock and therefore does not synchronize with an insertion by
reqsk_fastopen_remove() after that function has passed the TCP_LISTEN
check.

The subsequent reqsk_queue_alloc() also initializes rskq_rst_head,
rskq_rst_tail, and qlen in that order without holding the lock. If a
request_sock is added between the initialization of rskq_rst_head and
rskq_rst_tail, rskq_rst_head points to the request_sock while
rskq_rst_tail is NULL.

When a valid RST is later received for another accepted Fast Open child,
rskq_rst_head is not NULL, so reqsk_fastopen_remove() attempts to write
the request_sock pointer to rskq_rst_tail->dl_next while rskq_rst_tail is
NULL. KASAN reports:

  BUG: KASAN: null-ptr-deref in reqsk_fastopen_remove+0x147/0x210
  Write of size 8 at addr 0000000000000088 by task swapper/3/0
  ...
  Call Trace:
   <IRQ>
   ...
   reqsk_fastopen_remove+0x147/0x210
   tcp_check_req+0xa70/0x1060
   ...
   tcp_rcv_state_process+0x1cb/0x2ae0
   ...
   tcp_v4_do_rcv+0x1fe/0x740
   tcp_v4_rcv+0x1744/0x2070
   ...
   ip_protocol_deliver_rcu+0x5c/0x280
   ip_local_deliver_finish+0x171/0x330
   ip_local_deliver+0x107/0x370
   ...
   </IRQ>

To widen the race window, the issue was reproduced after adding
mdelay(3000) immediately after reqsk_fastopen_remove() checks that the
listener is in TCP_LISTEN and immediately after reqsk_queue_alloc() sets
rskq_rst_head to NULL.

Make inet_csk_listen_stop() acquire fastopenq.lock regardless of the
value of rskq_rst_head and detach the list while holding the lock. If
reqsk_fastopen_remove() has already passed the TCP_LISTEN check,
inet_csk_listen_stop() waits until the list insertion completes.

Also initialize rskq_rst_head, rskq_rst_tail, and qlen under the same
lock in reqsk_queue_alloc(). Drop the references to the detached
request_sock objects after releasing the lock.

Fixes: 0536fcc039a8 ("tcp: prepare fastopen code for upcoming listener changes")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
---
 net/ipv4/inet_connection_sock.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index e56beec438773..5590fc7efb88d 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -1333,9 +1333,11 @@ static int inet_ulp_can_listen(const struct sock *sk)
 
 static void reqsk_queue_alloc(struct request_sock_queue *queue)
 {
+	spin_lock_bh(&queue->fastopenq.lock);
 	queue->fastopenq.rskq_rst_head = NULL;
 	queue->fastopenq.rskq_rst_tail = NULL;
 	queue->fastopenq.qlen = 0;
+	spin_unlock_bh(&queue->fastopenq.lock);
 
 	queue->rskq_accept_head = NULL;
 }
@@ -1533,17 +1535,15 @@ void inet_csk_listen_stop(struct sock *sk)
 		if (!has_current_bpf_ctx())
 			cond_resched();
 	}
-	if (queue->fastopenq.rskq_rst_head) {
-		/* 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;
-		}
+	/* 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);
 }
-- 
2.43.0
Technical Details
Message-ID: <avGpsTb2hsGIjSRk@v4bel>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-359231-linux-kernel-netdev=dewy.ru

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-359231-linux-kernel-netdev=dewy.ru
From: imv4bel@gmail.com (Hyunwoo Kim)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net] tcp: fix NULL pointer dereference when restarting a Fast
 Open listener
Date: Mon, 9 Nov 2026 20:08:33 +0900
Organization: Usenet Network
Message-ID: <avGpsTb2hsGIjSRk@v4bel>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="335580"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:xfkL4QuQBxb12mjwK63FGsv7ZKo= sha256:1B9ACIFmbySd5kgxzQc/t2YK8IvstNPttfO1tA9steU=
	sha1:RHXbaEWEz5wYkeOPsWnaP1GuRCA= sha256:Hu1ZuWGiWwn8htBgaVup/nmbFqh+vCer6HwRFaSagz4=
Content-Disposition: inline
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 769941137A6; Mon,  9 Nov 2026 14:08:59 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.149
X-Spam-Status: No, score=-3.149 tagged_above=-9999 required=6.31
	tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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=gmail.com
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 dIzbDBiR7TiW;
	Mon,  9 Nov 2026 14:08:56 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-359231-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74])
	by mail.dewy.ru (Postfix) with ESMTPS id 40C111137A0; Mon,  9 Nov 2026 14:08:45 +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 E2F5B611116; Mon,  9 Nov 2026 11:08:44 +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=1794222522;
	b=J3k7kpeBWRWRMWAuNYco6z4hWMvV2w4l8Ghr8C/xIghTx3EB9kPcwWdiuGtKGLGU8CwE
	 eKrLBCMkUYTRZUhq4PKtaQm6IIvjV7V1vLzq+GKxutIkLACWOZjbJ8uGaEho9n8kkwdmz
	 eR2PjY//eGbt9IGwGxX1bb9B67xSySXeukBumKaXkIVBYhV9jbZZ7jyB1UrP2LbNpNS21
	 9sjqr2ULqE8mJrk/Hv1+OJHhtDhx7HFuKaoV6G6fFIRejcmlodn/Ljo5OLIQhW4/ZWA2d
	 D0lqd1yJcvvOX2QdVXnKZXdNe7NHUKoeUO7vtJ4l+iEjJU6LpjTy5Ww74pNn87n7Kkw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794222522;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:Date:From:To:Cc:Subject:Message-ID:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version:Content-Type:Content-Disposition;
	bh=fhrbprpRX7kmNcPax1vb/kgVqKCIO1cjiHj/rfQnbXw=;
	b=Ujhvnqb2klKAoiYjPx1c0ogV4xpGKbJcIM7xCPuyGaTp1WdTSOl+z6jye49aB9LrB9IL
	 cDUWTAamjSFuJ3/KS3I2QDRj20VEO6ANVWI/bBAOfCFalUwkSc9LVxtKsCS5oV7kQ/dP4
	 8xdKXr768NMK8sPeNmFAQwXUV8SX1Ol5aMbw21Rc39nTjPFPgQnJR2P1m0FVlDfcxqff1
	 TFu1KwHgJGQZuksO3DuIuNOGqc7LmteFmftx/+nJE+bGWxuQVWrxf5D4kwaB2AYJAycCL
	 iolwD0L0pG9Mmr/mk6n4N/GGDsKNet1HVXu+PfjNwajc06S7BMhqMr85ScdouvAXk4w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fm9inbie;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	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 115C0606A325;
	Mon,  9 Nov 2026 11:08:42 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fm9inbie
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.43
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794222521;
	b=mWGdjGJ4teiF1AMUrsvYqWquhlhF5Owa4Mk6HhNpOKzSthILPyC0kfBVO7SlGc10rAU0
	 /jd5QxuisdMscqkAnLIzfGnhy0MGSSOTwxQlCgZ8mVoLzA0Xrbh2VCxbXy4TpVr0FBybr
	 qQCcnd/cR7fLBZXK8HuUfMQSWWOPnVJyNlkLGSvcIdtzN608KVgT/14hve049xVJJoZJD
	 FNFE06fCLRp5SVsNORKOwwKx/zR+OhmVo1XLub2+/muVahw0y8Pi0Qjlgy/sj8u7u/+y3
	 2PVuNMeEaWGejw19WViMvY92fS7QcXpmZEYGSx48gT0PDdMG/v55x9Bh2IGu/8VSd0Q==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794222521;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc:
	 Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition;
	bh=fhrbprpRX7kmNcPax1vb/kgVqKCIO1cjiHj/rfQnbXw=;
	b=A6H7R/x2M5k0NZoD3jz/31PQism4qS6nPx6TTMjcNtdK2pHBVDx/W3uoDpHIMOuY3BA1
	 UEw7di2Tro78JoZ3AOpjxm9XF2hqzK563UkmbV0Sp2QPhVVvBaYGMU1bKHqMekRpkGbvL
	 3olN26TSF6UxhV4wZ366cYzIKCxM5cqZNhOTkHKMWM/esDckimxrpsKoqRTNNvT9QofmQ
	 wAmT2l5fSQhJoBxXB7Yi5BTFkUQsMCKETzqC9+vXWtPkFCc/fbL+/73vkHsii3amYpctA
	 NUO/pTk+/xRxOCKDXLFKuouNJqY0l5iFzgh6+UsFbr4cYxFwfRlHQHiVocogizGTvUA==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=fm9inbie;
	arc=none smtp.remote-ip=209.85.216.43
X-Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id C16DF606A321
	for <netdev@vger.kernel.org>; Mon,  9 Nov 2026 11:08:40 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C16DF606A321
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-3adac5b29ebso385107a91.2
        for <netdev@vger.kernel.org>; Mon, 09 Nov 2026 03:08:40 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1794222520; x=1794827320; darn=vger.kernel.org;
        h=content-disposition:content-type:mime-version:message-id:subject:cc
         :to:from:date:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=fhrbprpRX7kmNcPax1vb/kgVqKCIO1cjiHj/rfQnbXw=;
        b=fm9inbieny49XZbJnYsWzHOb+OWu8/+F21+6PWlDPyDwBUHncJY7UlyJDlXoR+If7y
         BOc684IJvxABsdSZryMhgCqkZJVKVpGHmXOWORLeTU/1WASVXq9DAMJxjMARurZgFprf
         Z+BG8MafRO9It0vRYzkx8wOnQ5eOmn/+ZGTMtFqAypBOi9dozMbMktZfcvUGCMi5F6R+
         DRhDqgiB+LIypBzWzTtWmhVAmwb1YpYmkQ+Y1bZ1JZlMSVfWII3ROeJXXbSS+zW7eaE7
         wxfDRgUmrImKZMtJra8s1qW6c6lGKlo3qhDmStTp1lBqONuh870FPPGUABOSP8mqaFnE
         WpGw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1794222520; x=1794827320;
        h=content-disposition:content-type:mime-version:message-id:subject:cc
         :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
         :message-id:reply-to:content-type;
        bh=fhrbprpRX7kmNcPax1vb/kgVqKCIO1cjiHj/rfQnbXw=;
        b=dJZg6tYV9uffUyg8LxOhcy0a5B0ggUt0vDZYsiwmwjY8ye/G+FLixi5RAnzNqykJ6O
         qzZovjOTHuodgHss8xGxuKLoe8Dt+cxaE+b+P9tQ1D/S0wQ9OmOhl8jQD7wcyYku7p9j
         xRY1P83JVDez6YnDLHFqO9btSHan0wEItAf1ZhXJnWmwulf61147vCJ8GtGmEHr3AQxY
         bjQrmm+DwmXZmHK0V+AK7QKdIRdMYl2f7B+EXPT9Lh3mrSDq/W5Zs5bkk1gyOGNIjBah
         nFBI5oeMG5x1jruGqAghV6Ee1sz/vXoxWifvzBXykdveq7WDfx6A9COkiTw8AK3fnWW6
         X5wg==
X-Gm-Message-State: APuU4Z8yP2drJBjA8HqICHZs3EusFfzrJHUX0EvdMZRmy+MGWeNzn8Ec
	2rDnuqPLu1WYU4iuHtEDzDPSQN46zXTWb7WD7/E1QD79d0/O7rp0BI2X
X-Gm-Gg: AYBFou1K3BLtf9JhUG8ttwOXydmrz/CqdT6cHK1sgRgyN4rgmgv+d3WB47tnlQzNblv
	G1cO0K7z1Hkn1F6iq4MRRVFFecJaIV/n+v1WMy6b7Ege/aLgUKLysh3Cu30AN3f/VQFEFY3fWg+
	pHpOeJwJv2JKWXhjGHsVxa+nPgbGkP/d7ccq9v/h9N37BcEHRrRRBFcSKdn/Hstq9OXFMsjMEtv
	vJAQBQM4HjX3c1VXmR8vWHIicKEYw+8Dff9Onk04CGnhd1AoWrtBkOSU8Kf5qYrHZnxYFBnhhjB
	lDy1UKLijYPLwyVgFBcA88poFq+Sn5dxGeuAfj3vE+VmrMH11rhy+lpSVN/paJ+nTP597lM/1+t
	yrmxesJgLGgf5vgy1grvEtGVSaPqDQw6+Hv+z/qjKqcdbqEBB3n7tAB29nLyxXsAB6yMQxDUVQP
	vlYZ2blSVqatZoHhlLUCytj5l5EHZs6jiLsktj7JffRf5lsSNVn94AzT42MjwvzpnuKCyU+eSQ+
	CYB6we9MlTKJ0Rm1/fOjNVMlB3vP5ykDqi4nUYeTZbnhUKpBA2i6i/WY9ziTGm3QXjhSkv1ycvD
	51AIsS0MK0geA2xfSNHhSrQAW9h8+z3qxcL9oWsmWaLrYhP19P4aLmXJI+wa/HJOItw+Lw==
X-Received: by 2002:a17:90b:3e8b:b0:3a7:ab31:2f4f with SMTP id 98e67ed59e1d1-3b12d3556f3mr3600152a91.28.1794222520031;
        Mon, 09 Nov 2026 03:08:40 -0800 (PST)
X-Received: from v4bel ([58.123.110.97])
        by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b12790bf20sm6389154a91.12.2026.11.09.03.08.35
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Mon, 09 Nov 2026 03:08:38 -0800 (PST)
X-Cc: netdev@vger.kernel.org, imv4bel@gmail.com
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