Merge branch 'amt-relay-tunnel-lifetime-validation-and-request-path-hardening'

Omar Ramadan says:

====================
amt: relay tunnel lifetime, validation and request-path hardening

This series hardens AMT relay tunnel lifetime, validates gateway input, and
keeps unauthenticated Requests from consuming relay state. The problems
fixed by patches 3 and 4, and the pre-Query drop in patch 5, were found
during the AMT IPv6 outer transport work, which is not included here.

I am using the existing IPv4 AMT relay and gateway implementation in a
multicast delivery network, where gateways on access networks send IGMP/MLD
membership state through a relay to reach downstream receivers.

The first patch detaches the receive path before amt_dev_stop() tears down
events and tunnels, so no receive-path reader can queue work after the
teardown. The second closes the gc_wq re-arm use-after-free, the double
free of a tunnel when amt_dev_stop() races amt_tunnel_expire(), and the
group/source timer-work lifetime bugs, makes teardown safe for RCU
readers, and bounds the nodes parked for garbage collection. The third
rejects Queries and Data from 0.0.0.0 before relay discovery and
revalidates deferred Queries. The fourth requires exactly four bytes for
IFLA_AMT_LOCAL_IP and IFLA_AMT_DISCOVERY_IP. The fifth makes pre-Query
drops visible, avoids counting successful reports as drops, and uses
concurrent-safe TX statistics. The sixth keeps Requests stateless,
authenticates Membership Updates and checks their IGMP/MLD message before
allocation, keys state by address and port, bounds per-source admission
at a share of max_tunnels, and silently drops failed endpoint admission.

Each commit message says how its problems were found. The problem in
patch 4 was triggered while writing an IPv6 selftest; the others were
found by review or code inspection.
====================

Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
This commit is contained in:
Jakub Kicinski
2026-11-18 17:31:47 -08:00
2 changed files with 548 additions and 155 deletions
+522 -149
View File
File diff suppressed because it is too large Load Diff
+26 -6
View File
@@ -240,12 +240,19 @@ struct amt_tunnel_list {
u32 nr_sources;
enum amt_status status;
struct delayed_work gc_wq;
/* Last time a Membership Update refreshed this tunnel, under ->lock.
* gc_wq re-arms itself from this rather than being re-armed by the
* Update path, so the Update path cannot re-queue the work of a
* tunnel that amt_tunnel_expire() is freeing.
*/
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,12 @@ 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];
/* For lockless readers of key; writers hold lock */
seqcount_spinlock_t key_seq;
struct sock __rcu *sk;
u32 max_groups;
u32 max_sources;
@@ -370,6 +387,7 @@ struct amt_dev {
#define AMT_IPHDR_OPTS 4
#define AMT_IP6HDR_OPTS 8
#define AMT_GC_INTERVAL (30 * 1000)
#define AMT_GC_KICK 2048
#define AMT_MAX_GROUP 32
#define AMT_MAX_SOURCE 128
#define AMT_HSIZE_SHIFT 8
@@ -383,6 +401,8 @@ struct amt_dev {
#define AMT_SECRET_TIMEOUT 60000
#define IANA_AMT_UDP_PORT 2268
#define AMT_MAX_TUNNELS 128
/* Upper bound of amt_max_tunnels_per_src(), the per-address tunnel cap */
#define AMT_MAX_TUNNELS_PER_SRC 16
#define AMT_MAX_REQS 128
#define AMT_GW_HLEN (sizeof(struct iphdr) + \
sizeof(struct udphdr) + \