netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net, netdev@vger.kernel.org, edumazet@google.com,
	pabeni@redhat.com
Subject: Re: [PATCH net 3/5] net: avoid UAF on deleted altname
Date: Tue, 17 Oct 2023 09:51:02 +0200	[thread overview]
Message-ID: <ZS485sWKKb99KrBx@nanopsycho> (raw)
In-Reply-To: <20231016201657.1754763-4-kuba@kernel.org>

Mon, Oct 16, 2023 at 10:16:55PM CEST, kuba@kernel.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@kernel.org>
>---
>CC: jiri@resnulli.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
>

  reply	other threads:[~2023-10-17  7:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-16 20:16 [PATCH net 0/5] net: fix bugs in device netns-move and rename Jakub Kicinski
2023-10-16 20:16 ` [PATCH net 1/5] net: fix ifname in netlink ntf during netns move Jakub Kicinski
2023-10-16 20:21   ` Jakub Kicinski
2023-10-16 20:16 ` [PATCH net 2/5] net: check for altname conflicts when changing netdev's netns Jakub Kicinski
2023-10-17  7:21   ` Jiri Pirko
2023-10-16 20:16 ` [PATCH net 3/5] net: avoid UAF on deleted altname Jakub Kicinski
2023-10-17  7:51   ` Jiri Pirko [this message]
2023-10-17 14:52     ` Jakub Kicinski
2023-10-17 16:10       ` Jiri Pirko
2023-10-17 16:35         ` Jiri Pirko
2023-10-17 18:07           ` Jakub Kicinski
2023-10-16 20:16 ` [PATCH net 4/5] net: move altnames together with the netdevice Jakub Kicinski
2023-10-17  7:51   ` Jiri Pirko
2023-10-16 20:16 ` [PATCH net 5/5] selftests: net: add very basic test for netdev names and namespaces Jakub Kicinski
2023-10-17 11:25   ` Przemek Kitszel
2023-10-17 14:58     ` Jakub Kicinski

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=ZS485sWKKb99KrBx@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).