From: Ilya Maximets <i.maximets@ovn.org>
To: Eric Dumazet <edumazet@google.com>
Cc: i.maximets@ovn.org, "David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
netdev@vger.kernel.org, eric.dumazet@gmail.com,
Dan Streetman <dan.streetman@canonical.com>,
Steffen Klassert <steffen.klassert@secunet.com>
Subject: Re: [PATCH net] net: defer final 'struct net' free in netns dismantle
Date: Tue, 3 Dec 2024 23:01:20 +0100 [thread overview]
Message-ID: <aa2a710f-d481-4d96-b3fe-358596bbd6f2@ovn.org> (raw)
In-Reply-To: <CANn89iLT6oAA-x+KX=sCAANBZKi1K52gOy-VW0hmofbO3GEhtw@mail.gmail.com>
On 12/3/24 19:33, Eric Dumazet wrote:
> On Tue, Dec 3, 2024 at 7:23 PM Ilya Maximets <i.maximets@ovn.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@ovn.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.
next prev parent reply other threads:[~2024-12-03 22:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-03 16:50 [PATCH net] net: defer final 'struct net' free in netns dismantle Eric Dumazet
2024-12-03 18:23 ` Ilya Maximets
2024-12-03 18:33 ` Eric Dumazet
2024-12-03 22:01 ` Ilya Maximets [this message]
2024-12-03 21:04 ` Stanislav Fomichev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aa2a710f-d481-4d96-b3fe-358596bbd6f2@ovn.org \
--to=i.maximets@ovn.org \
--cc=dan.streetman@canonical.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eric.dumazet@gmail.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=steffen.klassert@secunet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.