tcp: fix TFO max_qlen accounting across reuseport migration
Subsystems (3)
PATCH 1/1 tcp: fix TFO max_qlen accounting across reuseport migration
A listener's TCP_FASTOPEN max_qlen stops being accurate and lets through far more pending Fast Open requests than it was configured for.
This only shows up with SO_REUSEPORT listener migration, where closing a listener hands its still-pending TFO children over to a surviving one.
fastopenq.qlen is charged in tcp_fastopen_create_child() when the child is created and uncharged in reqsk_fastopen_remove() when the handshake completes. The uncharge follows rsk_listener of the request the child points at, and inet_reqsk_clone() has repointed the child at a new request owned by the new listener, so the ++ and the -- land on two different sockets. The new listener's qlen drifts negative and its limit no longer binds.
Charge the new listener during migration, like reqsk_queue_migrated() already does for queue->young and queue->qlen.
---
fastopenq.qlen is read without the lock in tcp_fastopen_queue_check() and has been since long before this patch, but as this is meant to be backported I left the READ_ONCE()/WRITE_ONCE() conversion to a separate patch.
--- net/ipv4/inet_connection_sock.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
net/ipv4/inet_connection_sock.c +16 -4
@@ -943,11 +943,23 @@ static struct request_sock *inet_reqsk_clone(struct request_sock *req, nreq->rsk_listener = sk; -/* We need not acquire fastopenq->lock -* because the child socket is locked in inet_csk_listen_stop(). -*/ -if (sk->sk_protocol ==IPPROTO_TCP &&tcp_rsk (nreq)->tfo_listener) +if (sk->sk_protocol ==IPPROTO_TCP &&tcp_rsk (nreq)->tfo_listener) { +struct fastopen_queue *fastopenq; + +/* reqsk_fastopen_remove() will uncharge nreq->rsk_listener, +* that is @sk, so charge it here. Unlike the listener +* being closed, @sk is live and needs its lock. +*/ + fastopenq = &inet_csk (sk)->icsk_accept_queue.fastopenq; +spin_lock_bh (&fastopenq->lock); + fastopenq->qlen++; +spin_unlock_bh (&fastopenq->lock); + +/* We need not acquire fastopenq->lock +* because the child socket is locked in inet_csk_listen_stop(). +*/ rcu_assign_pointer (tcp_sk (nreq->sk)->fastopen_rsk, nreq); + }return nreq; }
Signature · 1 line
2.43.0
Quoted 15 lines · Jiayuan Chen
A listener's
TCP_FASTOPENmax_qlenstops being accurate and lets through far more pending Fast Open requests than it was configured for.This only shows up with
SO_REUSEPORTlistener migration, where closing a listener hands its still-pending TFO children over to a surviving one.fastopenq.qlen is charged in
tcp_fastopen_create_child()when the child is created and uncharged inreqsk_fastopen_remove()when the handshake completes. The uncharge followsrsk_listenerof the request the child points at, andinet_reqsk_clone()has repointed the child at a new request owned by the new listener, so the ++ and the -- land on two different sockets. The new listener's qlen drifts negative and its limit no longer binds.
Quoted 5 lines
Charge the new listener during migration, like
reqsk_queue_migrated()already does forqueue->youngandqueue->qlen.Fixes 54b92e841937 ("tcp: Migrate TCP_ESTABLISHED/TCP_SYN_RECV sockets in accept queues.")Signed-off-by Jiayuan Chen <[email protected]>
Eric Dumazet
Reviewed-byQuoted 17 lines · Kuniyuki Iwashima
Quoted 15 lines · Jiayuan Chen
A listener's
TCP_FASTOPENmax_qlenstops being accurate and lets through far more pending Fast Open requests than it was configured for.This only shows up with
SO_REUSEPORTlistener migration, where closing a listener hands its still-pending TFO children over to a surviving one.fastopenq.qlen is charged in
tcp_fastopen_create_child()when the child is created and uncharged inreqsk_fastopen_remove()when the handshake completes. The uncharge followsrsk_listenerof the request the child points at, andinet_reqsk_clone()has repointed the child at a new request owned by the new listener, so the ++ and the -- land on two different sockets. The new listener's qlen drifts negative and its limit no longer binds.
Quoted 7 lines
Quoted 5 lines
Charge the new listener during migration, like
reqsk_queue_migrated()already does forqueue->youngandqueue->qlen.Fixes 54b92e841937 ("tcp: Migrate TCP_ESTABLISHED/TCP_SYN_RECV sockets in accept queues.")Signed-off-by Jiayuan Chen <[email protected]>Reviewed-by Kuniyuki Iwashima <[email protected]>
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 14 lines · On Mon, 3 Aug 2026 14:17:38 +0800 you wrote:
A listener's
TCP_FASTOPENmax_qlenstops being accurate and lets through far more pending Fast Open requests than it was configured for.This only shows up with
SO_REUSEPORTlistener migration, where closing a listener hands its still-pending TFO children over to a surviving one.fastopenq.qlen is charged in
tcp_fastopen_create_child()when the child is created and uncharged inreqsk_fastopen_remove()when the handshake completes. The uncharge followsrsk_listenerof the request the child points at, andinet_reqsk_clone()has repointed the child at a new request owned by the new listener, so the ++ and the -- land on two different sockets. The new listener's qlen drifts negative and its limit no longer binds.
Quoted 1 line
[...]
Here is the summary with links:
- [net] tcp: fix TFO max_qlen accounting across reuseport migration
https://git.kernel.org/netdev/net/c/a0ab2ba83e35
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html