[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZS6yBP+aZk67q8Tc@nanopsycho>
Date: Tue, 17 Oct 2023 18:10:44 +0200
From: Jiri Pirko <jiri@...nulli.us>
To: Jakub Kicinski <kuba@...nel.org>
Cc: davem@...emloft.net, netdev@...r.kernel.org, edumazet@...gle.com,
pabeni@...hat.com
Subject: Re: [PATCH net 3/5] net: avoid UAF on deleted altname
Tue, Oct 17, 2023 at 04:52:59PM CEST, kuba@...nel.org wrote:
>On Tue, 17 Oct 2023 09:51:02 +0200 Jiri Pirko wrote:
>> >but freed by kfree() with no synchronization point.
>> >
>> >Because the name nodes don't hold a reference on the netdevice
>> >either, take the heavier approach of inserting synchronization
>>
>> What about to use kfree_rcu() in netdev_name_node_free()
>> and treat node_name->dev as a rcu pointer instead?
>>
>> struct net_device *dev_get_by_name_rcu(struct net *net, const char *name)
>> {
>> struct netdev_name_node *node_name;
>>
>> node_name = netdev_name_node_lookup_rcu(net, name);
>> return node_name ? rcu_deferecence(node_name->dev) : NULL;
>> }
>>
>> This would avoid synchronize_rcu() in netdev_name_node_alt_destroy()
>>
>> Btw, the next patch is smooth with this.
>
>As I said in the commit message, I prefer the explicit sync.
>Re-inserting the device and taking refs already necessitate it.
You don't need any ref, just rcu_dereference() the netdev pointer.
Synchronize_rcu() should be avoided if possible.
Powered by blists - more mailing lists