tcp: Fix use-after-free of nreq in reqsk_timer_handler().
Subsystems (3)
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().
--- net/ipv4/inet_connection_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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,
Signature · 1 line
2.39.5 (Apple Git-154)
Quoted 22 lines · Kuniyuki Iwashima
The cited commit replaced
inet_csk_reqsk_queue_drop_and_put()with__inet_csk_reqsk_queue_drop()andreqsk_put()inreqsk_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().")Reported-by Liu Jian <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/ipv4/inet_connection_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/inet_connection_sock.c +0
-0
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 :)
Quoted 22 lines · Kuniyuki Iwashima
The cited commit replaced
inet_csk_reqsk_queue_drop_and_put()with__inet_csk_reqsk_queue_drop()andreqsk_put()inreqsk_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().")Reported-by Liu Jian <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/ipv4/inet_connection_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/inet_connection_sock.c +0
-0
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
-0static bool reqsk_queue_hash_req(struct request_sock *req,
Eric Dumazet
Reviewed-byQuoted 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()andreqsk_put()inreqsk_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().")Reported-by Liu Jian <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/ipv4/inet_connection_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/inet_connection_sock.c +0
-0@@ -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
-1drop:__inet_csk_reqsk_queue_drop (sk_listener, oreq, true); -reqsk_put (req); +reqsk_put (oreq); }Reviewed-by Liu Jian <[email protected]>Quoted 2 lines
net/ipv4/inet_connection_sock.c +0
-0static bool reqsk_queue_hash_req(struct request_sock *req,
Thanks.
Quoted 22 lines · Kuniyuki Iwashima
The cited commit replaced
inet_csk_reqsk_queue_drop_and_put()with__inet_csk_reqsk_queue_drop()andreqsk_put()inreqsk_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().")Reported-by Liu Jian <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/ipv4/inet_connection_sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/inet_connection_sock.c +0
-0
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);
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()andreqsk_put()inreqsk_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