linux/net/tipc
Jun Yang cba9ccb47e tipc: read le->link under the node lock in tipc_node_link_down()
tipc_node_link_down() caches the link pointer before taking n->lock:

	struct tipc_link *l = le->link;		/* unlocked */

	if (!l)
		return;
	tipc_node_write_lock(n);
	if (!tipc_link_is_establishing(l)) {	/* deref l */
	...
		tipc_link_reset(l);		/* write into l */
	if (delete) {
		kfree(l);
		le->link = NULL;

The delete=true caller frees that very object under n->lock, so the lock
does not protect the cached pointer against it:

 - CPU A, delete=false: tipc_rcv() on TIPC_LINK_DOWN_EVT, or the link
   supervision timer via tipc_node_timeout(), reads l unlocked and then
   dereferences it under n->lock;
 - CPU B, delete=true: netlink TIPC_NL_BEARER_DISABLE -> bearer_disable()
   -> tipc_node_delete_links() -> tipc_node_link_down(n, bearer_id, true)
   -> kfree(l).

The link is freed with plain kfree(), not kfree_rcu(), and for UDP bearers
disable_media() only schedules the asynchronous cleanup_bearer() work, so
its synchronize_net() runs after the links are already gone.  An in-flight
CPU A that has read l therefore dereferences freed memory once B frees it:
a use-after-free read in tipc_link_is_establishing(), and a use-after-free
write via tipc_link_reset() on the establishing branch.

The following trace was captured on 7.2.0-rc5-00284-gaf39eb111ce6:

  BUG: KASAN: slab-use-after-free in tipc_link_is_establishing (net/tipc/link.c:285)
  Read of size 4 at addr ffff88802e2aa068 by task swapper/2/0
   tipc_link_is_establishing (net/tipc/link.c:285)
   tipc_node_link_down (net/tipc/node.c:1076)
   tipc_node_timeout (net/tipc/node.c:843)
  Allocated by task 9549:
   tipc_link_create (net/tipc/link.c:490)
   tipc_node_check_dest (net/tipc/node.c:1279)
   tipc_disc_rcv (net/tipc/discover.c:252)
   tipc_udp_recv (net/tipc/udp_media.c:389)
  Freed by task 9549:
   tipc_node_link_down (net/tipc/node.c:1084)
   tipc_node_delete_links (net/tipc/node.c:1320)
   bearer_disable (net/tipc/bearer.c:414)
   __tipc_nl_bearer_disable (net/tipc/bearer.c:992)

Move the le->link read inside tipc_node_write_lock(), so it is serialised
against the kfree() in the delete path.  A racing teardown now either has
not run yet, and we see a valid link, or has already run, and we see NULL.

Fixes: 73f646cec3 ("tipc: delay ESTABLISH state event when link is established")
Cc: stable@kernel.org
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Assisted-by: tencentos-corvus-ai:kimi-k3
Signed-off-by: Jun Yang <junvyyang@tencent.com>
Reviewed-by: Tung Nguyen <tung.quang.nguyen@est.tech>
Link: https://patch.msgid.link/20260810102147.48191-1-juny24602@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2026-08-11 15:50:22 +02:00
..
addr.c tipc: adjust tipc_nodeid2string() to return string length 2025-09-30 11:22:39 +02:00
addr.h tipc: adjust tipc_nodeid2string() to return string length 2025-09-30 11:22:39 +02:00
bcast.c tipc: fix out-of-bounds read in broadcast Gap ACK blocks 2026-06-29 17:30:20 -07:00
bcast.h tipc: fix out-of-bounds read in broadcast Gap ACK blocks 2026-06-29 17:30:20 -07:00
bearer.c tipc: fix UAF in tipc_l2_send_msg() 2026-06-15 12:50:29 -07:00
bearer.h tipc: Remove unused function declarations 2023-08-03 12:51:45 +02:00
core.c tipc: avoid busy looping in tipc_exit_net() 2026-06-25 08:53:00 -07:00
core.h kernel.h: drop hex.h and update all hex.h users 2026-01-20 19:44:19 -08:00
crypto.c tipc: fix slab-use-after-free Read in tipc_aead_decrypt_done 2026-06-18 18:35:35 -07:00
crypto.h
diag.c sock_diag: add module pointer to "struct sock_diag_handler" 2024-01-23 15:13:54 +01:00
discover.c tipc: fix use-after-free of the discoverer in tipc_disc_rcv() 2026-06-21 14:28:22 -07:00
discover.h
eth_media.c
group.c tipc: fix bc_ackers underflow on duplicate GRP_ACK_MSG 2026-04-03 15:31:17 -07:00
group.h
ib_media.c
Kconfig ipv6: convert CONFIG_IPV6 to built-in only and clean up Kconfigs 2026-03-29 11:21:22 -07:00
link.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
link.h tipc: Remove unused declaration tipc_link_build_bc_sync_msg() 2023-08-09 13:03:14 -07:00
Makefile tipc: rename the module name diag to tipc_diag 2024-02-06 13:47:36 +01:00
monitor.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
monitor.h
msg.c tipc: fix double-free in tipc_buf_append() 2026-04-23 11:45:01 -07:00
msg.h
name_distr.c tipc: reject inverted service ranges from peer bindings 2026-06-11 16:01:16 -07:00
name_distr.h tipc: Remove unused function declarations 2023-08-03 12:51:45 +02:00
name_table.c Including fixes from IPsec, Bluetooth and netfilter 2026-02-26 08:00:13 -08:00
name_table.h net: tipc: remove one synchronize_net() from tipc_nametbl_stop() 2024-12-06 17:41:28 -08:00
net.c tipc: Fix use-after-free in tipc_mon_reinit_self(). 2025-11-10 18:14:40 -08:00
net.h tipc: Remove unused function declarations 2023-08-03 12:51:45 +02:00
netlink_compat.c tipc: fix infinite loop in __tipc_nl_compat_dumpit 2026-07-21 15:12:23 -07:00
netlink.c tipc: fix u16 MTU truncation in media and bearer MTU validation 2026-07-23 11:41:03 +02:00
netlink.h
node.c tipc: read le->link under the node lock in tipc_node_link_down() 2026-08-11 15:50:22 +02:00
node.h
socket.c tipc: avoid use-after-free in poll trace queue dumps 2026-07-27 15:18:59 -07:00
socket.h
subscr.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
subscr.h
sysctl.c net: Remove ctl_table sentinel elements from several networking subsystems 2024-05-03 13:29:42 +01:00
topsrv.c treewide: Replace kmalloc with kmalloc_obj for non-scalar types 2026-02-21 01:02:28 -08:00
topsrv.h
trace.c
trace.h tracing/treewide: Remove second parameter of __assign_str() 2024-05-22 20:14:47 -04:00
udp_media.c tipc: serialize udp bearer replicast list updates 2026-07-21 11:57:21 -07:00
udp_media.h