]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mpls: Pass net to mpls_dev_get().
authorKuniyuki Iwashima <kuniyu@google.com>
Wed, 29 Oct 2025 17:32:59 +0000 (17:32 +0000)
committerJakub Kicinski <kuba@kernel.org>
Tue, 4 Nov 2025 01:40:48 +0000 (17:40 -0800)
We will replace RTNL with a per-netns mutex to protect dev->mpls_ptr.

Then, we will use rcu_dereference_protected() with the lockdep_is_held()
annotation, which requires net to access the per-netns mutex.

However, dev_net(dev) is not safe without RTNL.

Let's pass net to mpls_dev_get().

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Reviewed-by: Guillaume Nault <gnault@redhat.com>
Link: https://patch.msgid.link/20251029173344.2934622-8-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/mpls/af_mpls.c
net/mpls/internal.h

index 10130b90c439a5b903b858cf9c8dfde4a124a69a..a715b12860e957aa40416761aed58fb739582724 100644 (file)
@@ -708,7 +708,7 @@ static int mpls_nh_assign_dev(struct net *net, struct mpls_route *rt,
 
        /* Ensure this is a supported device */
        err = -EINVAL;
-       if (!mpls_dev_get(dev))
+       if (!mpls_dev_get(net, dev))
                goto errout_put;
 
        if ((nh->nh_via_table == NEIGH_LINK_TABLE) &&
@@ -1288,7 +1288,7 @@ static int mpls_netconf_get_devconf(struct sk_buff *in_skb,
        if (!dev)
                goto errout;
 
-       mdev = mpls_dev_get(dev);
+       mdev = mpls_dev_get(net, dev);
        if (!mdev)
                goto errout;
 
@@ -1611,6 +1611,7 @@ static int mpls_dev_notify(struct notifier_block *this, unsigned long event,
                           void *ptr)
 {
        struct net_device *dev = netdev_notifier_info_to_dev(ptr);
+       struct net *net = dev_net(dev);
        struct mpls_dev *mdev;
        unsigned int flags;
        int err;
@@ -1625,7 +1626,7 @@ static int mpls_dev_notify(struct notifier_block *this, unsigned long event,
                goto out;
        }
 
-       mdev = mpls_dev_get(dev);
+       mdev = mpls_dev_get(net, dev);
        if (!mdev)
                goto out;
 
@@ -1658,7 +1659,7 @@ static int mpls_dev_notify(struct notifier_block *this, unsigned long event,
                if (err)
                        goto err;
 
-               mdev = mpls_dev_get(dev);
+               mdev = mpls_dev_get(net, dev);
                if (mdev) {
                        mpls_dev_sysctl_unregister(dev, mdev);
                        RCU_INIT_POINTER(dev->mpls_ptr, NULL);
@@ -1666,7 +1667,7 @@ static int mpls_dev_notify(struct notifier_block *this, unsigned long event,
                }
                break;
        case NETDEV_CHANGENAME:
-               mdev = mpls_dev_get(dev);
+               mdev = mpls_dev_get(net, dev);
                if (mdev) {
                        mpls_dev_sysctl_unregister(dev, mdev);
                        err = mpls_dev_sysctl_register(dev, mdev);
index 080e820100222a196826fbeb7ca18c5965762d72..0df01a5395eea1ba8efe7b80a4db1ff384d160b6 100644 (file)
@@ -190,7 +190,8 @@ static inline struct mpls_dev *mpls_dev_rcu(const struct net_device *dev)
        return rcu_dereference(dev->mpls_ptr);
 }
 
-static inline struct mpls_dev *mpls_dev_get(const struct net_device *dev)
+static inline struct mpls_dev *mpls_dev_get(const struct net *net,
+                                           const struct net_device *dev)
 {
        return rcu_dereference_rtnl(dev->mpls_ptr);
 }