diff options
author | Eric Dumazet <edumazet@google.com> | 2022-01-31 17:21:06 -0800 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-02-05 12:38:59 +0100 |
commit | def5e7070079b2a214b3b1a2fbec623e6fbfe34a (patch) | |
tree | 616ccae441908990ece581e31f9d1315bb056bb9 /net/core | |
parent | f36cacd6c933183c1a8827d5987cf2cfc0a44c76 (diff) | |
download | linux-stable-def5e7070079b2a214b3b1a2fbec623e6fbfe34a.tar.gz linux-stable-def5e7070079b2a214b3b1a2fbec623e6fbfe34a.tar.bz2 linux-stable-def5e7070079b2a214b3b1a2fbec623e6fbfe34a.zip |
rtnetlink: make sure to refresh master_dev/m_ops in __rtnl_newlink()
commit c6f6f2444bdbe0079e41914a35081530d0409963 upstream.
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: ba7d49b1f0f8 ("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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/rtnetlink.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 8ccce85562a1..198cc8b74dc3 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -3254,8 +3254,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]; @@ -3293,6 +3293,8 @@ replay: else dev = NULL; + master_dev = NULL; + m_ops = NULL; if (dev) { master_dev = netdev_master_upper_dev_get(dev); if (master_dev) |