Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v5 0/3] amt: configurable per-tunnel limits, with bounded report work
@ 2026-11-30  9:50 Omar Ramadan
  2026-11-30  9:50 ` [PATCH net-next v5 1/3] amt: make the A-B source walk linear Omar Ramadan
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Omar Ramadan @ 2026-11-30  9:50 UTC (permalink / raw)
  To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Simon Horman, Willem de Bruijn

A relay caps one gateway tunnel at 32 group and 128 source records, both
compile-time constants. v2 made them configurable [1]. Sashiko and Paolo
pointed out that at the new ceilings a single Membership Update can
livelock the host: records are applied under tunnel->lock in softirq,
and only the packet length bounds them [2].

This series keeps the processing in the RX path and bounds it instead:

1/3 makes the A-B case of amt_lookup_act_srcs() linear. It used to
    compare every source in the group with every source in the record.
2/3 charges every group record for the passes it makes over its group
    and stops applying records once a report exceeds twice the cost of
    refreshing the tunnel's whole state. A record for a group the
    tunnel has no room for does no walk of the group and is charged only
    for the group lookup, so a host joined to more groups than
    max_groups keeps its refreshes.
3/3 is v2 with the group ceiling lowered from 1024 to 512. The hashes
    keep their 256 buckets, so one tunnel at the ceilings holds about
    2.75 MiB [estimated, from pahole sizes]. Since twice a full refresh
    grows with the limits, it also caps the budget of 2/3 at what one
    report as large as the device's MTU can cost: a host splits its
    report to the MTU, so a report names at most mtu / 8 groups and
    mtu / 4 sources.

Changes in v5 (netdev's Sashiko review of v4 [4]):
 - 3/3 (Medium): the MTU bound no longer drops below a legitimate
   refresh when the relay's own MTU is low. It assumes at least an
   Ethernet link and covers at least min(max_groups, 187) groups. At the
   defaults the bound stays 120,320 unless the relay's MTU is below
   528, and is then no lower than the 60,160 that refreshing 32 groups
   costs; v4's message said the defaults always kept it.
 - 3/3 (Medium): a lookup that misses walks the whole chain of its
   bucket, which holds max_sources / hash_buckets entries on average,
   and was charged as one visit. It is now charged for that many, one
   at the defaults and 16 at 4096 sources, and the lookups the MTU bound
   may charge are capped at the sources a report of that size can name.
   The bound at the ceilings on a 1500-byte link is 440,448, up from
   v4's 416,256, which left the chain length out.
 - 2/3: a record for a group the tunnel has no room for is charged for
   its group lookup, at most max_groups chain entries; v4 charged it
   nothing, so one report of such records naming one group could repeat
   that lookup thousands of times uncharged. The message says the
   Update is reachable from the network, and the AMT_REC_LOOKUPS
   comment lists amt_add_srcs() as the seventh lookup.
 - The largest legitimate report at the ceilings on that link costs
   about 357,000, not the 348,000 of v4's cover letter.
 - I did not add Fixes: tags: 2/3 and 3/3 are net-next material here,
   and 1/3 only changes the A-B walk's complexity.

The work one Membership Update may cause, in bucket, source and
chain-entry visits [estimated, from the code], at 32 groups / 128
sources and at the ceilings of 512 groups / 4096 sources:

                          defaults    ceilings
  v3                       120,320   3,850,240
  v4                       120,320     416,256 (1500-byte stream link)
  this version             120,320     440,448 (1500-byte stream link)

Measured cost of one Membership Update under tunnel->lock, in a UML
guest (KASAN off, so slower than native; compare the columns only), with
the relay at the ceilings. v3 and this version were built from the same
base and booted alternately on one machine, five rounds each
[measured]. The measurement harness now fills the attack's group the way
a host does, in records that each fit the link's MTU; v4's harness sent
one 16 KB record at MTU 1500, which this version refuses:

  one Update, relay at the ceilings           v3, ms        v5, ms
  attack, stream MTU 1500 (64 KiB of empty
  records naming one 4,096-source group)      14.4 - 17.6   2.4 - 3.2
    records applied before the budget stops   119           14
  the same attack, stream MTU 65535           14.4 - 17.7   15.5 - 18.7
    records applied                           119           98
  refresh of 512 groups x 8 sources in
  1,400-byte reports, slowest report          0.19 - 0.28   0.14 - 0.23
  the same refresh in one 64 KiB report       1.9 - 3.9     1.4

The runner was slower than the one v4 was measured on, so compare the
columns, not v4's figures. At a relay MTU of 65535 this version does not
bound the attack below v3's: the first bound, twice a refresh, now
counts lookups by chain length, so it is about 1.5 times v4's 2.0
million there.

Without 2/3 (v2), the attack report held tunnel->lock for about two
seconds (measured for v3's cover letter, on another machine).

Deferring report processing to a per-tunnel work item would also take
the work out of softirq. I have not done that here: with the work
bounded, the deferral would add a queue and its own limits without
changing the worst case much. Happy to do it if you prefer.

This depends on the net series "amt: relay tunnel lifetime, validation
and request-path hardening" [3], which is in net-next; this is based on
ccb81d5e317b, which carries it.

Testing: tools/testing/selftests/net/amt.sh, unmodified, on net-next
24630ff92eff with this series applied, x86_64 under virtme-ng/KVM (4
vCPUs, 4 GiB) with generic KASAN (inline), PROVE_LOCKING, PROVE_RCU and
AMT=y: all six tests pass, amt.sh exits 0, and no KASAN, lockdep or
WARNING report appeared during the run. amt.sh does not reach the new
limits, so this covers the normal paths only; the budget is covered by
the measurements above. Each patch builds with W=1 C=1, with IPv6=y and
IPv6=n, with no warnings in amt. The struct layouts are unchanged from
v4: pahole gave 200 bytes for amt_group_node and 168 for
amt_tunnel_list, so with 256 bucket heads both stay within 4 KiB.

[1] https://lore.kernel.org/netdev/20261015231825.2852054-1-omar@blockcast.net/
[2] https://lore.kernel.org/netdev/361bbccf-6ce7-4b1f-bd55-4d8270423320@redhat.com/
[3] https://lore.kernel.org/netdev/20261110210538.217936-1-omar@blockcast.net/
[4] https://lore.kernel.org/netdev/20261124210501.70394-1-omar@blockcast.net/

Omar Ramadan (3):
  amt: make the A-B source walk linear
  amt: bound the source-state work of one Membership Update
  amt: make the per-tunnel group and source limits configurable

 drivers/net/amt.c        | 161 +++++++++++++++++++++++++++++++++------
 include/net/amt.h        |  21 +++++
 include/uapi/linux/amt.h |   8 ++
 3 files changed, 167 insertions(+), 23 deletions(-)


base-commit: ccb81d5e317b0ae2cc66ca1c628c0ca907928f94

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-30  9:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  9:50 [PATCH net-next v5 0/3] amt: configurable per-tunnel limits, with bounded report work Omar Ramadan
2026-11-30  9:50 ` [PATCH net-next v5 1/3] amt: make the A-B source walk linear Omar Ramadan
2026-11-30  9:50 ` [PATCH net-next v5 2/3] amt: bound the source-state work of one Membership Update Omar Ramadan
2026-11-30  9:50 ` [PATCH net-next v5 3/3] amt: make the per-tunnel group and source limits configurable Omar Ramadan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox