| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/20 05:57 | flow | patch-triage |
3mArgs:null Results: {
"EnableConfigs": [
"AMT",
"INET",
"IP_MULTICAST",
"IPV6"
],
"FocusSymbols": [
"amt_tunnel_get_or_create",
"amt_update_handler",
"amt_request_handler",
"amt_tunnel_expire",
"amt_group_work",
"amt_source_work",
"amt_group_gc_work",
"amt_destroy_source",
"amt_del_group",
"amt_rcv"
],
"KMSANReasoning": "The patch series addresses concurrency, lifetime management, and denial-of-service vulnerabilities in the AMT (Automatic Multicast Tunneling) driver:\n1. It implements a dedicated group GC queue, work synchronization, and 'dead' flags to prevent race conditions and use-after-free (UAF) bugs during group, source, and tunnel destruction.\n2. It makes relay request handling stateless, avoiding premature tunnel allocation from spoofed requests, and rotates 4 generations of SipHash keys for validating Membership Updates.\n3. It updates netlink policy validation and statistics helpers.\n\nFrom a memory initialization perspective:\n- All heap objects (`amt_tunnel_list`, `amt_group_node`, `amt_source_node`) are allocated via `kzalloc` or `kzalloc_obj`, ensuring all fields (including the new `dead` and `gc_node` members) are fully zeroed.\n- The `key` array on the stack in `amt_update_handler` is explicitly populated for all indices from `amt-\u003ekey[i]` before being passed to `siphash_3u32`.\n- `amt-\u003ekey` is initialized in `amt_dev_open` using `get_random_bytes(\u0026amt-\u003ekey, sizeof(amt-\u003ekey))`, fully covering all 4 array elements.\n- No kernel memory or uninitialized struct padding is copied to userspace.\n\nThe risks associated with these changes are concurrency, locking, and object lifetime issues (such as use-after-free or race conditions), which are covered by KASAN and LOCKDEP. KMSAN is not needed as there are no uninitialized memory read risks or info-leaks.",
"NeedsKMSAN": false,
"Reasoning": "The patch extensively refactors the lifecycle, garbage collection, concurrency control, and packet processing logic of the AMT (Automatic Multicast Tunneling) driver. It introduces a new group GC list and delayed work queue, updates delayed work cancellation and RCU freeing patterns, alters tunnel allocation semantics (deferring tunnel creation to the Membership Update handler instead of Request handling), and adds multi-generational SipHash keys. These changes touch reachable virtual network device code that can be created and driven via rtnetlink and network sockets without specialized hardware, warranting fuzzing for potential race conditions, UAFs, or workqueue/locking regressions.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/20 05:57 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 8a04eae34c5c057fcb5e7f0ec93d7b4d5052eee0\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Tue Oct 20 05:57:19 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/drivers/net/amt.c b/drivers/net/amt.c\nindex b53f8ec556615..faf32976305b3 100644\n--- a/drivers/net/amt.c\n+++ b/drivers/net/amt.c\n@@ -38,6 +38,10 @@ static HLIST_HEAD(source_gc_list);\n /* Lock for source_gc_list */\n static spinlock_t source_gc_lock;\n static struct delayed_work source_gc_wq;\n+static HLIST_HEAD(group_gc_list);\n+/* Lock for group_gc_list */\n+static spinlock_t group_gc_lock;\n+static struct delayed_work group_gc_wq;\n static char *status_str[] = {\n \t\"AMT_STATUS_INIT\",\n \t\"AMT_STATUS_SENT_DISCOVERY\",\n@@ -90,8 +94,9 @@ static void __amt_source_gc_work(void)\n \thlist_move_list(\u0026source_gc_list, \u0026gc_list);\n \tspin_unlock_bh(\u0026source_gc_lock);\n \n-\thlist_for_each_entry_safe(snode, t, \u0026gc_list, node) {\n-\t\thlist_del_rcu(\u0026snode-\u003enode);\n+\thlist_for_each_entry_safe(snode, t, \u0026gc_list, gc_node) {\n+\t\tcancel_delayed_work_sync(\u0026snode-\u003esource_timer);\n+\t\thlist_del_init(\u0026snode-\u003egc_node);\n \t\tkfree_rcu(snode, rcu);\n \t}\n }\n@@ -106,6 +111,39 @@ static void amt_source_gc_work(struct work_struct *work)\n \tspin_unlock_bh(\u0026source_gc_lock);\n }\n \n+static void __amt_group_gc_work(void)\n+{\n+\tstruct amt_group_node *gnode;\n+\tstruct hlist_head gc_list;\n+\tstruct hlist_node *t;\n+\n+\tspin_lock_bh(\u0026group_gc_lock);\n+\thlist_move_list(\u0026group_gc_list, \u0026gc_list);\n+\tspin_unlock_bh(\u0026group_gc_lock);\n+\n+\t/* Group deletion queues all of its sources first. Drain that queue\n+\t * before freeing the group so a source callback cannot dereference it.\n+\t */\n+\tcancel_delayed_work_sync(\u0026source_gc_wq);\n+\t__amt_source_gc_work();\n+\n+\thlist_for_each_entry_safe(gnode, t, \u0026gc_list, gc_node) {\n+\t\tcancel_delayed_work_sync(\u0026gnode-\u003egroup_timer);\n+\t\thlist_del_init(\u0026gnode-\u003egc_node);\n+\t\tkfree_rcu(gnode, rcu);\n+\t}\n+}\n+\n+static void amt_group_gc_work(struct work_struct *work)\n+{\n+\t__amt_group_gc_work();\n+\n+\tspin_lock_bh(\u0026group_gc_lock);\n+\tmod_delayed_work(amt_wq, \u0026group_gc_wq,\n+\t\t\t msecs_to_jiffies(AMT_GC_INTERVAL));\n+\tspin_unlock_bh(\u0026group_gc_lock);\n+}\n+\n static bool amt_addr_equal(union amt_addr *a, union amt_addr *b)\n {\n \treturn !memcmp(a, b, sizeof(union amt_addr));\n@@ -215,9 +253,14 @@ static struct amt_group_node *amt_lookup_group(struct amt_tunnel_list *tunnel,\n \n static void amt_destroy_source(struct amt_source_node *snode)\n {\n-\tstruct amt_group_node *gnode = snode-\u003egnode;\n+\tstruct amt_group_node *gnode;\n \tstruct amt_tunnel_list *tunnel;\n \n+\tif (READ_ONCE(snode-\u003edead))\n+\t\treturn;\n+\tWRITE_ONCE(snode-\u003edead, true);\n+\tgnode = snode-\u003egnode;\n+\n \ttunnel = gnode-\u003etunnel_list;\n \n \tif (!gnode-\u003ev6) {\n@@ -238,8 +281,9 @@ static void amt_destroy_source(struct amt_source_node *snode)\n \thlist_del_init_rcu(\u0026snode-\u003enode);\n \ttunnel-\u003enr_sources--;\n \tgnode-\u003enr_sources--;\n+\tRCU_INIT_POINTER(snode-\u003egnode, NULL);\n \tspin_lock_bh(\u0026source_gc_lock);\n-\thlist_add_head_rcu(\u0026snode-\u003enode, \u0026source_gc_list);\n+\thlist_add_head(\u0026snode-\u003egc_node, \u0026source_gc_list);\n \tspin_unlock_bh(\u0026source_gc_lock);\n }\n \n@@ -249,6 +293,9 @@ static void amt_del_group(struct amt_dev *amt, struct amt_group_node *gnode)\n \tstruct hlist_node *t;\n \tint i;\n \n+\tif (READ_ONCE(gnode-\u003edead))\n+\t\treturn;\n+\tWRITE_ONCE(gnode-\u003edead, true);\n \tif (cancel_delayed_work(\u0026gnode-\u003egroup_timer))\n \t\tdev_put(amt-\u003edev);\n \thlist_del_rcu(\u0026gnode-\u003enode);\n@@ -266,10 +313,10 @@ static void amt_del_group(struct amt_dev *amt, struct amt_group_node *gnode)\n \t\thlist_for_each_entry_safe(snode, t, \u0026gnode-\u003esources[i], node)\n \t\t\tamt_destroy_source(snode);\n \n-\t/* tunnel-\u003elock was acquired outside of amt_del_group()\n-\t * But rcu_read_lock() was acquired too so It's safe.\n-\t */\n-\tkfree_rcu(gnode, rcu);\n+\tRCU_INIT_POINTER(gnode-\u003etunnel_list, NULL);\n+\tspin_lock_bh(\u0026group_gc_lock);\n+\thlist_add_head(\u0026gnode-\u003egc_node, \u0026group_gc_list);\n+\tspin_unlock_bh(\u0026group_gc_lock);\n }\n \n /* If a source timer expires with a router filter-mode for the group of\n@@ -282,13 +329,28 @@ static void amt_source_work(struct work_struct *work)\n \tstruct amt_source_node *snode = container_of(to_delayed_work(work),\n \t\t\t\t\t\t struct amt_source_node,\n \t\t\t\t\t\t source_timer);\n-\tstruct amt_group_node *gnode = snode-\u003egnode;\n-\tstruct amt_dev *amt = gnode-\u003eamt;\n+\tstruct amt_group_node *gnode;\n+\tstruct amt_dev *amt;\n \tstruct amt_tunnel_list *tunnel;\n \n-\ttunnel = gnode-\u003etunnel_list;\n-\tspin_lock_bh(\u0026tunnel-\u003elock);\n \trcu_read_lock();\n+\tgnode = READ_ONCE(snode-\u003egnode);\n+\tif (!gnode) {\n+\t\trcu_read_unlock();\n+\t\treturn;\n+\t}\n+\tamt = READ_ONCE(gnode-\u003eamt);\n+\ttunnel = READ_ONCE(gnode-\u003etunnel_list);\n+\tif (!tunnel) {\n+\t\trcu_read_unlock();\n+\t\treturn;\n+\t}\n+\tspin_lock_bh(\u0026tunnel-\u003elock);\n+\tif (READ_ONCE(snode-\u003edead) || READ_ONCE(gnode-\u003edead)) {\n+\t\tspin_unlock_bh(\u0026tunnel-\u003elock);\n+\t\trcu_read_unlock();\n+\t\treturn;\n+\t}\n \tif (gnode-\u003efilter_mode == MCAST_INCLUDE) {\n \t\tamt_destroy_source(snode);\n \t\tif (!gnode-\u003enr_sources)\n@@ -299,8 +361,8 @@ static void amt_source_work(struct work_struct *work)\n \t\t */\n \t\tsnode-\u003estatus = AMT_SOURCE_STATUS_D_FWD;\n \t}\n-\trcu_read_unlock();\n \tspin_unlock_bh(\u0026tunnel-\u003elock);\n+\trcu_read_unlock();\n }\n \n static void amt_act_src(struct amt_tunnel_list *tunnel,\n@@ -368,6 +430,7 @@ static struct amt_source_node *amt_alloc_snode(struct amt_group_node *gnode,\n \tsnode-\u003estatus = AMT_SOURCE_STATUS_NONE;\n \tsnode-\u003eflags = AMT_SOURCE_NEW;\n \tINIT_HLIST_NODE(\u0026snode-\u003enode);\n+\tINIT_HLIST_NODE(\u0026snode-\u003egc_node);\n \tINIT_DELAYED_WORK(\u0026snode-\u003esource_timer, amt_source_work);\n \n \treturn snode;\n@@ -403,26 +466,40 @@ static void amt_group_work(struct work_struct *work)\n \tstruct amt_group_node *gnode = container_of(to_delayed_work(work),\n \t\t\t\t\t\t struct amt_group_node,\n \t\t\t\t\t\t group_timer);\n-\tstruct amt_tunnel_list *tunnel = gnode-\u003etunnel_list;\n-\tstruct amt_dev *amt = gnode-\u003eamt;\n+\tstruct amt_tunnel_list *tunnel;\n+\tstruct amt_dev *amt;\n \tstruct amt_source_node *snode;\n \tbool delete_group = true;\n \tstruct hlist_node *t;\n \tint i, buckets;\n \n+\trcu_read_lock();\n+\ttunnel = READ_ONCE(gnode-\u003etunnel_list);\n+\tamt = READ_ONCE(gnode-\u003eamt);\n+\tif (!tunnel) {\n+\t\trcu_read_unlock();\n+\t\tdev_put(amt-\u003edev);\n+\t\treturn;\n+\t}\n \tbuckets = amt-\u003ehash_buckets;\n \n \tspin_lock_bh(\u0026tunnel-\u003elock);\n+\tif (READ_ONCE(gnode-\u003edead)) {\n+\t\tspin_unlock_bh(\u0026tunnel-\u003elock);\n+\t\trcu_read_unlock();\n+\t\tdev_put(amt-\u003edev);\n+\t\treturn;\n+\t}\n \tif (gnode-\u003efilter_mode == MCAST_INCLUDE) {\n \t\t/* Not Used */\n \t\tspin_unlock_bh(\u0026tunnel-\u003elock);\n-\t\tgoto out;\n+\t\trcu_read_unlock();\n+\t\tdev_put(amt-\u003edev);\n+\t\treturn;\n \t}\n \n-\trcu_read_lock();\n-\tfor (i = 0; i \u003c buckets; i++) {\n-\t\thlist_for_each_entry_safe(snode, t,\n-\t\t\t\t\t \u0026gnode-\u003esources[i], node) {\n+\tfor (i = 0; i \u003c buckets; i++)\n+\t\thlist_for_each_entry_safe(snode, t, \u0026gnode-\u003esources[i], node) {\n \t\t\tif (!delayed_work_pending(\u0026snode-\u003esource_timer) ||\n \t\t\t snode-\u003estatus == AMT_SOURCE_STATUS_D_FWD) {\n \t\t\t\tamt_destroy_source(snode);\n@@ -431,14 +508,12 @@ static void amt_group_work(struct work_struct *work)\n \t\t\t\tsnode-\u003estatus = AMT_SOURCE_STATUS_FWD;\n \t\t\t}\n \t\t}\n-\t}\n \tif (delete_group)\n \t\tamt_del_group(amt, gnode);\n \telse\n \t\tgnode-\u003efilter_mode = MCAST_INCLUDE;\n-\trcu_read_unlock();\n \tspin_unlock_bh(\u0026tunnel-\u003elock);\n-out:\n+\trcu_read_unlock();\n \tdev_put(amt-\u003edev);\n }\n \n@@ -479,6 +554,7 @@ static struct amt_group_node *amt_add_group(struct amt_dev *amt,\n \tgnode-\u003etunnel_list = tunnel;\n \tgnode-\u003efilter_mode = MCAST_INCLUDE;\n \tINIT_HLIST_NODE(\u0026gnode-\u003enode);\n+\tINIT_HLIST_NODE(\u0026gnode-\u003egc_node);\n \tINIT_DELAYED_WORK(\u0026gnode-\u003egroup_timer, amt_group_work);\n \tfor (i = 0; i \u003c amt-\u003ehash_buckets; i++)\n \t\tINIT_HLIST_HEAD(\u0026gnode-\u003esources[i]);\n@@ -628,7 +704,7 @@ static void amt_send_discovery(struct amt_dev *amt)\n \t\t\t\t IPPROTO_UDP, 0,\n \t\t\t\t amt-\u003estream_dev-\u003eifindex);\n \tif (IS_ERR(rt)) {\n-\t\tamt-\u003edev-\u003estats.tx_errors++;\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_errors);\n \t\tgoto out;\n \t}\n \n@@ -638,7 +714,7 @@ static void amt_send_discovery(struct amt_dev *amt)\n \tskb = netdev_alloc_skb_ip_align(amt-\u003edev, len);\n \tif (!skb) {\n \t\tip_rt_put(rt);\n-\t\tamt-\u003edev-\u003estats.tx_errors++;\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_errors);\n \t\tgoto out;\n \t}\n \n@@ -683,7 +759,7 @@ static void amt_send_discovery(struct amt_dev *amt)\n \tip_send_check(iph);\n \terr = ip_local_out(amt-\u003enet, sk, skb);\n \tif (unlikely(net_xmit_eval(err)))\n-\t\tamt-\u003edev-\u003estats.tx_errors++;\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_errors);\n \n \tamt_update_gw_status(amt, AMT_STATUS_SENT_DISCOVERY, true);\n out:\n@@ -719,7 +795,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6)\n \t\t\t\t IPPROTO_UDP, 0,\n \t\t\t\t amt-\u003estream_dev-\u003eifindex);\n \tif (IS_ERR(rt)) {\n-\t\tamt-\u003edev-\u003estats.tx_errors++;\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_errors);\n \t\tgoto out;\n \t}\n \n@@ -729,7 +805,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6)\n \tskb = netdev_alloc_skb_ip_align(amt-\u003edev, len);\n \tif (!skb) {\n \t\tip_rt_put(rt);\n-\t\tamt-\u003edev-\u003estats.tx_errors++;\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_errors);\n \t\tgoto out;\n \t}\n \n@@ -776,7 +852,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6)\n \tip_send_check(iph);\n \terr = ip_local_out(amt-\u003enet, sk, skb);\n \tif (unlikely(net_xmit_eval(err)))\n-\t\tamt-\u003edev-\u003estats.tx_errors++;\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_errors);\n \n out:\n \trcu_read_unlock();\n@@ -784,11 +860,16 @@ static void amt_send_request(struct amt_dev *amt, bool v6)\n \n static bool amt_send_membership_query(struct amt_dev *amt,\n \t\t\t\t struct sk_buff *skb,\n-\t\t\t\t struct amt_tunnel_list *tunnel,\n+\t\t\t\t __be32 daddr, __be16 dport,\n+\t\t\t\t __be32 nonce, u64 mac,\n \t\t\t\t bool v6);\n \n-static void amt_send_igmp_gq(struct amt_dev *amt,\n-\t\t\t struct amt_tunnel_list *tunnel)\n+/* The destination is passed by value rather than as a tunnel: the requesting\n+ * source is not authenticated yet and no tunnel state exists for it - see\n+ * amt_request_handler().\n+ */\n+static void amt_send_igmp_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,\n+\t\t\t __be32 nonce, u64 mac)\n {\n \tstruct sk_buff *skb;\n \n@@ -797,8 +878,9 @@ static void amt_send_igmp_gq(struct amt_dev *amt,\n \t\treturn;\n \n \tskb_pull(skb, sizeof(struct ethhdr));\n-\tif (amt_send_membership_query(amt, skb, tunnel, false)) {\n-\t\tamt-\u003edev-\u003estats.tx_dropped++;\n+\tif (amt_send_membership_query(amt, skb, daddr, dport, nonce, mac,\n+\t\t\t\t false)) {\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_dropped);\n \t\tkfree_skb(skb);\n \t}\n }\n@@ -842,7 +924,7 @@ static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt)\n \n \tif (ipv6_dev_get_saddr(amt-\u003enet, amt-\u003edev, \u0026ip6h-\u003edaddr, 0,\n \t\t\t \u0026ip6h-\u003esaddr)) {\n-\t\tamt-\u003edev-\u003estats.tx_errors++;\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_errors);\n \t\tkfree_skb(skb);\n \t\treturn NULL;\n \t}\n@@ -876,7 +958,8 @@ static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt)\n \treturn skb;\n }\n \n-static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)\n+static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,\n+\t\t\t __be32 nonce, u64 mac)\n {\n \tstruct sk_buff *skb;\n \n@@ -885,13 +968,15 @@ static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)\n \t\treturn;\n \n \tskb_pull(skb, sizeof(struct ethhdr));\n-\tif (amt_send_membership_query(amt, skb, tunnel, true)) {\n-\t\tamt-\u003edev-\u003estats.tx_dropped++;\n+\tif (amt_send_membership_query(amt, skb, daddr, dport, nonce, mac,\n+\t\t\t\t true)) {\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_dropped);\n \t\tkfree_skb(skb);\n \t}\n }\n #else\n-static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)\n+static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,\n+\t\t\t __be32 nonce, u64 mac)\n {\n }\n #endif\n@@ -925,7 +1010,14 @@ static void amt_secret_work(struct work_struct *work)\n \t\t\t\t\t secret_wq);\n \n \tspin_lock_bh(\u0026amt-\u003elock);\n-\tget_random_bytes(\u0026amt-\u003ekey, sizeof(siphash_key_t));\n+\t/* Keep three previous generations for a 180-240s MAC lifetime.\n+\t * Its 180s floor exceeds the advertised QQIC (amt-\u003eqi, 125s),\n+\t * allowing the gateway to renew its MAC with a periodic Request.\n+\t */\n+\tamt-\u003ekey[3] = amt-\u003ekey[2];\n+\tamt-\u003ekey[2] = amt-\u003ekey[1];\n+\tamt-\u003ekey[1] = amt-\u003ekey[0];\n+\tget_random_bytes(\u0026amt-\u003ekey[0], sizeof(siphash_key_t));\n \tspin_unlock_bh(\u0026amt-\u003elock);\n \tmod_delayed_work(amt_wq, \u0026amt-\u003esecret_wq,\n \t\t\t msecs_to_jiffies(AMT_SECRET_TIMEOUT));\n@@ -1115,9 +1207,16 @@ static void amt_send_multicast_data(struct amt_dev *amt,\n \t\t\t 0);\n }\n \n+/* Send a Membership Query to a source that has not been authenticated yet.\n+ *\n+ * No per-source state exists at this point and none is created: the nonce and\n+ * the keyed MAC are carried in the Query and recomputed from the Membership\n+ * Update when it comes back, so everything this needs is passed by value.\n+ */\n static bool amt_send_membership_query(struct amt_dev *amt,\n \t\t\t\t struct sk_buff *skb,\n-\t\t\t\t struct amt_tunnel_list *tunnel,\n+\t\t\t\t __be32 daddr, __be16 dport,\n+\t\t\t\t __be32 nonce, u64 mac,\n \t\t\t\t bool v6)\n {\n \tstruct amt_header_membership_query *amtmq;\n@@ -1138,13 +1237,13 @@ static bool amt_send_membership_query(struct amt_dev *amt,\n \tskb_reset_inner_headers(skb);\n \tmemset(\u0026fl4, 0, sizeof(struct flowi4));\n \tfl4.flowi4_oif = amt-\u003estream_dev-\u003eifindex;\n-\tfl4.daddr = tunnel-\u003eip4;\n+\tfl4.daddr = daddr;\n \tfl4.saddr = amt-\u003elocal_ip;\n \tfl4.flowi4_dscp = inet_dsfield_to_dscp(AMT_TOS);\n \tfl4.flowi4_proto = IPPROTO_UDP;\n \trt = ip_route_output_key(amt-\u003enet, \u0026fl4);\n \tif (IS_ERR(rt)) {\n-\t\tnetdev_dbg(amt-\u003edev, \"no route to %pI4\\n\", \u0026tunnel-\u003eip4);\n+\t\tnetdev_dbg(amt-\u003edev, \"no route to %pI4\\n\", \u0026daddr);\n \t\treturn true;\n \t}\n \n@@ -1154,8 +1253,8 @@ static bool amt_send_membership_query(struct amt_dev *amt,\n \tamtmq-\u003ereserved = 0;\n \tamtmq-\u003el\t= 0;\n \tamtmq-\u003eg\t= 0;\n-\tamtmq-\u003enonce\t= tunnel-\u003enonce;\n-\tamtmq-\u003eresponse_mac = tunnel-\u003emac;\n+\tamtmq-\u003enonce\t= nonce;\n+\tamtmq-\u003eresponse_mac = mac;\n \n \tif (!v6)\n \t\tskb_set_inner_protocol(skb, htons(ETH_P_IP));\n@@ -1168,11 +1267,10 @@ static bool amt_send_membership_query(struct amt_dev *amt,\n \t\t\t ip4_dst_hoplimit(\u0026rt-\u003edst),\n \t\t\t 0,\n \t\t\t amt-\u003erelay_port,\n-\t\t\t tunnel-\u003esource_port,\n+\t\t\t dport,\n \t\t\t false,\n \t\t\t false,\n \t\t\t 0);\n-\tamt_update_relay_status(tunnel, AMT_STATUS_SENT_QUERY, true);\n \treturn false;\n }\n \n@@ -1236,7 +1334,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)\n \t\tgroup.ip6 = ipv6_hdr(skb)-\u003edaddr;\n #endif\n \t} else {\n-\t\tdev-\u003estats.tx_errors++;\n+\t\tDEV_STATS_INC(dev, tx_errors);\n \t\tgoto free;\n \t}\n \n@@ -1249,12 +1347,21 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)\n \t\t/* Gateway only passes IGMP/MLD packets */\n \t\tif (!report)\n \t\t\tgoto free;\n+\t\t/* A validated report can only be forwarded after the relay's\n+\t\t * family-specific Membership Query supplies the state echoed\n+\t\t * by the Membership Update. Log this readiness failure before\n+\t\t * the shared drop path accounts it.\n+\t\t */\n \t\tif ((!v6 \u0026\u0026 !READ_ONCE(amt-\u003eready4)) ||\n-\t\t (v6 \u0026\u0026 !READ_ONCE(amt-\u003eready6)))\n+\t\t (v6 \u0026\u0026 !READ_ONCE(amt-\u003eready6))) {\n+\t\t\tnetdev_dbg(dev, \"drop %s report: waiting for Membership Query\\n\",\n+\t\t\t\t v6 ? \"MLD\" : \"IGMP\");\n \t\t\tgoto free;\n+\t\t}\n \t\tif (amt_send_membership_update(amt, skb, v6))\n \t\t\tgoto free;\n-\t\tgoto unlock;\n+\t\t/* Sent: the tunnel consumed the skb. Not a drop. */\n+\t\treturn NETDEV_TX_OK;\n \t} else if (amt-\u003emode == AMT_MODE_RELAY) {\n \t\tif (!data)\n \t\t\tgoto free;\n@@ -1283,8 +1390,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)\n \treturn NETDEV_TX_OK;\n free:\n \tdev_kfree_skb(skb);\n-unlock:\n-\tdev-\u003estats.tx_dropped++;\n+\tDEV_STATS_INC(dev, tx_dropped);\n \treturn NETDEV_TX_OK;\n }\n \n@@ -1328,14 +1434,41 @@ static void amt_tunnel_expire(struct work_struct *work)\n \t\t\t\t\t\t struct amt_tunnel_list,\n \t\t\t\t\t\t gc_wq);\n \tstruct amt_dev *amt = tunnel-\u003eamt;\n+\tunsigned long deadline;\n \n \tspin_lock_bh(\u0026amt-\u003elock);\n+\t/* amt_dev_stop() has taken ownership of the teardown. */\n+\tif (READ_ONCE(tunnel-\u003edead)) {\n+\t\tspin_unlock_bh(\u0026amt-\u003elock);\n+\t\treturn;\n+\t}\n+\t/* A Membership Update may have refreshed the tunnel after this work\n+\t * was queued. Re-arm from last_seen rather than letting\n+\t * amt_update_handler() re-arm gc_wq: this handler is then the only\n+\t * context that frees the tunnel on the timeout path; amt_dev_stop()\n+\t * still owns teardown during device shutdown.\n+\t */\n+\tdeadline = READ_ONCE(tunnel-\u003elast_seen);\n+\tif (!deadline)\n+\t\tdeadline = jiffies;\n+\telse\n+\t\tdeadline += msecs_to_jiffies(amt_gmi(amt)) * 3;\n+\tif (time_before(jiffies, deadline)) {\n+\t\tmod_delayed_work(amt_wq, \u0026tunnel-\u003egc_wq, deadline - jiffies);\n+\t\tspin_unlock_bh(\u0026amt-\u003elock);\n+\t\treturn;\n+\t}\n+\tspin_lock_bh(\u0026tunnel-\u003elock);\n+\tWRITE_ONCE(tunnel-\u003edead, true);\n+\tspin_unlock_bh(\u0026tunnel-\u003elock);\n \trcu_read_lock();\n \tlist_del_rcu(\u0026tunnel-\u003elist);\n \tamt-\u003enr_tunnels--;\n \tamt_clear_groups(tunnel);\n \trcu_read_unlock();\n \tspin_unlock_bh(\u0026amt-\u003elock);\n+\tcancel_delayed_work_sync(\u0026group_gc_wq);\n+\t__amt_group_gc_work();\n \tkfree_rcu(tunnel, rcu);\n }\n \n@@ -2369,6 +2502,10 @@ static bool amt_membership_query_handler(struct amt_dev *amt,\n \tif (amtmq-\u003ereserved || amtmq-\u003eversion)\n \t\treturn true;\n \n+\t/* A deferred query may outlive a relay address change. */\n+\tif (ip_hdr(skb)-\u003esaddr != READ_ONCE(amt-\u003eremote_ip))\n+\t\treturn true;\n+\n \tif (amtmq-\u003enonce != amt-\u003enonce)\n \t\treturn true;\n \n@@ -2461,16 +2598,106 @@ static bool amt_membership_query_handler(struct amt_dev *amt,\n \treturn false;\n }\n \n+/* The tunnel of the gateway endpoint @saddr:@sport, or NULL. */\n+static struct amt_tunnel_list *amt_tunnel_lookup(struct amt_dev *amt,\n+\t\t\t\t\t\t __be32 saddr, __be16 sport)\n+{\n+\tstruct amt_tunnel_list *tunnel;\n+\n+\tlist_for_each_entry_rcu(tunnel, \u0026amt-\u003etunnel_list, list)\n+\t\tif (tunnel-\u003eip4 == saddr \u0026\u0026 tunnel-\u003esource_port == sport)\n+\t\t\treturn tunnel;\n+\treturn NULL;\n+}\n+\n+/* Look up the tunnel for a source whose Membership Update has already been\n+ * authenticated, creating it on first contact.\n+ *\n+ * This is now the only place tunnel state is allocated, so amt-\u003emax_tunnels\n+ * bounds the number of *verified* gateways rather than the number of\n+ * unverified Requests anyone can send. A fixed per-source cap additionally\n+ * stops one verified source address from monopolising the table.\n+ */\n+static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt,\n+\t\t\t\t\t\t\t__be32 saddr,\n+\t\t\t\t\t\t\t__be16 sport)\n+{\n+\tstruct amt_tunnel_list *tunnel;\n+\tint per_src = 0;\n+\tint i;\n+\n+\ttunnel = amt_tunnel_lookup(amt, saddr, sport);\n+\tif (tunnel)\n+\t\treturn tunnel;\n+\n+\tspin_lock_bh(\u0026amt-\u003elock);\n+\n+\t/* Re-check under the lock in case a concurrent Update won the race, and\n+\t * count how many tunnels this source already holds on the same walk.\n+\t */\n+\tlist_for_each_entry(tunnel, \u0026amt-\u003etunnel_list, list) {\n+\t\tif (tunnel-\u003eip4 != saddr)\n+\t\t\tcontinue;\n+\t\tif (tunnel-\u003esource_port == sport) {\n+\t\t\tspin_unlock_bh(\u0026amt-\u003elock);\n+\t\t\treturn tunnel;\n+\t\t}\n+\t\tper_src++;\n+\t}\n+\n+\tif (amt-\u003enr_tunnels \u003e= amt-\u003emax_tunnels ||\n+\t per_src \u003e= AMT_MAX_TUNNELS_PER_SRC) {\n+\t\tspin_unlock_bh(\u0026amt-\u003elock);\n+\t\treturn NULL;\n+\t}\n+\n+\tif (!netif_running(amt-\u003edev)) {\n+\t\tspin_unlock_bh(\u0026amt-\u003elock);\n+\t\treturn NULL;\n+\t}\n+\n+\ttunnel = kzalloc(sizeof(*tunnel) +\n+\t\t\t (sizeof(struct hlist_head) * amt-\u003ehash_buckets),\n+\t\t\t GFP_ATOMIC);\n+\tif (!tunnel) {\n+\t\tspin_unlock_bh(\u0026amt-\u003elock);\n+\t\treturn NULL;\n+\t}\n+\n+\ttunnel-\u003esource_port = sport;\n+\ttunnel-\u003eip4 = saddr;\n+\ttunnel-\u003eamt = amt;\n+\tspin_lock_init(\u0026tunnel-\u003elock);\n+\tfor (i = 0; i \u003c amt-\u003ehash_buckets; i++)\n+\t\tINIT_HLIST_HEAD(\u0026tunnel-\u003egroups[i]);\n+\n+\ttunnel-\u003elast_seen = jiffies;\n+\tINIT_DELAYED_WORK(\u0026tunnel-\u003egc_wq, amt_tunnel_expire);\n+\t__amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_UPDATE, false);\n+\n+\t/* Publish only once the entry is fully initialised. */\n+\tlist_add_tail_rcu(\u0026tunnel-\u003elist, \u0026amt-\u003etunnel_list);\n+\tamt-\u003enr_tunnels++;\n+\tmod_delayed_work(amt_wq, \u0026tunnel-\u003egc_wq,\n+\t\t\t msecs_to_jiffies(amt_gmi(amt)) * 3);\n+\tspin_unlock_bh(\u0026amt-\u003elock);\n+\n+\treturn tunnel;\n+}\n+\n static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)\n {\n \tstruct amt_header_membership_update *amtmu;\n \tstruct amt_tunnel_list *tunnel;\n \tstruct ethhdr *eth;\n \tstruct iphdr *iph;\n-\tint len, hdr_size;\n+\tsiphash_key_t key[4];\n+\tint len, hdr_size, i;\n \tu64 response_mac;\n+\tbool verified = false;\n \t__be32 saddr;\n \t__be32 nonce;\n+\t__be16 sport;\n \n \tsaddr = ip_hdr(skb)-\u003esaddr;\n \n@@ -2484,30 +2711,51 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)\n \n \tnonce = amtmu-\u003enonce;\n \tresponse_mac = amtmu-\u003eresponse_mac;\n+\t/* Snapshot the tunnel endpoint port before the encap is stripped. */\n+\tsport = udp_hdr(skb)-\u003esource;\n \n-\tif (iptunnel_pull_header(skb, hdr_size, skb-\u003eprotocol, false))\n-\t\treturn true;\n+\t/* Recompute the MAC handed out in the Membership Query. Four live\n+\t * secrets cover 180-240s, exceeding the advertised QQIC (amt-\u003eqi,\n+\t * 125s), so a periodic Request can renew the MAC before it expires.\n+\t * Authenticate before decapsulation or allocating tunnel state.\n+\t */\n+\tspin_lock_bh(\u0026amt-\u003elock);\n+\tfor (i = 0; i \u003c ARRAY_SIZE(key); i++)\n+\t\tkey[i] = amt-\u003ekey[i];\n+\tspin_unlock_bh(\u0026amt-\u003elock);\n \n-\tskb_reset_network_header(skb);\n+\tfor (i = 0; i \u003c ARRAY_SIZE(key); i++) {\n+\t\tu64 mac = siphash_3u32((__force u32)saddr,\n+\t\t\t\t (__force u32)sport,\n+\t\t\t\t (__force u32)nonce,\n+\t\t\t\t \u0026key[i]) \u003e\u003e 16;\n \n-\tlist_for_each_entry_rcu(tunnel, \u0026amt-\u003etunnel_list, list) {\n-\t\tif (tunnel-\u003eip4 == saddr) {\n-\t\t\tif ((nonce == tunnel-\u003enonce \u0026\u0026\n-\t\t\t response_mac == tunnel-\u003emac)) {\n-\t\t\t\tmod_delayed_work(amt_wq, \u0026tunnel-\u003egc_wq,\n-\t\t\t\t\t\t msecs_to_jiffies(amt_gmi(amt))\n-\t\t\t\t\t\t\t\t * 3);\n-\t\t\t\tgoto report;\n-\t\t\t} else {\n-\t\t\t\tnetdev_dbg(amt-\u003edev, \"Invalid MAC\\n\");\n-\t\t\t\treturn true;\n-\t\t\t}\n+\t\tif (response_mac == mac) {\n+\t\t\tverified = true;\n+\t\t\tbreak;\n \t\t}\n \t}\n \n-\treturn true;\n+\tif (!verified) {\n+\t\tnetdev_dbg(amt-\u003edev, \"Invalid MAC\\n\");\n+\t\treturn true;\n+\t}\n+\n+\ttunnel = amt_tunnel_get_or_create(amt, saddr, sport);\n+\tif (!tunnel)\n+\t\treturn true;\n+\n+\t/* Refresh liveness only. gc_wq is re-armed by amt_tunnel_expire()\n+\t * itself from last_seen, never from here, so this cannot re-queue the\n+\t * work of a tunnel that is being freed.\n+\t */\n+\tWRITE_ONCE(tunnel-\u003elast_seen, jiffies);\n+\n+\tif (iptunnel_pull_header(skb, hdr_size, skb-\u003eprotocol, false))\n+\t\treturn true;\n+\n+\tskb_reset_network_header(skb);\n \n-report:\n \tif (!pskb_may_pull(skb, sizeof(*iph)))\n \t\treturn true;\n \n@@ -2522,6 +2770,10 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)\n \t\t}\n \n \t\tspin_lock_bh(\u0026tunnel-\u003elock);\n+\t\tif (READ_ONCE(tunnel-\u003edead)) {\n+\t\t\tspin_unlock_bh(\u0026tunnel-\u003elock);\n+\t\t\treturn true;\n+\t\t}\n \t\tamt_igmp_report_handler(amt, skb, tunnel);\n \t\tspin_unlock_bh(\u0026tunnel-\u003elock);\n \n@@ -2542,6 +2794,10 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)\n \t\t}\n \n \t\tspin_lock_bh(\u0026tunnel-\u003elock);\n+\t\tif (READ_ONCE(tunnel-\u003edead)) {\n+\t\t\tspin_unlock_bh(\u0026tunnel-\u003elock);\n+\t\t\treturn true;\n+\t\t}\n \t\tamt_mld_report_handler(amt, skb, tunnel);\n \t\tspin_unlock_bh(\u0026tunnel-\u003elock);\n \n@@ -2601,7 +2857,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce,\n \t\t\t\t IPPROTO_UDP, 0,\n \t\t\t\t amt-\u003estream_dev-\u003eifindex);\n \tif (IS_ERR(rt)) {\n-\t\tamt-\u003edev-\u003estats.tx_errors++;\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_errors);\n \t\tgoto out;\n \t}\n \n@@ -2611,7 +2867,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce,\n \tskb = netdev_alloc_skb_ip_align(amt-\u003edev, len);\n \tif (!skb) {\n \t\tip_rt_put(rt);\n-\t\tamt-\u003edev-\u003estats.tx_errors++;\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_errors);\n \t\tgoto out;\n \t}\n \n@@ -2657,7 +2913,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce,\n \tip_send_check(iph);\n \terr = ip_local_out(amt-\u003enet, sk, skb);\n \tif (unlikely(net_xmit_eval(err)))\n-\t\tamt-\u003edev-\u003estats.tx_errors++;\n+\t\tDEV_STATS_INC(amt-\u003edev, tx_errors);\n \n out:\n \trcu_read_unlock();\n@@ -2684,15 +2940,29 @@ static bool amt_discovery_handler(struct amt_dev *amt, struct sk_buff *skb)\n \treturn false;\n }\n \n+/* Handle an AMT Relay Membership Request.\n+ *\n+ * The source of a Request is unauthenticated: it is a bare UDP datagram with a\n+ * trivially spoofable source address. Allocating tunnel state here let an\n+ * attacker fill the table from spoofed addresses, and let one spoofed packet\n+ * overwrite the nonce/MAC of an established tunnel and cut that gateway off.\n+ *\n+ * Nothing needs to be remembered at this point. Every input to the keyed MAC\n+ * is carried in the packet or is device state, so the MAC is generated here,\n+ * echoed back by the gateway in its Membership Update, and recomputed and\n+ * verified there - see amt_update_handler(). Tunnel state is created only once\n+ * that verification succeeds.\n+ */\n static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)\n {\n \tstruct amt_header_request *amtrh;\n \tstruct amt_tunnel_list *tunnel;\n-\tunsigned long long key;\n \tstruct udphdr *udph;\n \tstruct iphdr *iph;\n+\tsiphash_key_t key;\n+\tbool full, have = false;\n+\tint per_src = 0;\n \tu64 mac;\n-\tint i;\n \n \tif (!pskb_may_pull(skb, sizeof(*udph) + sizeof(*amtrh)))\n \t\treturn true;\n@@ -2704,59 +2974,41 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)\n \tif (amtrh-\u003ereserved1 || amtrh-\u003ereserved2 || amtrh-\u003eversion)\n \t\treturn true;\n \n-\tlist_for_each_entry_rcu(tunnel, \u0026amt-\u003etunnel_list, list)\n-\t\tif (tunnel-\u003eip4 == iph-\u003esaddr)\n-\t\t\tgoto send;\n-\n-\tspin_lock_bh(\u0026amt-\u003elock);\n-\tif (amt-\u003enr_tunnels \u003e= amt-\u003emax_tunnels) {\n-\t\tspin_unlock_bh(\u0026amt-\u003elock);\n-\t\ticmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);\n+\tif (!netif_running(amt-\u003edev) || !netif_running(amt-\u003estream_dev))\n \t\treturn true;\n-\t}\n \n-\ttunnel = kzalloc(sizeof(*tunnel) +\n-\t\t\t (sizeof(struct hlist_head) * amt-\u003ehash_buckets),\n-\t\t\t GFP_ATOMIC);\n-\tif (!tunnel) {\n-\t\tspin_unlock_bh(\u0026amt-\u003elock);\n-\t\treturn true;\n-\t}\n-\n-\ttunnel-\u003esource_port = udph-\u003esource;\n-\ttunnel-\u003eip4 = iph-\u003esaddr;\n-\n-\tmemcpy(\u0026key, \u0026tunnel-\u003ekey, sizeof(unsigned long long));\n-\ttunnel-\u003eamt = amt;\n-\tspin_lock_init(\u0026tunnel-\u003elock);\n-\tfor (i = 0; i \u003c amt-\u003ehash_buckets; i++)\n-\t\tINIT_HLIST_HEAD(\u0026tunnel-\u003egroups[i]);\n-\n-\tINIT_DELAYED_WORK(\u0026tunnel-\u003egc_wq, amt_tunnel_expire);\n-\n-\tlist_add_tail_rcu(\u0026tunnel-\u003elist, \u0026amt-\u003etunnel_list);\n-\ttunnel-\u003ekey = amt-\u003ekey;\n-\t__amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_REQUEST, true);\n-\tamt-\u003enr_tunnels++;\n-\tmod_delayed_work(amt_wq, \u0026tunnel-\u003egc_wq,\n-\t\t\t msecs_to_jiffies(amt_gmi(amt)));\n+\t/* Snapshot the secret and limits under the lock; keep the endpoint walk\n+\t * out of the lock so spoofed Requests cannot serialize relay updates.\n+\t */\n+\tspin_lock_bh(\u0026amt-\u003elock);\n+\tkey = amt-\u003ekey[0];\n+\tfull = amt-\u003enr_tunnels \u003e= amt-\u003emax_tunnels;\n \tspin_unlock_bh(\u0026amt-\u003elock);\n \n-send:\n-\ttunnel-\u003enonce = amtrh-\u003enonce;\n-\tmac = siphash_3u32((__force u32)tunnel-\u003eip4,\n-\t\t\t (__force u32)tunnel-\u003esource_port,\n-\t\t\t (__force u32)tunnel-\u003enonce,\n-\t\t\t \u0026tunnel-\u003ekey);\n-\ttunnel-\u003emac = mac \u003e\u003e 16;\n+\trcu_read_lock();\n+\tlist_for_each_entry_rcu(tunnel, \u0026amt-\u003etunnel_list, list) {\n+\t\tif (tunnel-\u003eip4 != iph-\u003esaddr)\n+\t\t\tcontinue;\n+\t\tper_src++;\n+\t\tif (tunnel-\u003esource_port == udph-\u003esource)\n+\t\t\thave = true;\n+\t}\n+\trcu_read_unlock();\n \n-\tif (!netif_running(amt-\u003edev) || !netif_running(amt-\u003estream_dev))\n+\t/* Withhold the Query when a new endpoint cannot get a tunnel. */\n+\tif (!have \u0026\u0026 (full || per_src \u003e= AMT_MAX_TUNNELS_PER_SRC))\n \t\treturn true;\n \n+\tmac = siphash_3u32((__force u32)iph-\u003esaddr,\n+\t\t\t (__force u32)udph-\u003esource,\n+\t\t\t (__force u32)amtrh-\u003enonce,\n+\t\t\t \u0026key) \u003e\u003e 16;\n \tif (!amtrh-\u003ep)\n-\t\tamt_send_igmp_gq(amt, tunnel);\n+\t\tamt_send_igmp_gq(amt, iph-\u003esaddr, udph-\u003esource, amtrh-\u003enonce,\n+\t\t\t\t mac);\n \telse\n-\t\tamt_send_mld_gq(amt, tunnel);\n+\t\tamt_send_mld_gq(amt, iph-\u003esaddr, udph-\u003esource, amtrh-\u003enonce,\n+\t\t\t\t mac);\n \n \treturn false;\n }\n@@ -2833,7 +3085,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)\n \t\t\t}\n \t\t\tgoto out;\n \t\tcase AMT_MSG_MULTICAST_DATA:\n-\t\t\tif (saddr != remote_ip) {\n+\t\t\tif (!remote_ip || saddr != remote_ip) {\n \t\t\t\tnetdev_dbg(amt-\u003edev, \"Invalid Relay IP\\n\");\n \t\t\t\terr = true;\n \t\t\t\tgoto drop;\n@@ -2844,7 +3096,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)\n \t\t\telse\n \t\t\t\tgoto out;\n \t\tcase AMT_MSG_MEMBERSHIP_QUERY:\n-\t\t\tif (saddr != remote_ip) {\n+\t\t\tif (!remote_ip || saddr != remote_ip) {\n \t\t\t\tnetdev_dbg(amt-\u003edev, \"Invalid Relay IP\\n\");\n \t\t\t\terr = true;\n \t\t\t\tgoto drop;\n@@ -3024,6 +3276,14 @@ static int amt_dev_open(struct net_device *dev)\n \tenable_delayed_work(\u0026amt-\u003ediscovery_wq);\n \tenable_delayed_work(\u0026amt-\u003ereq_wq);\n \n+\t/* Seed the keys before amt_socket_create() enables the encap receive\n+\t * path, so a Request or Update that arrives immediately is never\n+\t * verified against an all-zero (predictable) secret.\n+\t */\n+\tspin_lock_bh(\u0026amt-\u003elock);\n+\tget_random_bytes(\u0026amt-\u003ekey, sizeof(amt-\u003ekey));\n+\tspin_unlock_bh(\u0026amt-\u003elock);\n+\n \terr = amt_socket_create(amt);\n \tif (err) {\n \t\tdisable_delayed_work(\u0026amt-\u003ereq_wq);\n@@ -3034,7 +3294,6 @@ static int amt_dev_open(struct net_device *dev)\n \tamt-\u003ereq_cnt = 0;\n \tWRITE_ONCE(amt-\u003eremote_ip, 0);\n \tamt-\u003enonce = 0;\n-\tget_random_bytes(\u0026amt-\u003ekey, sizeof(siphash_key_t));\n \n \tamt-\u003estatus = AMT_STATUS_INIT;\n \tif (amt-\u003emode == AMT_MODE_GATEWAY) {\n@@ -3050,7 +3309,7 @@ static int amt_dev_open(struct net_device *dev)\n static int amt_dev_stop(struct net_device *dev)\n {\n \tstruct amt_dev *amt = netdev_priv(dev);\n-\tstruct amt_tunnel_list *tunnel, *tmp;\n+\tstruct amt_tunnel_list *tunnel;\n \tstruct sk_buff *skb;\n \tstruct sock *sk;\n \tint i;\n@@ -3079,11 +3338,38 @@ static int amt_dev_stop(struct net_device *dev)\n \tamt-\u003ereq_cnt = 0;\n \tWRITE_ONCE(amt-\u003eremote_ip, 0);\n \n-\tlist_for_each_entry_safe(tunnel, tmp, \u0026amt-\u003etunnel_list, list) {\n-\t\tlist_del_rcu(\u0026tunnel-\u003elist);\n-\t\tamt-\u003enr_tunnels--;\n+\t/* Mark every tunnel dead first, so a concurrent amt_tunnel_expire()\n+\t * sees -\u003edead and bails instead of freeing a tunnel in parallel; this\n+\t * path is then the sole freer.\n+\t */\n+\tspin_lock_bh(\u0026amt-\u003elock);\n+\tlist_for_each_entry(tunnel, \u0026amt-\u003etunnel_list, list) {\n+\t\tspin_lock_bh(\u0026tunnel-\u003elock);\n+\t\tWRITE_ONCE(tunnel-\u003edead, true);\n+\t\tspin_unlock_bh(\u0026tunnel-\u003elock);\n+\t}\n+\tspin_unlock_bh(\u0026amt-\u003elock);\n+\n+\t/* Unlink one tunnel at a time with list_del_rcu() rather than splicing\n+\t * the list onto a local head: a lockless reader walking tunnel_list\n+\t * must always terminate at \u0026amt-\u003etunnel_list, never at a stack head.\n+\t */\n+\tfor (;;) {\n+\t\tspin_lock_bh(\u0026amt-\u003elock);\n+\t\ttunnel = list_first_entry_or_null(\u0026amt-\u003etunnel_list,\n+\t\t\t\t\t\t struct amt_tunnel_list, list);\n+\t\tif (tunnel) {\n+\t\t\tlist_del_rcu(\u0026tunnel-\u003elist);\n+\t\t\tamt-\u003enr_tunnels--;\n+\t\t}\n+\t\tspin_unlock_bh(\u0026amt-\u003elock);\n+\t\tif (!tunnel)\n+\t\t\tbreak;\n+\n \t\tcancel_delayed_work_sync(\u0026tunnel-\u003egc_wq);\n \t\tamt_clear_groups(tunnel);\n+\t\tcancel_delayed_work_sync(\u0026group_gc_wq);\n+\t\t__amt_group_gc_work();\n \t\tkfree_rcu(tunnel, rcu);\n \t}\n \n@@ -3152,9 +3438,9 @@ static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = {\n \t[IFLA_AMT_RELAY_PORT]\t= { .type = NLA_U16 },\n \t[IFLA_AMT_GATEWAY_PORT]\t= { .type = NLA_U16 },\n \t[IFLA_AMT_LINK]\t\t= { .type = NLA_U32 },\n-\t[IFLA_AMT_LOCAL_IP]\t= { .len = sizeof_field(struct iphdr, daddr) },\n+\t[IFLA_AMT_LOCAL_IP]\t= NLA_POLICY_EXACT_LEN(sizeof(__be32)),\n \t[IFLA_AMT_REMOTE_IP]\t= { .len = sizeof_field(struct iphdr, daddr) },\n-\t[IFLA_AMT_DISCOVERY_IP]\t= { .len = sizeof_field(struct iphdr, daddr) },\n+\t[IFLA_AMT_DISCOVERY_IP]\t= NLA_POLICY_EXACT_LEN(sizeof(__be32)),\n \t[IFLA_AMT_MAX_TUNNELS]\t= { .type = NLA_U32 },\n };\n \n@@ -3461,11 +3747,17 @@ static int __init amt_init(void)\n \t}\n \n \tspin_lock_init(\u0026source_gc_lock);\n+\tspin_lock_init(\u0026group_gc_lock);\n \tspin_lock_bh(\u0026source_gc_lock);\n \tINIT_DELAYED_WORK(\u0026source_gc_wq, amt_source_gc_work);\n \tmod_delayed_work(amt_wq, \u0026source_gc_wq,\n \t\t\t msecs_to_jiffies(AMT_GC_INTERVAL));\n \tspin_unlock_bh(\u0026source_gc_lock);\n+\tspin_lock_bh(\u0026group_gc_lock);\n+\tINIT_DELAYED_WORK(\u0026group_gc_wq, amt_group_gc_work);\n+\tmod_delayed_work(amt_wq, \u0026group_gc_wq,\n+\t\t\t msecs_to_jiffies(AMT_GC_INTERVAL));\n+\tspin_unlock_bh(\u0026group_gc_lock);\n \n \treturn 0;\n \n@@ -3485,6 +3777,8 @@ static void __exit amt_fini(void)\n \tunregister_netdevice_notifier(\u0026amt_notifier_block);\n \tcancel_delayed_work_sync(\u0026source_gc_wq);\n \t__amt_source_gc_work();\n+\tcancel_delayed_work_sync(\u0026group_gc_wq);\n+\t__amt_group_gc_work();\n \tdestroy_workqueue(amt_wq);\n }\n module_exit(amt_fini);\ndiff --git a/include/net/amt.h b/include/net/amt.h\nindex 2846dde0cadce..4acfc3da0c5aa 100644\n--- a/include/net/amt.h\n+++ b/include/net/amt.h\n@@ -240,12 +240,19 @@ struct amt_tunnel_list {\n \tu32\t\t\tnr_sources;\n \tenum amt_status\t\tstatus;\n \tstruct delayed_work\tgc_wq;\n+\t/* Last time this tunnel was refreshed. gc_wq\n+\t * re-arms itself from this rather than being re-armed by the Update\n+\t * path, so the Update path cannot re-queue work for a tunnel that\n+\t * amt_tunnel_expire() is freeing on the timeout path.\n+\t */\n+\tunsigned long\t\tlast_seen;\n+\t/* Set under amt-\u003elock and tunnel-\u003elock by whichever freer reaches the\n+\t * tunnel first;\n+\t * the other then leaves it alone, so the tunnel is freed exactly once.\n+\t */\n+\tbool\t\t\tdead;\n \t__be16\t\t\tsource_port;\n \t__be32\t\t\tip4;\n-\t__be32\t\t\tnonce;\n-\tsiphash_key_t\t\tkey;\n-\tu64\t\t\tmac:48,\n-\t\t\t\treserved:16;\n \tstruct rcu_head\t\trcu;\n \tstruct hlist_head\tgroups[];\n };\n@@ -275,6 +282,7 @@ enum amt_source_status {\n /* protected by gnode-\u003elock */\n struct amt_source_node {\n \tstruct hlist_node\tnode;\n+\tstruct hlist_node\tgc_node;\n \tstruct amt_group_node\t*gnode;\n \tstruct delayed_work source_timer;\n \tunion amt_addr\t\tsource_addr;\n@@ -282,6 +290,8 @@ struct amt_source_node {\n #define AMT_SOURCE_OLD\t0\n #define AMT_SOURCE_NEW\t1\n \tu8\t\t\tflags;\n+\t/* Protected by gnode-\u003etunnel_list-\u003elock. */\n+\tbool\t\t\tdead;\n \tstruct rcu_head\t\trcu;\n };\n \n@@ -295,7 +305,10 @@ struct amt_group_node {\n \tu32\t\t\tnr_sources;\n \tstruct amt_tunnel_list\t*tunnel_list;\n \tstruct hlist_node\tnode;\n+\tstruct hlist_node\tgc_node;\n \tstruct delayed_work group_timer;\n+\t/* Protected by tunnel_list-\u003elock. */\n+\tbool\t\t\tdead;\n \tstruct rcu_head\t\trcu;\n \tstruct hlist_head\tsources[];\n };\n@@ -325,8 +338,10 @@ struct amt_dev {\n \tstruct work_struct\tevent_wq;\n \t/* AMT status */\n \tenum amt_status\t\tstatus;\n-\t/* Generated key */\n-\tsiphash_key_t\t\tkey;\n+\t/* Current key and three previous generations keep MACs valid for\n+\t * 180-240s, beyond the advertised QQIC (see amt_secret_work()).\n+\t */\n+\tsiphash_key_t\t\tkey[4];\n \tstruct sock\t __rcu *sk;\n \tu32\t\t\tmax_groups;\n \tu32\t\t\tmax_sources;\n@@ -383,6 +398,10 @@ struct amt_dev {\n #define AMT_SECRET_TIMEOUT\t60000\n #define IANA_AMT_UDP_PORT\t2268\n #define AMT_MAX_TUNNELS 128\n+/* Fixed per-source cap stops one verified source address from monopolising\n+ * the AMT_MAX_TUNNELS-slot table.\n+ */\n+#define AMT_MAX_TUNNELS_PER_SRC 16\n #define AMT_MAX_REQS\t\t128\n #define AMT_GW_HLEN (sizeof(struct iphdr) + \\\n \t\t sizeof(struct udphdr) + \\\n"
} |
| 2/1 | 2026/10/20 05:57 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"AMT",
"INET",
"IP_MULTICAST",
"IPV6"
],
"FocusSymbols": [
"amt_tunnel_get_or_create",
"amt_update_handler",
"amt_request_handler",
"amt_tunnel_expire",
"amt_group_work",
"amt_source_work",
"amt_group_gc_work",
"amt_destroy_source",
"amt_del_group",
"amt_rcv"
],
"Reasoning": "The patch extensively refactors the lifecycle, garbage collection, concurrency control, and packet processing logic of the AMT (Automatic Multicast Tunneling) driver. It introduces a new group GC list and delayed work queue, updates delayed work cancellation and RCU freeing patterns, alters tunnel allocation semantics (deferring tunnel creation to the Membership Update handler instead of Request handling), and adds multi-generational SipHash keys. These changes touch reachable virtual network device code that can be created and driven via rtnetlink and network sockets without specialized hardware, warranting fuzzing for potential race conditions, UAFs, or workqueue/locking regressions.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 8a04eae34c5c057fcb5e7f0ec93d7b4d5052eee0
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Oct 20 05:57:19 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index b53f8ec556615..faf32976305b3 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -38,6 +38,10 @@ static HLIST_HEAD(source_gc_list);
/* Lock for source_gc_list */
static spinlock_t source_gc_lock;
static struct delayed_work source_gc_wq;
+static HLIST_HEAD(group_gc_list);
+/* Lock for group_gc_list */
+static spinlock_t group_gc_lock;
+static struct delayed_work group_gc_wq;
static char *status_str[] = {
"AMT_STATUS_INIT",
"AMT_STATUS_SENT_DISCOVERY",
@@ -90,8 +94,9 @@ static void __amt_source_gc_work(void)
hlist_move_list(&source_gc_list, &gc_list);
spin_unlock_bh(&source_gc_lock);
- hlist_for_each_entry_safe(snode, t, &gc_list, node) {
- hlist_del_rcu(&snode->node);
+ hlist_for_each_entry_safe(snode, t, &gc_list, gc_node) {
+ cancel_delayed_work_sync(&snode->source_timer);
+ hlist_del_init(&snode->gc_node);
kfree_rcu(snode, rcu);
}
}
@@ -106,6 +111,39 @@ static void amt_source_gc_work(struct work_struct *work)
spin_unlock_bh(&source_gc_lock);
}
+static void __amt_group_gc_work(void)
+{
+ struct amt_group_node *gnode;
+ struct hlist_head gc_list;
+ struct hlist_node *t;
+
+ spin_lock_bh(&group_gc_lock);
+ hlist_move_list(&group_gc_list, &gc_list);
+ spin_unlock_bh(&group_gc_lock);
+
+ /* Group deletion queues all of its sources first. Drain that queue
+ * before freeing the group so a source callback cannot dereference it.
+ */
+ cancel_delayed_work_sync(&source_gc_wq);
+ __amt_source_gc_work();
+
+ hlist_for_each_entry_safe(gnode, t, &gc_list, gc_node) {
+ cancel_delayed_work_sync(&gnode->group_timer);
+ hlist_del_init(&gnode->gc_node);
+ kfree_rcu(gnode, rcu);
+ }
+}
+
+static void amt_group_gc_work(struct work_struct *work)
+{
+ __amt_group_gc_work();
+
+ spin_lock_bh(&group_gc_lock);
+ mod_delayed_work(amt_wq, &group_gc_wq,
+ msecs_to_jiffies(AMT_GC_INTERVAL));
+ spin_unlock_bh(&group_gc_lock);
+}
+
static bool amt_addr_equal(union amt_addr *a, union amt_addr *b)
{
return !memcmp(a, b, sizeof(union amt_addr));
@@ -215,9 +253,14 @@ static struct amt_group_node *amt_lookup_group(struct amt_tunnel_list *tunnel,
static void amt_destroy_source(struct amt_source_node *snode)
{
- struct amt_group_node *gnode = snode->gnode;
+ struct amt_group_node *gnode;
struct amt_tunnel_list *tunnel;
+ if (READ_ONCE(snode->dead))
+ return;
+ WRITE_ONCE(snode->dead, true);
+ gnode = snode->gnode;
+
tunnel = gnode->tunnel_list;
if (!gnode->v6) {
@@ -238,8 +281,9 @@ static void amt_destroy_source(struct amt_source_node *snode)
hlist_del_init_rcu(&snode->node);
tunnel->nr_sources--;
gnode->nr_sources--;
+ RCU_INIT_POINTER(snode->gnode, NULL);
spin_lock_bh(&source_gc_lock);
- hlist_add_head_rcu(&snode->node, &source_gc_list);
+ hlist_add_head(&snode->gc_node, &source_gc_list);
spin_unlock_bh(&source_gc_lock);
}
@@ -249,6 +293,9 @@ static void amt_del_group(struct amt_dev *amt, struct amt_group_node *gnode)
struct hlist_node *t;
int i;
+ if (READ_ONCE(gnode->dead))
+ return;
+ WRITE_ONCE(gnode->dead, true);
if (cancel_delayed_work(&gnode->group_timer))
dev_put(amt->dev);
hlist_del_rcu(&gnode->node);
@@ -266,10 +313,10 @@ static void amt_del_group(struct amt_dev *amt, struct amt_group_node *gnode)
hlist_for_each_entry_safe(snode, t, &gnode->sources[i], node)
amt_destroy_source(snode);
- /* tunnel->lock was acquired outside of amt_del_group()
- * But rcu_read_lock() was acquired too so It's safe.
- */
- kfree_rcu(gnode, rcu);
+ RCU_INIT_POINTER(gnode->tunnel_list, NULL);
+ spin_lock_bh(&group_gc_lock);
+ hlist_add_head(&gnode->gc_node, &group_gc_list);
+ spin_unlock_bh(&group_gc_lock);
}
/* If a source timer expires with a router filter-mode for the group of
@@ -282,13 +329,28 @@ static void amt_source_work(struct work_struct *work)
struct amt_source_node *snode = container_of(to_delayed_work(work),
struct amt_source_node,
source_timer);
- struct amt_group_node *gnode = snode->gnode;
- struct amt_dev *amt = gnode->amt;
+ struct amt_group_node *gnode;
+ struct amt_dev *amt;
struct amt_tunnel_list *tunnel;
- tunnel = gnode->tunnel_list;
- spin_lock_bh(&tunnel->lock);
rcu_read_lock();
+ gnode = READ_ONCE(snode->gnode);
+ if (!gnode) {
+ rcu_read_unlock();
+ return;
+ }
+ amt = READ_ONCE(gnode->amt);
+ tunnel = READ_ONCE(gnode->tunnel_list);
+ if (!tunnel) {
+ rcu_read_unlock();
+ return;
+ }
+ spin_lock_bh(&tunnel->lock);
+ if (READ_ONCE(snode->dead) || READ_ONCE(gnode->dead)) {
+ spin_unlock_bh(&tunnel->lock);
+ rcu_read_unlock();
+ return;
+ }
if (gnode->filter_mode == MCAST_INCLUDE) {
amt_destroy_source(snode);
if (!gnode->nr_sources)
@@ -299,8 +361,8 @@ static void amt_source_work(struct work_struct *work)
*/
snode->status = AMT_SOURCE_STATUS_D_FWD;
}
- rcu_read_unlock();
spin_unlock_bh(&tunnel->lock);
+ rcu_read_unlock();
}
static void amt_act_src(struct amt_tunnel_list *tunnel,
@@ -368,6 +430,7 @@ static struct amt_source_node *amt_alloc_snode(struct amt_group_node *gnode,
snode->status = AMT_SOURCE_STATUS_NONE;
snode->flags = AMT_SOURCE_NEW;
INIT_HLIST_NODE(&snode->node);
+ INIT_HLIST_NODE(&snode->gc_node);
INIT_DELAYED_WORK(&snode->source_timer, amt_source_work);
return snode;
@@ -403,26 +466,40 @@ static void amt_group_work(struct work_struct *work)
struct amt_group_node *gnode = container_of(to_delayed_work(work),
struct amt_group_node,
group_timer);
- struct amt_tunnel_list *tunnel = gnode->tunnel_list;
- struct amt_dev *amt = gnode->amt;
+ struct amt_tunnel_list *tunnel;
+ struct amt_dev *amt;
struct amt_source_node *snode;
bool delete_group = true;
struct hlist_node *t;
int i, buckets;
+ rcu_read_lock();
+ tunnel = READ_ONCE(gnode->tunnel_list);
+ amt = READ_ONCE(gnode->amt);
+ if (!tunnel) {
+ rcu_read_unlock();
+ dev_put(amt->dev);
+ return;
+ }
buckets = amt->hash_buckets;
spin_lock_bh(&tunnel->lock);
+ if (READ_ONCE(gnode->dead)) {
+ spin_unlock_bh(&tunnel->lock);
+ rcu_read_unlock();
+ dev_put(amt->dev);
+ return;
+ }
if (gnode->filter_mode == MCAST_INCLUDE) {
/* Not Used */
spin_unlock_bh(&tunnel->lock);
- goto out;
+ rcu_read_unlock();
+ dev_put(amt->dev);
+ return;
}
- rcu_read_lock();
- for (i = 0; i < buckets; i++) {
- hlist_for_each_entry_safe(snode, t,
- &gnode->sources[i], node) {
+ for (i = 0; i < buckets; i++)
+ hlist_for_each_entry_safe(snode, t, &gnode->sources[i], node) {
if (!delayed_work_pending(&snode->source_timer) ||
snode->status == AMT_SOURCE_STATUS_D_FWD) {
amt_destroy_source(snode);
@@ -431,14 +508,12 @@ static void amt_group_work(struct work_struct *work)
snode->status = AMT_SOURCE_STATUS_FWD;
}
}
- }
if (delete_group)
amt_del_group(amt, gnode);
else
gnode->filter_mode = MCAST_INCLUDE;
- rcu_read_unlock();
spin_unlock_bh(&tunnel->lock);
-out:
+ rcu_read_unlock();
dev_put(amt->dev);
}
@@ -479,6 +554,7 @@ static struct amt_group_node *amt_add_group(struct amt_dev *amt,
gnode->tunnel_list = tunnel;
gnode->filter_mode = MCAST_INCLUDE;
INIT_HLIST_NODE(&gnode->node);
+ INIT_HLIST_NODE(&gnode->gc_node);
INIT_DELAYED_WORK(&gnode->group_timer, amt_group_work);
for (i = 0; i < amt->hash_buckets; i++)
INIT_HLIST_HEAD(&gnode->sources[i]);
@@ -628,7 +704,7 @@ static void amt_send_discovery(struct amt_dev *amt)
IPPROTO_UDP, 0,
amt->stream_dev->ifindex);
if (IS_ERR(rt)) {
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -638,7 +714,7 @@ static void amt_send_discovery(struct amt_dev *amt)
skb = netdev_alloc_skb_ip_align(amt->dev, len);
if (!skb) {
ip_rt_put(rt);
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -683,7 +759,7 @@ static void amt_send_discovery(struct amt_dev *amt)
ip_send_check(iph);
err = ip_local_out(amt->net, sk, skb);
if (unlikely(net_xmit_eval(err)))
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
amt_update_gw_status(amt, AMT_STATUS_SENT_DISCOVERY, true);
out:
@@ -719,7 +795,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6)
IPPROTO_UDP, 0,
amt->stream_dev->ifindex);
if (IS_ERR(rt)) {
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -729,7 +805,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6)
skb = netdev_alloc_skb_ip_align(amt->dev, len);
if (!skb) {
ip_rt_put(rt);
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -776,7 +852,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6)
ip_send_check(iph);
err = ip_local_out(amt->net, sk, skb);
if (unlikely(net_xmit_eval(err)))
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
out:
rcu_read_unlock();
@@ -784,11 +860,16 @@ static void amt_send_request(struct amt_dev *amt, bool v6)
static bool amt_send_membership_query(struct amt_dev *amt,
struct sk_buff *skb,
- struct amt_tunnel_list *tunnel,
+ __be32 daddr, __be16 dport,
+ __be32 nonce, u64 mac,
bool v6);
-static void amt_send_igmp_gq(struct amt_dev *amt,
- struct amt_tunnel_list *tunnel)
+/* The destination is passed by value rather than as a tunnel: the requesting
+ * source is not authenticated yet and no tunnel state exists for it - see
+ * amt_request_handler().
+ */
+static void amt_send_igmp_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,
+ __be32 nonce, u64 mac)
{
struct sk_buff *skb;
@@ -797,8 +878,9 @@ static void amt_send_igmp_gq(struct amt_dev *amt,
return;
skb_pull(skb, sizeof(struct ethhdr));
- if (amt_send_membership_query(amt, skb, tunnel, false)) {
- amt->dev->stats.tx_dropped++;
+ if (amt_send_membership_query(amt, skb, daddr, dport, nonce, mac,
+ false)) {
+ DEV_STATS_INC(amt->dev, tx_dropped);
kfree_skb(skb);
}
}
@@ -842,7 +924,7 @@ static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt)
if (ipv6_dev_get_saddr(amt->net, amt->dev, &ip6h->daddr, 0,
&ip6h->saddr)) {
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
kfree_skb(skb);
return NULL;
}
@@ -876,7 +958,8 @@ static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt)
return skb;
}
-static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)
+static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,
+ __be32 nonce, u64 mac)
{
struct sk_buff *skb;
@@ -885,13 +968,15 @@ static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)
return;
skb_pull(skb, sizeof(struct ethhdr));
- if (amt_send_membership_query(amt, skb, tunnel, true)) {
- amt->dev->stats.tx_dropped++;
+ if (amt_send_membership_query(amt, skb, daddr, dport, nonce, mac,
+ true)) {
+ DEV_STATS_INC(amt->dev, tx_dropped);
kfree_skb(skb);
}
}
#else
-static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)
+static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,
+ __be32 nonce, u64 mac)
{
}
#endif
@@ -925,7 +1010,14 @@ static void amt_secret_work(struct work_struct *work)
secret_wq);
spin_lock_bh(&amt->lock);
- get_random_bytes(&amt->key, sizeof(siphash_key_t));
+ /* Keep three previous generations for a 180-240s MAC lifetime.
+ * Its 180s floor exceeds the advertised QQIC (amt->qi, 125s),
+ * allowing the gateway to renew its MAC with a periodic Request.
+ */
+ amt->key[3] = amt->key[2];
+ amt->key[2] = amt->key[1];
+ amt->key[1] = amt->key[0];
+ get_random_bytes(&amt->key[0], sizeof(siphash_key_t));
spin_unlock_bh(&amt->lock);
mod_delayed_work(amt_wq, &amt->secret_wq,
msecs_to_jiffies(AMT_SECRET_TIMEOUT));
@@ -1115,9 +1207,16 @@ static void amt_send_multicast_data(struct amt_dev *amt,
0);
}
+/* Send a Membership Query to a source that has not been authenticated yet.
+ *
+ * No per-source state exists at this point and none is created: the nonce and
+ * the keyed MAC are carried in the Query and recomputed from the Membership
+ * Update when it comes back, so everything this needs is passed by value.
+ */
static bool amt_send_membership_query(struct amt_dev *amt,
struct sk_buff *skb,
- struct amt_tunnel_list *tunnel,
+ __be32 daddr, __be16 dport,
+ __be32 nonce, u64 mac,
bool v6)
{
struct amt_header_membership_query *amtmq;
@@ -1138,13 +1237,13 @@ static bool amt_send_membership_query(struct amt_dev *amt,
skb_reset_inner_headers(skb);
memset(&fl4, 0, sizeof(struct flowi4));
fl4.flowi4_oif = amt->stream_dev->ifindex;
- fl4.daddr = tunnel->ip4;
+ fl4.daddr = daddr;
fl4.saddr = amt->local_ip;
fl4.flowi4_dscp = inet_dsfield_to_dscp(AMT_TOS);
fl4.flowi4_proto = IPPROTO_UDP;
rt = ip_route_output_key(amt->net, &fl4);
if (IS_ERR(rt)) {
- netdev_dbg(amt->dev, "no route to %pI4\n", &tunnel->ip4);
+ netdev_dbg(amt->dev, "no route to %pI4\n", &daddr);
return true;
}
@@ -1154,8 +1253,8 @@ static bool amt_send_membership_query(struct amt_dev *amt,
amtmq->reserved = 0;
amtmq->l = 0;
amtmq->g = 0;
- amtmq->nonce = tunnel->nonce;
- amtmq->response_mac = tunnel->mac;
+ amtmq->nonce = nonce;
+ amtmq->response_mac = mac;
if (!v6)
skb_set_inner_protocol(skb, htons(ETH_P_IP));
@@ -1168,11 +1267,10 @@ static bool amt_send_membership_query(struct amt_dev *amt,
ip4_dst_hoplimit(&rt->dst),
0,
amt->relay_port,
- tunnel->source_port,
+ dport,
false,
false,
0);
- amt_update_relay_status(tunnel, AMT_STATUS_SENT_QUERY, true);
return false;
}
@@ -1236,7 +1334,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
group.ip6 = ipv6_hdr(skb)->daddr;
#endif
} else {
- dev->stats.tx_errors++;
+ DEV_STATS_INC(dev, tx_errors);
goto free;
}
@@ -1249,12 +1347,21 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
/* Gateway only passes IGMP/MLD packets */
if (!report)
goto free;
+ /* A validated report can only be forwarded after the relay's
+ * family-specific Membership Query supplies the state echoed
+ * by the Membership Update. Log this readiness failure before
+ * the shared drop path accounts it.
+ */
if ((!v6 && !READ_ONCE(amt->ready4)) ||
- (v6 && !READ_ONCE(amt->ready6)))
+ (v6 && !READ_ONCE(amt->ready6))) {
+ netdev_dbg(dev, "drop %s report: waiting for Membership Query\n",
+ v6 ? "MLD" : "IGMP");
goto free;
+ }
if (amt_send_membership_update(amt, skb, v6))
goto free;
- goto unlock;
+ /* Sent: the tunnel consumed the skb. Not a drop. */
+ return NETDEV_TX_OK;
} else if (amt->mode == AMT_MODE_RELAY) {
if (!data)
goto free;
@@ -1283,8 +1390,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
return NETDEV_TX_OK;
free:
dev_kfree_skb(skb);
-unlock:
- dev->stats.tx_dropped++;
+ DEV_STATS_INC(dev, tx_dropped);
return NETDEV_TX_OK;
}
@@ -1328,14 +1434,41 @@ static void amt_tunnel_expire(struct work_struct *work)
struct amt_tunnel_list,
gc_wq);
struct amt_dev *amt = tunnel->amt;
+ unsigned long deadline;
spin_lock_bh(&amt->lock);
+ /* amt_dev_stop() has taken ownership of the teardown. */
+ if (READ_ONCE(tunnel->dead)) {
+ spin_unlock_bh(&amt->lock);
+ return;
+ }
+ /* A Membership Update may have refreshed the tunnel after this work
+ * was queued. Re-arm from last_seen rather than letting
+ * amt_update_handler() re-arm gc_wq: this handler is then the only
+ * context that frees the tunnel on the timeout path; amt_dev_stop()
+ * still owns teardown during device shutdown.
+ */
+ deadline = READ_ONCE(tunnel->last_seen);
+ if (!deadline)
+ deadline = jiffies;
+ else
+ deadline += msecs_to_jiffies(amt_gmi(amt)) * 3;
+ if (time_before(jiffies, deadline)) {
+ mod_delayed_work(amt_wq, &tunnel->gc_wq, deadline - jiffies);
+ spin_unlock_bh(&amt->lock);
+ return;
+ }
+ spin_lock_bh(&tunnel->lock);
+ WRITE_ONCE(tunnel->dead, true);
+ spin_unlock_bh(&tunnel->lock);
rcu_read_lock();
list_del_rcu(&tunnel->list);
amt->nr_tunnels--;
amt_clear_groups(tunnel);
rcu_read_unlock();
spin_unlock_bh(&amt->lock);
+ cancel_delayed_work_sync(&group_gc_wq);
+ __amt_group_gc_work();
kfree_rcu(tunnel, rcu);
}
@@ -2369,6 +2502,10 @@ static bool amt_membership_query_handler(struct amt_dev *amt,
if (amtmq->reserved || amtmq->version)
return true;
+ /* A deferred query may outlive a relay address change. */
+ if (ip_hdr(skb)->saddr != READ_ONCE(amt->remote_ip))
+ return true;
+
if (amtmq->nonce != amt->nonce)
return true;
@@ -2461,16 +2598,106 @@ static bool amt_membership_query_handler(struct amt_dev *amt,
return false;
}
+/* The tunnel of the gateway endpoint @saddr:@sport, or NULL. */
+static struct amt_tunnel_list *amt_tunnel_lookup(struct amt_dev *amt,
+ __be32 saddr, __be16 sport)
+{
+ struct amt_tunnel_list *tunnel;
+
+ list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list)
+ if (tunnel->ip4 == saddr && tunnel->source_port == sport)
+ return tunnel;
+ return NULL;
+}
+
+/* Look up the tunnel for a source whose Membership Update has already been
+ * authenticated, creating it on first contact.
+ *
+ * This is now the only place tunnel state is allocated, so amt->max_tunnels
+ * bounds the number of *verified* gateways rather than the number of
+ * unverified Requests anyone can send. A fixed per-source cap additionally
+ * stops one verified source address from monopolising the table.
+ */
+static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt,
+ __be32 saddr,
+ __be16 sport)
+{
+ struct amt_tunnel_list *tunnel;
+ int per_src = 0;
+ int i;
+
+ tunnel = amt_tunnel_lookup(amt, saddr, sport);
+ if (tunnel)
+ return tunnel;
+
+ spin_lock_bh(&amt->lock);
+
+ /* Re-check under the lock in case a concurrent Update won the race, and
+ * count how many tunnels this source already holds on the same walk.
+ */
+ list_for_each_entry(tunnel, &amt->tunnel_list, list) {
+ if (tunnel->ip4 != saddr)
+ continue;
+ if (tunnel->source_port == sport) {
+ spin_unlock_bh(&amt->lock);
+ return tunnel;
+ }
+ per_src++;
+ }
+
+ if (amt->nr_tunnels >= amt->max_tunnels ||
+ per_src >= AMT_MAX_TUNNELS_PER_SRC) {
+ spin_unlock_bh(&amt->lock);
+ return NULL;
+ }
+
+ if (!netif_running(amt->dev)) {
+ spin_unlock_bh(&amt->lock);
+ return NULL;
+ }
+
+ tunnel = kzalloc(sizeof(*tunnel) +
+ (sizeof(struct hlist_head) * amt->hash_buckets),
+ GFP_ATOMIC);
+ if (!tunnel) {
+ spin_unlock_bh(&amt->lock);
+ return NULL;
+ }
+
+ tunnel->source_port = sport;
+ tunnel->ip4 = saddr;
+ tunnel->amt = amt;
+ spin_lock_init(&tunnel->lock);
+ for (i = 0; i < amt->hash_buckets; i++)
+ INIT_HLIST_HEAD(&tunnel->groups[i]);
+
+ tunnel->last_seen = jiffies;
+ INIT_DELAYED_WORK(&tunnel->gc_wq, amt_tunnel_expire);
+ __amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_UPDATE, false);
+
+ /* Publish only once the entry is fully initialised. */
+ list_add_tail_rcu(&tunnel->list, &amt->tunnel_list);
+ amt->nr_tunnels++;
+ mod_delayed_work(amt_wq, &tunnel->gc_wq,
+ msecs_to_jiffies(amt_gmi(amt)) * 3);
+ spin_unlock_bh(&amt->lock);
+
+ return tunnel;
+}
+
static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
{
struct amt_header_membership_update *amtmu;
struct amt_tunnel_list *tunnel;
struct ethhdr *eth;
struct iphdr *iph;
- int len, hdr_size;
+ siphash_key_t key[4];
+ int len, hdr_size, i;
u64 response_mac;
+ bool verified = false;
__be32 saddr;
__be32 nonce;
+ __be16 sport;
saddr = ip_hdr(skb)->saddr;
@@ -2484,30 +2711,51 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
nonce = amtmu->nonce;
response_mac = amtmu->response_mac;
+ /* Snapshot the tunnel endpoint port before the encap is stripped. */
+ sport = udp_hdr(skb)->source;
- if (iptunnel_pull_header(skb, hdr_size, skb->protocol, false))
- return true;
+ /* Recompute the MAC handed out in the Membership Query. Four live
+ * secrets cover 180-240s, exceeding the advertised QQIC (amt->qi,
+ * 125s), so a periodic Request can renew the MAC before it expires.
+ * Authenticate before decapsulation or allocating tunnel state.
+ */
+ spin_lock_bh(&amt->lock);
+ for (i = 0; i < ARRAY_SIZE(key); i++)
+ key[i] = amt->key[i];
+ spin_unlock_bh(&amt->lock);
- skb_reset_network_header(skb);
+ for (i = 0; i < ARRAY_SIZE(key); i++) {
+ u64 mac = siphash_3u32((__force u32)saddr,
+ (__force u32)sport,
+ (__force u32)nonce,
+ &key[i]) >> 16;
- list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) {
- if (tunnel->ip4 == saddr) {
- if ((nonce == tunnel->nonce &&
- response_mac == tunnel->mac)) {
- mod_delayed_work(amt_wq, &tunnel->gc_wq,
- msecs_to_jiffies(amt_gmi(amt))
- * 3);
- goto report;
- } else {
- netdev_dbg(amt->dev, "Invalid MAC\n");
- return true;
- }
+ if (response_mac == mac) {
+ verified = true;
+ break;
}
}
- return true;
+ if (!verified) {
+ netdev_dbg(amt->dev, "Invalid MAC\n");
+ return true;
+ }
+
+ tunnel = amt_tunnel_get_or_create(amt, saddr, sport);
+ if (!tunnel)
+ return true;
+
+ /* Refresh liveness only. gc_wq is re-armed by amt_tunnel_expire()
+ * itself from last_seen, never from here, so this cannot re-queue the
+ * work of a tunnel that is being freed.
+ */
+ WRITE_ONCE(tunnel->last_seen, jiffies);
+
+ if (iptunnel_pull_header(skb, hdr_size, skb->protocol, false))
+ return true;
+
+ skb_reset_network_header(skb);
-report:
if (!pskb_may_pull(skb, sizeof(*iph)))
return true;
@@ -2522,6 +2770,10 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
}
spin_lock_bh(&tunnel->lock);
+ if (READ_ONCE(tunnel->dead)) {
+ spin_unlock_bh(&tunnel->lock);
+ return true;
+ }
amt_igmp_report_handler(amt, skb, tunnel);
spin_unlock_bh(&tunnel->lock);
@@ -2542,6 +2794,10 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
}
spin_lock_bh(&tunnel->lock);
+ if (READ_ONCE(tunnel->dead)) {
+ spin_unlock_bh(&tunnel->lock);
+ return true;
+ }
amt_mld_report_handler(amt, skb, tunnel);
spin_unlock_bh(&tunnel->lock);
@@ -2601,7 +2857,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce,
IPPROTO_UDP, 0,
amt->stream_dev->ifindex);
if (IS_ERR(rt)) {
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -2611,7 +2867,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce,
skb = netdev_alloc_skb_ip_align(amt->dev, len);
if (!skb) {
ip_rt_put(rt);
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -2657,7 +2913,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce,
ip_send_check(iph);
err = ip_local_out(amt->net, sk, skb);
if (unlikely(net_xmit_eval(err)))
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
out:
rcu_read_unlock();
@@ -2684,15 +2940,29 @@ static bool amt_discovery_handler(struct amt_dev *amt, struct sk_buff *skb)
return false;
}
+/* Handle an AMT Relay Membership Request.
+ *
+ * The source of a Request is unauthenticated: it is a bare UDP datagram with a
+ * trivially spoofable source address. Allocating tunnel state here let an
+ * attacker fill the table from spoofed addresses, and let one spoofed packet
+ * overwrite the nonce/MAC of an established tunnel and cut that gateway off.
+ *
+ * Nothing needs to be remembered at this point. Every input to the keyed MAC
+ * is carried in the packet or is device state, so the MAC is generated here,
+ * echoed back by the gateway in its Membership Update, and recomputed and
+ * verified there - see amt_update_handler(). Tunnel state is created only once
+ * that verification succeeds.
+ */
static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
{
struct amt_header_request *amtrh;
struct amt_tunnel_list *tunnel;
- unsigned long long key;
struct udphdr *udph;
struct iphdr *iph;
+ siphash_key_t key;
+ bool full, have = false;
+ int per_src = 0;
u64 mac;
- int i;
if (!pskb_may_pull(skb, sizeof(*udph) + sizeof(*amtrh)))
return true;
@@ -2704,59 +2974,41 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
if (amtrh->reserved1 || amtrh->reserved2 || amtrh->version)
return true;
- list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list)
- if (tunnel->ip4 == iph->saddr)
- goto send;
-
- spin_lock_bh(&amt->lock);
- if (amt->nr_tunnels >= amt->max_tunnels) {
- spin_unlock_bh(&amt->lock);
- icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
+ if (!netif_running(amt->dev) || !netif_running(amt->stream_dev))
return true;
- }
- tunnel = kzalloc(sizeof(*tunnel) +
- (sizeof(struct hlist_head) * amt->hash_buckets),
- GFP_ATOMIC);
- if (!tunnel) {
- spin_unlock_bh(&amt->lock);
- return true;
- }
-
- tunnel->source_port = udph->source;
- tunnel->ip4 = iph->saddr;
-
- memcpy(&key, &tunnel->key, sizeof(unsigned long long));
- tunnel->amt = amt;
- spin_lock_init(&tunnel->lock);
- for (i = 0; i < amt->hash_buckets; i++)
- INIT_HLIST_HEAD(&tunnel->groups[i]);
-
- INIT_DELAYED_WORK(&tunnel->gc_wq, amt_tunnel_expire);
-
- list_add_tail_rcu(&tunnel->list, &amt->tunnel_list);
- tunnel->key = amt->key;
- __amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_REQUEST, true);
- amt->nr_tunnels++;
- mod_delayed_work(amt_wq, &tunnel->gc_wq,
- msecs_to_jiffies(amt_gmi(amt)));
+ /* Snapshot the secret and limits under the lock; keep the endpoint walk
+ * out of the lock so spoofed Requests cannot serialize relay updates.
+ */
+ spin_lock_bh(&amt->lock);
+ key = amt->key[0];
+ full = amt->nr_tunnels >= amt->max_tunnels;
spin_unlock_bh(&amt->lock);
-send:
- tunnel->nonce = amtrh->nonce;
- mac = siphash_3u32((__force u32)tunnel->ip4,
- (__force u32)tunnel->source_port,
- (__force u32)tunnel->nonce,
- &tunnel->key);
- tunnel->mac = mac >> 16;
+ rcu_read_lock();
+ list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) {
+ if (tunnel->ip4 != iph->saddr)
+ continue;
+ per_src++;
+ if (tunnel->source_port == udph->source)
+ have = true;
+ }
+ rcu_read_unlock();
- if (!netif_running(amt->dev) || !netif_running(amt->stream_dev))
+ /* Withhold the Query when a new endpoint cannot get a tunnel. */
+ if (!have && (full || per_src >= AMT_MAX_TUNNELS_PER_SRC))
return true;
+ mac = siphash_3u32((__force u32)iph->saddr,
+ (__force u32)udph->source,
+ (__force u32)amtrh->nonce,
+ &key) >> 16;
if (!amtrh->p)
- amt_send_igmp_gq(amt, tunnel);
+ amt_send_igmp_gq(amt, iph->saddr, udph->source, amtrh->nonce,
+ mac);
else
- amt_send_mld_gq(amt, tunnel);
+ amt_send_mld_gq(amt, iph->saddr, udph->source, amtrh->nonce,
+ mac);
return false;
}
@@ -2833,7 +3085,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)
}
goto out;
case AMT_MSG_MULTICAST_DATA:
- if (saddr != remote_ip) {
+ if (!remote_ip || saddr != remote_ip) {
netdev_dbg(amt->dev, "Invalid Relay IP\n");
err = true;
goto drop;
@@ -2844,7 +3096,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)
else
goto out;
case AMT_MSG_MEMBERSHIP_QUERY:
- if (saddr != remote_ip) {
+ if (!remote_ip || saddr != remote_ip) {
netdev_dbg(amt->dev, "Invalid Relay IP\n");
err = true;
goto drop;
@@ -3024,6 +3276,14 @@ static int amt_dev_open(struct net_device *dev)
enable_delayed_work(&amt->discovery_wq);
enable_delayed_work(&amt->req_wq);
+ /* Seed the keys before amt_socket_create() enables the encap receive
+ * path, so a Request or Update that arrives immediately is never
+ * verified against an all-zero (predictable) secret.
+ */
+ spin_lock_bh(&amt->lock);
+ get_random_bytes(&amt->key, sizeof(amt->key));
+ spin_unlock_bh(&amt->lock);
+
err = amt_socket_create(amt);
if (err) {
disable_delayed_work(&amt->req_wq);
@@ -3034,7 +3294,6 @@ static int amt_dev_open(struct net_device *dev)
amt->req_cnt = 0;
WRITE_ONCE(amt->remote_ip, 0);
amt->nonce = 0;
- get_random_bytes(&amt->key, sizeof(siphash_key_t));
amt->status = AMT_STATUS_INIT;
if (amt->mode == AMT_MODE_GATEWAY) {
@@ -3050,7 +3309,7 @@ static int amt_dev_open(struct net_device *dev)
static int amt_dev_stop(struct net_device *dev)
{
struct amt_dev *amt = netdev_priv(dev);
- struct amt_tunnel_list *tunnel, *tmp;
+ struct amt_tunnel_list *tunnel;
struct sk_buff *skb;
struct sock *sk;
int i;
@@ -3079,11 +3338,38 @@ static int amt_dev_stop(struct net_device *dev)
amt->req_cnt = 0;
WRITE_ONCE(amt->remote_ip, 0);
- list_for_each_entry_safe(tunnel, tmp, &amt->tunnel_list, list) {
- list_del_rcu(&tunnel->list);
- amt->nr_tunnels--;
+ /* Mark every tunnel dead first, so a concurrent amt_tunnel_expire()
+ * sees ->dead and bails instead of freeing a tunnel in parallel; this
+ * path is then the sole freer.
+ */
+ spin_lock_bh(&amt->lock);
+ list_for_each_entry(tunnel, &amt->tunnel_list, list) {
+ spin_lock_bh(&tunnel->lock);
+ WRITE_ONCE(tunnel->dead, true);
+ spin_unlock_bh(&tunnel->lock);
+ }
+ spin_unlock_bh(&amt->lock);
+
+ /* Unlink one tunnel at a time with list_del_rcu() rather than splicing
+ * the list onto a local head: a lockless reader walking tunnel_list
+ * must always terminate at &amt->tunnel_list, never at a stack head.
+ */
+ for (;;) {
+ spin_lock_bh(&amt->lock);
+ tunnel = list_first_entry_or_null(&amt->tunnel_list,
+ struct amt_tunnel_list, list);
+ if (tunnel) {
+ list_del_rcu(&tunnel->list);
+ amt->nr_tunnels--;
+ }
+ spin_unlock_bh(&amt->lock);
+ if (!tunnel)
+ break;
+
cancel_delayed_work_sync(&tunnel->gc_wq);
amt_clear_groups(tunnel);
+ cancel_delayed_work_sync(&group_gc_wq);
+ __amt_group_gc_work();
kfree_rcu(tunnel, rcu);
}
@@ -3152,9 +3438,9 @@ static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = {
[IFLA_AMT_RELAY_PORT] = { .type = NLA_U16 },
[IFLA_AMT_GATEWAY_PORT] = { .type = NLA_U16 },
[IFLA_AMT_LINK] = { .type = NLA_U32 },
- [IFLA_AMT_LOCAL_IP] = { .len = sizeof_field(struct iphdr, daddr) },
+ [IFLA_AMT_LOCAL_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
[IFLA_AMT_REMOTE_IP] = { .len = sizeof_field(struct iphdr, daddr) },
- [IFLA_AMT_DISCOVERY_IP] = { .len = sizeof_field(struct iphdr, daddr) },
+ [IFLA_AMT_DISCOVERY_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
[IFLA_AMT_MAX_TUNNELS] = { .type = NLA_U32 },
};
@@ -3461,11 +3747,17 @@ static int __init amt_init(void)
}
spin_lock_init(&source_gc_lock);
+ spin_lock_init(&group_gc_lock);
spin_lock_bh(&source_gc_lock);
INIT_DELAYED_WORK(&source_gc_wq, amt_source_gc_work);
mod_delayed_work(amt_wq, &source_gc_wq,
msecs_to_jiffies(AMT_GC_INTERVAL));
spin_unlock_bh(&source_gc_lock);
+ spin_lock_bh(&group_gc_lock);
+ INIT_DELAYED_WORK(&group_gc_wq, amt_group_gc_work);
+ mod_delayed_work(amt_wq, &group_gc_wq,
+ msecs_to_jiffies(AMT_GC_INTERVAL));
+ spin_unlock_bh(&group_gc_lock);
return 0;
@@ -3485,6 +3777,8 @@ static void __exit amt_fini(void)
unregister_netdevice_notifier(&amt_notifier_block);
cancel_delayed_work_sync(&source_gc_wq);
__amt_source_gc_work();
+ cancel_delayed_work_sync(&group_gc_wq);
+ __amt_group_gc_work();
destroy_workqueue(amt_wq);
}
module_exit(amt_fini);
diff --git a/include/net/amt.h b/include/net/amt.h
index 2846dde0cadce..4acfc3da0c5aa 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -240,12 +240,19 @@ struct amt_tunnel_list {
u32 nr_sources;
enum amt_status status;
struct delayed_work gc_wq;
+ /* Last time this tunnel was refreshed. gc_wq
+ * re-arms itself from this rather than being re-armed by the Update
+ * path, so the Update path cannot re-queue work for a tunnel that
+ * amt_tunnel_expire() is freeing on the timeout path.
+ */
+ unsigned long last_seen;
+ /* Set under amt->lock and tunnel->lock by whichever freer reaches the
+ * tunnel first;
+ * the other then leaves it alone, so the tunnel is freed exactly once.
+ */
+ bool dead;
__be16 source_port;
__be32 ip4;
- __be32 nonce;
- siphash_key_t key;
- u64 mac:48,
- reserved:16;
struct rcu_head rcu;
struct hlist_head groups[];
};
@@ -275,6 +282,7 @@ enum amt_source_status {
/* protected by gnode->lock */
struct amt_source_node {
struct hlist_node node;
+ struct hlist_node gc_node;
struct amt_group_node *gnode;
struct delayed_work source_timer;
union amt_addr source_addr;
@@ -282,6 +290,8 @@ struct amt_source_node {
#define AMT_SOURCE_OLD 0
#define AMT_SOURCE_NEW 1
u8 flags;
+ /* Protected by gnode->tunnel_list->lock. */
+ bool dead;
struct rcu_head rcu;
};
@@ -295,7 +305,10 @@ struct amt_group_node {
u32 nr_sources;
struct amt_tunnel_list *tunnel_list;
struct hlist_node node;
+ struct hlist_node gc_node;
struct delayed_work group_timer;
+ /* Protected by tunnel_list->lock. */
+ bool dead;
struct rcu_head rcu;
struct hlist_head sources[];
};
@@ -325,8 +338,10 @@ struct amt_dev {
struct work_struct event_wq;
/* AMT status */
enum amt_status status;
- /* Generated key */
- siphash_key_t key;
+ /* Current key and three previous generations keep MACs valid for
+ * 180-240s, beyond the advertised QQIC (see amt_secret_work()).
+ */
+ siphash_key_t key[4];
struct sock __rcu *sk;
u32 max_groups;
u32 max_sources;
@@ -383,6 +398,10 @@ struct amt_dev {
#define AMT_SECRET_TIMEOUT 60000
#define IANA_AMT_UDP_PORT 2268
#define AMT_MAX_TUNNELS 128
+/* Fixed per-source cap stops one verified source address from monopolising
+ * the AMT_MAX_TUNNELS-slot table.
+ */
+#define AMT_MAX_TUNNELS_PER_SRC 16
#define AMT_MAX_REQS 128
#define AMT_GW_HLEN (sizeof(struct iphdr) + \
sizeof(struct udphdr) + \
|
| 3/2 | 2026/10/20 05:57 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16957 output: 27 thoughts: 98 Thoughts: Okay, here's my take on those thoughts, framed as my own mental processing: **Analyzing the AMT Patch** Alright, so the patch touches `drivers/net/amt.c` and `include/net/amt.h`. That immediately tells me we're dealing with the AMT driver, and the header file tells me it's low level networking. AMT…right, Automatic Multicast Tunneling. RFC 7450. It's that multicast-over-unicast protocol. So, this confirms it's a kernel-space virtual network device driver, specifically implemented in `drivers/net/amt.c`. Now, the next logical step, before diving into the code itself, is to confirm its configuration options. I need to figure out how it's enabled and if there are any specific feature flags. Is this driven by `CONFIG_AMT`? I'll probably run `grepper` in the kernel source tree, or I could just quickly check the relevant Kconfig file in `drivers/net`. Gotta get the big picture first! |
| 4/2 | 2026/10/20 05:57 | tool | grepper |
0mArgs:{
"Expression": "config AMT",
"PathPrefixes": [
"drivers/net/"
]
}Results: {
"Output": "drivers/net/Kconfig=289=config PFCP\n--\ndrivers/net/Kconfig-301-\ndrivers/net/Kconfig:302:config AMT\ndrivers/net/Kconfig-303-\ttristate \"Automatic Multicast Tunneling (AMT)\"\n"
} |
| 5/2 | 2026/10/20 05:57 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17386 output: 34 thoughts: 22 Thoughts: Here's a summary of my thought process, tailored for an expert like yourself: **Diving into the Network Driver Configuration** Okay, so I need to understand the configuration dependencies for this network driver. My first instinct is to zero in on `drivers/net/Kconfig`, specifically around line 302. That's usually where the meat of the configuration logic and any potential dependencies are declared. Time to see what's gating the inclusion of this particular driver, what other features or options it might rely on, and how it fits into the broader network subsystem configuration. I'm expecting to see things like `depends on` statements, maybe some `select` directives, and potentially conditional defaults or prompt messages. Let's see what gems are buried in that Kconfig file! |
| 6/2 | 2026/10/20 05:57 | tool | read-file |
0mArgs:{
"File": "drivers/net/Kconfig",
"FirstLine": 300,
"LineCount": 25
}Results: {
"Contents": " 300:\t\t will be called pfcp.\n 301:\t\n 302:\tconfig AMT\n 303:\t\ttristate \"Automatic Multicast Tunneling (AMT)\"\n 304:\t\tdepends on INET \u0026\u0026 IP_MULTICAST\n 305:\t\tselect NET_UDP_TUNNEL\n 306:\t\thelp\n 307:\t\t This allows one to create AMT(Automatic Multicast Tunneling)\n 308:\t\t virtual interfaces that provide multicast tunneling.\n 309:\t\t There are two roles, Gateway, and Relay.\n 310:\t\t Gateway Encapsulates IGMP/MLD traffic from listeners to the Relay.\n 311:\t\t Gateway Decapsulates multicast traffic from the Relay to Listeners.\n 312:\t\t Relay Encapsulates multicast traffic from Sources to Gateway.\n 313:\t\t Relay Decapsulates IGMP/MLD traffic from Gateway.\n 314:\t\n 315:\t\t To compile this drivers as a module, choose M here: the module\n 316:\t\t will be called amt.\n 317:\t\n 318:\tconfig MACSEC\n 319:\t\ttristate \"IEEE 802.1AE MAC-level encryption (MACsec)\"\n 320:\t\tselect CRYPTO\n 321:\t\tselect CRYPTO_AES\n 322:\t\tselect CRYPTO_GCM\n 323:\t\tselect GRO_CELLS\n 324:\t\thelp\n"
} |
| 7/2 | 2026/10/20 05:57 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17989 output: 34 thoughts: 52 Thoughts: Okay, let's see. My current train of thought is focused on configuring AMT. I know that `config AMT` is inherently dependent on both `INET` and `IP_MULTICAST`. So, the question now is, how do I actually reach and configure this AMT setup? The natural approach is to consider `rtnl` (rtnetlink), specifically using `ip link`. Given my familiarity with the Linux networking stack, I immediately think of the `amt.c` file as the likely source for how this is implemented. Specifically, I'm going to look for implementations of `rtnl_link_ops` within that source code. That seems like the right place to start looking for details on how the AMT interface interacts with rtnetlink and, by extension, the `ip link` tool. I'm going to use the code to confirm if AMT is indeed managed through this established infrastructure. |
| 8/2 | 2026/10/20 05:57 | tool | grepper |
0mArgs:{
"Expression": "rtnl_link_ops",
"PathPrefixes": [
"drivers/net/amt.c"
]
}Results: {
"Output": "drivers/net/amt.c=3632=static int amt_fill_info(struct sk_buff *skb, const struct net_device *dev)\n--\ndrivers/net/amt.c-3665-\ndrivers/net/amt.c:3666:static struct rtnl_link_ops amt_link_ops __read_mostly = {\ndrivers/net/amt.c-3667-\t.kind\t\t= \"amt\",\n"
} |
| 9/2 | 2026/10/20 05:57 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 18385 output: 30 thoughts: 2081 Thoughts: **AMT Driver Deep Dive for Fuzzing: A Synthesis** Okay, here's the deal: AMT (Address Management Tunnel) is ripe for fuzzing. It's a virtual network device type created via `rtnetlink` and fully accessible in a QEMU environment, perfect for Syzkaller. I've been digging into the recent changes, and they're significant enough to warrant some serious attention. The patch touches `drivers/net/amt.c` and `include/net/amt.h`. My immediate takeaway is that this isn't just a minor tweak; it's a major restructuring of lifecycle management, locking, workqueues, and packet handling within the AMT driver. This is *exactly* the kind of deep, architectural change that cries out for fuzzing. My primary concern with fuzzing is reachability. Good news: this driver is easily reachable using standard netlink and socket/netdev tools. This means Syzkaller can go to town without requiring any special hardware. Looking at the code, I see a substantial overhaul of concurrency management. The changes include additions of new structures like `group_gc_list`, `group_gc_lock`, `group_gc_wq`, and the introduction of new work handlers such as `__amt_group_gc_work`, `amt_group_gc_work`, `amt_source_gc_work`. Modifications to functions like `amt_destroy_source`, `amt_del_group`, `amt_source_work`, `amt_group_work`, `amt_tunnel_expire` include the addition of checks for `READ_ONCE(snode->dead)` and `WRITE_ONCE(snode->dead, true)`, as well as using the `gc_node` member, and cancellation of delayed work. This kind of heavy-handed concurrency control is always a good target. The modifications to packet-handling functions like `amt_update_handler` and `amt_request_handler` are particularly interesting. They've been rewritten to avoid immediate tunnel allocation, with stateless MAC generation. These are entry points, and therefore ideal focus targets. Also, `amt_rcv` is another UDP handler that's worth targeting, as is `amt_dev_xmit`, because they interact directly with incoming network data, which is a key fuzzing vector. My current line of reasoning: The changes introduce locking, synchronization primitives (RCU, spinlocks, delayed work cancellations, dead flags, garbage collection lists). This makes the code particularly vulnerable to race conditions and concurrency bugs. The code also directly handles incoming network packets (`amt_rcv`, `amt_update_handler`, `amt_request_handler`, `amt_dev_xmit`). Also, the timer/delayed work concurrency (`amt_source_work`, `amt_group_work`, `amt_tunnel_expire`, `amt_group_gc_work`, `amt_source_gc_work`) needs careful scrutiny. My focus symbols, based on the principle of targeting specific feature logic and entrypoints, should be: `amt_tunnel_get_or_create`, `amt_update_handler`, `amt_request_handler`, `amt_tunnel_expire`, `amt_group_work`, `amt_source_work`, `amt_group_gc_work`, `amt_dev_xmit`, `amt_rcv`, and `amt_dev_stop`. These functions are specific, non-ubiquitous entry points and handlers that implement the new logic, or changed entry points for the feature being reviewed. As far as configuration goes, I need to make sure the kernel is built with `CONFIG_AMT` (depends on `INET` and `IP_MULTICAST`) and `NET_UDP_TUNNEL` enabled. Final verdict: AMT is a prime target. The architecture changes, coupled with its accessibility, make it an excellent candidate for fuzzing. |
| 10/2 | 2026/10/20 05:58 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_",
"PathPrefixes": [
"drivers/net/amt.c"
]
}Results: {
"Output": "drivers/net/amt.c=79=static struct igmpv3_grec igmpv3_zero_grec;\ndrivers/net/amt.c-80-\ndrivers/net/amt.c:81:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-82-#define MLD2_ALL_NODE_INIT { { { 0xff, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01 } } }\n--\ndrivers/net/amt.c=254=static void amt_destroy_source(struct amt_source_node *snode)\n--\ndrivers/net/amt.c-270-\t\t\t \u0026gnode-\u003egroup_addr.ip4);\ndrivers/net/amt.c:271:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-272-\t} else {\n--\ndrivers/net/amt.c=290=static void amt_del_group(struct amt_dev *amt, struct amt_group_node *gnode)\n--\ndrivers/net/amt.c-306-\t\t\t \u0026gnode-\u003egroup_addr.ip4);\ndrivers/net/amt.c:307:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-308-\telse\n--\ndrivers/net/amt.c=368=static void amt_act_src(struct amt_tunnel_list *tunnel,\n--\ndrivers/net/amt.c-409-\t\t\t action_str[act]);\ndrivers/net/amt.c:410:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-411-\telse\n--\ndrivers/net/amt.c=531=static struct amt_group_node *amt_add_group(struct amt_dev *amt,\n--\ndrivers/net/amt.c-568-\t\t\t \u0026gnode-\u003egroup_addr.ip4);\ndrivers/net/amt.c:569:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-570-\telse\n--\ndrivers/net/amt.c=871=static void amt_send_igmp_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,\n--\ndrivers/net/amt.c-887-\ndrivers/net/amt.c:888:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-889-static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt)\n--\ndrivers/net/amt.c=1277=static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)\n--\ndrivers/net/amt.c-1282-\tunion amt_addr group = {0,};\ndrivers/net/amt.c:1283:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1284-\tstruct ipv6hdr *ip6h;\n--\ndrivers/net/amt.c-1313-\t\tgroup.ip4 = ip_hdr(skb)-\u003edaddr;\ndrivers/net/amt.c:1314:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1315-\t} else if (iph-\u003eversion == 6) {\n--\ndrivers/net/amt.c-1374-\t\t\t\t\t\tgoto found;\ndrivers/net/amt.c:1375:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1376-\t\t\t\t} else {\n--\ndrivers/net/amt.c=1475=static void amt_cleanup_srcs(struct amt_dev *amt,\n--\ndrivers/net/amt.c-1499-\t\t\t\t\t \u0026gnode-\u003egroup_addr.ip4);\ndrivers/net/amt.c:1500:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1501-\t\t\telse\n--\ndrivers/net/amt.c=1511=static void amt_add_srcs(struct amt_dev *amt, struct amt_tunnel_list *tunnel,\n--\ndrivers/net/amt.c-1516-\tstruct amt_source_node *snode;\ndrivers/net/amt.c:1517:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1518-\tstruct mld2_grec *mld_grec;\n--\ndrivers/net/amt.c-1528-\t} else {\ndrivers/net/amt.c:1529:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1530-\t\tmld_grec = grec;\n--\ndrivers/net/amt.c-1540-\t\t\tsrc.ip4 = igmp_grec-\u003egrec_src[i];\ndrivers/net/amt.c:1541:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1542-\t\telse\n--\ndrivers/net/amt.c-1560-\t\t\t\t\t \u0026gnode-\u003egroup_addr.ip4);\ndrivers/net/amt.c:1561:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1562-\t\t\telse\n--\ndrivers/net/amt.c=1591=static void amt_lookup_act_srcs(struct amt_tunnel_list *tunnel,\n--\ndrivers/net/amt.c-1601-\tstruct igmpv3_grec *igmp_grec;\ndrivers/net/amt.c:1602:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1603-\tstruct mld2_grec *mld_grec;\n--\ndrivers/net/amt.c-1613-\t} else {\ndrivers/net/amt.c:1614:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1615-\t\tmld_grec = grec;\n--\ndrivers/net/amt.c-1628-\t\t\t\tsrc.ip4 = igmp_grec-\u003egrec_src[i];\ndrivers/net/amt.c:1629:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1630-\t\t\telse\n--\ndrivers/net/amt.c-1651-\t\t\t\tsrc.ip4 = igmp_grec-\u003egrec_src[i];\ndrivers/net/amt.c:1652:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1653-\t\t\telse\n--\ndrivers/net/amt.c-1672-\t\t\t\t\t\tsrc.ip4 = igmp_grec-\u003egrec_src[j];\ndrivers/net/amt.c:1673:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1674-\t\t\t\t\telse\n--\ndrivers/net/amt.c=1685=out_sub:;\n--\ndrivers/net/amt.c-1693-\t\t\t\tsrc.ip4 = igmp_grec-\u003egrec_src[i];\ndrivers/net/amt.c:1694:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-1695-\t\t\telse\n--\ndrivers/net/amt.c=2193=static void amt_igmp_report_handler(struct amt_dev *amt, struct sk_buff *skb,\n--\ndrivers/net/amt.c-2212-\ndrivers/net/amt.c:2213:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-2214-/* RFC 3810\n--\ndrivers/net/amt.c=2415=static bool amt_multicast_data_handler(struct amt_dev *amt, struct sk_buff *skb)\n--\ndrivers/net/amt.c-2454-\t\tip_eth_mc_map(iph-\u003edaddr, eth-\u003eh_dest);\ndrivers/net/amt.c:2455:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-2456-\t} else if (iph-\u003eversion == 6) {\n--\ndrivers/net/amt.c=2486=static bool amt_membership_query_handler(struct amt_dev *amt,\n--\ndrivers/net/amt.c-2552-\t\tip_eth_mc_map(iph-\u003edaddr, eth-\u003eh_dest);\ndrivers/net/amt.c:2553:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-2554-\t} else if (iph-\u003eversion == 6) {\n--\ndrivers/net/amt.c=2688=static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)\n--\ndrivers/net/amt.c-2786-\t\tip_eth_mc_map(iph-\u003edaddr, eth-\u003eh_dest);\ndrivers/net/amt.c:2787:#if IS_ENABLED(CONFIG_IPV6)\ndrivers/net/amt.c-2788-\t} else if (iph-\u003eversion == 6) {\n"
} |
| 11/2 | 2026/10/20 05:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23697 output: 29 thoughts: 102 Thoughts: Okay, here's my understanding, considering I'm trying to make sure all the necessary configurations are enabled: **My Configuration Checklist for AMT and IPv6 Support** Right, so I'm looking at the dependencies here. It's clear that `CONFIG_IPV6` is pretty fundamental to the `amt.c` module. I can see that it's crucial for things like MLD reports and IPv6 multicast functionality. That's a good place to start. Now, I also see that `CONFIG_AMT` itself *depends* on both `CONFIG_INET` and `CONFIG_IP_MULTICAST`. So, to make sure everything's in order, and that I'm not missing anything, my initial list of EnableConfigs should definitely include: * `AMT` * `INET` * `IP_MULTICAST` * `IPV6` I'll make sure to double-check the Kconfig file for `IP_MULTICAST` to make sure there's nothing strange, but this seems pretty solid, as a starting point. |
| 12/2 | 2026/10/20 05:58 | tool | grepper |
0mArgs:{
"Expression": "config IP_MULTICAST",
"PathPrefixes": [
"net/"
]
}Results: {
"Output": "net/ipv4/Kconfig-4-#\nnet/ipv4/Kconfig:5:config IP_MULTICAST\nnet/ipv4/Kconfig-6-\tbool \"IP: multicasting\"\n"
} |
| 13/2 | 2026/10/20 05:58 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24122 output: 260 thoughts: 1238 Thoughts: **AMT Driver Triage: A Deep Dive** Okay, let's break this down. First, I need to understand how these AMT devices are even *created*. The `ip link add` command with the `amt` type and mode (relay or gateway) is the starting point, along with the associated netlink policy. That's the foundation. From there, I see the core logic lies within the `amt_rcv()` and `amt_dev_xmit()` functions – the entry points for packet reception and transmission, respectively. It looks like a complex interplay of delayed work handlers (`amt_tunnel_expire`, `amt_group_gc_work`, and the like) running concurrently on workqueues. This screams concurrency challenges. Now, let's get into the *specific* changes. I need to understand how these areas have been modified because they are likely to be where bugs are hiding: 1. `amt_tunnel_get_or_create`: Dynamic tunnel creation during `amt_update_handler`. It seems to involve checks on resource limits (`amt->nr_tunnels` and `AMT_MAX_TUNNELS_PER_SRC`) and initialization of locks and the `amt_tunnel_expire` delayed work. Any race condition between tunnel creation and tunnel usage is potentially bad. 2. `amt_tunnel_expire`: This is critical. It re-arms the delayed work based on a `last_seen` timestamp. If the tunnel expires, it's marked as dead, unlinked from the RCU list, and group cleanup starts, including canceling a workqueue and freeing the tunnel. The cleanup steps are worth a closer look for order-of-operations issues. 3. Group and Source Garbage Collection: This is where things get interesting. I see a shift from the previous approach where sources were freed in `__amt_source_gc_work` directly via `snode->node` to a more structured approach with a `group_gc_list`, `group_gc_lock`, and a workqueue (`group_gc_wq`). Groups and sources are now marked as "dead" in `amt_del_group()` and `amt_destroy_source()` respectively, and queued for garbage collection. This separation indicates an intention to improve concurrency but always introduces race conditions. The fact that `__amt_group_gc_work()` now cancels `source_gc_wq` and flushes `__amt_source_gc_work()` *before* freeing groups is, in itself, a good sign, but a good sign that things are complex and could contain subtle concurrency issues. 4. Work Callbacks: `amt_source_work` and `amt_group_work` check for `READ_ONCE(snode->dead)` and `READ_ONCE(gnode->dead)`. This seems like a reasonable approach to avoid processing "dead" entries, but it's important to confirm that any race conditions or use-after-free conditions are addressed. 5. Authentication and Stateless Queries: The move to stateless calculation of keyed MACs in `amt_request_handler` is interesting for efficiency but warrants attention from a security perspective. 6. Multi-generational SipHash keys: Another change that needs close attention for security issues. 7. Teardown Logic in `amt_dev_stop`. This is especially complex. Overall, these changes are significant. We're talking about fundamental modifications to reachable network virtualization (AMT) code. There are changes to concurrency handling, reference counting, delayed work scheduling, and memory lifecycle. This sounds like an ideal scenario for subtle race conditions, use-after-free bugs, deadlocks, and delayed work flushes. Now, the important part: What specific functions are targets for fuzzing? Let's compile a list: * `amt_tunnel_get_or_create` * `amt_tunnel_expire` * `amt_update_handler` * `amt_request_handler` * `amt_group_work` * `amt_source_work` * `amt_group_gc_work` * `amt_del_group` * `amt_destroy_source` * `amt_dev_stop` Wait, are these names *ubiquitous*? No! They're all very specific to the AMT driver, which means they're very specific to this code path, which is a good thing for fuzzing. I quickly double-checked the symbol names to verify they exist and are correctly spelled in `drivers/net/amt.c` and they are all there. The configs needed for this are `AMT`, `INET`, `IP_MULTICAST`, and `IPV6`. **Verdict: WorthFuzzing |
| 14/2 | 2026/10/20 05:58 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"AMT",
"INET",
"IP_MULTICAST",
"IPV6"
],
"FocusSymbols": [
"amt_tunnel_get_or_create",
"amt_update_handler",
"amt_request_handler",
"amt_tunnel_expire",
"amt_group_work",
"amt_source_work",
"amt_group_gc_work",
"amt_destroy_source",
"amt_del_group",
"amt_rcv"
],
"Reasoning": "The patch extensively refactors the lifecycle, garbage collection, concurrency control, and packet processing logic of the AMT (Automatic Multicast Tunneling) driver. It introduces a new group GC list and delayed work queue, updates delayed work cancellation and RCU freeing patterns, alters tunnel allocation semantics (deferring tunnel creation to the Membership Update handler instead of Request handling), and adds multi-generational SipHash keys. These changes touch reachable virtual network device code that can be created and driven via rtnetlink and network sockets without specialized hardware, warranting fuzzing for potential race conditions, UAFs, or workqueue/locking regressions.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"AMT",
"INET",
"IP_MULTICAST",
"IPV6"
],
"FocusSymbols": [
"amt_tunnel_get_or_create",
"amt_update_handler",
"amt_request_handler",
"amt_tunnel_expire",
"amt_group_work",
"amt_source_work",
"amt_group_gc_work",
"amt_destroy_source",
"amt_del_group",
"amt_rcv"
],
"Reasoning": "The patch extensively refactors the lifecycle, garbage collection, concurrency control, and packet processing logic of the AMT (Automatic Multicast Tunneling) driver. It introduces a new group GC list and delayed work queue, updates delayed work cancellation and RCU freeing patterns, alters tunnel allocation semantics (deferring tunnel creation to the Membership Update handler instead of Request handling), and adds multi-generational SipHash keys. These changes touch reachable virtual network device code that can be created and driven via rtnetlink and network sockets without specialized hardware, warranting fuzzing for potential race conditions, UAFs, or workqueue/locking regressions.",
"WorthFuzzing": true
} |
| 15/1 | 2026/10/20 05:58 | action | If |
1mArgs:{
"WorthFuzzing": true
}Results: null |
| 16/2 | 2026/10/20 05:58 | agent | kmsan-evaluator |
1mModel:core Args: null Results: {
"KMSANReasoning": "The patch series addresses concurrency, lifetime management, and denial-of-service vulnerabilities in the AMT (Automatic Multicast Tunneling) driver:\n1. It implements a dedicated group GC queue, work synchronization, and 'dead' flags to prevent race conditions and use-after-free (UAF) bugs during group, source, and tunnel destruction.\n2. It makes relay request handling stateless, avoiding premature tunnel allocation from spoofed requests, and rotates 4 generations of SipHash keys for validating Membership Updates.\n3. It updates netlink policy validation and statistics helpers.\n\nFrom a memory initialization perspective:\n- All heap objects (`amt_tunnel_list`, `amt_group_node`, `amt_source_node`) are allocated via `kzalloc` or `kzalloc_obj`, ensuring all fields (including the new `dead` and `gc_node` members) are fully zeroed.\n- The `key` array on the stack in `amt_update_handler` is explicitly populated for all indices from `amt-\u003ekey[i]` before being passed to `siphash_3u32`.\n- `amt-\u003ekey` is initialized in `amt_dev_open` using `get_random_bytes(\u0026amt-\u003ekey, sizeof(amt-\u003ekey))`, fully covering all 4 array elements.\n- No kernel memory or uninitialized struct padding is copied to userspace.\n\nThe risks associated with these changes are concurrency, locking, and object lifetime issues (such as use-after-free or race conditions), which are covered by KASAN and LOCKDEP. KMSAN is not needed as there are no uninitialized memory read risks or info-leaks.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 8a04eae34c5c057fcb5e7f0ec93d7b4d5052eee0
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Oct 20 05:57:19 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index b53f8ec556615..faf32976305b3 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -38,6 +38,10 @@ static HLIST_HEAD(source_gc_list);
/* Lock for source_gc_list */
static spinlock_t source_gc_lock;
static struct delayed_work source_gc_wq;
+static HLIST_HEAD(group_gc_list);
+/* Lock for group_gc_list */
+static spinlock_t group_gc_lock;
+static struct delayed_work group_gc_wq;
static char *status_str[] = {
"AMT_STATUS_INIT",
"AMT_STATUS_SENT_DISCOVERY",
@@ -90,8 +94,9 @@ static void __amt_source_gc_work(void)
hlist_move_list(&source_gc_list, &gc_list);
spin_unlock_bh(&source_gc_lock);
- hlist_for_each_entry_safe(snode, t, &gc_list, node) {
- hlist_del_rcu(&snode->node);
+ hlist_for_each_entry_safe(snode, t, &gc_list, gc_node) {
+ cancel_delayed_work_sync(&snode->source_timer);
+ hlist_del_init(&snode->gc_node);
kfree_rcu(snode, rcu);
}
}
@@ -106,6 +111,39 @@ static void amt_source_gc_work(struct work_struct *work)
spin_unlock_bh(&source_gc_lock);
}
+static void __amt_group_gc_work(void)
+{
+ struct amt_group_node *gnode;
+ struct hlist_head gc_list;
+ struct hlist_node *t;
+
+ spin_lock_bh(&group_gc_lock);
+ hlist_move_list(&group_gc_list, &gc_list);
+ spin_unlock_bh(&group_gc_lock);
+
+ /* Group deletion queues all of its sources first. Drain that queue
+ * before freeing the group so a source callback cannot dereference it.
+ */
+ cancel_delayed_work_sync(&source_gc_wq);
+ __amt_source_gc_work();
+
+ hlist_for_each_entry_safe(gnode, t, &gc_list, gc_node) {
+ cancel_delayed_work_sync(&gnode->group_timer);
+ hlist_del_init(&gnode->gc_node);
+ kfree_rcu(gnode, rcu);
+ }
+}
+
+static void amt_group_gc_work(struct work_struct *work)
+{
+ __amt_group_gc_work();
+
+ spin_lock_bh(&group_gc_lock);
+ mod_delayed_work(amt_wq, &group_gc_wq,
+ msecs_to_jiffies(AMT_GC_INTERVAL));
+ spin_unlock_bh(&group_gc_lock);
+}
+
static bool amt_addr_equal(union amt_addr *a, union amt_addr *b)
{
return !memcmp(a, b, sizeof(union amt_addr));
@@ -215,9 +253,14 @@ static struct amt_group_node *amt_lookup_group(struct amt_tunnel_list *tunnel,
static void amt_destroy_source(struct amt_source_node *snode)
{
- struct amt_group_node *gnode = snode->gnode;
+ struct amt_group_node *gnode;
struct amt_tunnel_list *tunnel;
+ if (READ_ONCE(snode->dead))
+ return;
+ WRITE_ONCE(snode->dead, true);
+ gnode = snode->gnode;
+
tunnel = gnode->tunnel_list;
if (!gnode->v6) {
@@ -238,8 +281,9 @@ static void amt_destroy_source(struct amt_source_node *snode)
hlist_del_init_rcu(&snode->node);
tunnel->nr_sources--;
gnode->nr_sources--;
+ RCU_INIT_POINTER(snode->gnode, NULL);
spin_lock_bh(&source_gc_lock);
- hlist_add_head_rcu(&snode->node, &source_gc_list);
+ hlist_add_head(&snode->gc_node, &source_gc_list);
spin_unlock_bh(&source_gc_lock);
}
@@ -249,6 +293,9 @@ static void amt_del_group(struct amt_dev *amt, struct amt_group_node *gnode)
struct hlist_node *t;
int i;
+ if (READ_ONCE(gnode->dead))
+ return;
+ WRITE_ONCE(gnode->dead, true);
if (cancel_delayed_work(&gnode->group_timer))
dev_put(amt->dev);
hlist_del_rcu(&gnode->node);
@@ -266,10 +313,10 @@ static void amt_del_group(struct amt_dev *amt, struct amt_group_node *gnode)
hlist_for_each_entry_safe(snode, t, &gnode->sources[i], node)
amt_destroy_source(snode);
- /* tunnel->lock was acquired outside of amt_del_group()
- * But rcu_read_lock() was acquired too so It's safe.
- */
- kfree_rcu(gnode, rcu);
+ RCU_INIT_POINTER(gnode->tunnel_list, NULL);
+ spin_lock_bh(&group_gc_lock);
+ hlist_add_head(&gnode->gc_node, &group_gc_list);
+ spin_unlock_bh(&group_gc_lock);
}
/* If a source timer expires with a router filter-mode for the group of
@@ -282,13 +329,28 @@ static void amt_source_work(struct work_struct *work)
struct amt_source_node *snode = container_of(to_delayed_work(work),
struct amt_source_node,
source_timer);
- struct amt_group_node *gnode = snode->gnode;
- struct amt_dev *amt = gnode->amt;
+ struct amt_group_node *gnode;
+ struct amt_dev *amt;
struct amt_tunnel_list *tunnel;
- tunnel = gnode->tunnel_list;
- spin_lock_bh(&tunnel->lock);
rcu_read_lock();
+ gnode = READ_ONCE(snode->gnode);
+ if (!gnode) {
+ rcu_read_unlock();
+ return;
+ }
+ amt = READ_ONCE(gnode->amt);
+ tunnel = READ_ONCE(gnode->tunnel_list);
+ if (!tunnel) {
+ rcu_read_unlock();
+ return;
+ }
+ spin_lock_bh(&tunnel->lock);
+ if (READ_ONCE(snode->dead) || READ_ONCE(gnode->dead)) {
+ spin_unlock_bh(&tunnel->lock);
+ rcu_read_unlock();
+ return;
+ }
if (gnode->filter_mode == MCAST_INCLUDE) {
amt_destroy_source(snode);
if (!gnode->nr_sources)
@@ -299,8 +361,8 @@ static void amt_source_work(struct work_struct *work)
*/
snode->status = AMT_SOURCE_STATUS_D_FWD;
}
- rcu_read_unlock();
spin_unlock_bh(&tunnel->lock);
+ rcu_read_unlock();
}
static void amt_act_src(struct amt_tunnel_list *tunnel,
@@ -368,6 +430,7 @@ static struct amt_source_node *amt_alloc_snode(struct amt_group_node *gnode,
snode->status = AMT_SOURCE_STATUS_NONE;
snode->flags = AMT_SOURCE_NEW;
INIT_HLIST_NODE(&snode->node);
+ INIT_HLIST_NODE(&snode->gc_node);
INIT_DELAYED_WORK(&snode->source_timer, amt_source_work);
return snode;
@@ -403,26 +466,40 @@ static void amt_group_work(struct work_struct *work)
struct amt_group_node *gnode = container_of(to_delayed_work(work),
struct amt_group_node,
group_timer);
- struct amt_tunnel_list *tunnel = gnode->tunnel_list;
- struct amt_dev *amt = gnode->amt;
+ struct amt_tunnel_list *tunnel;
+ struct amt_dev *amt;
struct amt_source_node *snode;
bool delete_group = true;
struct hlist_node *t;
int i, buckets;
+ rcu_read_lock();
+ tunnel = READ_ONCE(gnode->tunnel_list);
+ amt = READ_ONCE(gnode->amt);
+ if (!tunnel) {
+ rcu_read_unlock();
+ dev_put(amt->dev);
+ return;
+ }
buckets = amt->hash_buckets;
spin_lock_bh(&tunnel->lock);
+ if (READ_ONCE(gnode->dead)) {
+ spin_unlock_bh(&tunnel->lock);
+ rcu_read_unlock();
+ dev_put(amt->dev);
+ return;
+ }
if (gnode->filter_mode == MCAST_INCLUDE) {
/* Not Used */
spin_unlock_bh(&tunnel->lock);
- goto out;
+ rcu_read_unlock();
+ dev_put(amt->dev);
+ return;
}
- rcu_read_lock();
- for (i = 0; i < buckets; i++) {
- hlist_for_each_entry_safe(snode, t,
- &gnode->sources[i], node) {
+ for (i = 0; i < buckets; i++)
+ hlist_for_each_entry_safe(snode, t, &gnode->sources[i], node) {
if (!delayed_work_pending(&snode->source_timer) ||
snode->status == AMT_SOURCE_STATUS_D_FWD) {
amt_destroy_source(snode);
@@ -431,14 +508,12 @@ static void amt_group_work(struct work_struct *work)
snode->status = AMT_SOURCE_STATUS_FWD;
}
}
- }
if (delete_group)
amt_del_group(amt, gnode);
else
gnode->filter_mode = MCAST_INCLUDE;
- rcu_read_unlock();
spin_unlock_bh(&tunnel->lock);
-out:
+ rcu_read_unlock();
dev_put(amt->dev);
}
@@ -479,6 +554,7 @@ static struct amt_group_node *amt_add_group(struct amt_dev *amt,
gnode->tunnel_list = tunnel;
gnode->filter_mode = MCAST_INCLUDE;
INIT_HLIST_NODE(&gnode->node);
+ INIT_HLIST_NODE(&gnode->gc_node);
INIT_DELAYED_WORK(&gnode->group_timer, amt_group_work);
for (i = 0; i < amt->hash_buckets; i++)
INIT_HLIST_HEAD(&gnode->sources[i]);
@@ -628,7 +704,7 @@ static void amt_send_discovery(struct amt_dev *amt)
IPPROTO_UDP, 0,
amt->stream_dev->ifindex);
if (IS_ERR(rt)) {
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -638,7 +714,7 @@ static void amt_send_discovery(struct amt_dev *amt)
skb = netdev_alloc_skb_ip_align(amt->dev, len);
if (!skb) {
ip_rt_put(rt);
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -683,7 +759,7 @@ static void amt_send_discovery(struct amt_dev *amt)
ip_send_check(iph);
err = ip_local_out(amt->net, sk, skb);
if (unlikely(net_xmit_eval(err)))
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
amt_update_gw_status(amt, AMT_STATUS_SENT_DISCOVERY, true);
out:
@@ -719,7 +795,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6)
IPPROTO_UDP, 0,
amt->stream_dev->ifindex);
if (IS_ERR(rt)) {
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -729,7 +805,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6)
skb = netdev_alloc_skb_ip_align(amt->dev, len);
if (!skb) {
ip_rt_put(rt);
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -776,7 +852,7 @@ static void amt_send_request(struct amt_dev *amt, bool v6)
ip_send_check(iph);
err = ip_local_out(amt->net, sk, skb);
if (unlikely(net_xmit_eval(err)))
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
out:
rcu_read_unlock();
@@ -784,11 +860,16 @@ static void amt_send_request(struct amt_dev *amt, bool v6)
static bool amt_send_membership_query(struct amt_dev *amt,
struct sk_buff *skb,
- struct amt_tunnel_list *tunnel,
+ __be32 daddr, __be16 dport,
+ __be32 nonce, u64 mac,
bool v6);
-static void amt_send_igmp_gq(struct amt_dev *amt,
- struct amt_tunnel_list *tunnel)
+/* The destination is passed by value rather than as a tunnel: the requesting
+ * source is not authenticated yet and no tunnel state exists for it - see
+ * amt_request_handler().
+ */
+static void amt_send_igmp_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,
+ __be32 nonce, u64 mac)
{
struct sk_buff *skb;
@@ -797,8 +878,9 @@ static void amt_send_igmp_gq(struct amt_dev *amt,
return;
skb_pull(skb, sizeof(struct ethhdr));
- if (amt_send_membership_query(amt, skb, tunnel, false)) {
- amt->dev->stats.tx_dropped++;
+ if (amt_send_membership_query(amt, skb, daddr, dport, nonce, mac,
+ false)) {
+ DEV_STATS_INC(amt->dev, tx_dropped);
kfree_skb(skb);
}
}
@@ -842,7 +924,7 @@ static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt)
if (ipv6_dev_get_saddr(amt->net, amt->dev, &ip6h->daddr, 0,
&ip6h->saddr)) {
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
kfree_skb(skb);
return NULL;
}
@@ -876,7 +958,8 @@ static struct sk_buff *amt_build_mld_gq(struct amt_dev *amt)
return skb;
}
-static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)
+static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,
+ __be32 nonce, u64 mac)
{
struct sk_buff *skb;
@@ -885,13 +968,15 @@ static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)
return;
skb_pull(skb, sizeof(struct ethhdr));
- if (amt_send_membership_query(amt, skb, tunnel, true)) {
- amt->dev->stats.tx_dropped++;
+ if (amt_send_membership_query(amt, skb, daddr, dport, nonce, mac,
+ true)) {
+ DEV_STATS_INC(amt->dev, tx_dropped);
kfree_skb(skb);
}
}
#else
-static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)
+static void amt_send_mld_gq(struct amt_dev *amt, __be32 daddr, __be16 dport,
+ __be32 nonce, u64 mac)
{
}
#endif
@@ -925,7 +1010,14 @@ static void amt_secret_work(struct work_struct *work)
secret_wq);
spin_lock_bh(&amt->lock);
- get_random_bytes(&amt->key, sizeof(siphash_key_t));
+ /* Keep three previous generations for a 180-240s MAC lifetime.
+ * Its 180s floor exceeds the advertised QQIC (amt->qi, 125s),
+ * allowing the gateway to renew its MAC with a periodic Request.
+ */
+ amt->key[3] = amt->key[2];
+ amt->key[2] = amt->key[1];
+ amt->key[1] = amt->key[0];
+ get_random_bytes(&amt->key[0], sizeof(siphash_key_t));
spin_unlock_bh(&amt->lock);
mod_delayed_work(amt_wq, &amt->secret_wq,
msecs_to_jiffies(AMT_SECRET_TIMEOUT));
@@ -1115,9 +1207,16 @@ static void amt_send_multicast_data(struct amt_dev *amt,
0);
}
+/* Send a Membership Query to a source that has not been authenticated yet.
+ *
+ * No per-source state exists at this point and none is created: the nonce and
+ * the keyed MAC are carried in the Query and recomputed from the Membership
+ * Update when it comes back, so everything this needs is passed by value.
+ */
static bool amt_send_membership_query(struct amt_dev *amt,
struct sk_buff *skb,
- struct amt_tunnel_list *tunnel,
+ __be32 daddr, __be16 dport,
+ __be32 nonce, u64 mac,
bool v6)
{
struct amt_header_membership_query *amtmq;
@@ -1138,13 +1237,13 @@ static bool amt_send_membership_query(struct amt_dev *amt,
skb_reset_inner_headers(skb);
memset(&fl4, 0, sizeof(struct flowi4));
fl4.flowi4_oif = amt->stream_dev->ifindex;
- fl4.daddr = tunnel->ip4;
+ fl4.daddr = daddr;
fl4.saddr = amt->local_ip;
fl4.flowi4_dscp = inet_dsfield_to_dscp(AMT_TOS);
fl4.flowi4_proto = IPPROTO_UDP;
rt = ip_route_output_key(amt->net, &fl4);
if (IS_ERR(rt)) {
- netdev_dbg(amt->dev, "no route to %pI4\n", &tunnel->ip4);
+ netdev_dbg(amt->dev, "no route to %pI4\n", &daddr);
return true;
}
@@ -1154,8 +1253,8 @@ static bool amt_send_membership_query(struct amt_dev *amt,
amtmq->reserved = 0;
amtmq->l = 0;
amtmq->g = 0;
- amtmq->nonce = tunnel->nonce;
- amtmq->response_mac = tunnel->mac;
+ amtmq->nonce = nonce;
+ amtmq->response_mac = mac;
if (!v6)
skb_set_inner_protocol(skb, htons(ETH_P_IP));
@@ -1168,11 +1267,10 @@ static bool amt_send_membership_query(struct amt_dev *amt,
ip4_dst_hoplimit(&rt->dst),
0,
amt->relay_port,
- tunnel->source_port,
+ dport,
false,
false,
0);
- amt_update_relay_status(tunnel, AMT_STATUS_SENT_QUERY, true);
return false;
}
@@ -1236,7 +1334,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
group.ip6 = ipv6_hdr(skb)->daddr;
#endif
} else {
- dev->stats.tx_errors++;
+ DEV_STATS_INC(dev, tx_errors);
goto free;
}
@@ -1249,12 +1347,21 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
/* Gateway only passes IGMP/MLD packets */
if (!report)
goto free;
+ /* A validated report can only be forwarded after the relay's
+ * family-specific Membership Query supplies the state echoed
+ * by the Membership Update. Log this readiness failure before
+ * the shared drop path accounts it.
+ */
if ((!v6 && !READ_ONCE(amt->ready4)) ||
- (v6 && !READ_ONCE(amt->ready6)))
+ (v6 && !READ_ONCE(amt->ready6))) {
+ netdev_dbg(dev, "drop %s report: waiting for Membership Query\n",
+ v6 ? "MLD" : "IGMP");
goto free;
+ }
if (amt_send_membership_update(amt, skb, v6))
goto free;
- goto unlock;
+ /* Sent: the tunnel consumed the skb. Not a drop. */
+ return NETDEV_TX_OK;
} else if (amt->mode == AMT_MODE_RELAY) {
if (!data)
goto free;
@@ -1283,8 +1390,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
return NETDEV_TX_OK;
free:
dev_kfree_skb(skb);
-unlock:
- dev->stats.tx_dropped++;
+ DEV_STATS_INC(dev, tx_dropped);
return NETDEV_TX_OK;
}
@@ -1328,14 +1434,41 @@ static void amt_tunnel_expire(struct work_struct *work)
struct amt_tunnel_list,
gc_wq);
struct amt_dev *amt = tunnel->amt;
+ unsigned long deadline;
spin_lock_bh(&amt->lock);
+ /* amt_dev_stop() has taken ownership of the teardown. */
+ if (READ_ONCE(tunnel->dead)) {
+ spin_unlock_bh(&amt->lock);
+ return;
+ }
+ /* A Membership Update may have refreshed the tunnel after this work
+ * was queued. Re-arm from last_seen rather than letting
+ * amt_update_handler() re-arm gc_wq: this handler is then the only
+ * context that frees the tunnel on the timeout path; amt_dev_stop()
+ * still owns teardown during device shutdown.
+ */
+ deadline = READ_ONCE(tunnel->last_seen);
+ if (!deadline)
+ deadline = jiffies;
+ else
+ deadline += msecs_to_jiffies(amt_gmi(amt)) * 3;
+ if (time_before(jiffies, deadline)) {
+ mod_delayed_work(amt_wq, &tunnel->gc_wq, deadline - jiffies);
+ spin_unlock_bh(&amt->lock);
+ return;
+ }
+ spin_lock_bh(&tunnel->lock);
+ WRITE_ONCE(tunnel->dead, true);
+ spin_unlock_bh(&tunnel->lock);
rcu_read_lock();
list_del_rcu(&tunnel->list);
amt->nr_tunnels--;
amt_clear_groups(tunnel);
rcu_read_unlock();
spin_unlock_bh(&amt->lock);
+ cancel_delayed_work_sync(&group_gc_wq);
+ __amt_group_gc_work();
kfree_rcu(tunnel, rcu);
}
@@ -2369,6 +2502,10 @@ static bool amt_membership_query_handler(struct amt_dev *amt,
if (amtmq->reserved || amtmq->version)
return true;
+ /* A deferred query may outlive a relay address change. */
+ if (ip_hdr(skb)->saddr != READ_ONCE(amt->remote_ip))
+ return true;
+
if (amtmq->nonce != amt->nonce)
return true;
@@ -2461,16 +2598,106 @@ static bool amt_membership_query_handler(struct amt_dev *amt,
return false;
}
+/* The tunnel of the gateway endpoint @saddr:@sport, or NULL. */
+static struct amt_tunnel_list *amt_tunnel_lookup(struct amt_dev *amt,
+ __be32 saddr, __be16 sport)
+{
+ struct amt_tunnel_list *tunnel;
+
+ list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list)
+ if (tunnel->ip4 == saddr && tunnel->source_port == sport)
+ return tunnel;
+ return NULL;
+}
+
+/* Look up the tunnel for a source whose Membership Update has already been
+ * authenticated, creating it on first contact.
+ *
+ * This is now the only place tunnel state is allocated, so amt->max_tunnels
+ * bounds the number of *verified* gateways rather than the number of
+ * unverified Requests anyone can send. A fixed per-source cap additionally
+ * stops one verified source address from monopolising the table.
+ */
+static struct amt_tunnel_list *amt_tunnel_get_or_create(struct amt_dev *amt,
+ __be32 saddr,
+ __be16 sport)
+{
+ struct amt_tunnel_list *tunnel;
+ int per_src = 0;
+ int i;
+
+ tunnel = amt_tunnel_lookup(amt, saddr, sport);
+ if (tunnel)
+ return tunnel;
+
+ spin_lock_bh(&amt->lock);
+
+ /* Re-check under the lock in case a concurrent Update won the race, and
+ * count how many tunnels this source already holds on the same walk.
+ */
+ list_for_each_entry(tunnel, &amt->tunnel_list, list) {
+ if (tunnel->ip4 != saddr)
+ continue;
+ if (tunnel->source_port == sport) {
+ spin_unlock_bh(&amt->lock);
+ return tunnel;
+ }
+ per_src++;
+ }
+
+ if (amt->nr_tunnels >= amt->max_tunnels ||
+ per_src >= AMT_MAX_TUNNELS_PER_SRC) {
+ spin_unlock_bh(&amt->lock);
+ return NULL;
+ }
+
+ if (!netif_running(amt->dev)) {
+ spin_unlock_bh(&amt->lock);
+ return NULL;
+ }
+
+ tunnel = kzalloc(sizeof(*tunnel) +
+ (sizeof(struct hlist_head) * amt->hash_buckets),
+ GFP_ATOMIC);
+ if (!tunnel) {
+ spin_unlock_bh(&amt->lock);
+ return NULL;
+ }
+
+ tunnel->source_port = sport;
+ tunnel->ip4 = saddr;
+ tunnel->amt = amt;
+ spin_lock_init(&tunnel->lock);
+ for (i = 0; i < amt->hash_buckets; i++)
+ INIT_HLIST_HEAD(&tunnel->groups[i]);
+
+ tunnel->last_seen = jiffies;
+ INIT_DELAYED_WORK(&tunnel->gc_wq, amt_tunnel_expire);
+ __amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_UPDATE, false);
+
+ /* Publish only once the entry is fully initialised. */
+ list_add_tail_rcu(&tunnel->list, &amt->tunnel_list);
+ amt->nr_tunnels++;
+ mod_delayed_work(amt_wq, &tunnel->gc_wq,
+ msecs_to_jiffies(amt_gmi(amt)) * 3);
+ spin_unlock_bh(&amt->lock);
+
+ return tunnel;
+}
+
static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
{
struct amt_header_membership_update *amtmu;
struct amt_tunnel_list *tunnel;
struct ethhdr *eth;
struct iphdr *iph;
- int len, hdr_size;
+ siphash_key_t key[4];
+ int len, hdr_size, i;
u64 response_mac;
+ bool verified = false;
__be32 saddr;
__be32 nonce;
+ __be16 sport;
saddr = ip_hdr(skb)->saddr;
@@ -2484,30 +2711,51 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
nonce = amtmu->nonce;
response_mac = amtmu->response_mac;
+ /* Snapshot the tunnel endpoint port before the encap is stripped. */
+ sport = udp_hdr(skb)->source;
- if (iptunnel_pull_header(skb, hdr_size, skb->protocol, false))
- return true;
+ /* Recompute the MAC handed out in the Membership Query. Four live
+ * secrets cover 180-240s, exceeding the advertised QQIC (amt->qi,
+ * 125s), so a periodic Request can renew the MAC before it expires.
+ * Authenticate before decapsulation or allocating tunnel state.
+ */
+ spin_lock_bh(&amt->lock);
+ for (i = 0; i < ARRAY_SIZE(key); i++)
+ key[i] = amt->key[i];
+ spin_unlock_bh(&amt->lock);
- skb_reset_network_header(skb);
+ for (i = 0; i < ARRAY_SIZE(key); i++) {
+ u64 mac = siphash_3u32((__force u32)saddr,
+ (__force u32)sport,
+ (__force u32)nonce,
+ &key[i]) >> 16;
- list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) {
- if (tunnel->ip4 == saddr) {
- if ((nonce == tunnel->nonce &&
- response_mac == tunnel->mac)) {
- mod_delayed_work(amt_wq, &tunnel->gc_wq,
- msecs_to_jiffies(amt_gmi(amt))
- * 3);
- goto report;
- } else {
- netdev_dbg(amt->dev, "Invalid MAC\n");
- return true;
- }
+ if (response_mac == mac) {
+ verified = true;
+ break;
}
}
- return true;
+ if (!verified) {
+ netdev_dbg(amt->dev, "Invalid MAC\n");
+ return true;
+ }
+
+ tunnel = amt_tunnel_get_or_create(amt, saddr, sport);
+ if (!tunnel)
+ return true;
+
+ /* Refresh liveness only. gc_wq is re-armed by amt_tunnel_expire()
+ * itself from last_seen, never from here, so this cannot re-queue the
+ * work of a tunnel that is being freed.
+ */
+ WRITE_ONCE(tunnel->last_seen, jiffies);
+
+ if (iptunnel_pull_header(skb, hdr_size, skb->protocol, false))
+ return true;
+
+ skb_reset_network_header(skb);
-report:
if (!pskb_may_pull(skb, sizeof(*iph)))
return true;
@@ -2522,6 +2770,10 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
}
spin_lock_bh(&tunnel->lock);
+ if (READ_ONCE(tunnel->dead)) {
+ spin_unlock_bh(&tunnel->lock);
+ return true;
+ }
amt_igmp_report_handler(amt, skb, tunnel);
spin_unlock_bh(&tunnel->lock);
@@ -2542,6 +2794,10 @@ static bool amt_update_handler(struct amt_dev *amt, struct sk_buff *skb)
}
spin_lock_bh(&tunnel->lock);
+ if (READ_ONCE(tunnel->dead)) {
+ spin_unlock_bh(&tunnel->lock);
+ return true;
+ }
amt_mld_report_handler(amt, skb, tunnel);
spin_unlock_bh(&tunnel->lock);
@@ -2601,7 +2857,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce,
IPPROTO_UDP, 0,
amt->stream_dev->ifindex);
if (IS_ERR(rt)) {
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -2611,7 +2867,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce,
skb = netdev_alloc_skb_ip_align(amt->dev, len);
if (!skb) {
ip_rt_put(rt);
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
goto out;
}
@@ -2657,7 +2913,7 @@ static void amt_send_advertisement(struct amt_dev *amt, __be32 nonce,
ip_send_check(iph);
err = ip_local_out(amt->net, sk, skb);
if (unlikely(net_xmit_eval(err)))
- amt->dev->stats.tx_errors++;
+ DEV_STATS_INC(amt->dev, tx_errors);
out:
rcu_read_unlock();
@@ -2684,15 +2940,29 @@ static bool amt_discovery_handler(struct amt_dev *amt, struct sk_buff *skb)
return false;
}
+/* Handle an AMT Relay Membership Request.
+ *
+ * The source of a Request is unauthenticated: it is a bare UDP datagram with a
+ * trivially spoofable source address. Allocating tunnel state here let an
+ * attacker fill the table from spoofed addresses, and let one spoofed packet
+ * overwrite the nonce/MAC of an established tunnel and cut that gateway off.
+ *
+ * Nothing needs to be remembered at this point. Every input to the keyed MAC
+ * is carried in the packet or is device state, so the MAC is generated here,
+ * echoed back by the gateway in its Membership Update, and recomputed and
+ * verified there - see amt_update_handler(). Tunnel state is created only once
+ * that verification succeeds.
+ */
static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
{
struct amt_header_request *amtrh;
struct amt_tunnel_list *tunnel;
- unsigned long long key;
struct udphdr *udph;
struct iphdr *iph;
+ siphash_key_t key;
+ bool full, have = false;
+ int per_src = 0;
u64 mac;
- int i;
if (!pskb_may_pull(skb, sizeof(*udph) + sizeof(*amtrh)))
return true;
@@ -2704,59 +2974,41 @@ static bool amt_request_handler(struct amt_dev *amt, struct sk_buff *skb)
if (amtrh->reserved1 || amtrh->reserved2 || amtrh->version)
return true;
- list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list)
- if (tunnel->ip4 == iph->saddr)
- goto send;
-
- spin_lock_bh(&amt->lock);
- if (amt->nr_tunnels >= amt->max_tunnels) {
- spin_unlock_bh(&amt->lock);
- icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_UNREACH, 0);
+ if (!netif_running(amt->dev) || !netif_running(amt->stream_dev))
return true;
- }
- tunnel = kzalloc(sizeof(*tunnel) +
- (sizeof(struct hlist_head) * amt->hash_buckets),
- GFP_ATOMIC);
- if (!tunnel) {
- spin_unlock_bh(&amt->lock);
- return true;
- }
-
- tunnel->source_port = udph->source;
- tunnel->ip4 = iph->saddr;
-
- memcpy(&key, &tunnel->key, sizeof(unsigned long long));
- tunnel->amt = amt;
- spin_lock_init(&tunnel->lock);
- for (i = 0; i < amt->hash_buckets; i++)
- INIT_HLIST_HEAD(&tunnel->groups[i]);
-
- INIT_DELAYED_WORK(&tunnel->gc_wq, amt_tunnel_expire);
-
- list_add_tail_rcu(&tunnel->list, &amt->tunnel_list);
- tunnel->key = amt->key;
- __amt_update_relay_status(tunnel, AMT_STATUS_RECEIVED_REQUEST, true);
- amt->nr_tunnels++;
- mod_delayed_work(amt_wq, &tunnel->gc_wq,
- msecs_to_jiffies(amt_gmi(amt)));
+ /* Snapshot the secret and limits under the lock; keep the endpoint walk
+ * out of the lock so spoofed Requests cannot serialize relay updates.
+ */
+ spin_lock_bh(&amt->lock);
+ key = amt->key[0];
+ full = amt->nr_tunnels >= amt->max_tunnels;
spin_unlock_bh(&amt->lock);
-send:
- tunnel->nonce = amtrh->nonce;
- mac = siphash_3u32((__force u32)tunnel->ip4,
- (__force u32)tunnel->source_port,
- (__force u32)tunnel->nonce,
- &tunnel->key);
- tunnel->mac = mac >> 16;
+ rcu_read_lock();
+ list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) {
+ if (tunnel->ip4 != iph->saddr)
+ continue;
+ per_src++;
+ if (tunnel->source_port == udph->source)
+ have = true;
+ }
+ rcu_read_unlock();
- if (!netif_running(amt->dev) || !netif_running(amt->stream_dev))
+ /* Withhold the Query when a new endpoint cannot get a tunnel. */
+ if (!have && (full || per_src >= AMT_MAX_TUNNELS_PER_SRC))
return true;
+ mac = siphash_3u32((__force u32)iph->saddr,
+ (__force u32)udph->source,
+ (__force u32)amtrh->nonce,
+ &key) >> 16;
if (!amtrh->p)
- amt_send_igmp_gq(amt, tunnel);
+ amt_send_igmp_gq(amt, iph->saddr, udph->source, amtrh->nonce,
+ mac);
else
- amt_send_mld_gq(amt, tunnel);
+ amt_send_mld_gq(amt, iph->saddr, udph->source, amtrh->nonce,
+ mac);
return false;
}
@@ -2833,7 +3085,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)
}
goto out;
case AMT_MSG_MULTICAST_DATA:
- if (saddr != remote_ip) {
+ if (!remote_ip || saddr != remote_ip) {
netdev_dbg(amt->dev, "Invalid Relay IP\n");
err = true;
goto drop;
@@ -2844,7 +3096,7 @@ static int amt_rcv(struct sock *sk, struct sk_buff *skb)
else
goto out;
case AMT_MSG_MEMBERSHIP_QUERY:
- if (saddr != remote_ip) {
+ if (!remote_ip || saddr != remote_ip) {
netdev_dbg(amt->dev, "Invalid Relay IP\n");
err = true;
goto drop;
@@ -3024,6 +3276,14 @@ static int amt_dev_open(struct net_device *dev)
enable_delayed_work(&amt->discovery_wq);
enable_delayed_work(&amt->req_wq);
+ /* Seed the keys before amt_socket_create() enables the encap receive
+ * path, so a Request or Update that arrives immediately is never
+ * verified against an all-zero (predictable) secret.
+ */
+ spin_lock_bh(&amt->lock);
+ get_random_bytes(&amt->key, sizeof(amt->key));
+ spin_unlock_bh(&amt->lock);
+
err = amt_socket_create(amt);
if (err) {
disable_delayed_work(&amt->req_wq);
@@ -3034,7 +3294,6 @@ static int amt_dev_open(struct net_device *dev)
amt->req_cnt = 0;
WRITE_ONCE(amt->remote_ip, 0);
amt->nonce = 0;
- get_random_bytes(&amt->key, sizeof(siphash_key_t));
amt->status = AMT_STATUS_INIT;
if (amt->mode == AMT_MODE_GATEWAY) {
@@ -3050,7 +3309,7 @@ static int amt_dev_open(struct net_device *dev)
static int amt_dev_stop(struct net_device *dev)
{
struct amt_dev *amt = netdev_priv(dev);
- struct amt_tunnel_list *tunnel, *tmp;
+ struct amt_tunnel_list *tunnel;
struct sk_buff *skb;
struct sock *sk;
int i;
@@ -3079,11 +3338,38 @@ static int amt_dev_stop(struct net_device *dev)
amt->req_cnt = 0;
WRITE_ONCE(amt->remote_ip, 0);
- list_for_each_entry_safe(tunnel, tmp, &amt->tunnel_list, list) {
- list_del_rcu(&tunnel->list);
- amt->nr_tunnels--;
+ /* Mark every tunnel dead first, so a concurrent amt_tunnel_expire()
+ * sees ->dead and bails instead of freeing a tunnel in parallel; this
+ * path is then the sole freer.
+ */
+ spin_lock_bh(&amt->lock);
+ list_for_each_entry(tunnel, &amt->tunnel_list, list) {
+ spin_lock_bh(&tunnel->lock);
+ WRITE_ONCE(tunnel->dead, true);
+ spin_unlock_bh(&tunnel->lock);
+ }
+ spin_unlock_bh(&amt->lock);
+
+ /* Unlink one tunnel at a time with list_del_rcu() rather than splicing
+ * the list onto a local head: a lockless reader walking tunnel_list
+ * must always terminate at &amt->tunnel_list, never at a stack head.
+ */
+ for (;;) {
+ spin_lock_bh(&amt->lock);
+ tunnel = list_first_entry_or_null(&amt->tunnel_list,
+ struct amt_tunnel_list, list);
+ if (tunnel) {
+ list_del_rcu(&tunnel->list);
+ amt->nr_tunnels--;
+ }
+ spin_unlock_bh(&amt->lock);
+ if (!tunnel)
+ break;
+
cancel_delayed_work_sync(&tunnel->gc_wq);
amt_clear_groups(tunnel);
+ cancel_delayed_work_sync(&group_gc_wq);
+ __amt_group_gc_work();
kfree_rcu(tunnel, rcu);
}
@@ -3152,9 +3438,9 @@ static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = {
[IFLA_AMT_RELAY_PORT] = { .type = NLA_U16 },
[IFLA_AMT_GATEWAY_PORT] = { .type = NLA_U16 },
[IFLA_AMT_LINK] = { .type = NLA_U32 },
- [IFLA_AMT_LOCAL_IP] = { .len = sizeof_field(struct iphdr, daddr) },
+ [IFLA_AMT_LOCAL_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
[IFLA_AMT_REMOTE_IP] = { .len = sizeof_field(struct iphdr, daddr) },
- [IFLA_AMT_DISCOVERY_IP] = { .len = sizeof_field(struct iphdr, daddr) },
+ [IFLA_AMT_DISCOVERY_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
[IFLA_AMT_MAX_TUNNELS] = { .type = NLA_U32 },
};
@@ -3461,11 +3747,17 @@ static int __init amt_init(void)
}
spin_lock_init(&source_gc_lock);
+ spin_lock_init(&group_gc_lock);
spin_lock_bh(&source_gc_lock);
INIT_DELAYED_WORK(&source_gc_wq, amt_source_gc_work);
mod_delayed_work(amt_wq, &source_gc_wq,
msecs_to_jiffies(AMT_GC_INTERVAL));
spin_unlock_bh(&source_gc_lock);
+ spin_lock_bh(&group_gc_lock);
+ INIT_DELAYED_WORK(&group_gc_wq, amt_group_gc_work);
+ mod_delayed_work(amt_wq, &group_gc_wq,
+ msecs_to_jiffies(AMT_GC_INTERVAL));
+ spin_unlock_bh(&group_gc_lock);
return 0;
@@ -3485,6 +3777,8 @@ static void __exit amt_fini(void)
unregister_netdevice_notifier(&amt_notifier_block);
cancel_delayed_work_sync(&source_gc_wq);
__amt_source_gc_work();
+ cancel_delayed_work_sync(&group_gc_wq);
+ __amt_group_gc_work();
destroy_workqueue(amt_wq);
}
module_exit(amt_fini);
diff --git a/include/net/amt.h b/include/net/amt.h
index 2846dde0cadce..4acfc3da0c5aa 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -240,12 +240,19 @@ struct amt_tunnel_list {
u32 nr_sources;
enum amt_status status;
struct delayed_work gc_wq;
+ /* Last time this tunnel was refreshed. gc_wq
+ * re-arms itself from this rather than being re-armed by the Update
+ * path, so the Update path cannot re-queue work for a tunnel that
+ * amt_tunnel_expire() is freeing on the timeout path.
+ */
+ unsigned long last_seen;
+ /* Set under amt->lock and tunnel->lock by whichever freer reaches the
+ * tunnel first;
+ * the other then leaves it alone, so the tunnel is freed exactly once.
+ */
+ bool dead;
__be16 source_port;
__be32 ip4;
- __be32 nonce;
- siphash_key_t key;
- u64 mac:48,
- reserved:16;
struct rcu_head rcu;
struct hlist_head groups[];
};
@@ -275,6 +282,7 @@ enum amt_source_status {
/* protected by gnode->lock */
struct amt_source_node {
struct hlist_node node;
+ struct hlist_node gc_node;
struct amt_group_node *gnode;
struct delayed_work source_timer;
union amt_addr source_addr;
@@ -282,6 +290,8 @@ struct amt_source_node {
#define AMT_SOURCE_OLD 0
#define AMT_SOURCE_NEW 1
u8 flags;
+ /* Protected by gnode->tunnel_list->lock. */
+ bool dead;
struct rcu_head rcu;
};
@@ -295,7 +305,10 @@ struct amt_group_node {
u32 nr_sources;
struct amt_tunnel_list *tunnel_list;
struct hlist_node node;
+ struct hlist_node gc_node;
struct delayed_work group_timer;
+ /* Protected by tunnel_list->lock. */
+ bool dead;
struct rcu_head rcu;
struct hlist_head sources[];
};
@@ -325,8 +338,10 @@ struct amt_dev {
struct work_struct event_wq;
/* AMT status */
enum amt_status status;
- /* Generated key */
- siphash_key_t key;
+ /* Current key and three previous generations keep MACs valid for
+ * 180-240s, beyond the advertised QQIC (see amt_secret_work()).
+ */
+ siphash_key_t key[4];
struct sock __rcu *sk;
u32 max_groups;
u32 max_sources;
@@ -383,6 +398,10 @@ struct amt_dev {
#define AMT_SECRET_TIMEOUT 60000
#define IANA_AMT_UDP_PORT 2268
#define AMT_MAX_TUNNELS 128
+/* Fixed per-source cap stops one verified source address from monopolising
+ * the AMT_MAX_TUNNELS-slot table.
+ */
+#define AMT_MAX_TUNNELS_PER_SRC 16
#define AMT_MAX_REQS 128
#define AMT_GW_HLEN (sizeof(struct iphdr) + \
sizeof(struct udphdr) + \
|
| 17/3 | 2026/10/20 05:58 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16169 output: 37 thoughts: 1053 Thoughts: **KMSAN Evaluation for AMT Driver Patch Series** Okay, let's break this down. My goal is to determine if this patch series for `drivers/net/amt.c` and `include/net/amt.h` warrants a dedicated KMSAN fuzzing session, in addition to the standard KASAN run. The critical distinction, as I understand it, is that KMSAN looks for uninitialized memory reads and kernel-to-user information leaks, while KASAN and other standard detectors cover OOB, UAF, double frees, and locking issues. The rule is clear: if KASAN already has our backs, no need for KMSAN. My focus has to be on checking: 1. Kernel data sent to user space where uninitialized fields could be exposed. 2. Conditional logic that depends on potentially uninitialized variables. 3. Complex data structure allocation/initialization that could lead to later uninitialized reads. 4. Anything that creates a path to read uninitialized bytes of existing buffers, even indirectly. The patch introduces significant changes related to garbage collection, race condition fixes, and UAF prevention in AMT source and group management. I see workqueues, `hlist_del_init`, `cancel_delayed_work_sync`, and `kfree_rcu` calls, which are all part of the fix to a UAF in group/source destruction and timers/GC. The presence of `dead` flags, atomics, `READ_ONCE`/`WRITE_ONCE`, and RCU synchronization further points to preventing memory corruption from concurrency issues. These are the kinds of issues that KASAN, LOCKDEP, and standard bug detectors are meant to find. Now, for specific code blocks: The race and UAF fixes involving garbage collection and timers seem to be the primary focus. The code modifies `amt_destroy_source`, `amt_del_group`, `amt_source_work`, `amt_group_work`, and `amt_tunnel_expire` using the `dead` flag, atomic/READ_ONCE/WRITE_ONCE, checks, delayed\_work cancellation, and rcu synchronization. This looks like the patches are *fixing* potential concurrency issues, which KASAN, not KMSAN, is for. In the handlers `amt_update_handler` and `amt_request_handler`, I spot stateful vs. stateless handling of membership requests/updates. `siphash_key_t key[4]` is declared. This is the critical piece I need to carefully analyze for KMSAN. I see the keys are initialized with random bytes in both `amt_secret_work` (key refresh) and `amt_dev_open` (initialization). The whole array of four keys is initialized in `amt_dev_open` using `get_random_bytes`. In `amt_secret_work`, the keys are shifted and the first key is re-initialized with `get_random_bytes`. This initialization flow appears correct, which means that there shouldn't be any uninitialized key elements. To be sure, I'll need to double-check when `amt_dev` is allocated (is it zeroed or initialized? what about its members?). Based on this analysis, I'm leaning towards *not* needing KMSAN. The fixes address race conditions, UAF issues, and correct handling of key initialization. These are primarily KASAN-type bugs. But, I am going to double check where the `amt_dev` structure is allocated and initialized to be absolutely sure no members are left uninitialized. I don't see any obvious paths where uninitialized kernel data is being sent to userspace. |
| 18/3 | 2026/10/20 05:58 | tool | grepper |
0mArgs:{
"Expression": "alloc_netdev|netdev_priv",
"PathPrefixes": [
"drivers/net/amt.c"
]
}Results: {
"Output": "drivers/net/amt.c=1277=static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)\ndrivers/net/amt.c-1278-{\ndrivers/net/amt.c:1279:\tstruct amt_dev *amt = netdev_priv(dev);\ndrivers/net/amt.c-1280-\tstruct amt_tunnel_list *tunnel;\n--\ndrivers/net/amt.c=3266=static int amt_dev_open(struct net_device *dev)\ndrivers/net/amt.c-3267-{\ndrivers/net/amt.c:3268:\tstruct amt_dev *amt = netdev_priv(dev);\ndrivers/net/amt.c-3269-\tint err;\n--\ndrivers/net/amt.c=3309=static int amt_dev_stop(struct net_device *dev)\ndrivers/net/amt.c-3310-{\ndrivers/net/amt.c:3311:\tstruct amt_dev *amt = netdev_priv(dev);\ndrivers/net/amt.c-3312-\tstruct amt_tunnel_list *tunnel;\n--\ndrivers/net/amt.c=3383=static int amt_dev_init(struct net_device *dev)\ndrivers/net/amt.c-3384-{\ndrivers/net/amt.c:3385:\tstruct amt_dev *amt = netdev_priv(dev);\ndrivers/net/amt.c-3386-\tint err;\n--\ndrivers/net/amt.c=3397=static void amt_dev_uninit(struct net_device *dev)\ndrivers/net/amt.c-3398-{\ndrivers/net/amt.c:3399:\tstruct amt_dev *amt = netdev_priv(dev);\ndrivers/net/amt.c-3400-\n--\ndrivers/net/amt.c=3487=static int amt_newlink(struct net_device *dev,\n--\ndrivers/net/amt.c-3491-\tstruct net *link_net = rtnl_newlink_link_net(params);\ndrivers/net/amt.c:3492:\tstruct amt_dev *amt = netdev_priv(dev);\ndrivers/net/amt.c-3493-\tstruct nlattr **data = params-\u003edata;\n--\ndrivers/net/amt.c=3611=static void amt_dellink(struct net_device *dev, struct list_head *head)\ndrivers/net/amt.c-3612-{\ndrivers/net/amt.c:3613:\tstruct amt_dev *amt = netdev_priv(dev);\ndrivers/net/amt.c-3614-\n--\ndrivers/net/amt.c=3632=static int amt_fill_info(struct sk_buff *skb, const struct net_device *dev)\ndrivers/net/amt.c-3633-{\ndrivers/net/amt.c:3634:\tconst struct amt_dev *amt = netdev_priv(dev);\ndrivers/net/amt.c-3635-\t__be32 remote_ip;\n--\ndrivers/net/amt.c=3679=static struct net_device *amt_lookup_upper_dev(struct net_device *dev)\n--\ndrivers/net/amt.c-3685-\t\tif (netif_is_amt(upper_dev)) {\ndrivers/net/amt.c:3686:\t\t\tamt = netdev_priv(upper_dev);\ndrivers/net/amt.c-3687-\t\t\tif (amt-\u003estream_dev == dev)\n--\ndrivers/net/amt.c=3695=static int amt_device_event(struct notifier_block *unused,\n--\ndrivers/net/amt.c-3706-\t\treturn NOTIFY_DONE;\ndrivers/net/amt.c:3707:\tamt = netdev_priv(upper_dev);\ndrivers/net/amt.c-3708-\n"
} |
| 19/3 | 2026/10/20 05:58 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19066 output: 40 thoughts: 17 Thoughts: Here's a first-person summary, tailored for an expert audience, based on the provided starting point: **Diving into the AMT net_device Implementation** Okay, so I need to get a handle on how the `net_device` is configured and integrated within the AMT (Active Management Technology) framework. That's the crux of understanding its network behavior. My immediate thought is to trace the registration process; where and how is this thing actually being brought online? Are there specific initialization routines within the AMT code that are crucial to its functionality, or is it a fairly standard network device registration? I'll need to look for calls to `register_netdev()` or similar functions, and understand the context around them. Are any special flags being set during registration that are specific to the AMT implementation? I'm anticipating there will be some AMT-specific quirks and interactions that I need to uncover. I'll probably start by looking for a well-defined entry point or initialization function related to network configuration in the AMT subsystem. Let's see what we can find. |
| 20/3 | 2026/10/20 05:58 | tool | grepper |
0mArgs:{
"Expression": "rtnl_link_ops.*amt_link_ops",
"PathPrefixes": [
"drivers/net/amt.c"
]
}Results: {
"Output": "drivers/net/amt.c=3632=static int amt_fill_info(struct sk_buff *skb, const struct net_device *dev)\n--\ndrivers/net/amt.c-3665-\ndrivers/net/amt.c:3666:static struct rtnl_link_ops amt_link_ops __read_mostly = {\ndrivers/net/amt.c-3667-\t.kind\t\t= \"amt\",\n"
} |
| 21/3 | 2026/10/20 05:58 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19466 output: 36 thoughts: 32 Thoughts: Here's my take on the thought process, from an expert's perspective: **Diving into the AMT Driver** Okay, so we need to understand how the `rtnl_link_ops` are handled in the AMT driver. Right now, my intuition is telling me that something isn't quite right with how it's interacting with the routing layer. Let's get right to the source. Specifically, I need to pinpoint the implementation details. Let's jump into `drivers/net/amt.c` and focus on lines 3660 to 3675. That should be where the relevant declarations and hopefully the initialization of `rtnl_link_ops` are located. I'm expecting to find the standard structure assignment, and I’m hoping to glean whether we're using a standard implementation or if there is a problem with any custom callbacks. I'll be looking for any signs of non-standard handling that could explain the symptoms we are experiencing. I'm prepared to dissect the code and look for anything unusual in how the functions are linked with the routing interface. From here, I will check the definitions. |
| 22/3 | 2026/10/20 05:59 | tool | read-file |
0mArgs:{
"File": "drivers/net/amt.c",
"FirstLine": 3660,
"LineCount": 25
}Results: {
"Contents": "3660:\t\n3661:\tnla_put_failure:\n3662:\t\trcu_read_unlock();\n3663:\t\treturn -EMSGSIZE;\n3664:\t}\n3665:\t\n3666:\tstatic struct rtnl_link_ops amt_link_ops __read_mostly = {\n3667:\t\t.kind\t\t= \"amt\",\n3668:\t\t.maxtype\t= IFLA_AMT_MAX,\n3669:\t\t.policy\t\t= amt_policy,\n3670:\t\t.priv_size\t= sizeof(struct amt_dev),\n3671:\t\t.setup\t\t= amt_link_setup,\n3672:\t\t.validate\t= amt_validate,\n3673:\t\t.newlink\t= amt_newlink,\n3674:\t\t.dellink\t= amt_dellink,\n3675:\t\t.get_size = amt_get_size,\n3676:\t\t.fill_info = amt_fill_info,\n3677:\t};\n3678:\t\n3679:\tstatic struct net_device *amt_lookup_upper_dev(struct net_device *dev)\n3680:\t{\n3681:\t\tstruct net_device *upper_dev;\n3682:\t\tstruct amt_dev *amt;\n3683:\t\n3684:\t\tfor_each_netdev(dev_net(dev), upper_dev) {\n"
} |
| 23/3 | 2026/10/20 05:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20166 output: 46 thoughts: 716 Thoughts: **Analyzing AMT Membership Query Initialization** Okay, let's break this down systematically. I'm looking at the initialization of the membership query within the AMT (Automatic Multicast Tunneling) driver. First, I see that `priv_size` is based on `sizeof(struct amt_dev)`. The netdev's private memory is initialized to all zeros by `alloc_netdev_mqs()`. This is important because it sets a baseline for the structure. Then, within `amt_dev_open`, the `amt->key` is populated. Specifically, a random key is generated using `get_random_bytes` and written to `amt->key`. I'm confident that `amt->key` is fully initialized at this point because `get_random_bytes` is designed to provide cryptographically secure random bytes to fill the entire key space. Now, in `amt_update_handler`, the code explicitly copies the entire `amt->key` to a local `key` array. This `key` is an array of four `siphash_key_t` elements, which are each explicitly filled from `amt->key`. Therefore, this stack variable `key` is completely initialized and usable. Next, I'm focusing on `amt_send_membership_query`. The function accepts a few arguments, including `nonce` and `mac`. Let's see how those come to be. Within `amt_request_handler`, a `siphash_key_t key` is declared on the stack, and, crucially, only `amt->key[0]` is assigned to `key`. I'm going to have to make sure that the `amt->key` array is valid. The `key` then gets passed down, along with a `nonce`. Finally, inside `amt_send_membership_query`, the fields of `amtmq` (AMT membership query message) are being initialized. Specifically, the following fields are set: `type`, `reserved`, `l`, `g`, `nonce`, and `response_mac`. These fields are being set with their given arguments. So, `amtmq` seems completely initialized before being pushed onto the skb. So far, it looks solid. I need to make sure I understand the `amt_header_membership_query` definition and exactly how `amtmq` is *actually* pushed onto the skb to be absolutely certain, but on the surface, this initialization appears correct and safe. |
| 24/3 | 2026/10/20 05:59 | tool | grepper |
0mArgs:{
"Expression": "struct amt_header_membership_query",
"PathPrefixes": [
"drivers/net/amt.c",
"include/net/amt.h"
]
}Results: {
"Output": "drivers/net/amt.c=1216=static bool amt_send_membership_query(struct amt_dev *amt,\n--\ndrivers/net/amt.c-1221-{\ndrivers/net/amt.c:1222:\tstruct amt_header_membership_query *amtmq;\ndrivers/net/amt.c-1223-\tstruct rtable *rt;\n--\ndrivers/net/amt.c=2486=static bool amt_membership_query_handler(struct amt_dev *amt,\n--\ndrivers/net/amt.c-2488-{\ndrivers/net/amt.c:2489:\tstruct amt_header_membership_query *amtmq;\ndrivers/net/amt.c-2490-\tstruct ethhdr *eth, *oeth;\n--\ndrivers/net/amt.c-2500-\ndrivers/net/amt.c:2501:\tamtmq = (struct amt_header_membership_query *)(udp_hdr(skb) + 1);\ndrivers/net/amt.c-2502-\tif (amtmq-\u003ereserved || amtmq-\u003eversion)\n--\ninclude/net/amt.h=136=struct amt_header_request {\n--\ninclude/net/amt.h-154-\ninclude/net/amt.h:155:struct amt_header_membership_query {\ninclude/net/amt.h-156-#if defined(__LITTLE_ENDIAN_BITFIELD)\n--\ninclude/net/amt.h=207=struct amt_headers {\n--\ninclude/net/amt.h-211-\t\tstruct amt_header_request request;\ninclude/net/amt.h:212:\t\tstruct amt_header_membership_query query;\ninclude/net/amt.h-213-\t\tstruct amt_header_membership_update update;\n--\ninclude/net/amt.h=226=struct amt_relay_headers {\n--\ninclude/net/amt.h-228-\t\tstruct amt_header_advertisement advertisement;\ninclude/net/amt.h:229:\t\tstruct amt_header_membership_query query;\ninclude/net/amt.h-230-\t\tstruct amt_header_mcast_data data;\n"
} |
| 25/3 | 2026/10/20 05:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22020 output: 35 thoughts: 33 Thoughts: Here's my summary, as if I were thinking these thoughts: **Diving into the AMT Header** Okay, time to get my hands dirty. I need to refresh my memory on the specifics of the AMT header. Let's start by looking at `include/net/amt.h`. Specifically, I'm going to jump to lines 155 through 180. That's the likely location for the `amt_header_membership_query` structure definition. I want to carefully examine the fields there. Understanding that structure is fundamental to understanding the whole AMT process. I need to make sure I grasp every nuance of its composition, the specific data it carries, and how it relates to the overall membership querying mechanism. I need to know this inside and out. |
| 26/3 | 2026/10/20 05:59 | tool | read-file |
0mArgs:{
"File": "include/net/amt.h",
"FirstLine": 155,
"LineCount": 25
}Results: {
"Contents": " 155:\tstruct amt_header_membership_query {\n 156:\t#if defined(__LITTLE_ENDIAN_BITFIELD)\n 157:\t\tu64\ttype:4,\n 158:\t\t\tversion:4,\n 159:\t\t\treserved:6,\n 160:\t\t\tl:1,\n 161:\t\t\tg:1,\n 162:\t\t\tresponse_mac:48;\n 163:\t#elif defined(__BIG_ENDIAN_BITFIELD)\n 164:\t\tu64\tversion:4,\n 165:\t\t\ttype:4,\n 166:\t\t\tg:1,\n 167:\t\t\tl:1,\n 168:\t\t\treserved:6,\n 169:\t\t\tresponse_mac:48;\n 170:\t#else\n 171:\t#error \"Please fix \u003casm/byteorder.h\u003e\"\n 172:\t#endif\n 173:\t\t__be32\tnonce;\n 174:\t} __packed;\n 175:\t\n 176:\tstruct amt_header_membership_update {\n 177:\t#if defined(__LITTLE_ENDIAN_BITFIELD)\n 178:\t\tu64\ttype:4,\n 179:\t\t\tversion:4,\n"
} |
| 27/3 | 2026/10/20 05:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22599 output: 34 thoughts: 220 Thoughts: Okay, let me break this down. **Analyzing the Structure and Allocation Logic** Right, so we're looking at `struct amt_header_membership_query`, and it's *packed*. That's a good starting point. The patch itself seems straightforward in how it's handling the `nonce` and `mac` values. Before, they were assigned directly to `amtmq->nonce` and `amtmq->response_mac`, and now we're passing them by value. It's essentially just a change in how we're assigning them. No red flags regarding uninitialized fields or the like, which is good. Now, the interesting bit: allocations. Specifically, the `amt_alloc_snode` function. I need to understand how it allocates the `snode` structure. Let's look at the code snippet. It sets `snode->status`, `snode->flags` (which is initialized to `AMT_SOURCE_NEW`), and then initializes a few `hlist_node`s: `snode->node` and `snode->gc_node`. We also see the initialization of `snode->source_timer`. It's pretty standard, nothing obviously problematic here either. I just need to verify how these elements are allocated and deallocated as I keep moving through the code to make sure there are no leaks or unexpected behavior. |
| 28/3 | 2026/10/20 05:59 | tool | grepper |
0mArgs:{
"Expression": "amt_alloc_snode",
"PathPrefixes": [
"drivers/net/amt.c"
]
}Results: {
"Output": "drivers/net/amt.c=368=static void amt_act_src(struct amt_tunnel_list *tunnel,\n--\ndrivers/net/amt.c-418-\ndrivers/net/amt.c:419:static struct amt_source_node *amt_alloc_snode(struct amt_group_node *gnode,\ndrivers/net/amt.c-420-\t\t\t\t\t union amt_addr *src)\n--\ndrivers/net/amt.c=1511=static void amt_add_srcs(struct amt_dev *amt, struct amt_tunnel_list *tunnel,\n--\ndrivers/net/amt.c-1548-\ndrivers/net/amt.c:1549:\t\tsnode = amt_alloc_snode(gnode, \u0026src);\ndrivers/net/amt.c-1550-\t\tif (snode) {\n"
} |
| 29/3 | 2026/10/20 05:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 23372 output: 35 thoughts: 12 Thoughts: Okay, here's my interpretation of "Let's read `amt_alloc_snode`", assuming I'm an expert in this field: **Diving into `amt_alloc_snode`** Alright, time to crack this open. "Let's read `amt_alloc_snode`" - that's my cue. I'm immediately focusing on this specific function, and my mental gears are already whirring. What am I *expecting* to see in `amt_alloc_snode`? Based on the name, my initial assumption is that this code is dealing with the allocation of a storage node, probably within some sort of storage management system or perhaps even the core memory management. The "amt" prefix *could* be a project or module identifier, and "snode" likely points to "storage node." So, what I want to understand is how the system handles the creation or retrieval of these storage units. I'll be looking for clues about the underlying data structures being used, the memory allocation strategies, how the system deals with potential resource contention, and any associated locking mechanisms. I'll need to know whether it's a simple allocator, a more complex system with pools or caching, or if it leverages any existing allocation frameworks. Time to dive in and see how this system works. |
| 30/3 | 2026/10/20 05:59 | tool | read-file |
0mArgs:{
"File": "drivers/net/amt.c",
"FirstLine": 418,
"LineCount": 25
}Results: {
"Contents": " 418:\t\n 419:\tstatic struct amt_source_node *amt_alloc_snode(struct amt_group_node *gnode,\n 420:\t\t\t\t\t\t union amt_addr *src)\n 421:\t{\n 422:\t\tstruct amt_source_node *snode;\n 423:\t\n 424:\t\tsnode = kzalloc_obj(*snode, GFP_ATOMIC);\n 425:\t\tif (!snode)\n 426:\t\t\treturn NULL;\n 427:\t\n 428:\t\tmemcpy(\u0026snode-\u003esource_addr, src, sizeof(union amt_addr));\n 429:\t\tsnode-\u003egnode = gnode;\n 430:\t\tsnode-\u003estatus = AMT_SOURCE_STATUS_NONE;\n 431:\t\tsnode-\u003eflags = AMT_SOURCE_NEW;\n 432:\t\tINIT_HLIST_NODE(\u0026snode-\u003enode);\n 433:\t\tINIT_HLIST_NODE(\u0026snode-\u003egc_node);\n 434:\t\tINIT_DELAYED_WORK(\u0026snode-\u003esource_timer, amt_source_work);\n 435:\t\n 436:\t\treturn snode;\n 437:\t}\n 438:\t\n 439:\t/* RFC 3810 - 7.2.2. Definition of Filter Timers\n 440:\t *\n 441:\t * Router Mode Filter Timer Actions/Comments\n 442:\t * ----------- ----------------- ----------------\n"
} |
| 31/3 | 2026/10/20 05:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24098 output: 33 thoughts: 31 Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue: **Investigating Memory Allocation and Group Addition** Right, so `kzalloc_obj` zeroes the memory. That much is clear. But I need to be absolutely certain about the implications of that for the broader system, especially when dealing with group additions. My concern is, does `amt_add_group` interact with this zeroing behavior in any significant way? Are there assumptions in either function that could cause an issue? Maybe the caller expects initialized memory and the zeroing creates some subtle, yet serious, state? Hmm, I need to understand `amt_add_group`'s implementation, and how it handles potential zeroed structures. Let's dig into `amt_add_group`. |
| 32/3 | 2026/10/20 05:59 | tool | grepper |
0mArgs:{
"Expression": "amt_add_group",
"PathPrefixes": [
"drivers/net/amt.c"
]
}Results: {
"Output": "drivers/net/amt.c=464=static void amt_group_work(struct work_struct *work)\n--\ndrivers/net/amt.c-530- */\ndrivers/net/amt.c:531:static struct amt_group_node *amt_add_group(struct amt_dev *amt,\ndrivers/net/amt.c-532-\t\t\t\t\t struct amt_tunnel_list *tunnel,\n--\ndrivers/net/amt.c=2060=static void amt_igmpv2_report_handler(struct amt_dev *amt, struct sk_buff *skb,\n--\ndrivers/net/amt.c-2074-\tif (!gnode) {\ndrivers/net/amt.c:2075:\t\tgnode = amt_add_group(amt, tunnel, \u0026group, \u0026host, false);\ndrivers/net/amt.c-2076-\t\tif (!IS_ERR(gnode)) {\n--\ndrivers/net/amt.c=2115=static void amt_igmpv3_report_handler(struct amt_dev *amt, struct sk_buff *skb,\n--\ndrivers/net/amt.c-2152-\t\tif (!gnode) {\ndrivers/net/amt.c:2153:\t\t\tgnode = amt_add_group(amt, tunnel, \u0026group, \u0026host,\ndrivers/net/amt.c-2154-\t\t\t\t\t false);\n--\ndrivers/net/amt.c=2228=static void amt_mldv1_report_handler(struct amt_dev *amt, struct sk_buff *skb,\n--\ndrivers/net/amt.c-2240-\tif (!gnode) {\ndrivers/net/amt.c:2241:\t\tgnode = amt_add_group(amt, tunnel, \u0026group, \u0026host, true);\ndrivers/net/amt.c-2242-\t\tif (!IS_ERR(gnode)) {\n--\ndrivers/net/amt.c=2284=static void amt_mldv2_report_handler(struct amt_dev *amt, struct sk_buff *skb,\n--\ndrivers/net/amt.c-2321-\t\tif (!gnode) {\ndrivers/net/amt.c:2322:\t\t\tgnode = amt_add_group(amt, tunnel, \u0026group, \u0026host,\ndrivers/net/amt.c-2323-\t\t\t\t\t ETH_P_IPV6);\n"
} |
| 33/3 | 2026/10/20 05:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24941 output: 35 thoughts: 11 Thoughts: Okay, here's my interpretation of "Let's read `amt_add_group`", assuming a field of expertise is implicit, and presented as a first-person summary: **Diving into `amt_add_group`** Alright, time to crack open `amt_add_group`. Given the context, this likely contains the logic for, well, adding a new group, whatever "amt" signifies within the application or system. I need to understand this code, and fast. I want to see how the addition of this group impacts other systems. I need to grasp the input parameters, the data validation procedures, any security checks involved and how the data is stored. Specifically, I'm looking for the following: * **Data Integrity:** How the `amt_add_group` function ensures that any data entered is valid and prevents corruption. * **Security Context:** How user permissions are checked to ensure appropriate authorization. * **Dependencies:** Any interactions with other modules or database tables and what the implications are. * **Error handling:** Is this function robust enough to handle unexpected input? Is there proper logging? * **Performance:** Can the function scale and handle many groups added? * **Modularity:** Is it well-organized? Is it designed in a way that allows easy changes and updates later on? This could be a critical piece of the puzzle, and a thorough understanding of this is essential to evaluate the functionality or troubleshoot any problems. Let's see what we've got. |
| 34/3 | 2026/10/20 05:59 | tool | read-file |
0mArgs:{
"File": "drivers/net/amt.c",
"FirstLine": 530,
"LineCount": 40
}Results: {
"Contents": " 530:\t */\n 531:\tstatic struct amt_group_node *amt_add_group(struct amt_dev *amt,\n 532:\t\t\t\t\t\t struct amt_tunnel_list *tunnel,\n 533:\t\t\t\t\t\t union amt_addr *group,\n 534:\t\t\t\t\t\t union amt_addr *host,\n 535:\t\t\t\t\t\t bool v6)\n 536:\t{\n 537:\t\tstruct amt_group_node *gnode;\n 538:\t\tu32 hash;\n 539:\t\tint i;\n 540:\t\n 541:\t\tif (tunnel-\u003enr_groups \u003e= amt-\u003emax_groups)\n 542:\t\t\treturn ERR_PTR(-ENOSPC);\n 543:\t\n 544:\t\tgnode = kzalloc(sizeof(*gnode) +\n 545:\t\t\t\t(sizeof(struct hlist_head) * amt-\u003ehash_buckets),\n 546:\t\t\t\tGFP_ATOMIC);\n 547:\t\tif (unlikely(!gnode))\n 548:\t\t\treturn ERR_PTR(-ENOMEM);\n 549:\t\n 550:\t\tgnode-\u003eamt = amt;\n 551:\t\tgnode-\u003egroup_addr = *group;\n 552:\t\tgnode-\u003ehost_addr = *host;\n 553:\t\tgnode-\u003ev6 = v6;\n 554:\t\tgnode-\u003etunnel_list = tunnel;\n 555:\t\tgnode-\u003efilter_mode = MCAST_INCLUDE;\n 556:\t\tINIT_HLIST_NODE(\u0026gnode-\u003enode);\n 557:\t\tINIT_HLIST_NODE(\u0026gnode-\u003egc_node);\n 558:\t\tINIT_DELAYED_WORK(\u0026gnode-\u003egroup_timer, amt_group_work);\n 559:\t\tfor (i = 0; i \u003c amt-\u003ehash_buckets; i++)\n 560:\t\t\tINIT_HLIST_HEAD(\u0026gnode-\u003esources[i]);\n 561:\t\n 562:\t\thash = amt_group_hash(tunnel, group);\n 563:\t\thlist_add_head_rcu(\u0026gnode-\u003enode, \u0026tunnel-\u003egroups[hash]);\n 564:\t\ttunnel-\u003enr_groups++;\n 565:\t\n 566:\t\tif (!gnode-\u003ev6)\n 567:\t\t\tnetdev_dbg(amt-\u003edev, \"Join group %pI4\\n\",\n 568:\t\t\t\t \u0026gnode-\u003egroup_addr.ip4);\n 569:\t#if IS_ENABLED(CONFIG_IPV6)\n"
} |
| 35/3 | 2026/10/20 05:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 25972 output: 33 thoughts: 576 Thoughts: **My Analysis of AMT Code** Okay, so I'm seeing `kzalloc` used again. Specifically, in `amt_tunnel_get_or_create`. It allocates memory for the `tunnel` structure and a set of hash lists. This is pretty standard stuff, using `GFP_ATOMIC` which makes sense for the context. The code initializes the tunnel, its locks, and worker queue. It seems the entry is fully initialized before it's published to the list, which is good practice to avoid race conditions. They also update relay status and schedule a delayed work queue for garbage collection. Now, I'm shifting my focus to the netlink interaction and how data is shared. I see a change in `amt_policy`. They're now using `NLA_POLICY_EXACT_LEN` for `IFLA_AMT_LOCAL_IP` and `IFLA_AMT_DISCOVERY_IP`. This is an important security measure – ensuring the length of the IP addresses passed via netlink is exactly 4 bytes (for IPv4). This change likely prevents any potential buffer overflows or other size-related vulnerabilities by enforcing strict input validation. My next step is to examine `amt_fill_info` to understand how this validated data is subsequently exposed or used to see if there's any risk of uninitialized memory being copied to user space. |
| 36/3 | 2026/10/20 05:59 | tool | grepper |
0mArgs:{
"Expression": "amt_fill_info",
"PathPrefixes": [
"drivers/net/amt.c"
]
}Results: {
"Output": "drivers/net/amt.c=3620=static size_t amt_get_size(const struct net_device *dev)\n--\ndrivers/net/amt.c-3631-\ndrivers/net/amt.c:3632:static int amt_fill_info(struct sk_buff *skb, const struct net_device *dev)\ndrivers/net/amt.c-3633-{\n--\ndrivers/net/amt.c=3666=static struct rtnl_link_ops amt_link_ops __read_mostly = {\n--\ndrivers/net/amt.c-3675-\t.get_size = amt_get_size,\ndrivers/net/amt.c:3676:\t.fill_info = amt_fill_info,\ndrivers/net/amt.c-3677-};\n"
} |
| 37/3 | 2026/10/20 05:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 27085 output: 36 thoughts: 11 Thoughts: Okay, here's my interpretation of "Let's read `amt_fill_info`", presented as a first-person account suitable for an expert: **Diving into `amt_fill_info`** Alright, time to get to it. The phrase "Let's read `amt_fill_info`" immediately triggers a certain expectation. I'm assuming that this is a pointer, a variable, or some structure that is describing how a process fills a certain quantity, presumably an amount. I will assess what the variable name and content indicates, and then I can proceed. Depending on the data structure, I'll need to know what kind of format it's likely to be encoded in, and how to read the information properly. I need to understand what this `amt_fill_info` is meant to accomplish, what context it lives in, and what problem it's designed to solve. The specific details, like the data types of its components, are less important right now than the overall function it's intended to describe. Let's see what's in there. |
| 38/3 | 2026/10/20 05:59 | tool | read-file |
0mArgs:{
"File": "drivers/net/amt.c",
"FirstLine": 3632,
"LineCount": 35
}Results: {
"Contents": "3632:\tstatic int amt_fill_info(struct sk_buff *skb, const struct net_device *dev)\n3633:\t{\n3634:\t\tconst struct amt_dev *amt = netdev_priv(dev);\n3635:\t\t__be32 remote_ip;\n3636:\t\n3637:\t\trcu_read_lock();\n3638:\t\tif (nla_put_u32(skb, IFLA_AMT_MODE, amt-\u003emode))\n3639:\t\t\tgoto nla_put_failure;\n3640:\t\tif (nla_put_be16(skb, IFLA_AMT_RELAY_PORT, amt-\u003erelay_port))\n3641:\t\t\tgoto nla_put_failure;\n3642:\t\tif (nla_put_be16(skb, IFLA_AMT_GATEWAY_PORT, amt-\u003egw_port))\n3643:\t\t\tgoto nla_put_failure;\n3644:\t\tif (nla_put_u32(skb, IFLA_AMT_LINK, amt-\u003estream_dev-\u003eifindex))\n3645:\t\t\tgoto nla_put_failure;\n3646:\t\tif (nla_put_in_addr(skb, IFLA_AMT_LOCAL_IP, amt-\u003elocal_ip))\n3647:\t\t\tgoto nla_put_failure;\n3648:\t\tif (nla_put_in_addr(skb, IFLA_AMT_DISCOVERY_IP, amt-\u003ediscovery_ip))\n3649:\t\t\tgoto nla_put_failure;\n3650:\t\n3651:\t\tremote_ip = READ_ONCE(amt-\u003eremote_ip);\n3652:\t\tif (remote_ip)\n3653:\t\t\tif (nla_put_in_addr(skb, IFLA_AMT_REMOTE_IP, remote_ip))\n3654:\t\t\t\tgoto nla_put_failure;\n3655:\t\tif (nla_put_u32(skb, IFLA_AMT_MAX_TUNNELS, amt-\u003emax_tunnels))\n3656:\t\t\tgoto nla_put_failure;\n3657:\t\n3658:\t\trcu_read_unlock();\n3659:\t\treturn 0;\n3660:\t\n3661:\tnla_put_failure:\n3662:\t\trcu_read_unlock();\n3663:\t\treturn -EMSGSIZE;\n3664:\t}\n3665:\t\n3666:\tstatic struct rtnl_link_ops amt_link_ops __read_mostly = {\n"
} |
| 39/3 | 2026/10/20 05:59 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 28053 output: 377 thoughts: 2414 Thoughts: **Patch Analysis and KMSAN Justification** Okay, let's break this down. First, the scalar `in_addr` values are untouched, so we can ignore that. My focus is on the core changes and their impact on memory safety and security. This patch is all about beefing up the AMT (Autonomous Management Technology) driver, specifically dealing with group and source teardown, and mitigating some serious vulnerabilities in the AMT Relay. It's touching `drivers/net/amt.c` and `include/net/amt.h`. The first thing I see is the replacement of `kfree_rcu` and incorrect delayed work flushing with a much more robust deferred garbage collection mechanism. This includes things like the `group_gc_list`, `group_gc_lock`, `group_gc_wq`, and careful draining of the `source_gc_wq` to prevent UAF (Use-After-Free) bugs related to dereferencing freed groups from a source timer callback. The use of `cancel_delayed_work_sync` is crucial for preventing races, and the introduction of `READ_ONCE` on `dead` flags on various structures (`snode`, `gnode`, `tunnel`) is essential to prevent concurrent teardown races (UAF, double frees, general race conditions). The `amt_dev_stop` function now properly marks tunnels as dead under a lock, then unlinks, synchronizes work, and drains the garbage collector. This is *much* safer. Secondly, and perhaps more importantly, the patch addresses some significant vulnerabilities in `amt_update_handler` and `amt_request_handler`. Previously, `amt_request_handler` created a tunnel on receiving unauthenticated Membership Requests. A malicious actor could exploit this by flooding requests, leading to resource exhaustion (DoS) or even hijacking tunnel state. Now, `amt_request_handler` is completely stateless. It calculates the MAC using `siphash` and sends a membership query with the MAC and nonce *without* allocating a tunnel entry. The tunnel entry is only allocated in `amt_update_handler` after the response MAC is verified. This is a *massive* security improvement. The use of four key generations (`amt->key[4]`) and key rotation in `amt_secret_work` is clever, keeping keys valid for a good period across rotations. The keys are properly initialized with random bytes in `amt_dev_open`. The other minor changes—statistics updates using `DEV_STATS_INC` and RTNL policy updates—are relatively trivial but still good to see. Now, let's get into the nitty-gritty of memory initialization and potential KMSAN concerns. I need to make sure that nothing new introduces uninitialized memory reads. I'm going through each relevant section methodically: * In `amt_secret_work`, the key rotation logic is secure. The keys are initialized during `amt_dev_open()` and all stack memory is correctly initialized. The code grabs the existing keys, shifts them down, and then grabs new, properly initialized random bytes for `amt->key[0]`. * In `amt_update_handler`, the `key[4]` array is populated from the initialized `amt->key` and then used. No issues here. * In `amt_request_handler`, the `key` is initialized from `amt->key[0]`, and all other variables used in the calculations (`full`, `have`, `mac`) are initialized before use. * The `amt_tunnel_get_or_create` function allocates with `kzalloc`, which is great! It zeros out the memory, and initializes all struct fields: `last_seen`, `source_port`, `ip4`, `amt`, etc. * `amt_tunnel_expire` properly initializes `deadline`, using `last_seen` which was initialized during tunnel creation or updates. No structures are sent to userspace, nothing is uninitialized, and the conditionals use initialized booleans/counters. The risks this patch is addressing are *entirely* related to concurrency, synchronization, object lifetimes, and preventing resource exhaustion. These are all things KASAN, LOCKDEP, and the normal debugging tools are well-suited to handle. KASAN will catch any UAF, double frees, or out-of-bounds accesses. LOCKDEP will catch any locking issues. I'm confident that KMSAN is *not* needed here. The patch doesn't introduce any uninitialized memory reads or information leaks to userspace. The rule is clear: *If KASAN or standard debuggers can catch it, don't use KMSAN.* KMSAN is for those tricky uninitialized memory risks that the standard tools miss. This patch is solid on |
| 40/3 | 2026/10/20 06:00 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series addresses concurrency, lifetime management, and denial-of-service vulnerabilities in the AMT (Automatic Multicast Tunneling) driver:\n1. It implements a dedicated group GC queue, work synchronization, and 'dead' flags to prevent race conditions and use-after-free (UAF) bugs during group, source, and tunnel destruction.\n2. It makes relay request handling stateless, avoiding premature tunnel allocation from spoofed requests, and rotates 4 generations of SipHash keys for validating Membership Updates.\n3. It updates netlink policy validation and statistics helpers.\n\nFrom a memory initialization perspective:\n- All heap objects (`amt_tunnel_list`, `amt_group_node`, `amt_source_node`) are allocated via `kzalloc` or `kzalloc_obj`, ensuring all fields (including the new `dead` and `gc_node` members) are fully zeroed.\n- The `key` array on the stack in `amt_update_handler` is explicitly populated for all indices from `amt-\u003ekey[i]` before being passed to `siphash_3u32`.\n- `amt-\u003ekey` is initialized in `amt_dev_open` using `get_random_bytes(\u0026amt-\u003ekey, sizeof(amt-\u003ekey))`, fully covering all 4 array elements.\n- No kernel memory or uninitialized struct padding is copied to userspace.\n\nThe risks associated with these changes are concurrency, locking, and object lifetime issues (such as use-after-free or race conditions), which are covered by KASAN and LOCKDEP. KMSAN is not needed as there are no uninitialized memory read risks or info-leaks.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series addresses concurrency, lifetime management, and denial-of-service vulnerabilities in the AMT (Automatic Multicast Tunneling) driver:\n1. It implements a dedicated group GC queue, work synchronization, and 'dead' flags to prevent race conditions and use-after-free (UAF) bugs during group, source, and tunnel destruction.\n2. It makes relay request handling stateless, avoiding premature tunnel allocation from spoofed requests, and rotates 4 generations of SipHash keys for validating Membership Updates.\n3. It updates netlink policy validation and statistics helpers.\n\nFrom a memory initialization perspective:\n- All heap objects (`amt_tunnel_list`, `amt_group_node`, `amt_source_node`) are allocated via `kzalloc` or `kzalloc_obj`, ensuring all fields (including the new `dead` and `gc_node` members) are fully zeroed.\n- The `key` array on the stack in `amt_update_handler` is explicitly populated for all indices from `amt-\u003ekey[i]` before being passed to `siphash_3u32`.\n- `amt-\u003ekey` is initialized in `amt_dev_open` using `get_random_bytes(\u0026amt-\u003ekey, sizeof(amt-\u003ekey))`, fully covering all 4 array elements.\n- No kernel memory or uninitialized struct padding is copied to userspace.\n\nThe risks associated with these changes are concurrency, locking, and object lifetime issues (such as use-after-free or race conditions), which are covered by KASAN and LOCKDEP. KMSAN is not needed as there are no uninitialized memory read risks or info-leaks.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|