Skip to content

Commit

Permalink
net: avoid UAF on deleted altname
Browse files Browse the repository at this point in the history
Altnames are accessed under RCU (dev_get_by_name_rcu())
but freed by kfree() with no synchronization point.

Each node has one or two allocations (node and a variable-size
name, sometimes the name is netdev->name). Adding rcu_heads
here is a bit tedious. Besides most code which unlists the names
already has rcu barriers - so take the simpler approach of adding
synchronize_rcu(). Note that the one on the unregistration path
(which matters more) is removed by the next fix.

Fixes: ff92741 ("net: introduce name_node struct to be used in hashlist")
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Jakub Kicinski authored and Paolo Abeni committed Oct 19, 2023
1 parent 7663d52 commit 1a83f4a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ int netdev_name_node_alt_create(struct net_device *dev, const char *name)
static void __netdev_name_node_alt_destroy(struct netdev_name_node *name_node)
{
list_del(&name_node->list);
netdev_name_node_del(name_node);
kfree(name_node->name);
netdev_name_node_free(name_node);
}
Expand All @@ -364,6 +363,8 @@ int netdev_name_node_alt_destroy(struct net_device *dev, const char *name)
if (name_node == dev->name_node || name_node->dev != dev)
return -EINVAL;

netdev_name_node_del(name_node);
synchronize_rcu();
__netdev_name_node_alt_destroy(name_node);

return 0;
Expand Down Expand Up @@ -10941,6 +10942,7 @@ void unregister_netdevice_many_notify(struct list_head *head,
synchronize_net();

list_for_each_entry(dev, head, unreg_list) {
struct netdev_name_node *name_node;
struct sk_buff *skb = NULL;

/* Shutdown queueing discipline. */
Expand Down Expand Up @@ -10968,6 +10970,9 @@ void unregister_netdevice_many_notify(struct list_head *head,
dev_uc_flush(dev);
dev_mc_flush(dev);

netdev_for_each_altname(dev, name_node)
netdev_name_node_del(name_node);
synchronize_rcu();
netdev_name_node_alt_flush(dev);
netdev_name_node_free(dev->name_node);

Expand Down

0 comments on commit 1a83f4a

Please sign in to comment.