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: <CANn89iJP8gy24JOhwvydsDeVieAQFBmL4evt00vtOvW8tPPb7g@mail.gmail.com>
Date: Thu, 7 Mar 2024 10:51:15 +0100
From: Eric Dumazet <edumazet@...gle.com>
To: Kuniyuki Iwashima <kuniyu@...zon.com>
Cc: "David S. Miller" <davem@...emloft.net>, Jakub Kicinski <kuba@...nel.org>, 
	Paolo Abeni <pabeni@...hat.com>, Allison Henderson <allison.henderson@...cle.com>, 
	Kuniyuki Iwashima <kuni1840@...il.com>, netdev@...r.kernel.org, linux-rdma@...r.kernel.org, 
	rds-devel@....oracle.com
Subject: Re: [PATCH v3 net 1/2] tcp: Restart iteration after removing reqsk in inet_twsk_purge().

On Thu, Mar 7, 2024 at 12:05 AM Kuniyuki Iwashima <kuniyu@...zon.com> wrote:
>
> Commit 740ea3c4a0b2 ("tcp: Clean up kernel listener's reqsk in
> inet_twsk_purge()") added changes in inet_twsk_purge() to purge
> reqsk in per-netns ehash during netns dismantle.
>
> inet_csk_reqsk_queue_drop_and_put() will remove reqsk from per-netns
> ehash, but the iteration uses sk_nulls_for_each_rcu(), which is not
> safe.
>
> After removing reqsk, we need to restart iteration.
>
> Note that we need not check net->ns.count here because per-netns
> ehash does not have reqsk in other live netns.  We will check
> net->ns.count in the following patch.
>
> Fixes: 740ea3c4a0b2 ("tcp: Clean up kernel listener's reqsk in inet_twsk_purge()")
> Reported-by: Eric Dumazet <edumazet@...gle.com>
> Signed-off-by: Kuniyuki Iwashima <kuniyu@...zon.com>
> ---
>  net/ipv4/inet_timewait_sock.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/net/ipv4/inet_timewait_sock.c b/net/ipv4/inet_timewait_sock.c
> index 5befa4de5b24..00cbebaa2c68 100644
> --- a/net/ipv4/inet_timewait_sock.c
> +++ b/net/ipv4/inet_timewait_sock.c
> @@ -287,6 +287,8 @@ void inet_twsk_purge(struct inet_hashinfo *hashinfo, int family)
>                                         struct request_sock *req = inet_reqsk(sk);
>
>                                         inet_csk_reqsk_queue_drop_and_put(req->rsk_listener, req);
> +
> +                                       goto restart;
>                                 }
>
>                                 continue;

Note how the RCU rules that I followed for TCP_TIME_WAIT made
me to grab a reference on tw->tw_refcnt, using refcount_inc_not_zero()

I think your code had multiple bugs, because
inet_csk_reqsk_queue_drop_and_put() could cause UAF
if the timer already fired and refcount went to zero already.

We also could add sk_nulls_for_each_rcu_safe() to avoid these pesky
"goto restart;"

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ