* [PATCH net] rtnetlink: fix rtnl_dump_ifinfo() error path
@ 2024-11-21 19:41 Eric Dumazet
2024-11-21 20:41 ` Joe Damato
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Eric Dumazet @ 2024-11-21 19:41 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni
Cc: netdev, eric.dumazet, Eric Dumazet, syzbot, Kuniyuki Iwashima
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: 43c7ce69d28e ("rtnetlink: Protect struct rtnl_link_ops with SRCU.")
Reported-by: syzbot <syzkaller@googlegroups.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
---
net/core/rtnetlink.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index dd142f444659d9a5da084bddb26736b1602cc2cb..58df76fe408a4677db52a3c1f94674119dc4c925 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2442,7 +2442,9 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
tgt_net = rtnl_get_net_ns_capable(skb->sk, netnsid);
if (IS_ERR(tgt_net)) {
NL_SET_ERR_MSG(extack, "Invalid target network namespace id");
- return PTR_ERR(tgt_net);
+ err = PTR_ERR(tgt_net);
+ netnsid = -1;
+ goto out;
}
break;
case IFLA_EXT_MASK:
@@ -2457,7 +2459,8 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
default:
if (cb->strict_check) {
NL_SET_ERR_MSG(extack, "Unsupported attribute in link dump request");
- return -EINVAL;
+ err = -EINVAL;
+ goto out;
}
}
}
@@ -2479,11 +2482,14 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
break;
}
- if (kind_ops)
- rtnl_link_ops_put(kind_ops, ops_srcu_index);
cb->seq = tgt_net->dev_base_seq;
nl_dump_check_consistent(cb, nlmsg_hdr(skb));
+
+out:
+
+ if (kind_ops)
+ rtnl_link_ops_put(kind_ops, ops_srcu_index);
if (netnsid >= 0)
put_net(tgt_net);
--
2.47.0.371.ga323438b13-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH net] rtnetlink: fix rtnl_dump_ifinfo() error path
2024-11-21 19:41 [PATCH net] rtnetlink: fix rtnl_dump_ifinfo() error path Eric Dumazet
@ 2024-11-21 20:41 ` Joe Damato
2024-11-21 21:32 ` Kuniyuki Iwashima
2024-11-25 0:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Joe Damato @ 2024-11-21 20:41 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
eric.dumazet, syzbot, Kuniyuki Iwashima
On Thu, Nov 21, 2024 at 07:41:05PM +0000, Eric Dumazet wrote:
> 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: 43c7ce69d28e ("rtnetlink: Protect struct rtnl_link_ops with SRCU.")
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: Joe Damato <jdamato@fastly.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] rtnetlink: fix rtnl_dump_ifinfo() error path
2024-11-21 19:41 [PATCH net] rtnetlink: fix rtnl_dump_ifinfo() error path Eric Dumazet
2024-11-21 20:41 ` Joe Damato
@ 2024-11-21 21:32 ` Kuniyuki Iwashima
2024-11-25 0:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Kuniyuki Iwashima @ 2024-11-21 21:32 UTC (permalink / raw)
To: edumazet; +Cc: davem, eric.dumazet, kuba, kuniyu, netdev, pabeni, syzkaller
From: Eric Dumazet <edumazet@google.com>
Date: Thu, 21 Nov 2024 19:41:05 +0000
> 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: 43c7ce69d28e ("rtnetlink: Protect struct rtnl_link_ops with SRCU.")
> Reported-by: syzbot <syzkaller@googlegroups.com>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
I missed the error paths, thanks!
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] rtnetlink: fix rtnl_dump_ifinfo() error path
2024-11-21 19:41 [PATCH net] rtnetlink: fix rtnl_dump_ifinfo() error path Eric Dumazet
2024-11-21 20:41 ` Joe Damato
2024-11-21 21:32 ` Kuniyuki Iwashima
@ 2024-11-25 0:50 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-11-25 0:50 UTC (permalink / raw)
To: Eric Dumazet; +Cc: davem, kuba, pabeni, netdev, eric.dumazet, syzkaller, kuniyu
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Thu, 21 Nov 2024 19:41:05 +0000 you wrote:
> 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
>
> [...]
Here is the summary with links:
- [net] rtnetlink: fix rtnl_dump_ifinfo() error path
https://git.kernel.org/netdev/net/c/9b234a97b10c
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-11-25 0:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-21 19:41 [PATCH net] rtnetlink: fix rtnl_dump_ifinfo() error path Eric Dumazet
2024-11-21 20:41 ` Joe Damato
2024-11-21 21:32 ` Kuniyuki Iwashima
2024-11-25 0:50 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox