]> git.baikalelectronics.ru Git - kernel.git/commitdiff
rtnetlink: make sure to refresh master_dev/m_ops in __rtnl_newlink()
authorEric Dumazet <edumazet@google.com>
Tue, 1 Feb 2022 01:21:06 +0000 (17:21 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 2 Feb 2022 04:19:00 +0000 (20:19 -0800)
While looking at one unrelated syzbot bug, I found the replay logic
in __rtnl_newlink() to potentially trigger use-after-free.

It is better to clear master_dev and m_ops inside the loop,
in case we have to replay it.

Fixes: 47b8fbf467a7 ("rtnetlink: provide api for getting and setting slave info")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Jiri Pirko <jiri@nvidia.com>
Link: https://lore.kernel.org/r/20220201012106.216495-1-eric.dumazet@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/rtnetlink.c

index e476403231f00053e1a261f31a8760325c75c941..710da8a36729d6a9293b610b029bd33aa38d6514 100644 (file)
@@ -3275,8 +3275,8 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
        struct nlattr *slave_attr[RTNL_SLAVE_MAX_TYPE + 1];
        unsigned char name_assign_type = NET_NAME_USER;
        struct nlattr *linkinfo[IFLA_INFO_MAX + 1];
-       const struct rtnl_link_ops *m_ops = NULL;
-       struct net_device *master_dev = NULL;
+       const struct rtnl_link_ops *m_ops;
+       struct net_device *master_dev;
        struct net *net = sock_net(skb->sk);
        const struct rtnl_link_ops *ops;
        struct nlattr *tb[IFLA_MAX + 1];
@@ -3314,6 +3314,8 @@ replay:
        else
                dev = NULL;
 
+       master_dev = NULL;
+       m_ops = NULL;
        if (dev) {
                master_dev = netdev_master_upper_dev_get(dev);
                if (master_dev)