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: <20241204160006.61496-1-kuniyu@amazon.com>
Date: Thu, 5 Dec 2024 01:00:06 +0900
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: <edumazet@...gle.com>
CC: <davem@...emloft.net>, <ebiederm@...ssion.com>, <jmaloy@...hat.com>,
	<kuba@...nel.org>, <kuni1840@...il.com>, <kuniyu@...zon.com>,
	<netdev@...r.kernel.org>, <pabeni@...hat.com>, <syzkaller@...glegroups.com>,
	<tipc-discussion@...ts.sourceforge.net>, <ying.xue@...driver.com>
Subject: Re: [PATCH v2 net] tipc: Fix use-after-free of kernel socket in cleanup_bearer().

From: Eric Dumazet <edumazet@...gle.com>
Date: Wed, 4 Dec 2024 16:01:10 +0100
> > diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c
> > index 439f75539977..b7e25e7e9933 100644
> > --- a/net/tipc/udp_media.c
> > +++ b/net/tipc/udp_media.c
> > @@ -814,10 +814,10 @@ static void cleanup_bearer(struct work_struct *work)
> >                 kfree_rcu(rcast, rcu);
> >         }
> >
> > -       atomic_dec(&tipc_net(sock_net(ub->ubsock->sk))->wq_count);
> >         dst_cache_destroy(&ub->rcast.dst_cache);
> >         udp_tunnel_sock_release(ub->ubsock);
> >         synchronize_net();
> > +       atomic_dec(&tipc_net(sock_net(ub->ubsock->sk))->wq_count);
> 
> Note that ub->ubsock->sk is NULL at this point.
> 
> I am testing the following fix, does it make sense to you ?

Ah yes, net needs to be cached before sock_release().

Thanks for catching this !


> 
> diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c
> index b7e25e7e9933b69aa6a3364e3287c358b7ac9421..1d359de9dd6ad7ff60b6b93f620ff6783e385106
> 100644
> --- a/net/tipc/udp_media.c
> +++ b/net/tipc/udp_media.c
> @@ -807,6 +807,7 @@ static void cleanup_bearer(struct work_struct *work)
>  {
>         struct udp_bearer *ub = container_of(work, struct udp_bearer, work);
>         struct udp_replicast *rcast, *tmp;
> +       struct tipc_net *tn;
> 
>         list_for_each_entry_safe(rcast, tmp, &ub->rcast.list, list) {
>                 dst_cache_destroy(&rcast->dst_cache);
> @@ -814,10 +815,14 @@ static void cleanup_bearer(struct work_struct *work)
>                 kfree_rcu(rcast, rcu);
>         }
> 
> +       tn = tipc_net(sock_net(ub->ubsock->sk));
> +
>         dst_cache_destroy(&ub->rcast.dst_cache);
>         udp_tunnel_sock_release(ub->ubsock);
> +
> +       /* Note: we could use a call_rcu() to avoid another synchronize_net() */
>         synchronize_net();
> -       atomic_dec(&tipc_net(sock_net(ub->ubsock->sk))->wq_count);
> +       atomic_dec(&tn->wq_count);
>         kfree(ub);
>  }

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ