[PATCH v1] net: amt: store tunnel->key before adding tunnel to tunnel_list
From: Binbin Deng
Date: Mon Nov 30 2026 - 03:59:00 EST
amt_request_handler() publishes a newly created tunnel with
list_add_tail_rcu(&tunnel->list, &amt->tunnel_list) and only afterwards
stores tunnel->key = amt->key.
The lockless lookup at the top of the same function walks
amt->tunnel_list without holding amt->lock, so a concurrent Request
from the same source address can find the just-published tunnel, jump
to the send label and read tunnel->key through siphash_3u32() while the
creating CPU is still storing it. The Membership Query response is then
MACed with a partially stored (e.g. all zero) key, and the plain
16-byte store races the lockless 8-byte load.
BUG: KCSAN: data-race in amt_rcv / siphash_3u32
write to 0xffff888102618098 of 16 bytes by interrupt on cpu 0:
amt_rcv+0x2218/0x3ca0
udp_queue_rcv_one_skb+0x48c/0x640
udp_queue_rcv_skb+0x112/0x4e0
udp_rcv+0x900/0x1020
ip_protocol_deliver_rcu+0x104/0x220
ip_local_deliver+0xad/0x1c0
ip_rcv+0x1aa/0x1d0
__netif_receive_skb+0x19/0xa0
read to 0xffff8881026270a0 of 8 bytes by interrupt on cpu 1:
siphash_3u32+0x24/0x220
amt_rcv+0x1812/0x3c90
udp_queue_rcv_one_skb+0x48c/0x640
udp_rcv+0x900/0x1020 ...
Trigger environment: x86_64 QEMU/KVM guest, -smp 4, kernel built with
CONFIG_KCSAN=y. An AMT relay (amt0, mode relay, local 10.1.0.1, UDP
port 2268) with a veth uplink, and two sender threads on different CPUs
emitting 8-byte AMT Request datagrams (type 3) to UDP port 2268 while
rotating through the same set of source addresses, so that the request
creating a new tunnel always races concurrent requests matching it.
Fix by storing tunnel->key before the RCU publication.
Fixes: cbc21dc1cfe9 ("amt: add data plane of amt interface")
Signed-off-by: Binbin Deng <18983559317@xxxxxxx>
---
drivers/net/amt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index bddc24e1856d..51125c85d135 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -2752,8 +2752,8 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
INIT_DELAYED_WORK(&tunnel->gc_wq, amt_tunnel_expire);
- list_add_tail_rcu(&tunnel->list, &amt->tunnel_list);
tunnel->key = amt->key;
+ list_add_tail_rcu(&tunnel->list, &amt->tunnel_list);
__amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_REQUEST, true);
amt->nr_tunnels++;
mod_delayed_work(amt_wq, &tunnel->gc_wq,
--
2.43.0