Skip to contentSkip to conversation

tcp: Two fixes for socket migration in reqsk_timer_handler().

PATCH Applied Kuniyuki Iwashima 2 participants 4 messages May 6 – May 8

Subsystems (3)
lore
Share & tools
lore

Kuniyuki Iwashima

author reviewer
#0 lore raw

cover 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
author reviewer
#1 lore raw

PATCH 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.

Fixes 83fccfc3940c ("inet: fix potential deadlock in reqsk_queue_unlink()")

---
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
index 928654c34156..971f9db2c586 100644
@@ -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
author reviewer
#2 lore raw

PATCH 2/2 tcp: Fix imbalanced icsk_accept_queue count.

In reply to Kuniyuki Iwashima

When 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().

Fixes e8c526f2bdf1 ("tcp/dccp: Don't use timer_pending() in reqsk_queue_unlink().")
---
 net/ipv4/inet_connection_sock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/inet_connection_sock.c +1 -1
index 971f9db2c586..dbcd37dfdc15 100644
@@ -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
#3 lore raw
In reply to Kuniyuki Iwashima
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_queue count.

[...]

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