Skip to content

Commit c6f6f24

Browse files
edumazetkuba-moo
authored andcommitted
rtnetlink: make sure to refresh master_dev/m_ops in __rtnl_newlink()
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: ba7d49b ("rtnetlink: provide api for getting and setting slave info") Signed-off-by: Eric Dumazet <[email protected]> Cc: Jiri Pirko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 04c2a47 commit c6f6f24

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

net/core/rtnetlink.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,8 +3275,8 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
32753275
struct nlattr *slave_attr[RTNL_SLAVE_MAX_TYPE + 1];
32763276
unsigned char name_assign_type = NET_NAME_USER;
32773277
struct nlattr *linkinfo[IFLA_INFO_MAX + 1];
3278-
const struct rtnl_link_ops *m_ops = NULL;
3279-
struct net_device *master_dev = NULL;
3278+
const struct rtnl_link_ops *m_ops;
3279+
struct net_device *master_dev;
32803280
struct net *net = sock_net(skb->sk);
32813281
const struct rtnl_link_ops *ops;
32823282
struct nlattr *tb[IFLA_MAX + 1];
@@ -3314,6 +3314,8 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
33143314
else
33153315
dev = NULL;
33163316

3317+
master_dev = NULL;
3318+
m_ops = NULL;
33173319
if (dev) {
33183320
master_dev = netdev_master_upper_dev_get(dev);
33193321
if (master_dev)

0 commit comments

Comments
 (0)