lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <27d46d3a-b636-4ccf-adfe-41363ad93946@linux.dev>
Date: Tue, 15 Oct 2024 10:37:50 -0700
From: Martin KaFai Lau <martin.lau@...ux.dev>
To: Kuniyuki Iwashima <kuniyu@...zon.com>
Cc: "David S. Miller" <davem@...emloft.net>,
 Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
 Paolo Abeni <pabeni@...hat.com>, David Ahern <dsahern@...nel.org>,
 Martin KaFai Lau <martin.lau@...nel.org>,
 Kuniyuki Iwashima <kuni1840@...il.com>, netdev@...r.kernel.org
Subject: Re: [PATCH v3 net] tcp/dccp: Don't use timer_pending() in
 reqsk_queue_unlink().

On 10/14/24 3:33 PM, Kuniyuki Iwashima wrote:
> Martin KaFai Lau reported use-after-free [0] in reqsk_timer_handler().
> 
>    """
>    We are seeing a use-after-free from a bpf prog attached to
>    trace_tcp_retransmit_synack. The program passes the req->sk to the
>    bpf_sk_storage_get_tracing kernel helper which does check for null
>    before using it.
>    """
> 
> The commit 83fccfc3940c ("inet: fix potential deadlock in
> reqsk_queue_unlink()") added timer_pending() in reqsk_queue_unlink() not
> to call del_timer_sync() from reqsk_timer_handler(), but it introduced a
> small race window.
> 
> Before the timer is called, expire_timers() calls detach_timer(timer, true)
> to clear timer->entry.pprev and marks it as not pending.
> 
> If reqsk_queue_unlink() checks timer_pending() just after expire_timers()
> calls detach_timer(), TCP will miss del_timer_sync(); the reqsk timer will
> continue running and send multiple SYN+ACKs until it expires.
> 
> The reported UAF could happen if req->sk is close()d earlier than the timer
> expiration, which is 63s by default.
> 
> The scenario would be
> 
>    1. inet_csk_complete_hashdance() calls inet_csk_reqsk_queue_drop(),
>       but del_timer_sync() is missed
> 
>    2. reqsk timer is executed and scheduled again
> 
>    3. req->sk is accept()ed and reqsk_put() decrements rsk_refcnt, but
>       reqsk timer still has another one, and inet_csk_accept() does not
>       clear req->sk for non-TFO sockets
> 
>    4. sk is close()d
> 
>    5. reqsk timer is executed again, and BPF touches req->sk
> 
> Let's not use timer_pending() by passing the caller context to
> __inet_csk_reqsk_queue_drop().
> 
> 
> Fixes: 83fccfc3940c ("inet: fix potential deadlock in reqsk_queue_unlink()")
> Reported-by: Martin KaFai Lau <martin.lau@...nel.org>
> Closes: https://lore.kernel.org/netdev/eb6684d0-ffd9-4bdc-9196-33f690c25824@linux.dev/
> Link: https://lore.kernel.org/netdev/b55e2ca0-42f2-4b7c-b445-6ffd87ca74a0@linux.dev/ [1]
> Signed-off-by: Kuniyuki Iwashima <kuniyu@...zon.com>

Reviewed-by: Martin KaFai Lau <martin.lau@...nel.org>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ