* FAILED: patch "[PATCH] tcp: fix request_sock use-after-free during Fast Open" failed to apply to 6.12-stable tree
@ 2026-11-25 8:56 gregkh
2026-11-25 14:45 ` [PATCH 6.12.y 1/2] tcp: fastopen: note that a child socket was created Sasha Levin
0 siblings, 1 reply; 3+ messages in thread
From: gregkh @ 2026-11-25 8:56 UTC (permalink / raw)
To: imv4bel, kuba, kuniyu; +Cc: stable
The patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 62754aad50d0b30938bd8ce30b43474ce502a2af
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2026112552-threefold-playset-c83a@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 62754aad50d0b30938bd8ce30b43474ce502a2af Mon Sep 17 00:00:00 2001
From: Hyunwoo Kim <imv4bel@gmail.com>
Date: Wed, 11 Nov 2026 15:24:03 +0900
Subject: [PATCH] tcp: fix request_sock use-after-free during Fast Open
accept()
Commit e3d95ad7da4f ("inet: avoid fastopen lock for regular accept()")
made inet_csk_accept() check tfo_listener before taking fastopenq.lock
to avoid taking the lock for connections that did not use Fast Open.
reqsk_fastopen_remove() clears tfo_listener while holding fastopenq.lock,
then reads req->sk. If inet_csk_accept() concurrently observes
tfo_listener after it has been cleared, it skips fastopenq.lock and
drops the last reference to the request_sock. This can free the
request_sock while reqsk_fastopen_remove() is still using it.
If the freed memory is reused for a new request_sock with req->sk ==
NULL, the reset path in reqsk_fastopen_remove() can append the new
request_sock to the original listener's list of requests that caused an
RST. After the new request_sock is freed, the next append writes through
the stale rskq_rst_tail into freed memory.
KASAN reported the following use-after-free when writing
fastopenq->rskq_rst_tail->dl_next = req:
BUG: KASAN: slab-use-after-free in reqsk_fastopen_remove+0x142/0x210
Write of size 8 at addr ffff888108230688 by task swapper/5/0
...
Call Trace:
<IRQ>
...
reqsk_fastopen_remove+0x142/0x210
tcp_check_req+0x96f/0xdd0
...
tcp_rcv_state_process+0x19c/0x26b0
...
tcp_v4_do_rcv+0x16e/0x490
tcp_v4_rcv+0x14a0/0x1af0
...
ip_protocol_deliver_rcu+0x39/0x1e0
ip_local_deliver_finish+0x124/0x1e0
ip_local_deliver+0xfb/0x1e0
...
</IRQ>
To widen the race windows, mdelay(5) was added after newsk = req->sk,
mdelay(20) after the if (req) reqsk_put(req) block, and mdelay(100)
after tcp_rsk(req)->tfo_listener = false. The KASAN report above was
reproduced with this kernel.
For the lockless check, use tcp_sk(newsk)->syn_fastopen_child instead of
tfo_listener, which reqsk_fastopen_remove() clears.
syn_fastopen_child is a field of the Fast Open child TCP socket
referenced by newsk, not of the request_sock. It is set before the child
socket is added to the accept queue. The paths that call
reqsk_fastopen_remove() in response to a remote ACK or RST do not clear
this field.
inet_csk_accept() uses this field to take fastopenq.lock only for Fast
Open child sockets and rechecks tfo_listener while holding the lock.
Connections that did not use Fast Open continue to avoid the lock.
Fixes: e3d95ad7da4f ("inet: avoid fastopen lock for regular accept()")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/avQKA_YTAThtbsYU@v4bel
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 37cc8606d683..6c079929e06f 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -683,7 +683,7 @@ struct sock *inet_csk_accept(struct sock *sk, struct proto_accept_arg *arg)
newsk = req->sk;
if (sk->sk_protocol == IPPROTO_TCP &&
- tcp_rsk(req)->tfo_listener) {
+ tcp_sk(newsk)->syn_fastopen_child) {
spin_lock_bh(&queue->fastopenq.lock);
if (tcp_rsk(req)->tfo_listener) {
/* We are still waiting for the final ACK from 3WHS
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 6.12.y 1/2] tcp: fastopen: note that a child socket was created
2026-11-25 8:56 FAILED: patch "[PATCH] tcp: fix request_sock use-after-free during Fast Open" failed to apply to 6.12-stable tree gregkh
@ 2026-11-25 14:45 ` Sasha Levin
2026-11-25 14:45 ` [PATCH 6.12.y 2/2] tcp: fix request_sock use-after-free during Fast Open accept() Sasha Levin
0 siblings, 1 reply; 3+ messages in thread
From: Sasha Levin @ 2026-11-25 14:45 UTC (permalink / raw)
To: stable
Cc: Jeremy Harris, Eric Dumazet, Neal Cardwell, Jakub Kicinski,
Sasha Levin
From: Jeremy Harris <jgh@exim.org>
[ Upstream commit bc2550b4e195754fbb24aac1f012d3dd9e3b4edc ]
tcp: fastopen: note that a child socket was created
This uses up the last bit in a field of tcp_sock.
Signed-off-by: Jeremy Harris <jgh@exim.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Neal Cardwell <ncardwell@google.com>
Link: https://patch.msgid.link/20250423124334.4916-2-jgh@exim.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Stable-dep-of: 62754aad50d0 ("tcp: fix request_sock use-after-free during Fast Open accept()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
include/linux/tcp.h | 3 ++-
net/ipv4/tcp.c | 1 +
net/ipv4/tcp_fastopen.c | 1 +
3 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 00ea96fec2273..ea54a107f307c 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -384,7 +384,8 @@ struct tcp_sock {
syn_fastopen:1, /* SYN includes Fast Open option */
syn_fastopen_exp:1,/* SYN includes Fast Open exp. option */
syn_fastopen_ch:1, /* Active TFO re-enabling probe */
- syn_data_acked:1;/* data in SYN is acked by SYN-ACK */
+ syn_data_acked:1,/* data in SYN is acked by SYN-ACK */
+ syn_fastopen_child:1; /* created TFO passive child socket */
u8 keepalive_probes; /* num of allowed keep alive probes */
u32 tcp_tx_delay; /* delay (in usec) added to TX packets */
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 69b4e194ba135..d1999b1cedaa1 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -3400,6 +3400,7 @@ int tcp_disconnect(struct sock *sk, int flags)
tp->rack.reo_wnd_persist = 0;
tp->rack.dsack_seen = 0;
tp->syn_data_acked = 0;
+ tp->syn_fastopen_child = 0;
tp->rx_opt.saw_tstamp = 0;
tp->rx_opt.dsack = 0;
tp->rx_opt.num_sacks = 0;
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index ac4fa51240290..6ccee7480232d 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -404,6 +404,7 @@ struct sock *tcp_try_fastopen(struct sock *sk, struct sk_buff *skb,
}
NET_INC_STATS(sock_net(sk),
LINUX_MIB_TCPFASTOPENPASSIVE);
+ tcp_sk(child)->syn_fastopen_child = 1;
return child;
}
NET_INC_STATS(sock_net(sk),
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 6.12.y 2/2] tcp: fix request_sock use-after-free during Fast Open accept()
2026-11-25 14:45 ` [PATCH 6.12.y 1/2] tcp: fastopen: note that a child socket was created Sasha Levin
@ 2026-11-25 14:45 ` Sasha Levin
0 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2026-11-25 14:45 UTC (permalink / raw)
To: stable; +Cc: Hyunwoo Kim, Kuniyuki Iwashima, Jakub Kicinski, Sasha Levin
From: Hyunwoo Kim <imv4bel@gmail.com>
[ Upstream commit 62754aad50d0b30938bd8ce30b43474ce502a2af ]
Commit e3d95ad7da4f ("inet: avoid fastopen lock for regular accept()")
made inet_csk_accept() check tfo_listener before taking fastopenq.lock
to avoid taking the lock for connections that did not use Fast Open.
reqsk_fastopen_remove() clears tfo_listener while holding fastopenq.lock,
then reads req->sk. If inet_csk_accept() concurrently observes
tfo_listener after it has been cleared, it skips fastopenq.lock and
drops the last reference to the request_sock. This can free the
request_sock while reqsk_fastopen_remove() is still using it.
If the freed memory is reused for a new request_sock with req->sk ==
NULL, the reset path in reqsk_fastopen_remove() can append the new
request_sock to the original listener's list of requests that caused an
RST. After the new request_sock is freed, the next append writes through
the stale rskq_rst_tail into freed memory.
KASAN reported the following use-after-free when writing
fastopenq->rskq_rst_tail->dl_next = req:
BUG: KASAN: slab-use-after-free in reqsk_fastopen_remove+0x142/0x210
Write of size 8 at addr ffff888108230688 by task swapper/5/0
...
Call Trace:
<IRQ>
...
reqsk_fastopen_remove+0x142/0x210
tcp_check_req+0x96f/0xdd0
...
tcp_rcv_state_process+0x19c/0x26b0
...
tcp_v4_do_rcv+0x16e/0x490
tcp_v4_rcv+0x14a0/0x1af0
...
ip_protocol_deliver_rcu+0x39/0x1e0
ip_local_deliver_finish+0x124/0x1e0
ip_local_deliver+0xfb/0x1e0
...
</IRQ>
To widen the race windows, mdelay(5) was added after newsk = req->sk,
mdelay(20) after the if (req) reqsk_put(req) block, and mdelay(100)
after tcp_rsk(req)->tfo_listener = false. The KASAN report above was
reproduced with this kernel.
For the lockless check, use tcp_sk(newsk)->syn_fastopen_child instead of
tfo_listener, which reqsk_fastopen_remove() clears.
syn_fastopen_child is a field of the Fast Open child TCP socket
referenced by newsk, not of the request_sock. It is set before the child
socket is added to the accept queue. The paths that call
reqsk_fastopen_remove() in response to a remote ACK or RST do not clear
this field.
inet_csk_accept() uses this field to take fastopenq.lock only for Fast
Open child sockets and rechecks tfo_listener while holding the lock.
Connections that did not use Fast Open continue to avoid the lock.
Fixes: e3d95ad7da4f ("inet: avoid fastopen lock for regular accept()")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/avQKA_YTAThtbsYU@v4bel
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
net/ipv4/inet_connection_sock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index 6b6a195ca7954..7439996bdc0c2 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -683,7 +683,7 @@ struct sock *inet_csk_accept(struct sock *sk, struct proto_accept_arg *arg)
newsk = req->sk;
if (sk->sk_protocol == IPPROTO_TCP &&
- tcp_rsk(req)->tfo_listener) {
+ tcp_sk(newsk)->syn_fastopen_child) {
spin_lock_bh(&queue->fastopenq.lock);
if (tcp_rsk(req)->tfo_listener) {
/* We are still waiting for the final ACK from 3WHS
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 14:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 8:56 FAILED: patch "[PATCH] tcp: fix request_sock use-after-free during Fast Open" failed to apply to 6.12-stable tree gregkh
2026-11-25 14:45 ` [PATCH 6.12.y 1/2] tcp: fastopen: note that a child socket was created Sasha Levin
2026-11-25 14:45 ` [PATCH 6.12.y 2/2] tcp: fix request_sock use-after-free during Fast Open accept() Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox