Article View: linux.kernel.netdev
Article #13227Re: [PATCH net] tcp: fix NULL pointer dereference when restarting a Fast Open listener
From: Hyunwoo Kim
Date: Mon, 09 Nov 2026 13:57
Date: Mon, 09 Nov 2026 13:57
113 lines
15917 bytes
15917 bytes
On Mon, Nov 09, 2026 at 01:55:44PM +0100, Eric Dumazet wrote:
> Le lun. 9 nov. 2026 ร 12:08, Hyunwoo Kim <imv4bel@gmail.com> a รฉcrit :
> >
> > 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);
>
> I do not think this spin_lock_bh() is _needed_ here, this hunk is
> misleading/distracting.
>
> Once inet_csk_listen_stop() takes fastopenq.lock unconditionally,
> reqsk_fastopen_remove() either inserted its req before we grabbed the lock
> (and we free it), or it will see sk_state != TCP_LISTEN and will not insert
> anything. Nothing can be added to rskq_rst_head until inet_csk_listen_start()
> sets TCP_LISTEN again, after reqsk_queue_alloc().
Ah, yes, that spin lock is unnecessary.
>
> The double mdelay() needed to reproduce the NULL deref shows the window:
> shutdown() + listen() would have to complete while reqsk_fastopen_remove()
> is between its TCP_LISTEN check and the list insertion.
>
> Please let's focus on the real issue, which is solely in
> inet_csk_listen_stop().
>
> Also note the more likely outcome of this race is a leak: a req stranded
> in rskq_rst_head holds a reference on the listener, and a subsequent
> close() will not call inet_csk_listen_stop() again. This is worth
> mentioning in the changelog.
>
> Please send a v2 with only the inet_csk_listen_stop() part.
Ok. I'll do that.
Best regards,
Hyunwoo Kim
Technical Details
Message-ID:
<avHRROArfXiPqwz5@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-359348-linux-kernel-netdev=dewy.ruReferences:
<avGpsTb2hsGIjSRk@v4bel> <CAL4WiirT7+1BDp97UWmBC8xpwDbNn1q0kWhztB9Gvs_i9u2shA@mail.gmail.com>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-359348-linux-kernel-netdev=dewy.ru
From: imv4bel@gmail.com (Hyunwoo Kim)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] tcp: fix NULL pointer dereference when restarting a
Fast Open listener
Date: Mon, 9 Nov 2026 22:57:24 +0900
Organization: Usenet Network
Message-ID: <avHRROArfXiPqwz5@v4bel>
References: <avGpsTb2hsGIjSRk@v4bel>
<CAL4WiirT7+1BDp97UWmBC8xpwDbNn1q0kWhztB9Gvs_i9u2shA@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="372300"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:aow3miYr9CP3vxvrVq35NHXFws8= sha256:s1bhtF9EKg+7AVAQTY6vyz1vWNA81Po/J52sO//aNPg=
sha1:pc0+8VuT+gIDj0HuCDXrWzVKfrQ= sha256:YdJX17CBQ0ziEfVZccnHNiafeR0uVho0YhZpzwZgEqU=
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 E4024113817; Mon, 9 Nov 2026 17:04:00 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, 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 jcyN9TAS5SiT;
Mon, 9 Nov 2026 17:03:53 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-359348-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id 88DD3113811; Mon, 9 Nov 2026 17:03:45 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 3901BC2DAE; Mon, 9 Nov 2026 13:57:35 +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=1794232651;
b=HPC08ri0uvDsxrCqzTtT3D+9+zZN0juz72VoasOjV74xXJGyd/nDntFQsgxkSGvMGqYK
VzIe73nrDmO08Nb4WELlBpIHWqOTt9q1dJOt+i7bA6IG0uUjZ5v7e8DyI0oj/pLdwY97i
bhg3HM3pJDCdGqTOC5si1S5HpjyPCu3dv0mFMVAsvGucKswjBM9V9yF/lhWmOgoHD7jVK
PURzsZX7dNhz0jxu7mNzuGs2N8+UppoVwdDBL79uzWkcJmDfnT52P4PSXFv5lL/TPqoit
DpYqU8ASaQBEYzVYq0DAZbSnjCDjAWl7KgYMo7oT/wTmVRY98Sknf4ld1KZh9GvBJxw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794232651;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:Date:From:To:Cc:Subject:Message-ID:
References:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
Content-Disposition:Content-Transfer-Encoding:In-Reply-To;
bh=pUWL0pcwmbMQZs/L2xhsjyboSQEvYXx95/cF1VP0qEM=;
b=ClJML3mZ3Q0T0JYgMSUo0GGdYdIogsHrD/A5XJ39xmYN2t2UYEYDR33Oj6+z74RgdFin
I9zC2CLhfGgMLlZDouMZ6kayu41Taclom463IG3lOuKxv4gyuIrLKdti5Q+py0Jx7R0iY
z8W5XOm6H5AP4pou2fRN0DYfeHg/IWrFBbwZSV6FZdhk42JHMxKW9sA5sm77OtZXDBOj9
3IuAuBQxnAOjdsKJOd50V8jzBS8joGmvERQloHFqU0ZlvReiDId7PfdaRNIrJ1iMQfJl6
L2O1R4YwNnZ/W5bqVS/oBNeKB8YIZbsvHu9kc0USeHpINmxz2/QGBRhaAac1eAb9iLA==
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="n/q1DN31";
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 9737E606A33F;
Mon, 9 Nov 2026 13:57:31 +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=n/q1DN31
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.179
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794232650;
b=XQnd/oHFmy9WjE9+E2DxGybrwmBCLhqMrgsqADCJyT1ghMOFz5DT1p+V/hxoVmkv5IZL
KWxpzoGmOkKsb3hUa/NWkWHlWB0aK68DU6zYpI6Q8L5AtDzCXvI2lpB1zM/vDfha0/wMf
pfeK48lgnIzZXerzVLxl6h3XYlQE8GwcUw4r26Q9CA3G2HrZHZYOPyYxLKkZl53VoGO2Q
YU5QNTgNpdCEydV+bsc/U7axEtKCRiacWmuFNALOblrpqbzSEUa3x7TqfAH//vEQVe+gv
YCis1b5JN8UvHaaRPQWzWdZXREOyCLRc2RP5W/HqPsFJ4+koa5LL1Pq4sklgkUBE8mg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794232650;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
Content-Type:Content-Disposition:Content-Transfer-Encoding:
In-Reply-To;
bh=pUWL0pcwmbMQZs/L2xhsjyboSQEvYXx95/cF1VP0qEM=;
b=2E6217T0xhkIXnCbDS1sKK2tQEG5+54ZdT0Daxf89fwmbHCz/yLwNi/lXU+UuSifk9/e
ILIA73miqMK1ESL296x5XLeKDgxCQcLpq9ryJ3+Jn5oZP0d7+/8E5vAZ+YQX8SyCxlJFy
2slpyLE/QPYVyF7XM28mizzHFDScWkZ4dpdw40Mj6dojZsE/bx8R8nwz16wZ6o8AqwR2L
7Gm8TdiPm2m8AtQdW0eoQ1UdmS7M8VlhCEkYj4C8/6DLHKowaR1oH7VdLl/RLnSgzODf/
kAIUPqpVKFp5gJ33bojzCR57WBsqaSKiDfj48XF8MR1xiN3VdoGfGMIdmPq/SrmkNPA==
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="n/q1DN31";
arc=none smtp.remote-ip=209.85.210.179
X-Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179])
(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 564CD606A321
for <netdev@vger.kernel.org>; Mon, 9 Nov 2026 13:57:30 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 564CD606A321
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-pf1-f179.google.com with SMTP id d2e1a72fcca58-8a4c72951b8so498961b3a.3
for <netdev@vger.kernel.org>; Mon, 09 Nov 2026 05:57:30 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1794232650; x=1794837450; darn=vger.kernel.org;
h=in-reply-to:content-transfer-encoding:content-disposition
:content-type:mime-version:references:message-id:subject:cc:to:from
:date:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=pUWL0pcwmbMQZs/L2xhsjyboSQEvYXx95/cF1VP0qEM=;
b=n/q1DN31kTUn6449EOw0z6AWYDWPy7GuJD6qCtUxgFOlA/vCnt4FCc5SlbUkBJROC/
8JpulzT/u2Cmv40lqGKct8Pe9/ZGNtNrmKfQdE8rsavznK8Kd1LqPCdlGlcfe7ctDnqf
0Bpw1p+6jO9fhXCw/eeIVw9M15VnURA0AaAsQ7fC7xlwSDkdQWFifuHz7/UNfRadPK4N
4m6516tI4qkRKW+wLutY0+ls1BhLbzIcpuGc9eIelO+8a0xD0nyZ0ydABDRf39HKBw7E
zTluwG/8o3VFve33ReJXHtLaUfoP3YryhkEbC6hp6ElzLs4WGu6VtlMa1y8lfjy4hapC
sgzQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794232650; x=1794837450;
h=in-reply-to:content-transfer-encoding:content-disposition
:content-type:mime-version:references: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=pUWL0pcwmbMQZs/L2xhsjyboSQEvYXx95/cF1VP0qEM=;
b=RvcjAYPdlXoQSj9PBRqTx06Yx9XRnVUkCQy3G022XNJa1MGRO1i/clNJRKJMzXsU5G
wYvu+dyR6C7w3goO90w1l5yxafslKCbJ031LppJCPAkMGO5ttdT30Pklul3pgQKOviJR
dokpZFE3CSAKMv0NxLDN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-Received: by 2002:a05:6a00:1706:b0:878:34d7:697b with SMTP id d2e1a72fcca58-8b66f4db364mr3469416b3a.41.1794232649513;
Mon, 09 Nov 2026 05:57:29 -0800 (PST)
X-Received: from v4bel ([58.123.110.97])
by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8b648e54de9sm1372614b3a.14.2026.11.09.05.57.26
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Mon, 09 Nov 2026 05:57:29 -0800 (PST)
X-Cc: Neal Cardwell <ncardwell@google.com>,
Kuniyuki Iwashima <kuniyu@google.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, 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
X-In-Reply-To: <CAL4WiirT7+1BDp97UWmBC8xpwDbNn1q0kWhztB9Gvs_i9u2shA@mail.gmail.com>