lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Tue, 17 Oct 2023 09:51:02 +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

Mon, Oct 16, 2023 at 10:16:55PM CEST, kuba@...nel.org wrote:
>Altnames are accessed under RCU (__dev_get_by_name())

dev_get_by_name_rcu()


>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.


>points. Subsequent patch will remove the one added on device
>deletion path.
>
>Fixes: ff92741270bf ("net: introduce name_node struct to be used in hashlist")
>Signed-off-by: Jakub Kicinski <kuba@...nel.org>
>---
>CC: jiri@...nulli.us
>---
> net/core/dev.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
>diff --git a/net/core/dev.c b/net/core/dev.c
>index f4fa2692cf6d..7d5107cd5792 100644
>--- a/net/core/dev.c
>+++ b/net/core/dev.c
>@@ -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);
> }
>@@ -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;
>@@ -10937,6 +10938,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. */
>@@ -10964,6 +10966,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);
> 
>-- 
>2.41.0
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ