Skip to contentSkip to conversation

tcp: Fix use-after-free of nreq in reqsk_timer_handler().

PATCH Applied Kuniyuki Iwashima 6 participants 6 messages Nov 23, 2024 – Nov 28, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: Fix use-after-free of nreq in reqsk_timer_handler().

The cited commit replaced inet_csk_reqsk_queue_drop_and_put() with __inet_csk_reqsk_queue_drop() and reqsk_put() in reqsk_timer_handler().

Then, oreq should be passed to reqsk_put() instead of req; otherwise use-after-free of nreq could happen when reqsk is migrated but the retry attempt failed (e.g. due to timeout).

Let's pass oreq to reqsk_put().

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 491c2c6b683e..6872b5aff73e 100644
@@ -1191,7 +1191,7 @@ static void reqsk_timer_handler(struct timer_list *t)
 
 drop:
 	__inet_csk_reqsk_queue_drop(sk_listener, oreq, true);
-	reqsk_put(req);
+	reqsk_put(oreq);
 }
 
 static bool reqsk_queue_hash_req(struct request_sock *req,
Signature · 1 line
2.39.5 (Apple Git-154)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · Kuniyuki Iwashima

The cited commit replaced inet_csk_reqsk_queue_drop_and_put() with __inet_csk_reqsk_queue_drop() and reqsk_put() in reqsk_timer_handler().

Then, oreq should be passed to reqsk_put() instead of req; otherwise use-after-free of nreq could happen when reqsk is migrated but the retry attempt failed (e.g. due to timeout).

Let's pass oreq to reqsk_put().

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 +0 -0
index 491c2c6b683e..6872b5aff73e 100644

net/ipv4/inet_connection_sock.c static void reqsk_timer_handler(struct timer_list *t) · line 1197

Quoted 8 lines
net/ipv4/inet_connection_sock.c +1 -1
@@ -1191,7 +1191,7 @@ static void reqsk_timer_handler(struct timer_list *t)
 
  drop:
  	__inet_csk_reqsk_queue_drop(sk_listener, oreq, true);
-	reqsk_put(req);
+	reqsk_put(oreq);
  }
 
  static bool reqsk_queue_hash_req(struct request_sock *req,

That indeed fixes the fix :)

Reviewed-by on v1 1/1
#2 lore raw
In reply to Kuniyuki Iwashima
Quoted 22 lines · Kuniyuki Iwashima

The cited commit replaced inet_csk_reqsk_queue_drop_and_put() with __inet_csk_reqsk_queue_drop() and reqsk_put() in reqsk_timer_handler().

Then, oreq should be passed to reqsk_put() instead of req; otherwise use-after-free of nreq could happen when reqsk is migrated but the retry attempt failed (e.g. due to timeout).

Let's pass oreq to reqsk_put().

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 +0 -0
index 491c2c6b683e..6872b5aff73e 100644

net/ipv4/inet_connection_sock.c static void reqsk_timer_handler(struct timer_list *t) · line 1195

Quoted 6 lines
net/ipv4/inet_connection_sock.c +1 -1
@@ -1191,7 +1191,7 @@ static void reqsk_timer_handler(struct timer_list *t)
 
  drop:
  	__inet_csk_reqsk_queue_drop(sk_listener, oreq, true);
-	reqsk_put(req);
+	reqsk_put(oreq);
  }
Quoted 2 lines
net/ipv4/inet_connection_sock.c +0 -0
  static bool reqsk_queue_hash_req(struct request_sock *req,
Reviewed-by
#3 lore raw
Quoted 27 lines · liujian (CE)
Quoted 23 lines · Kuniyuki Iwashima

The cited commit replaced inet_csk_reqsk_queue_drop_and_put() with __inet_csk_reqsk_queue_drop() and reqsk_put() in reqsk_timer_handler().

Then, oreq should be passed to reqsk_put() instead of req; otherwise use-after-free of nreq could happen when reqsk is migrated but the retry attempt failed (e.g. due to timeout).

Let's pass oreq to reqsk_put().

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 +0 -0
index 491c2c6b683e..6872b5aff73e 100644
@@ -1191,7 +1191,7 @@ static void reqsk_timer_handler(struct timer_list *t)
 
Quoted 8 lines

net/ipv4/inet_connection_sock.c static void reqsk_timer_handler(struct timer_list *t) · line 1195

Quoted 5 lines
net/ipv4/inet_connection_sock.c +1 -1
  drop:
      __inet_csk_reqsk_queue_drop(sk_listener, oreq, true);
-     reqsk_put(req);
+     reqsk_put(oreq);
  }
Quoted 2 lines
net/ipv4/inet_connection_sock.c +0 -0
  static bool reqsk_queue_hash_req(struct request_sock *req,

Thanks.

Reviewed-by on v1 1/1
#4 lore raw
In reply to Kuniyuki Iwashima
Quoted 22 lines · Kuniyuki Iwashima

The cited commit replaced inet_csk_reqsk_queue_drop_and_put() with __inet_csk_reqsk_queue_drop() and reqsk_put() in reqsk_timer_handler().

Then, oreq should be passed to reqsk_put() instead of req; otherwise use-after-free of nreq could happen when reqsk is migrated but the retry attempt failed (e.g. due to timeout).

Let's pass oreq to reqsk_put().

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 +0 -0
index 491c2c6b683e..6872b5aff73e 100644

net/ipv4/inet_connection_sock.c static void reqsk_timer_handler(struct timer_list *t) · line 1194

Quoted 5 lines
net/ipv4/inet_connection_sock.c +1 -1
@@ -1191,7 +1191,7 @@ static void reqsk_timer_handler(struct timer_list *t)
 
  drop:
  	__inet_csk_reqsk_queue_drop(sk_listener, oreq, true);
-	reqsk_put(req);
+	reqsk_put(oreq);
#5 lore raw
In reply to Kuniyuki Iwashima
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 8 lines · On Sat, 23 Nov 2024 09:42:36 -0800 you wrote:

The cited commit replaced inet_csk_reqsk_queue_drop_and_put() with __inet_csk_reqsk_queue_drop() and reqsk_put() in reqsk_timer_handler().

Then, oreq should be passed to reqsk_put() instead of req; otherwise use-after-free of nreq could happen when reqsk is migrated but the retry attempt failed (e.g. due to timeout).

[...]

Here is the summary with links:
- [v1,net] tcp: Fix use-after-free of nreq in reqsk_timer_handler().

    https://git.kernel.org/netdev/net/c/c31e72d021db

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html