Skip to content

Commit 9b234a9

Browse files
edumazetkuba-moo
authored andcommitted
rtnetlink: fix rtnl_dump_ifinfo() error path
syzbot found that rtnl_dump_ifinfo() could return with a lock held [1] Move code around so that rtnl_link_ops_put() and put_net() can be called at the end of this function. [1] WARNING: lock held when returning to user space! 6.12.0-rc7-syzkaller-01681-g38f83a57aa8e #0 Not tainted syz-executor399/5841 is leaving the kernel with locks still held! 1 lock held by syz-executor399/5841: #0: ffffffff8f46c2a0 (&ops->srcu#2){.+.+}-{0:0}, at: rcu_lock_acquire include/linux/rcupdate.h:337 [inline] #0: ffffffff8f46c2a0 (&ops->srcu#2){.+.+}-{0:0}, at: rcu_read_lock include/linux/rcupdate.h:849 [inline] #0: ffffffff8f46c2a0 (&ops->srcu#2){.+.+}-{0:0}, at: rtnl_link_ops_get+0x22/0x250 net/core/rtnetlink.c:555 Fixes: 43c7ce6 ("rtnetlink: Protect struct rtnl_link_ops with SRCU.") Reported-by: syzbot <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Joe Damato <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 078f644 commit 9b234a9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

net/core/rtnetlink.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,7 +2442,9 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
24422442
tgt_net = rtnl_get_net_ns_capable(skb->sk, netnsid);
24432443
if (IS_ERR(tgt_net)) {
24442444
NL_SET_ERR_MSG(extack, "Invalid target network namespace id");
2445-
return PTR_ERR(tgt_net);
2445+
err = PTR_ERR(tgt_net);
2446+
netnsid = -1;
2447+
goto out;
24462448
}
24472449
break;
24482450
case IFLA_EXT_MASK:
@@ -2457,7 +2459,8 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
24572459
default:
24582460
if (cb->strict_check) {
24592461
NL_SET_ERR_MSG(extack, "Unsupported attribute in link dump request");
2460-
return -EINVAL;
2462+
err = -EINVAL;
2463+
goto out;
24612464
}
24622465
}
24632466
}
@@ -2479,11 +2482,14 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
24792482
break;
24802483
}
24812484

2482-
if (kind_ops)
2483-
rtnl_link_ops_put(kind_ops, ops_srcu_index);
24842485

24852486
cb->seq = tgt_net->dev_base_seq;
24862487
nl_dump_check_consistent(cb, nlmsg_hdr(skb));
2488+
2489+
out:
2490+
2491+
if (kind_ops)
2492+
rtnl_link_ops_put(kind_ops, ops_srcu_index);
24872493
if (netnsid >= 0)
24882494
put_net(tgt_net);
24892495

0 commit comments

Comments
 (0)