Skip to content

Commit 38a1f50

Browse files
edumazetkuba-moo
authored andcommitted
phonet: do not call synchronize_rcu() from phonet_route_del()
Calling synchronize_rcu() while holding rcu_read_lock() is not permitted [1] Move the synchronize_rcu() + dev_put() to route_doit(). Alternative would be to not use rcu_read_lock() in route_doit(). [1] WARNING: suspicious RCU usage 6.12.0-rc5-syzkaller-01056-gf07a6e6ceb05 #0 Not tainted ----------------------------- kernel/rcu/tree.c:4092 Illegal synchronize_rcu() in RCU read-side critical section! other info that might help us debug this: rcu_scheduler_active = 2, debug_locks = 1 1 lock held by syz-executor427/5840: #0: ffffffff8e937da0 (rcu_read_lock){....}-{1:2}, at: rcu_lock_acquire include/linux/rcupdate.h:337 [inline] #0: ffffffff8e937da0 (rcu_read_lock){....}-{1:2}, at: rcu_read_lock include/linux/rcupdate.h:849 [inline] #0: ffffffff8e937da0 (rcu_read_lock){....}-{1:2}, at: route_doit+0x3d6/0x640 net/phonet/pn_netlink.c:264 stack backtrace: CPU: 1 UID: 0 PID: 5840 Comm: syz-executor427 Not tainted 6.12.0-rc5-syzkaller-01056-gf07a6e6ceb05 #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x241/0x360 lib/dump_stack.c:120 lockdep_rcu_suspicious+0x226/0x340 kernel/locking/lockdep.c:6821 synchronize_rcu+0xea/0x360 kernel/rcu/tree.c:4089 phonet_route_del+0xc6/0x140 net/phonet/pn_dev.c:409 route_doit+0x514/0x640 net/phonet/pn_netlink.c:275 rtnetlink_rcv_msg+0x791/0xcf0 net/core/rtnetlink.c:6790 netlink_rcv_skb+0x1e3/0x430 net/netlink/af_netlink.c:2551 netlink_unicast_kernel net/netlink/af_netlink.c:1331 [inline] netlink_unicast+0x7f6/0x990 net/netlink/af_netlink.c:1357 netlink_sendmsg+0x8e4/0xcb0 net/netlink/af_netlink.c:1901 sock_sendmsg_nosec net/socket.c:729 [inline] __sock_sendmsg+0x221/0x270 net/socket.c:744 sock_write_iter+0x2d7/0x3f0 net/socket.c:1165 new_sync_write fs/read_write.c:590 [inline] vfs_write+0xaeb/0xd30 fs/read_write.c:683 ksys_write+0x183/0x2b0 fs/read_write.c:736 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f Fixes: 17a1ac0 ("phonet: Don't hold RTNL for route_doit().") Reported-by: syzbot <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Cc: Remi Denis-Courmont <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 48171c6 commit 38a1f50

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

net/phonet/pn_dev.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,9 @@ int phonet_route_del(struct net_device *dev, u8 daddr)
406406

407407
if (!dev)
408408
return -ENOENT;
409-
synchronize_rcu();
410-
dev_put(dev);
409+
410+
/* Note : our caller must call synchronize_rcu() and dev_put(dev) */
411+
411412
return 0;
412413
}
413414

net/phonet/pn_netlink.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
233233
{
234234
struct net *net = sock_net(skb->sk);
235235
struct nlattr *tb[RTA_MAX+1];
236+
bool sync_needed = false;
236237
struct net_device *dev;
237238
struct rtmsg *rtm;
238239
u32 ifindex;
@@ -269,13 +270,20 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
269270
return -ENODEV;
270271
}
271272

272-
if (nlh->nlmsg_type == RTM_NEWROUTE)
273+
if (nlh->nlmsg_type == RTM_NEWROUTE) {
273274
err = phonet_route_add(dev, dst);
274-
else
275+
} else {
275276
err = phonet_route_del(dev, dst);
277+
if (!err)
278+
sync_needed = true;
279+
}
276280

277281
rcu_read_unlock();
278282

283+
if (sync_needed) {
284+
synchronize_rcu();
285+
dev_put(dev);
286+
}
279287
if (!err)
280288
rtm_phonet_notify(net, nlh->nlmsg_type, ifindex, dst);
281289

0 commit comments

Comments
 (0)