From: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2 v3 10/10] ms/tcp: fix request_sock use-after-free during Fast Open accept()
Date: Thu, 26 Nov 2026 08:11:10 +0200 [thread overview]
Message-ID: <20261126062617.2133758-12-eva.kurchatova@virtuozzo.com> (raw)
In-Reply-To: <20261126062617.2133758-2-eva.kurchatova@virtuozzo.com>
From: Hyunwoo Kim <imv4bel@gmail.com>
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>
(cherry picked from commit 62754aad50d0b30938bd8ce30b43474ce502a2af)
https://virtuozzo.atlassian.net/browse/VSTOR-156045
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
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 bf1abf88cae6..8af596b3e9e0 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -681,7 +681,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.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-26 6:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 6:11 [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 01/10] ms/tcp: Fix potential UAF in reqsk_timer_handler() Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 02/10] ms/tcp: Fix imbalanced icsk_accept_queue count Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 03/10] ms/inet: reject unhashed sockets during established lookups Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 04/10] ms/net: restore refcount ordering for lockless socket access Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 05/10] ms/tcp: ipv6: do not read ireq->pktopts from tcp_v6_send_synack() Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 06/10] ms/tcp: ipv6: free ireq->ipv6_opt after an RCU grace period Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 07/10] ms/tcp: free saved_syn " Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 08/10] ms/tcp: Pass req->rsk_listener to inet_csk_reqsk_queue_drop() in tcp_check_req() Eva Kurchatova
2026-11-26 6:11 ` [Devel] [PATCH hci-8.2 v3 09/10] ms/tcp: fastopen: note that a child socket was created Eva Kurchatova
2026-11-26 6:11 ` Eva Kurchatova [this message]
2026-11-30 15:50 ` [Devel] [PATCH hci-8.2 v3 00/10] ms/net: backport request migration RCU fixes and lockless refcount ordering Konstantin Khorenko
2026-11-30 15:51 ` Konstantin Khorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261126062617.2133758-12-eva.kurchatova@virtuozzo.com \
--to=eva.kurchatova@virtuozzo.com \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.com \
--cc=vladimir.riabchun@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.