[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aa2a710f-d481-4d96-b3fe-358596bbd6f2@ovn.org>
Date: Tue, 3 Dec 2024 23:01:20 +0100
From: Ilya Maximets <i.maximets@....org>
To: Eric Dumazet <edumazet@...gle.com>
Cc: i.maximets@....org, "David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>, Paolo Abeni <pabeni@...hat.com>,
netdev@...r.kernel.org, eric.dumazet@...il.com,
Dan Streetman <dan.streetman@...onical.com>,
Steffen Klassert <steffen.klassert@...unet.com>
Subject: Re: [PATCH net] net: defer final 'struct net' free in netns dismantle
On 12/3/24 19:33, Eric Dumazet wrote:
> On Tue, Dec 3, 2024 at 7:23 PM Ilya Maximets <i.maximets@....org> wrote:
>>
>> On 12/3/24 17:50, Eric Dumazet wrote:
>>> Ilya reported a slab-use-after-free in dst_destroy [1]
>>>
>>> Issue is in xfrm6_net_init() and xfrm4_net_init() :
>>>
>>> They copy xfrm[46]_dst_ops_template into net->xfrm.xfrm[46]_dst_ops.
>>>
>>> But net structure might be freed before all the dst callbacks are
>>> called. So when dst_destroy() calls later :
>>>
>>> if (dst->ops->destroy)
>>> dst->ops->destroy(dst);
>>>
>>> dst->ops points to the old net->xfrm.xfrm[46]_dst_ops, which has been freed.
>>>
>>> See a relevant issue fixed in :
>>>
>>> ac888d58869b ("net: do not delay dst_entries_add() in dst_release()")
>>>
>>> A fix is to queue the 'struct net' to be freed after one
>>> another cleanup_net() round (and existing rcu_barrier())
>>>
>>> [1]
>>
>> <snip>
>>
>> Hi, Eric. Thanks for the patch!
>>
>> Though I tried to test it by applying directly on top of v6.12 tag, but I got
>> the following UAF shortly after booting the kernel. Seems like podman service
>> was initializing something and creating namespaces for that.
>>
>> I can try applying the change on top of net tree, if that helps.
>>
>> Best regards, Ilya Maximets.
>
> Oh right, a llist_for_each_entry_safe() should be better I think.
>
> diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
> index 2d98539f378ee4f1a9c0074381a155cff8024da3..70fea7c1a4b0a4fdbd0dd5d5acb7c6d786553996
> 100644
> --- a/net/core/net_namespace.c
> +++ b/net/core/net_namespace.c
> @@ -448,12 +448,12 @@ static LLIST_HEAD(defer_free_list);
> static void net_complete_free(void)
> {
> struct llist_node *kill_list;
> - struct net *net;
> + struct net *net, *next;
>
> /* Get the list of namespaces to free from last round. */
> kill_list = llist_del_all(&defer_free_list);
>
> - llist_for_each_entry(net, kill_list, defer_free_list)
> + llist_for_each_entry_safe(net, next, kill_list, defer_free_list)
> kmem_cache_free(net_cachep, net);
>
> }
Tried with the above change applied. With it I see neither of the
use-after-free issues. So, it seems to be working fine.
So, for the patch + the diff above:
Tested-by: Ilya Maximets <i.maximets@....org>
Note: For some reason I can't boot the 'net/main' kernel (something
about being unable to verify modules, didn't have much time to debug),
so I tested on top of v6.12 tag.
Best regards, Ilya Maximets.
Powered by blists - more mailing lists