tipc: hold a reference to nodes found by link name
Subsystems (4)
PATCH 1/1 tipc: hold a reference to nodes found by link name
tipc_node_find_by_name() returns a node after dropping its RCU read lock without taking a reference. The LINK_SET, LINK_GET and LINK_RESET_STATS handlers then lock and access the node, racing with timer-driven cleanup of a down peer. Generic netlink serialization does not exclude the node timer.
The following interleaving can leave a handler using a freed node:
CPU 0: find the node under RCU and release the node read lock CPU 1: tipc_node_timeout() clears the links and unlinks the down node CPU 1: drop the list and timer references, queuing tipc_node_free() CPU 0: leave the RCU read-side critical section
CPU 1: complete the grace period and free the node
CPU 0: acquire the node lock through the stale pointer
LINK_SET also uses the node's media address after releasing the node lock, when passing queued packets to tipc_bearer_xmit().
KASAN reported:
BUG: KASAN: slab-use-after-free in _raw_read_lock_bh+0x1d/0x40 Write of size 4 at addr ffff888112723808 by task poc/87 Call Trace: _raw_read_lock_bh+0x1d/0x40 tipc_nl_node_set_link+0x30e/0x680 genl_family_rcv_msg_doit+0x1e0/0x2c0 genl_rcv_msg+0x419/0x6d0 netlink_rcv_skb+0x11f/0x350 Allocated by task 28: tipc_node_create+0x9c1/0x1fa0 tipc_node_check_dest+0x121/0x11e0 tipc_disc_rcv+0xdbf/0x1430 Freed by task 87: kfree+0x149/0x330 rcu_core+0x50a/0x1850 Last potentially related work creation: __call_rcu_common.constprop.0+0x71/0xa10 tipc_node_timeout+0xb1b/0xe70
Acquire a reference to the selected node with kref_get_unless_zero() before leaving RCU, returning NULL if the node has already been released. Release that reference on every caller exit after the last node access, including transmission in LINK_SET. Keep the existing link lookup order and locking so concurrent link removal still takes the existing error paths.
--- net/tipc/node.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/tipc/node.c +7 -0
@@ -2424,6 +2424,8 @@ static struct tipc_node *tipc_node_find_by_name(struct net *net,if (found_node)break ; } +if (found_node && !kref_get_unless_zero (&found_node->kref)) + found_node =NULL ;rcu_read_unlock ();return found_node;
@@ -2507,6 +2509,7 @@ int tipc_nl_node_set_link(struct sk_buff *skb, struct genl_info *info)tipc_node_read_unlock (node);tipc_bearer_xmit (net, bearer_id, &xmitq, &node->links[bearer_id].maddr,NULL ); +tipc_node_put (node);return res; }
@@ -2558,12 +2561,14 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info) link = node->links[bearer_id].link;if (!link) {tipc_node_read_unlock (node); +tipc_node_put (node); err = -EINVAL ; goto err_free; } err =__tipc_nl_add_link (net, &msg, link,0 );tipc_node_read_unlock (node); +tipc_node_put (node);if (err) goto err_free; }
@@ -2634,11 +2639,13 @@ int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info)if (!link) {spin_unlock_bh (&le->lock);tipc_node_read_unlock (node); +tipc_node_put (node);return -EINVAL ; }tipc_link_reset_stats (link);spin_unlock_bh (&le->lock);tipc_node_read_unlock (node); +tipc_node_put (node);return 0 ; }
Signature · 1 line
2.43.0
Tung Quang Nguyen
maintainerQuoted 31 lines
Subject: [PATCH net] tipc: hold a reference to nodes found by link name
tipc_node_find_by_name()returns a node after dropping its RCU read lock without taking a reference. TheLINK_SET,LINK_GETandLINK_RESET_STATShandlers then lock and access the node, racing with timer-driven cleanup of a down peer. Generic netlink serialization does not exclude the node timer.The following interleaving can leave a handler using a freed node:
CPU 0: find the node under RCU and release the node read lock CPU 1:
tipc_node_timeout()clears the links and unlinks the down node CPU 1: drop the list and timer references, queuingtipc_node_free()CPU 0: leave the RCU read-side critical section
CPU 1: complete the grace period and free the node
CPU 0: acquire the node lock through the stale pointer
LINK_SETalso uses the node's media address after releasing the node lock, when passing queued packets totipc_bearer_xmit().KASAN reported:
BUG: KASAN: slab-use-after-free in _raw_read_lock_bh+0x1d/0x40 Write of size 4 at addr ffff888112723808 by task poc/87 Call Trace: _raw_read_lock_bh+0x1d/0x40 tipc_nl_node_set_link+0x30e/0x680 genl_family_rcv_msg_doit+0x1e0/0x2c0 genl_rcv_msg+0x419/0x6d0 netlink_rcv_skb+0x11f/0x350 Allocated by task 28: tipc_node_create+0x9c1/0x1fa0
Quoted 9 lines
tipc_node_check_dest+0x121/0x11e0 tipc_disc_rcv+0xdbf/0x1430 Freed by task 87: kfree+0x149/0x330 rcu_core+0x50a/0x1850 Last potentially related work creation: __call_rcu_common.constprop.0+0x71/0xa10 tipc_node_timeout+0xb1b/0xe70
Can you update your changelog with decoded stack trace ?
With decoded stack trace, It helps me understand how your reproducer triggers the issue.
Quoted 18 lines
Acquire a reference to the selected node with
kref_get_unless_zero()before leaving RCU, returning NULL if the node has already been released. Release that reference on every caller exit after the last node access, including transmission inLINK_SET. Keep the existing link lookup order and locking so concurrent link removal still takes the existing error paths.Fixes 6a939f365bdb ("tipc: Auto removal of peer down node instance")Signed-off-by Chengfeng Ye <[email protected]>---
net/tipc/node.c| 7 +++++++1 file changed, 7 insertions(+)net/tipc/node.c index renamed from net/tipc/node.c +0
-0
bd91378b7540..2726bee3bb40100644
net/tipc/node.c static struct tipc_node · line 2429
Quoted 6 lines
net/tipc/node.c +2
-0@@ -2424,6 +2424,8 @@ static struct tipc_node *tipc_node_find_by_name(struct net *net, if (found_node) break; } + if (found_node && !kref_get_unless_zero(&found_node->kref)) + found_node = NULL;
This checking is not optimal.
Try this:
net/tipc/node.c +4 -1
@@ -2421,8 +2421,11 @@ static struct tipc_node *tipc_node_find_by_name(struct net *net, } }tipc_node_read_unlock (n); -if (found_node) +if (found_node) { +if (!kref_get_unless_zero (&found_node->kref)) + found_node =NULL ;break ; + } }rcu_read_unlock ();
Quoted 46 lines
net/tipc/node.c +0
-0rcu_read_unlock ();return found_node;net/tipc/node.c +1
-0@@ -2507,6 +2509,7 @@ int tipc_nl_node_set_link(struct sk_buff *skb, struct genl_info *info)tipc_node_read_unlock (node );tipc_bearer_xmit (net, bearer_id, &xmitq, &node- >links[bearer_id].maddr,NULL ); +tipc_node_put (node);return res;}
net/tipc/node.c +2
-0@@ -2558,12 +2561,14 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info) link = node->links[bearer_id].link;if (!link) {tipc_node_read_unlock (node); +tipc_node_put (node); err = -EINVAL ; goto err_free; } err =__tipc_nl_add_link (net, &msg, link,0 );tipc_node_read_unlock (node); +tipc_node_put (node);if (err) goto err_free;}net/tipc/node.c +2
-1@@ -2634,11 +2639,13 @@ int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info)if (!link) {spin_unlock_bh (&le->lock);tipc_node_read_unlock (node); +tipc_node_put (node);return -EINVAL ; }tipc_link_reset_stats (link);spin_unlock_bh (&le->lock);tipc_node_read_unlock (node); +tipc_node_put (node);return 0 ; } --2.43.0
Quoted 42 lines · Tung Quang Nguyen
Quoted 32 lines
Subject: [PATCH net] tipc: hold a reference to nodes found by link name
tipc_node_find_by_name()returns a node after dropping its RCU read lock without taking a reference. TheLINK_SET,LINK_GETandLINK_RESET_STATShandlers then lock and access the node, racing with timer-driven cleanup of a down peer. Generic netlink serialization does not exclude the node timer.The following interleaving can leave a handler using a freed node:
CPU 0: find the node under RCU and release the node read lock CPU 1:
tipc_node_timeout()clears the links and unlinks the down node CPU 1: drop the list and timer references, queuingtipc_node_free()CPU 0: leave the RCU read-side critical section
CPU 1: complete the grace period and free the node
CPU 0: acquire the node lock through the stale pointer
LINK_SETalso uses the node's media address after releasing the node lock, when passing queued packets totipc_bearer_xmit().KASAN reported:
BUG: KASAN: slab-use-after-free in _raw_read_lock_bh+0x1d/0x40 Write of size 4 at addr ffff888112723808 by task poc/87 Call Trace: _raw_read_lock_bh+0x1d/0x40 tipc_nl_node_set_link+0x30e/0x680 genl_family_rcv_msg_doit+0x1e0/0x2c0 genl_rcv_msg+0x419/0x6d0 netlink_rcv_skb+0x11f/0x350 Allocated by task 28: tipc_node_create+0x9c1/0x1fa0Quoted 9 lines
tipc_node_check_dest+0x121/0x11e0 tipc_disc_rcv+0xdbf/0x1430 Freed by task 87: kfree+0x149/0x330 rcu_core+0x50a/0x1850 Last potentially related work creation: __call_rcu_common.constprop.0+0x71/0xa10 tipc_node_timeout+0xb1b/0xe70
Quoted 2 lines
Can you update your changelog with decoded stack trace ?
With decoded stack trace, It helps me understand how your reproducer triggers the issue.
The partial decoded stack trace is attached on the changelog on v2.
https://lore.kernel.org/netdev/[email protected]/T/#t
I will send you the full KASAN report as well as the reproduction method in a separate private email.
Quoted 90 lines
Quoted 18 lines
Acquire a reference to the selected node with
kref_get_unless_zero()before leaving RCU, returning NULL if the node has already been released. Release that reference on every caller exit after the last node access, including transmission inLINK_SET. Keep the existing link lookup order and locking so concurrent link removal still takes the existing error paths.Fixes 6a939f365bdb ("tipc: Auto removal of peer down node instance")Signed-off-by Chengfeng Ye <[email protected]>---
net/tipc/node.c| 7 +++++++1 file changed, 7 insertions(+)net/tipc/node.c index renamed from net/tipc/node.c +0
-0
bd91378b7540..2726bee3bb40100644net/tipc/node.c static struct tipc_node · line 2429
Quoted 6 lines
net/tipc/node.c +2
-0@@ -2424,6 +2424,8 @@ static struct tipc_node *tipc_node_find_by_name(struct net *net, if (found_node) break; } + if (found_node && !kref_get_unless_zero(&found_node->kref)) + found_node = NULL;This checking is not optimal.
Try this:net/tipc/node.c +4
-1@@ -2421,8 +2421,11 @@ static struct tipc_node *tipc_node_find_by_name(struct net *net, } }tipc_node_read_unlock (n); -if (found_node) +if (found_node) { +if (!kref_get_unless_zero (&found_node->kref)) + found_node =NULL ;break ; + } }rcu_read_unlock ();Quoted 44 lines
net/tipc/node.c +0
-0rcu_read_unlock ();return found_node;net/tipc/node.c +1
-0@@ -2507,6 +2509,7 @@ int tipc_nl_node_set_link(struct sk_buff *skb, struct genl_info *info)tipc_node_read_unlock (node );tipc_bearer_xmit (net, bearer_id, &xmitq, &node- >links[bearer_id].maddr,NULL ); +tipc_node_put (node);return res;}
net/tipc/node.c +2
-0@@ -2558,12 +2561,14 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info) link = node->links[bearer_id].link;if (!link) {tipc_node_read_unlock (node); +tipc_node_put (node); err = -EINVAL ; goto err_free; } err =__tipc_nl_add_link (net, &msg, link,0 );tipc_node_read_unlock (node); +tipc_node_put (node);if (err) goto err_free;}net/tipc/node.c +2
-0@@ -2634,11 +2639,13 @@ int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info)if (!link) {spin_unlock_bh (&le->lock);tipc_node_read_unlock (node); +tipc_node_put (node);return -EINVAL ; }tipc_link_reset_stats (link);spin_unlock_bh (&le->lock);tipc_node_read_unlock (node); +tipc_node_put (node);return 0 ; }
Quoted 3 lines
Quoted 2 lines
--
2.43.0
The adjustment has been adapted in v2.
Hi Tung,
The full KASAN report I just got from 7.3-rc5 branch is attached below, and I use the following kernel side delay instrumentation to make the trigger stable.
net/tipc/node.c +2 -1
@@ -45,9 +45,10 @@#include "netlink.h" #include "trace.h" #include "crypto.h" +#include <linux/delay.h> #define INVALID_NODE_SIG 0x10000 -#define NODE_CLEANUP_AFTER 300000 +#define NODE_CLEANUP_AFTER 300/* Flags used to take different actions according to flag type * TIPC_NOTIFY_NODE_DOWN: notify node is down
@@ -2434,6 +2435,7 @@ int tipc_nl_node_set_link(struct sk_buff *skb,
struct genl_info *info)
int err;
int res = 0;
int bearer_id;
+ int i;
char *name;
struct tipc_link *link;
struct tipc_node *node;
@@ -2464,6 +2466,12 @@ int tipc_nl_node_set_link(struct sk_buff *skb,
struct genl_info *info)
if (!node)
return -EINVAL;+ mdelay(2);
+ for (i = 0; i < 45; i++) {
+ schedule();
+ mdelay(1);
+ }
+
tipc_node_read_lock(node);
link = node->links[bearer_id].link;In summary, the reproducer creates two TIPC nodes in separate network namespaces connected through a veth pair and UDP bearers. Once the TIPC link is established, the main namespace repeatedly sends TIPC_NL_LINK_SET requests using the discovered link name.
Concurrently, the peer namespace disables its bearer. This causes the corresponding node to lose contact and eventually be removed by tipc_node_timeout(). A LINK_SET request can find that node through tipc_node_find_by_name() and retain its unreferenced pointer while the timer removes and frees it. The request then calls tipc_node_read_lock() through the stale pointer, producing the KASAN use-after-free.
[ 4.579090] BUG: KASAN: slab-use-after-free in _raw_read_lock_bh
(./include/linux/instrumented.h:112 ./include/linux/atomic/atomic-instrumented.h:141 ./include/asm-generic/qrwlock.h:82 ./include/linux/rwlock_api_smp.h:193 kernel/locking/spinlock.c:287)
[ 4.579120] Write of size 4 at addr ffff88807e06f008 by task poc/92 [ 4.579122] [ 4.579125] CPU: 0 UID: 0 PID: 92 Comm: poc Not tainted 7.3.0-rc5-dirty #29 PREEMPT(lazy) [ 4.579128] Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 [ 4.579129] Call Trace: [ 4.579136] <TASK> [ 4.579139] dump_stack_lvl (lib/dump_stack.c:94 lib/dump_stack.c:120) [ 4.579152] print_report (mm/kasan/report.c:378 mm/kasan/report.c:482) [ 4.579173] ? __pfx__raw_spin_lock_irqsave (kernel/locking/spinlock.c:190) [ 4.579175] ? _raw_read_lock_bh
(./include/linux/instrumented.h:112 ./include/linux/atomic/atomic-instrumented.h:141 ./include/asm-generic/qrwlock.h:82 ./include/linux/rwlock_api_smp.h:193 kernel/locking/spinlock.c:287)
[ 4.579177] kasan_report (mm/kasan/report.c:595) [ 4.579179] ? _raw_read_lock_bh
(./include/linux/instrumented.h:112 ./include/linux/atomic/atomic-instrumented.h:141 ./include/asm-generic/qrwlock.h:82 ./include/linux/rwlock_api_smp.h:193 kernel/locking/spinlock.c:287)
[ 4.579181] kasan_check_range (mm/kasan/generic.c:186 mm/kasan/generic.c:200) [ 4.579185] _raw_read_lock_bh (./include/linux/instrumented.h:112 ./include/linux/atomic/atomic-instrumented.h:141 ./include/asm-generic/qrwlock.h:82 ./include/linux/rwlock_api_smp.h:193 kernel/locking/spinlock.c:287) [ 4.579187] tipc_nl_node_set_link (net/tipc/node.c:376 net/tipc/node.c:2475) [ 4.579193] ? __pfx_tipc_nl_node_set_link (net/tipc/node.c:2388) [ 4.579195] ? __asan_memset (mm/kasan/shadow.c:84 (discriminator 1)) [ 4.579197] ? __pfx___nla_validate_parse (lib/nlattr.c:270) [ 4.579211] ? __nla_parse (lib/nlattr.c:732) [ 4.579212] ? genl_family_rcv_msg_attrs_parse.isra.0 (./include/net/netlink.h:789 (discriminator 2) net/netlink/genetlink.c:944 (discriminator 2)) [ 4.579231] ? genl_family_rcv_msg_doit (net/netlink/genetlink.c:1114) [ 4.579233] genl_family_rcv_msg_doit (net/netlink/genetlink.c:1114) [ 4.579235] ? __pfx_genl_family_rcv_msg_doit (./include/net/netlink.h:785 (discriminator 1)) [ 4.579237] ? __pfx_cred_has_capability.isra.0 (./include/linux/list.h:457 (discriminator 4)) [ 4.579248] genl_rcv_msg (net/netlink/genetlink.c:1194 net/netlink/genetlink.c:1209) [ 4.579250] ? __pfx_genl_rcv_msg (net/netlink/genetlink.c:1079) [ 4.579252] ? __pfx_tipc_nl_node_set_link (net/tipc/node.c:2388) [ 4.579254] netlink_rcv_skb (net/netlink/af_netlink.c:2575) [ 4.579256] ? __pfx_genl_rcv_msg (net/netlink/genetlink.c:1079) [ 4.579258] ? __pfx_netlink_rcv_skb (./include/linux/skbuff.h:2701) [ 4.579260] ? __pfx___netlink_lookup (net/netlink/af_netlink.c:2909) [ 4.579262] ? selinux_netlink_send (security/selinux/hooks.c:6404) [ 4.579264] genl_rcv (net/netlink/genetlink.c:1218) [ 4.579267] netlink_unicast (net/netlink/af_netlink.c:1338 net/netlink/af_netlink.c:1364) [ 4.579269] ? __pfx_netlink_unicast (./arch/x86/include/asm/bitops.h:202) [ 4.579271] ? __pfx_sock_has_perm (./security/selinux/include/objsec.h:240 (discriminator 1)) [ 4.579273] netlink_sendmsg (net/netlink/af_netlink.c:1919) [ 4.579275] ? __pfx_netlink_sendmsg (./include/net/net_namespace.h:422) [ 4.579278] ? selinux_socket_sendmsg (security/selinux/hooks.c:5395) [ 4.579280] ? fdget (./include/linux/rcupdate.h:882 fs/file.c:1100 fs/file.c:1200 fs/file.c:1208) [ 4.579290] __sys_sendto (net/socket.c:800 (discriminator 1) net/socket.c:815 (discriminator 1) net/socket.c:2281 (discriminator 1)) [ 4.579301] ? __pfx___sys_sendto (net/socket.c:2235) [ 4.579303] ? __sys_bind (./include/linux/file.h:63 ./include/linux/file.h:83 net/socket.c:1963) [ 4.579305] ? fput (./include/linux/instrumented.h:112 ./include/linux/atomic/atomic-instrumented.h:3766 ./include/linux/file_ref.h:157 fs/file_table.c:588) [ 4.579310] ? __sys_setsockopt (./include/linux/file.h:63 ./include/linux/file.h:83 net/socket.c:2414) [ 4.579312] __x64_sys_sendto (net/socket.c:2288 net/socket.c:2284 net/socket.c:2284) [ 4.579314] ? fpregs_assert_state_consistent (./include/linux/instrumented.h:82 ./include/asm-generic/bitops/instrumented-non-atomic.h:141 ./include/linux/thread_info.h:133 arch/x86/kernel/fpu/core.c:912) [ 4.579325] do_syscall_64 (arch/x86/entry/syscall_64.c:61 arch/x86/entry/syscall_64.c:84) [ 4.579330] entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) [ 4.579334] RIP: 0033:0x422e6a [ 4.579336] Code: e0 89 7d e8 89 4d d4 e8 84 be 02 00 44 8b 55 d4
48 8b 55 d8 45 31 c9 89 c3 48 8b 75 e0 8b 7d e8 45 31 c0 b8 2c 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 36 89 df 48 89 45 e8 e8 d3 be 02 00 48 8b 45
All code
========
0: e0 89 loopne 0xffffffffffffff8b
2: 7d e8 jge 0xffffffffffffffec
4: 89 4d d4 mov %ecx,-0x2c(%rbp) 7: e8 84 be 02 00 call 0x2be90 c: 44 8b 55 d4 mov -0x2c(%rbp),%r10d 10: 48 8b 55 d8 mov -0x28(%rbp),%rdx 14: 45 31 c9 xor %r9d,%r9d 17: 89 c3 mov %eax,%ebx 19: 48 8b 75 e0 mov -0x20(%rbp),%rsi 1d: 8b 7d e8 mov -0x18(%rbp),%edi 20: 45 31 c0 xor %r8d,%r8d 23: b8 2c 00 00 00 mov $0x2c,%eax 28: 0f 05 syscall 2a:* 48 3d 00 f0 ff ff cmp $0xfffffffffffff000,%rax <-- trapping instruction 30: 77 36 ja 0x68 32: 89 df mov %ebx,%edi 34: 48 89 45 e8 mov %rax,-0x18(%rbp) 38: e8 d3 be 02 00 call 0x2bf10 3d: 48 rex.W 3e: 8b .byte 0x8b 3f: 45 rex.RB
Code starting with the faulting instruction
===========================================
0: 48 3d 00 f0 ff ff cmp $0xfffffffffffff000,%rax 6: 77 36 ja 0x3e 8: 89 df mov %ebx,%edi a: 48 89 45 e8 mov %rax,-0x18(%rbp) e: e8 d3 be 02 00 call 0x2bee6 13: 48 rex.W 14: 8b .byte 0x8b 15: 45 rex.RB [ 4.579340] RSP: 002b:00007f3ed2ca20f0 EFLAGS: 00000246 ORIG_RAX: 000000000000002c [ 4.579348] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 0000000000422e6a [ 4.579350] RDX: 0000000000000048 RSI: 00007f3ed2ca2130 RDI: 0000000000000003 [ 4.579351] RBP: 00007f3ed2ca2120 R08: 0000000000000000 R09: 0000000000000000 [ 4.579352] R10: 0000000000000000 R11: 0000000000000246 R12: 000000000049e630 [ 4.579353] R13: 0000000000000000 R14: 000000000000000b R15: 00007ffc2b74eac0 [ 4.579355] </TASK> [ 4.579355] [ 4.579356] Allocated by task 0: [ 4.579358] kasan_save_stack (mm/kasan/common.c:57) [ 4.579364] kasan_save_track (mm/kasan/common.c:78) [ 4.579365] __kasan_kmalloc (mm/kasan/common.c:398 mm/kasan/common.c:415) [ 4.579367] __kmalloc_cache_noprof (./include/linux/kasan.h:263 mm/slub.c:5563) [ 4.579371] tipc_node_create (./include/linux/slab.h:991 ./include/linux/slab.h:1312 net/tipc/node.c:539) [ 4.579372] tipc_node_check_dest (net/tipc/node.c:1196) [ 4.579374] tipc_disc_rcv (net/tipc/discover.c:252) [ 4.579377] tipc_rcv (net/tipc/node.c:2137) [ 4.579378] tipc_udp_recv (net/tipc/udp_media.c:389 (discriminator 1)) [ 4.579381] udp_queue_rcv_one_skb (net/ipv4/udp.c:2432) [ 4.579392] udp_unicast_rcv_skb (net/ipv4/udp.c:2620) [ 4.579394] ip_protocol_deliver_rcu (net/ipv4/ip_input.c:207 (discriminator 4)) [ 4.579399] ip_local_deliver_finish (net/ipv4/ip_input.c:241 (discriminator 1)) [ 4.579400] ip_local_deliver (./include/linux/netfilter.h:325 ./include/linux/netfilter.h:319 net/ipv4/ip_input.c:262) [ 4.579402] ip_rcv (./include/net/dst.h:481 (discriminator 6)
net/ipv4/ip_input.c:492 (discriminator 6)./include/linux/netfilter.h:325 (discriminator 6)./include/linux/netfilter.h:319 (discriminator 6)net/ipv4/ip_input.c:612 (discriminator 6))
[ 4.579403] __netif_receive_skb_one_core (net/core/dev.c:6265 (discriminator 4)) [ 4.579412] process_backlog (net/core/dev.c:6729) [ 4.579413] __napi_poll (net/core/dev.c:7798) [ 4.579414] net_rx_action (net/core/dev.c:7861 net/core/dev.c:8018) [ 4.579415] handle_softirqs (kernel/softirq.c:645) [ 4.579423] __irq_exit_rcu (kernel/softirq.c:679 kernel/softirq.c:519 kernel/softirq.c:758) [ 4.579424] sysvec_apic_timer_interrupt (arch/x86/kernel/apic/apic.c:1062 (discriminator 35) arch/x86/kernel/apic/apic.c:1062 (discriminator 35)) [ 4.579428] asm_sysvec_apic_timer_interrupt (./arch/x86/include/asm/idtentry.h:674) [ 4.579429] [ 4.579430] Freed by task 92: [ 4.579433] kasan_save_stack (mm/kasan/common.c:57) [ 4.579434] kasan_save_track (mm/kasan/common.c:78) [ 4.579436] kasan_save_free_info (mm/kasan/generic.c:584) [ 4.579438] __kasan_slab_free (mm/kasan/common.c:253 mm/kasan/common.c:285) [ 4.579440] kfree (./include/linux/kasan.h:235 mm/slub.c:2748 mm/slub.c:6508 mm/slub.c:6801) [ 4.579447] rcu_core (kernel/rcu/tree.c:2650 kernel/rcu/tree.c:2919) [ 4.579457] handle_softirqs (kernel/softirq.c:645) [ 4.579458] __irq_exit_rcu (kernel/softirq.c:679 kernel/softirq.c:519 kernel/softirq.c:758) [ 4.579459] sysvec_apic_timer_interrupt (arch/x86/kernel/apic/apic.c:1062 (discriminator 35) arch/x86/kernel/apic/apic.c:1062 (discriminator 35)) [ 4.579461] asm_sysvec_apic_timer_interrupt (./arch/x86/include/asm/idtentry.h:674) [ 4.579462] [ 4.579463] Last potentially related work creation: [ 4.579464] kasan_save_stack (mm/kasan/common.c:57) [ 4.579465] kasan_record_aux_stack (mm/kasan/generic.c:556) [ 4.579467] __call_rcu_common.constprop.0 (kernel/rcu/tree.c:3181) [ 4.579469] tipc_node_timeout (net/tipc/node.c:315 ./include/linux/kref.h:65 net/tipc/node.c:320 net/tipc/node.c:814) [ 4.579470] call_timer_fn (kernel/time/timer.c:1748) [ 4.579479] __run_timers (kernel/time/timer.c:1799 kernel/time/timer.c:2374) [ 4.579480] timer_expire_remote (kernel/time/timer.c:2386 kernel/time/timer.c:2378 kernel/time/timer.c:2136) [ 4.579482] tmigr_handle_remote_up (kernel/time/timer_migration.c:985 kernel/time/timer_migration.c:1076) [ 4.579488] __walk_groups_from (kernel/time/timer_migration.c:564) [ 4.579490] tmigr_handle_remote (kernel/time/timer_migration.c:581 kernel/time/timer_migration.c:1135) [ 4.579492] run_timer_softirq (kernel/time/timer.c:2409) [ 4.579493] handle_softirqs (kernel/softirq.c:645) [ 4.579494] __irq_exit_rcu (kernel/softirq.c:679 kernel/softirq.c:519 kernel/softirq.c:758) [ 4.579496] sysvec_apic_timer_interrupt (arch/x86/kernel/apic/apic.c:1062 (discriminator 35) arch/x86/kernel/apic/apic.c:1062 (discriminator 35)) [ 4.579497] asm_sysvec_apic_timer_interrupt (./arch/x86/include/asm/idtentry.h:674) [ 4.579499] [ 4.579499] The buggy address belongs to the object at ffff88807e06f000 [ 4.579499] which belongs to the cache kmalloc-part-11-1k of size 1024 [ 4.579501] The buggy address is located 8 bytes inside of [ 4.579501] freed 1024-byte region [ffff88807e06f000, ffff88807e06f400) [ 4.579503] [ 4.579504] The buggy address belongs to the physical page: [ 4.579506] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7e068 [ 4.579510] head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 [ 4.579512] flags: 0x100000000000040(head|node=0|zone=1) [ 4.579516] page_type: f5(slab) [ 4.579520] raw: 0100000000000040 ffff888001056500 dead000000000100 dead000000000122 [ 4.579522] raw: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000 [ 4.579524] head: 0100000000000040 ffff888001056500 dead000000000100 dead000000000122 [ 4.579525] head: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000 [ 4.579527] head: 0100000000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff [ 4.579528] head: 0000000000000000 0000000000000000 00000000ffffffff 0000000000000000 [ 4.579529] page dumped because: kasan: bad access detected [ 4.579530] [ 4.579530] Memory state around the buggy address: [ 4.579531] ffff88807e06ef00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 4.579534] ffff88807e06ef80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc [ 4.579535] >ffff88807e06f000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 4.579536] ^ [ 4.579537] ffff88807e06f080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 4.579538] ffff88807e06f100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb [ 4.579539] ================================================================== [ 4.579550] Disabling lock debugging due to kernel taint
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [High] The fix is incomplete.
- [Low] The kernel-doc for tipc_node_find_by_name() in net/tipc/node.c no longer matches the function.
--
tipc: hold a reference to nodes found by link name
The patch makes tipc_node_find_by_name() take a node reference with kref_get_unless_zero() before it leaves the RCU read-side section. The LINK_SET, LINK_GET and LINK_RESET_STATS handlers now drop that reference with tipc_node_put() after their last access to the node. This closes a use-after-free against timer-driven cleanup of a down peer.
net/tipc/node.c static struct tipc_node *tipc_node_find_by_name(struct net *net, · line 2431
Quoted 13 lines
net/tipc/node.c +2
-0@@ -2424,6 +2424,8 @@ static struct tipc_node *tipc_node_find_by_name(struct net *net,if (found_node)break ; } +if (found_node && !kref_get_unless_zero (&found_node->kref)) + found_node =NULL ;rcu_read_unlock ();return found_node;
[Severity: Low]
This isn't a bug, but should the kernel-doc above tipc_node_find_by_name() be updated to match the new contract? It still says:
* Returns pointer to node owning the link, or 0 if no matching link is found.
After this change, a non-NULL return carries a reference that the caller must drop with tipc_node_put(). NULL can also now mean that a link matched but the node's refcount had already reached zero.
The comment also documents the parameter as @name, while the real parameter is link_name. That mismatch was already there before this patch.
[ ... ]
net/tipc/node.c int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info) · line 2650
Quoted 13 lines
net/tipc/node.c +2
-0@@ -2634,11 +2639,13 @@ int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info)if (!link) {spin_unlock_bh (&le->lock);tipc_node_read_unlock (node); +tipc_node_put (node);return -EINVAL ; }tipc_link_reset_stats (link);spin_unlock_bh (&le->lock);tipc_node_read_unlock (node); +tipc_node_put (node);return 0 ; }
[Severity: High]
Is the fix complete for the handlers named in the commit message? The broadcast branch earlier in tipc_nl_node_reset_link_stats() never calls tipc_node_find_by_name(), so it takes no node reference:
} else if (strstr(link_name, tipc_bclink_name)) {
rcu_read_lock();
list_for_each_entry_rcu(node, &tn->node_list, list) {
tipc_node_read_lock(node);
link = node->bc_entry.link;
if (link && !strcmp(link_name, tipc_link_name(link))) {
err = tipc_bclink_reset_stats(net, link);
...Only the node struct waits for an RCU grace period. The broadcast link is freed right away, and the pointer is never cleared:
net/tipc/node.c:tipc_node_kref_release() {
...
kfree(n->bc_entry.link);
call_rcu(&n->rcu, tipc_node_free);
}Could this interleaving still happen?
CPU0 (reset_link_stats, broadcast branch)
rcu_read_lock()
list_for_each_entry_rcu() reaches node N
CPU1
tipc_node_timeout()
tipc_node_cleanup()
tipc_node_clear_links(), tipc_node_delete_from_list()
tipc_node_put(n)
tipc_node_kref_release()
kfree(n->bc_entry.link)CPU0
tipc_node_read_lock(N) /* N still valid under RCU */
link = N->bc_entry.link /* stale, non-NULL */
tipc_link_name(link) /* reads freed memory */
tipc_bclink_reset_stats(net, link)
tipc_link_reset_stats() /* memset of l->stats in freed memory */The LINK_GET dump path looks exposed in the same way. When TIPC_NLA_LINK_BROADCAST is set, it runs:
tipc_nl_node_dump_link()->__tipc_nl_add_node_links()->tipc_nl_add_bc_link()
if (bc_link) {
*prev_link = i;
err = tipc_nl_add_bc_link(net, msg, node->bc_entry.link);This reads bcl->name, bcl->max_win and bcl->stats from the possibly freed link and copies them into the netlink reply. It also runs without a node reference.
TIPC_NL_LINK_RESET_STATS only needs GENL_UNS_ADMIN_PERM. The LINK_GET dumpit has no permission flag.
Two possible fixes: take a node reference with kref_get_unless_zero() during the RCU walk before touching bc_entry.link, as this patch already does in tipc_node_find_by_name(). Or move the kfree(n->bc_entry.link) into the RCU callback tipc_node_free().
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260927064036.3691962-1-nicoyip.dev%40gmail.com