]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tcp: Fix potential UAF in reqsk_timer_handler().
authorKuniyuki Iwashima <kuniyu@google.com>
Wed, 6 May 2026 03:59:18 +0000 (03:59 +0000)
committerJakub Kicinski <kuba@kernel.org>
Fri, 8 May 2026 21:54:50 +0000 (14:54 -0700)
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()")
Reported-by: Damiano Melotti <melotti@google.com>
Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20260506035954.1563147-2-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/inet_connection_sock.c

index 928654c34156b609b544e40f231d618d7c491a2f..971f9db2c5869a5e2e03ce2311ded3f9822fd659 100644 (file)
@@ -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;
                }