Subject: Re: [PATCH net 3/5] net: avoid UAF on deleted altname

From: Jakub Kicinski <[email-masked]>
Date: Tue, 17 Oct 2023 07:52:59 -0700

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.