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 8/8] ms/tcp: purge Fast Open RST queue when listen() fails
Date: Mon, 30 Nov 2026 20:45:53 +0200 [thread overview]
Message-ID: <20261130184822.2743885-9-eva.kurchatova@virtuozzo.com> (raw)
In-Reply-To: <20261130184822.2743885-1-eva.kurchatova@virtuozzo.com>
From: Eric Dumazet <edumazet@kernel.org>
inet_csk_listen_start() moves the socket to TCP_LISTEN before calling
->get_port() and ->hash(). If one of them fails, the socket goes back
to TCP_CLOSE without going through inet_csk_listen_stop().
If the socket was a Fast Open listener in a previous life, and was
stopped with shutdown(SHUT_RD) or connect(AF_UNSPEC) while an accepted
Fast Open child was still in TCP_SYN_RECV state, the request_sock of
this child still points to the listener.
A valid RST received for this child while the listener is transiently
in TCP_LISTEN state makes reqsk_fastopen_remove() queue the
request_sock in rskq_rst_head. When listen() fails, for instance with
-EADDRINUSE because another SO_REUSEADDR socket started listening on
the same port, nothing reclaims it:
- __tcp_close(), tcp_disconnect() and tcp_abort() only call
inet_csk_listen_stop() for sockets in TCP_LISTEN state.
- A later successful listen() overwrites rskq_rst_head in
reqsk_queue_alloc().
The request_sock is leaked, together with the reference it holds
on the listener.
Move the rskq_rst_head purge to a helper, and call it from the
inet_csk_listen_start() error path as well, after the socket state
has been set back to TCP_CLOSE: reqsk_fastopen_remove() checks
sk_state under fastopenq.lock, so it either queued the request before
the purge acquires the lock, or does not queue it at all.
Reported-by: Sashiko AI review <netdev-bot+sashiko@kernel.org>
Closes: https://lore.kernel.org/netdev/179450310167.2199510.18107423940014989443@kernel.org/
Fixes: 0536fcc039a8 ("tcp: prepare fastopen code for upcoming listener changes")
Signed-off-by: Eric Dumazet <edumazet@kernel.org>
Reviewed-by: Hyunwoo Kim <imv4bel@gmail.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20261114111247.21995-1-edumazet@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
(cherry picked from commit 342e62fd34c2674e82bffc89cb5c7091924986d9)
Rebase note: conflict in context only. reqsk_queue_alloc(), next to
which upstream adds reqsk_fastopen_purge_rst(), is still in
net/core/request_sock.c here; d5c539155431 ("inet: move
reqsk_queue_alloc() to net/ipv4/inet_connection_sock.c") is not taken.
https://virtuozzo.atlassian.net/browse/VSTOR-157577
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
net/ipv4/inet_connection_sock.c | 35 ++++++++++++++++++++++-----------
1 file changed, 24 insertions(+), 11 deletions(-)
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
index dedbf38535db..1ee030974faf 100644
--- a/net/ipv4/inet_connection_sock.c
+++ b/net/ipv4/inet_connection_sock.c
@@ -1315,6 +1315,22 @@ static int inet_ulp_can_listen(const struct sock *sk)
return 0;
}
+/* Free all the reqs queued in rskq_rst_head. */
+static void reqsk_fastopen_purge_rst(struct request_sock_queue *queue)
+{
+ struct request_sock *next, *req;
+
+ 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;
+ }
+}
+
int inet_csk_listen_start(struct sock *sk)
{
struct inet_connection_sock *icsk = inet_csk(sk);
@@ -1348,6 +1364,12 @@ int inet_csk_listen_start(struct sock *sk)
}
inet_sk_set_state(sk, TCP_CLOSE);
+
+ /* A Fast Open child accepted before a previous shutdown() of this
+ * listener might have queued its request in rskq_rst_head while
+ * we were transiently in TCP_LISTEN state.
+ */
+ reqsk_fastopen_purge_rst(&icsk->icsk_accept_queue);
return err;
}
EXPORT_SYMBOL_GPL(inet_csk_listen_start);
@@ -1455,7 +1477,7 @@ void inet_csk_listen_stop(struct sock *sk)
{
struct inet_connection_sock *icsk = inet_csk(sk);
struct request_sock_queue *queue = &icsk->icsk_accept_queue;
- struct request_sock *next, *req;
+ struct request_sock *req;
/* Following specs, it would be better either to send FIN
* (and enter FIN-WAIT-1, it is normal close)
@@ -1511,16 +1533,7 @@ void inet_csk_listen_stop(struct sock *sk)
if (!has_current_bpf_ctx())
cond_resched();
}
- /* 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;
- }
+ reqsk_fastopen_purge_rst(queue);
WARN_ON_ONCE(sk->sk_ack_backlog);
}
EXPORT_SYMBOL_GPL(inet_csk_listen_stop);
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-30 18:50 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 18:45 [Devel] [PATCH hci-8.2 0/8] ms: backport additional TFO and CALIPSO fixes Eva Kurchatova
2026-11-30 18:45 ` [Devel] [PATCH hci-8.2 1/8] ms/tcp: clear sock_ops cb flags before force-closing a child socket Eva Kurchatova
2026-12-01 1:17 ` no-reply
2026-11-30 18:45 ` [Devel] [PATCH hci-8.2 2/8] ms/tcp: Skip cond_resched() in inet_csk_listen_stop() under BPF context Eva Kurchatova
2026-12-01 1:18 ` no-reply
2026-11-30 18:45 ` [Devel] [PATCH hci-8.2 3/8] ms/net/ipv6: Introduce payload_len helpers Eva Kurchatova
2026-12-01 1:21 ` no-reply
2026-11-30 18:45 ` [Devel] [PATCH hci-8.2 4/8] ms/calipso: keep BIG TCP payload_len in calipso_skbuff_setattr() Eva Kurchatova
2026-12-01 1:22 ` no-reply
2026-11-30 18:45 ` [Devel] [PATCH hci-8.2 5/8] ms/calipso: hash the cache key, not the option start, in calipso_cache_add() Eva Kurchatova
2026-12-01 1:23 ` no-reply
2026-11-30 18:45 ` [Devel] [PATCH hci-8.2 6/8] ms/calipso: update payload_len when removing the CALIPSO option Eva Kurchatova
2026-12-01 1:25 ` no-reply
2026-11-30 18:45 ` [Devel] [PATCH hci-8.2 7/8] ms/tcp: fix NULL pointer dereference when restarting a Fast Open listener Eva Kurchatova
2026-12-01 1:25 ` no-reply
2026-11-30 18:45 ` Eva Kurchatova [this message]
2026-12-01 1:28 ` [Devel] [PATCH hci-8.2 8/8] ms/tcp: purge Fast Open RST queue when listen() fails no-reply
2026-12-01 11:37 ` [Devel] [PATCH hci-8.2 0/8] ms: backport additional TFO and CALIPSO fixes Eva Kurchatova (Virtuozzo)
2026-12-01 15:42 ` Eva Kurchatova (Virtuozzo)
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=20261130184822.2743885-9-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox