tipc: fix UAF race in tipc_mon_peer_up/down/remove_peer vs bearer teardown
Subsystems (4)
PATCH 1/1 tipc: fix UAF race in tipc_mon_peer_up/down/remove_peer vs bearer teardown
From: Kai Aizen <[email protected]>
CVE-2025-40280 fixed tipc_mon_reinit_self() accessing monitors[] from a workqueue without RTNL. That patch closed the workqueue path by adding rtnl_lock() around the call.
However, three additional functions in the same subsystem access tipc_net->monitors[] from softirq context with no RCU protection at all:
tipc_mon_peer_up() - called from tipc_node_write_unlock() tipc_mon_peer_down() - called from tipc_node_write_unlock() tipc_mon_remove_peer() - called from tipc_node_link_down()
These three are invoked from the packet receive path (tipc_rcv -> tipc_node_write_unlock / tipc_node_link_down) and hold only the per-node rwlock, not RTNL.
Concurrently, bearer_disable() -- which always holds RTNL per its own inline documentation -- calls tipc_mon_delete(), which:
1. acquires mon->lock
2. sets tn->monitors[bearer_id] = NULL
3. frees all peer entries
4. releases mon->lock
5. calls kfree(mon) <-- no synchronize_rcu()
The race is structural: there is no shared lock between the data-path reader (which reads monitors[id] then acquires mon->lock) and the teardown path (which acquires mon->lock, NULLs the slot, then frees). A softirq thread can read a non-NULL mon pointer, get preempted, and resume after kfree(mon) has run on another CPU, then call write_lock_bh(&mon->lock) on freed memory:
CPU 0 (softirq / tipc_rcv) CPU 1 (RTNL / bearer_disable)
tipc_mon_peer_up()
mon = tipc_monitor(net, id)
[mon is non-NULL]
tipc_mon_delete()
write_lock_bh(&mon->lock)
tn->monitors[id] = NULL
...
write_unlock_bh(&mon->lock)
kfree(mon)
write_lock_bh(&mon->lock) <-- UAFThe fix mirrors the existing bearer_list[] pattern in the same module:
convert monitors[] to __rcu, use rcu_assign_pointer() on creation, RCU_INIT_POINTER() + synchronize_rcu() on deletion (before the kfree), and the appropriate rcu_dereference_bh() vs rtnl_dereference() variant at each read site depending on execution context.
synchronize_rcu() in tipc_mon_delete() is placed after the write_unlock_bh() and before timer_shutdown_sync() + kfree() to ensure all softirq-context readers that already observed the old pointer have completed before the memory is freed.
--- net/tipc/core.h | 2 +- net/tipc/monitor.c | 45 +++++++++++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 17 deletions(-)
net/tipc/core.h +1 -1
@@ -109,7 +109,7 @@ struct tipc_net {u32 num_links;/* Neighbor monitoring list */ -struct tipc_monitor *monitors[MAX_BEARERS ]; +struct tipc_monitor __rcu *monitors[MAX_BEARERS ];int mon_threshold;/* Bearer list */
net/tipc/monitor.c +29 -16
142 lines not on this page · raw message
Signature · 1 line
2.43.0
syzbot ci has tested the following series
syzbot ci has tested the following series
[v1] [PATCH net] tipc: fix UAF race in tipc_mon_peer_up/down/remove_peer vs bearer teardown
https://lore.kernel.org/all/20260415061211.45530-1-95986478+SnailSploit@users.noreply.github.com
* [PATCH] [PATCH net] tipc: fix UAF race in tipc_mon_peer_up/down/remove_peer vs bearer teardown
and found the following issue:
WARNING: suspicious RCU usage in tipc_mon_delete
Full report is available here:
https://ci.syzbot.org/series/6267bc07-4172-4821-b3e5-dac381479d9d
***
WARNING: suspicious RCU usage in tipc_mon_delete
tree: net-next URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/netdev/net-next.git base: 35c2c39832e569449b9192fa1afbbc4c66227af7 arch: amd64 compiler: Debian clang version 21.1.8 (++20251221033036+2078da43e25a-1~exp1~20251221153213.50), Debian LLD 21.1.8 config: https://ci.syzbot.org/builds/a29dabe7-96d8-4072-bc2c-d798a349301e/config syz repro: https://ci.syzbot.org/findings/f144d75a-7c29-41a1-988e-09892a89baa1/syz_repro
tipc: Disabling bearer <eth:syzkaller0>
=============================
WARNING: suspicious RCU usage
syzkaller #0 Not tainted
-----------------------------net/tipc/monitor.c:108 suspicious rcu_dereference_check() usage!
other info that might help us debug this:
rcu_scheduler_active = 2, debug_locks = 1
1 lock held by syz.2.19/5962:
#0: ffffffff8fbcba48 (rtnl_mutex){+.+.}-{4:4}, at: tun_detach drivers/net/tun.c:634 [inline] #0: ffffffff8fbcba48 (rtnl_mutex){+.+.}-{4:4}, at: tun_chr_close+0x3e/0x1c0 drivers/net/tun.c:3438
stack backtrace: CPU: 1 UID: 0 PID: 5962 Comm: syz.2.19 Not tainted syzkaller #0 PREEMPT(full) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 lockdep_rcu_suspicious+0x13f/0x1d0 kernel/locking/lockdep.c:6876 tipc_monitor_rcu_bh+0xf5/0x110 net/tipc/monitor.c:108 get_self net/tipc/monitor.c:209 [inline] tipc_mon_delete+0x10b/0x4d0 net/tipc/monitor.c:704 tipc_l2_device_event+0x370/0x680 net/tipc/bearer.c:-1 notifier_call_chain+0x1be/0x400 kernel/notifier.c:85 call_netdevice_notifiers_extack net/core/dev.c:2287 [inline] call_netdevice_notifiers net/core/dev.c:2301 [inline] unregister_netdevice_many_notify+0x17a5/0x22c0 net/core/dev.c:12464 unregister_netdevice_many net/core/dev.c:12527 [inline] unregister_netdevice_queue+0x31f/0x360 net/core/dev.c:12337 unregister_netdevice include/linux/netdevice.h:3427 [inline] __tun_detach+0x6d9/0x15d0 drivers/net/tun.c:621 tun_detach drivers/net/tun.c:637 [inline] tun_chr_close+0x10a/0x1c0 drivers/net/tun.c:3438 __fput+0x44f/0xa70 fs/file_table.c:469 task_work_run+0x1d9/0x270 kernel/task_work.c:233 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline] __exit_to_user_mode_loop kernel/entry/common.c:67 [inline] exit_to_user_mode_loop+0xed/0x480 kernel/entry/common.c:98 __exit_to_user_mode_prepare include/linux/irq-entry-common.h:226 [inline] syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:256 [inline] syscall_exit_to_user_mode include/linux/entry-common.h:325 [inline] do_syscall_64+0x32d/0xf80 arch/x86/entry/syscall_64.c:100 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f7b26d9c819 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffec30cee78 EFLAGS: 00000246 ORIG_RAX: 00000000000001b4 RAX: 0000000000000000 RBX: 00007ffec30cef60 RCX: 00007f7b26d9c819 RDX: 0000000000000000 RSI: 000000000000001e RDI: 0000000000000003 RBP: 0000000000011900 R08: 0000000000000001 R09: 0000000000000000 R10: 0000001b2e520000 R11: 0000000000000246 R12: 00007ffec30cefa0 R13: 00007f7b27015fac R14: 000000000001193b R15: 00007f7b27015fa0 </TASK>
***
If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message:
---
This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at [email protected].
To test a patch for this bug, please reply with #syz test (should be on a separate line).
The patch should be attached to the email.
Note: arguments like custom git repos and branches are not supported.
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi SnailSploit,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net/main]
url: https://github.com/intel-lab-lkp/linux/commits/SnailSploit-Kai-Aizen/tipc-fix-UAF-race-in-tipc_mon_peer_up-down-remove_peer-vs-bearer-teardown/20260425-075205 base: net/main patch link: https://lore.kernel.org/r/20260415061211.45530-1-95986478%2BSnailSploit%40users.noreply.github.com patch subject: [PATCH] [PATCH net] tipc: fix UAF race in tipc_mon_peer_up/down/remove_peer vs bearer teardown config: arc-randconfig-002-20260430 (https://download.01.org/0day-ci/archive/20260430/[email protected]/config) compiler: arc-linux-gcc (GCC) 8.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260430/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> net/tipc/monitor.c:112:29: warning: 'tipc_monitor_rtnl' defined but not used [-Wunused-function]
static struct tipc_monitor *tipc_monitor_rtnl(struct net *net, int bearer_id)
^~~~~~~~~~~~~~~~~
vim +/tipc_monitor_rtnl +112 net/tipc/monitor.c
110
111 /* tipc_monitor_rtnl - dereference monitors[] from RTNL-held control path. */
> 112 static struct tipc_monitor *tipc_monitor_rtnl(struct net *net, int bearer_id)
113 {
114 return rtnl_dereference(tipc_net(net)->monitors[bearer_id]);
115 }
116
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki