Files
linux/include
Omar Ramadan 8ddd3a1c20 amt: create relay tunnels only from authenticated Updates
An AMT Request has an unauthenticated, spoofable source address. Allocating
tunnel state from that path allowed spoofed Requests to consume tunnel
slots or overwrite the nonce and MAC of an established gateway.

Keep Requests stateless by deriving the Query MAC from the source
address, source port, nonce, and current secret, and retain four secret
generations so a gateway can renew its MAC across rotations.
Authenticate the Membership Update before decapsulation, and create or
refresh tunnel state only once ip_mc_check_igmp() or ipv6_mc_check_mld()
has accepted the encapsulated message. Key verified state by the
address/port endpoint, enforce global and per-source limits, and
silently reject an endpoint that cannot be admitted: withhold the Query
rather than send ICMP Host Unreachable to a source address nothing has
authenticated yet.

A MAC is now accepted only for a bounded time after the Query that
carried it. Before, a tunnel copied the secret when a Request created it
and never saw it rotate, so its MAC never expired. Now the secret
rotates every 60 seconds and four generations are kept, so a MAC is
accepted for 180 to 240 seconds. RFC 7450 section 5.2.3.5.4 has a
gateway start a query timer when it accepts a Query, with a duration it
SHOULD compute from the Query's QQIC (125 seconds here), and section
5.2.3.5.5 has it send a new Request when that timer expires, so a
gateway that times its next Request from QQIC renews its MAC inside the
window. The in-tree gateway re-Requests every two seconds while its
Requests are answered. A gateway that never sends another Request kept
working before; now its Updates are dropped as Invalid MAC once the
window has passed. So is the first Update after a new join from a
gateway that, as section 5.2.3.5.4 also allows, uses a longer timer
while it has no group subscriptions to report: it is dropped until that
gateway's next Request.

Which MACs are accepted changes too. Before, an Update had to carry the
nonce and MAC of the latest Request from its address; now any pair
minted for its address and port within the window is accepted. The MAC
never covered the encapsulated report, so this changes only how long a
pair seen by an on-path observer stays usable: off-path senders still
cannot produce a valid pair.

The secret is now seeded before amt_socket_create() enables the receive
path. It was seeded after the socket was created since
commit b9022b53ad ("amt: add control plane of amt interface"), when
there was no receive path yet, and
commit cbc21dc1cf ("amt: add data plane of amt interface") added
amt_rcv() and the per-tunnel copy of the key without moving it. Since
then a Request that arrived during amt_dev_open() could get a tunnel
whose MAC used an all-zero key (on the first open) or the previous key
for the tunnel's whole life.

amt_update_tunnel() retries once when it finds its tunnel dead, and the
lookup skips dead tunnels, so an Update that races amt_tunnel_expire()
creates the replacement instead of being dropped. The Request path's
per-source count and the re-check under amt->lock in
amt_tunnel_get_or_create() skip them too. Every tunnel is now created by
an Update, which stamps last_seen, so amt_tunnel_expire() no longer
treats a last_seen of 0 as never refreshed. amt_tunnel_get_or_create()
also rechecks netif_running() under amt->lock before it links a tunnel.
dev_close() clears the running state before it calls amt_dev_stop(),
which drains the list under amt->lock, so an Update still being received
while the device goes down cannot link a tunnel after the drain.

Every Membership Update, forged ones included, reads the secret
generations to check its MAC. Their writers hold amt->lock and update
them inside a seqcount, amt->key_seq. The Update path copies them in a
key_seq read loop, so reading them takes amt->lock only on PREEMPT_RT,
to wait for a writer.

Keying by address and port lets one address hold several tunnels; before
this patch the Request path looked tunnels up by address alone, so an
address normally held only one. amt_max_tunnels_per_src() bounds that
at an eighth of max_tunnels, at least one tunnel and at most
AMT_MAX_TUNNELS_PER_SRC (16): 16 at the default 128 slots, 2 at 16. One
address then holds at most an eighth of a table of eight or more slots,
while gateways behind NAT still get several tunnels once the table has
16 or more slots. A configurable limit needs new uAPI, so it is left
for net-next.

Found by code inspection against RFC 7450; not triggered at runtime.
The Sashiko AI review of an earlier posting pointed out the undocumented
behaviour changes and that a fixed per-source cap let one address fill
a small table.

Fixes: cbc21dc1cf ("amt: add data plane of amt interface")
Signed-off-by: Omar Ramadan <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
2026-11-18 17:26:45 -08:00
..
…
…
…
…
…
2026-10-23 22:57:34 -04:00
…
…
…