tcp: Two fixes for socket migration in reqsk_timer_handler().
Subsystems (3)
Kuniyuki Iwashima
reviewercover tcp: Two fixes for socket migration in reqsk_timer_handler().
The series fixes two bugs in the error path of socket migration in reqsk_timer_handler().
Patch 1 fixes a potential UAF in reqsk_timer_handler().
Patch 2 fixes imbalanced icsk_accept_queue count.
Kuniyuki Iwashima (2):
tcp: Fix potential UAF in reqsk_timer_handler().
tcp: Fix imbalanced icsk_accept_queue count.
net/ipv4/inet_connection_sock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Kuniyuki Iwashima
reviewerPATCH 1/2 tcp: Fix potential UAF in reqsk_timer_handler().
When TCP socket migration fails at inet_ehash_insert() in reqsk_timer_handler(), we jump to the no_ownership: label and free the new reqsk immediately with __reqsk_free().
Thus, we must stop the new reqsk's timer before jumping to the label, but the timer might be missed since the cited commit, resulting in UAF.
As we are in the original reqsk's timer context, we can safely call timer_delete_sync() for the new reqsk.
Let's pass false to __inet_csk_reqsk_queue_drop() to stop the new reqsk's timer.
---
In case Sashiko asks
"What happens if TFO reqsk is migrated in reqsk_timer_handler() ?"
, the answer is
"TFO does not use reqsk_timer_handler()."
--- net/ipv4/inet_connection_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/inet_connection_sock.c +1 -1
@@ -1108,7 +1108,7 @@ static void reqsk_timer_handler(struct timer_list *t)if (!inet_ehash_insert (req_to_sk (nreq),req_to_sk (oreq),NULL )) {/* delete timer */ -__inet_csk_reqsk_queue_drop (sk_listener, nreq, true); +__inet_csk_reqsk_queue_drop (sk_listener, nreq, false); goto no_ownership; }
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Kuniyuki Iwashima
reviewerPATCH 2/2 tcp: Fix imbalanced icsk_accept_queue count.
In reply to Kuniyuki IwashimaWhen TCP socket migration happens in reqsk_timer_handler(), @sk_listener will be updated with the new listener.
When we call __inet_csk_reqsk_queue_drop(), the listener must be the one stored in req->rsk_listener.
The cited commit accidentally replaced oreq->rsk_listener with sk_listener, leading to imbalanced icsk_accept_queue count.
Let's pass the correct listener to __inet_csk_reqsk_queue_drop().
--- net/ipv4/inet_connection_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/inet_connection_sock.c +1 -1
@@ -1134,7 +1134,7 @@ static void reqsk_timer_handler(struct timer_list *t) } drop: -__inet_csk_reqsk_queue_drop (sk_listener, oreq, true); +__inet_csk_reqsk_queue_drop (oreq->rsk_listener, oreq, true);reqsk_put (oreq); }
Signature · 1 line
2.54.0.545.g6539524ca2-goog
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Wed, 6 May 2026 03:59:17 +0000 you wrote:
The series fixes two bugs in the error path of socket migration in
reqsk_timer_handler().Patch 1 fixes a potential UAF in
reqsk_timer_handler().Patch 2 fixes imbalanced
icsk_accept_queuecount.[...]
Here is the summary with links:
- [v1,net,1/2] tcp: Fix potential UAF in reqsk_timer_handler().
https://git.kernel.org/netdev/net/c/97c8a3c1f73d - [v1,net,2/2] tcp: Fix imbalanced icsk_accept_queue count. https://git.kernel.org/netdev/net/c/7eca3292cac7
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html