* [PATCH net-next v4 0/3] amt: configurable per-tunnel limits, with bounded report work
@ 2026-11-24 21:04 Omar Ramadan
2026-11-24 21:04 ` [PATCH net-next v4 1/3] amt: make the A-B source walk linear Omar Ramadan
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Omar Ramadan @ 2026-11-24 21:04 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, Simon Horman
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 and is not charged, 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.
The work one Membership Update may cause, in bucket and source 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
this version 120,320 416,256 (1500-byte stream link)
The largest legitimate report at the ceilings, on that link, costs
about 348,000.
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]:
one Update, relay at the ceilings v3, ms v4, ms
attack, stream MTU 1500 (64 KiB of empty
records naming one 4,096-source group) 8.2 - 8.9 1.3 - 1.6
records applied before the budget stops 119 13
the same attack, stream MTU 65535 8.4 - 8.9 5.3 - 5.7
records applied 119 66
refresh of 512 groups x 8 sources in
1,400-byte reports, slowest report 0.14 - 0.15 0.11 - 0.13
the same refresh in one 64 KiB report 1.5 1.1 - 1.2
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
24630ff92eff, the net-next merge of net that brought it in.
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. pahole gives 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/179547826432.3135.16263442399696125291@kernel.org/
v4:
- 3/3: keep hash_buckets at AMT_HSIZE (256). Growing it to 512 put
every group and tunnel node in kmalloc-8k and doubled their memory [4].
- 3/3: cap the 2/3 budget at the cost of one MTU-sized report. At the
ceilings v3 allowed 3.85M visits per Update, 32 times the default [4].
- 2/3: AMT_REC_WALKS and AMT_REC_LOOKUPS are an upper bound, not the
exact maxima; say so (Sashiko).
v3: https://lore.kernel.org/netdev/20261122235724.2898320-1-omar@blockcast.net/
v2: https://lore.kernel.org/netdev/20261015231825.2852054-1-omar@blockcast.net/
v1: https://lore.kernel.org/netdev/20261014221334.2443184-1-omar@blockcast.net/
Assisted-by: LLM
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 | 127 ++++++++++++++++++++++++++++++++-------
include/net/amt.h | 19 ++++++
include/uapi/linux/amt.h | 8 +++
3 files changed, 131 insertions(+), 23 deletions(-)
base-commit: 24630ff92eff08500ec4772728d4b1fa08c28f47
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v4 1/3] amt: make the A-B source walk linear
2026-11-24 21:04 [PATCH net-next v4 0/3] amt: configurable per-tunnel limits, with bounded report work Omar Ramadan
@ 2026-11-24 21:04 ` Omar Ramadan
2026-11-24 21:05 ` [PATCH net-next v4 2/3] amt: bound the source-state work of one Membership Update Omar Ramadan
2026-11-24 21:05 ` [PATCH net-next v4 3/3] amt: make the per-tunnel group and source limits configurable Omar Ramadan
2 siblings, 0 replies; 6+ messages in thread
From: Omar Ramadan @ 2026-11-24 21:04 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, Simon Horman
amt_lookup_act_srcs() computes A-B, the sources of the group's state that
a received record does not name, by comparing every source in the group
with every source in the record. That runs under tunnel->lock in
softirq, and only the packet length bounds the record, so a single
Membership Update can already cost |A| * |B| address compares at the
current 128-source default.
Mark the group's sources that the record names with one hash lookup per
record source, then act on the unmarked ones in a single pass over the
group, clearing the marks as it goes. The cost becomes O(|A| + |B|) and
the result is unchanged: a marked source is skipped whatever its filter
state, exactly as the pairwise compare skipped it.
Found by review (Sashiko, on the limits patch); not triggered at runtime.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 43 ++++++++++++++++++++++---------------------
include/net/amt.h | 2 ++
2 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index b145ed3..79d68bc 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -1649,7 +1649,7 @@ static void amt_lookup_act_srcs(struct amt_tunnel_list *tunnel,
union amt_addr src = {0,};
struct hlist_node *t;
u16 nsrcs;
- int i, j;
+ int i;
if (!v6) {
igmp_grec = grec;
@@ -1705,28 +1705,29 @@ static void amt_lookup_act_srcs(struct amt_tunnel_list *tunnel,
}
break;
case AMT_OPS_SUB:
- /* A-B */
- for (i = 0; i < amt->hash_buckets; i++) {
- hlist_for_each_entry_safe(snode, t, &gnode->sources[i],
- node) {
- if (!amt_status_filter(snode, filter))
- continue;
- for (j = 0; j < nsrcs; j++) {
- if (!v6)
- src.ip4 = igmp_grec->grec_src[j];
+ /* A-B: mark every source of A that B names, then act on the
+ * unmarked ones in a single pass over the group, clearing the
+ * marks as we go. This is O(|A| + |B|) rather than |A| * |B|.
+ */
+ for (i = 0; i < nsrcs; i++) {
+ if (!v6)
+ src.ip4 = igmp_grec->grec_src[i];
#if IS_ENABLED(CONFIG_IPV6)
- else
- memcpy(&src.ip6,
- &mld_grec->grec_src[j],
- sizeof(struct in6_addr));
+ else
+ memcpy(&src.ip6, &mld_grec->grec_src[i],
+ sizeof(struct in6_addr));
#endif
- if (amt_addr_equal(&snode->source_addr,
- &src))
- goto out_sub;
- }
- amt_act_src(tunnel, gnode, snode, act);
- continue;
-out_sub:;
+ snode = amt_lookup_src(tunnel, gnode, AMT_FILTER_ALL,
+ &src);
+ if (snode)
+ snode->sub_mark = true;
+ }
+ for (i = 0; i < amt->hash_buckets; i++) {
+ hlist_for_each_entry(snode, &gnode->sources[i], node) {
+ if (snode->sub_mark)
+ snode->sub_mark = false;
+ else if (amt_status_filter(snode, filter))
+ amt_act_src(tunnel, gnode, snode, act);
}
}
break;
diff --git a/include/net/amt.h b/include/net/amt.h
index 9ba0971..f36efcd 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -287,6 +287,8 @@ struct amt_source_node {
struct delayed_work source_timer;
union amt_addr source_addr;
enum amt_source_status status;
+ /* Scratch mark for the A-B source walk, under tunnel_list->lock. */
+ bool sub_mark;
#define AMT_SOURCE_OLD 0
#define AMT_SOURCE_NEW 1
u8 flags;
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v4 2/3] amt: bound the source-state work of one Membership Update
2026-11-24 21:04 [PATCH net-next v4 0/3] amt: configurable per-tunnel limits, with bounded report work Omar Ramadan
2026-11-24 21:04 ` [PATCH net-next v4 1/3] amt: make the A-B source walk linear Omar Ramadan
@ 2026-11-24 21:05 ` Omar Ramadan
2026-11-28 21:28 ` netdev-bot+sashiko
2026-11-24 21:05 ` [PATCH net-next v4 3/3] amt: make the per-tunnel group and source limits configurable Omar Ramadan
2 siblings, 1 reply; 6+ messages in thread
From: Omar Ramadan @ 2026-11-24 21:05 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, Simon Horman
The relay applies every group record in a Membership Update under
tunnel->lock in softirq, and ip_mc_may_pull() is the only bound on how
many records it applies. Each record walks its group's hash buckets and
sources several times, so a report that names the same full group in
many short records costs far more than one that refreshes the whole
tunnel. At the current defaults a 1.5 KB Update of about 180 empty
records against one group already walks the group's 256 buckets some
nine hundred times.
Charge each record for the passes the mode handlers and
amt_cleanup_srcs() make over its group and for its per-source lookups,
and stop applying records once the total exceeds twice what refreshing
every group the tunnel may hold, with every source, would cost. A report
that refreshes the tunnel's whole state uses half the budget; one that
exceeds it is truncated, as a lost report would be, and the next
periodic report restores the state. A record for a group the tunnel has
no room for does no walk and is not charged, so records the relay
refuses cannot use up the budget and truncate the same records from
every report.
Found by review (Sashiko, on the limits patch); not triggered at runtime.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++
include/net/amt.h | 8 +++++++
2 files changed, 62 insertions(+)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 79d68bc..177bc0b 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -2157,6 +2157,30 @@ static void amt_igmpv2_leave_handler(struct amt_dev *amt, struct sk_buff *skb,
amt_del_group(amt, gnode);
}
+/* The source-state work one group record can cause: AMT_REC_WALKS passes
+ * over the group's buckets and sources, which add_srcs may grow by nsrcs,
+ * plus AMT_REC_LOOKUPS hash lookups per record source.
+ */
+static u64 amt_rec_cost(const struct amt_dev *amt, u32 nr_sources, u16 nsrcs)
+{
+ return (u64)AMT_REC_WALKS * (amt->hash_buckets + nr_sources + nsrcs) +
+ (u64)AMT_REC_LOOKUPS * nsrcs;
+}
+
+/* The most work one Membership Update may cause: twice what refreshing
+ * every group the tunnel may hold, with every source, costs. The packet
+ * length used to be the only bound, and a report that names one full
+ * group many times costs far more than one that refreshes the whole
+ * tunnel.
+ */
+static u64 amt_report_budget(const struct amt_dev *amt)
+{
+ return 2 * ((u64)AMT_REC_WALKS *
+ ((u64)amt->max_groups * amt->hash_buckets +
+ 2 * amt->max_sources) +
+ (u64)AMT_REC_LOOKUPS * amt->max_sources);
+}
+
static void amt_igmpv3_report_handler(struct amt_dev *amt, struct sk_buff *skb,
struct amt_tunnel_list *tunnel)
{
@@ -2167,6 +2191,7 @@ static void amt_igmpv3_report_handler(struct amt_dev *amt, struct sk_buff *skb,
union amt_addr group, host;
struct igmpv3_grec *grec;
__be32 saddr;
+ u64 budget = amt_report_budget(amt), work = 0;
u16 nsrcs;
u16 ngrec;
int i;
@@ -2194,6 +2219,20 @@ static void amt_igmpv3_report_handler(struct amt_dev *amt, struct sk_buff *skb,
memset(&host, 0, sizeof(union amt_addr));
host.ip4 = saddr;
gnode = amt_lookup_group(tunnel, &group, &host, false);
+ /* A record for a group the tunnel has no room for does no
+ * walk, so it is not charged. Charging it would let a host
+ * joined to more than max_groups groups lose the same tail
+ * records from every report.
+ */
+ if (!gnode && tunnel->nr_groups >= amt->max_groups)
+ continue;
+ work += amt_rec_cost(amt, gnode ? gnode->nr_sources : 0, nsrcs);
+ if (work > budget) {
+ netdev_dbg(amt->dev,
+ "Membership Update over work budget, %u of %u records ignored\n",
+ ngrec - i, ngrec);
+ break;
+ }
if (!gnode) {
gnode = amt_add_group(amt, tunnel, &group, &host,
false);
@@ -2335,6 +2374,7 @@ static void amt_mldv2_report_handler(struct amt_dev *amt, struct sk_buff *skb,
union amt_addr group, host;
struct mld2_grec *grec;
struct in6_addr saddr;
+ u64 budget = amt_report_budget(amt), work = 0;
u16 nsrcs;
u16 ngrec;
int i;
@@ -2362,6 +2402,20 @@ static void amt_mldv2_report_handler(struct amt_dev *amt, struct sk_buff *skb,
memset(&host, 0, sizeof(union amt_addr));
host.ip6 = saddr;
gnode = amt_lookup_group(tunnel, &group, &host, true);
+ /* A record for a group the tunnel has no room for does no
+ * walk, so it is not charged. Charging it would let a host
+ * joined to more than max_groups groups lose the same tail
+ * records from every report.
+ */
+ if (!gnode && tunnel->nr_groups >= amt->max_groups)
+ continue;
+ work += amt_rec_cost(amt, gnode ? gnode->nr_sources : 0, nsrcs);
+ if (work > budget) {
+ netdev_dbg(amt->dev,
+ "Membership Update over work budget, %u of %u records ignored\n",
+ ngrec - i, ngrec);
+ break;
+ }
if (!gnode) {
gnode = amt_add_group(amt, tunnel, &group, &host,
ETH_P_IPV6);
diff --git a/include/net/amt.h b/include/net/amt.h
index f36efcd..82aaa6b 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -392,6 +392,14 @@ struct amt_dev {
#define AMT_GC_KICK 2048
#define AMT_MAX_GROUP 32
#define AMT_MAX_SOURCE 128
+/* Per group record, an upper bound on the passes the mode handlers plus
+ * amt_cleanup_srcs() make over a group's buckets and sources, and on the
+ * hash lookups they make per record source. The handlers need at most 5
+ * and 7 (EXCLUDE TO_IN and EXCLUDE BLOCK); the bound is rounded up so a
+ * later pass does not silently exceed it. See amt_rec_cost().
+ */
+#define AMT_REC_WALKS 7
+#define AMT_REC_LOOKUPS 8
#define AMT_HSIZE_SHIFT 8
#define AMT_HSIZE (1 << AMT_HSIZE_SHIFT)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next v4 3/3] amt: make the per-tunnel group and source limits configurable
2026-11-24 21:04 [PATCH net-next v4 0/3] amt: configurable per-tunnel limits, with bounded report work Omar Ramadan
2026-11-24 21:04 ` [PATCH net-next v4 1/3] amt: make the A-B source walk linear Omar Ramadan
2026-11-24 21:05 ` [PATCH net-next v4 2/3] amt: bound the source-state work of one Membership Update Omar Ramadan
@ 2026-11-24 21:05 ` Omar Ramadan
2026-11-28 21:28 ` netdev-bot+sashiko
2 siblings, 1 reply; 6+ messages in thread
From: Omar Ramadan @ 2026-11-24 21:05 UTC (permalink / raw)
To: Taehee Yoo, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, Simon Horman
A relay caps the state one gateway tunnel can hold at AMT_MAX_GROUP (32)
group records and AMT_MAX_SOURCE (128) source records, counted across
all of the tunnel's groups. Both are compile-time constants. An SSM
receiver uses a source record for every (S,G) it joins, so a gateway that
needs more than 32 groups or 128 channels through one tunnel has the
excess joins dropped, and the relay operator cannot raise either limit.
Add IFLA_AMT_MAX_GROUPS and IFLA_AMT_MAX_SOURCES, read when the link is
created, like IFLA_AMT_MAX_TUNNELS. Zero or an absent attribute keeps the
current defaults. Gateways drive these allocations, so the policy caps
them at 512 groups and 4096 sources per tunnel, and strict_start_type
has it validate them, and any attribute added after them, strictly.
Report both limits in amt_fill_info().
The group and source hashes keep their AMT_HSIZE (256) buckets. Sizing
them from max_sources would push every group node and tunnel node into
kmalloc-8k once max_sources passed 2048, doubling per-group memory; at
4096 sources in one group a chain averages 16 entries, which only makes
a lookup longer.
Raising the limits also raises the previous patch's bound on the work of
one Membership Update, twice what refreshing every group the tunnel may
hold costs: about 2.0 million bucket and source visits at 512 groups and
4096 sources, 17 times the default 120,320. Cap it at what one
legitimate report can cost. A host splits its report to the MTU, so a
report names at most mtu / 8 groups, IGMPv3 records being the smallest.
On a 1500-byte stream link (relay MTU 1460) that caps one Update at
about 416,000 visits at the ceilings, 3.5 times the default, above the
roughly 348,000 that the largest legitimate report costs. The defaults
keep the previous bound. A report larger than the relay's own MTU, from
a gateway on a jumbo link to a relay on a standard one, has the records
past the bound ignored at high limits, as an over-budget report already
does.
Assisted-by: LLM
Signed-off-by: Omar Ramadan <omar@blockcast.net>
---
drivers/net/amt.c | 48 +++++++++++++++++++++++++++++++---------
include/net/amt.h | 9 ++++++++
include/uapi/linux/amt.h | 8 +++++++
3 files changed, 54 insertions(+), 11 deletions(-)
diff --git a/drivers/net/amt.c b/drivers/net/amt.c
index 177bc0b..fd907eb 100644
--- a/drivers/net/amt.c
+++ b/drivers/net/amt.c
@@ -2167,18 +2167,33 @@ static u64 amt_rec_cost(const struct amt_dev *amt, u32 nr_sources, u16 nsrcs)
(u64)AMT_REC_LOOKUPS * nsrcs;
}
-/* The most work one Membership Update may cause: twice what refreshing
- * every group the tunnel may hold, with every source, costs. The packet
- * length used to be the only bound, and a report that names one full
- * group many times costs far more than one that refreshes the whole
- * tunnel.
+/* The work of a report naming @recs groups, each walked in full, plus two
+ * passes over every source the tunnel may hold and a lookup per source.
+ */
+static u64 amt_report_cost(const struct amt_dev *amt, u64 recs)
+{
+ return (u64)AMT_REC_WALKS *
+ (recs * amt->hash_buckets + 2 * (u64)amt->max_sources) +
+ (u64)AMT_REC_LOOKUPS * amt->max_sources;
+}
+
+/* The most work one Membership Update may cause. The packet length used
+ * to be the only bound, and a report that names one full group many times
+ * costs far more than one that refreshes the whole tunnel.
+ *
+ * Twice what refreshing every group the tunnel may hold costs, but never
+ * more than a report as large as this device's MTU can legitimately cost:
+ * a host splits its report to the MTU (RFC 3376 s4.2.16, RFC 3810
+ * s5.2.15), so one report names at most mtu / 8 groups, IGMPv3 records
+ * being the smallest. The second bound is what limits the work at high
+ * IFLA_AMT_MAX_GROUPS; at the defaults the first is the smaller.
*/
static u64 amt_report_budget(const struct amt_dev *amt)
{
- return 2 * ((u64)AMT_REC_WALKS *
- ((u64)amt->max_groups * amt->hash_buckets +
- 2 * amt->max_sources) +
- (u64)AMT_REC_LOOKUPS * amt->max_sources);
+ u64 recs = READ_ONCE(amt->dev->mtu) / sizeof(struct igmpv3_grec);
+
+ return min(2 * amt_report_cost(amt, amt->max_groups),
+ amt_report_cost(amt, recs));
}
static void amt_igmpv3_report_handler(struct amt_dev *amt, struct sk_buff *skb,
@@ -3583,6 +3598,7 @@ static void amt_link_setup(struct net_device *dev)
}
static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = {
+ [IFLA_AMT_UNSPEC] = { .strict_start_type = IFLA_AMT_MAX_GROUPS },
[IFLA_AMT_MODE] = { .type = NLA_U32 },
[IFLA_AMT_RELAY_PORT] = { .type = NLA_U16 },
[IFLA_AMT_GATEWAY_PORT] = { .type = NLA_U16 },
@@ -3591,6 +3607,8 @@ static const struct nla_policy amt_policy[IFLA_AMT_MAX + 1] = {
[IFLA_AMT_REMOTE_IP] = { .len = sizeof_field(struct iphdr, daddr) },
[IFLA_AMT_DISCOVERY_IP] = NLA_POLICY_EXACT_LEN(sizeof(__be32)),
[IFLA_AMT_MAX_TUNNELS] = { .type = NLA_U32 },
+ [IFLA_AMT_MAX_GROUPS] = NLA_POLICY_MAX(NLA_U32, AMT_MAX_GROUP_LIMIT),
+ [IFLA_AMT_MAX_SOURCES] = NLA_POLICY_MAX(NLA_U32, AMT_MAX_SOURCE_LIMIT),
};
static int amt_validate(struct nlattr *tb[], struct nlattr *data[],
@@ -3657,8 +3675,10 @@ static int amt_newlink(struct net_device *dev,
spin_lock_init(&amt->lock);
seqcount_spinlock_init(&amt->key_seq, &amt->lock);
- amt->max_groups = AMT_MAX_GROUP;
- amt->max_sources = AMT_MAX_SOURCE;
+ amt->max_groups = nla_get_u32_default(data[IFLA_AMT_MAX_GROUPS], 0) ?:
+ AMT_MAX_GROUP;
+ amt->max_sources = nla_get_u32_default(data[IFLA_AMT_MAX_SOURCES], 0) ?:
+ AMT_MAX_SOURCE;
amt->hash_buckets = AMT_HSIZE;
amt->nr_tunnels = 0;
get_random_bytes(&amt->hash_seed, sizeof(amt->hash_seed));
@@ -3774,6 +3794,8 @@ static size_t amt_get_size(const struct net_device *dev)
nla_total_size(sizeof(__u16)) + /* IFLA_AMT_GATEWAY_PORT */
nla_total_size(sizeof(__u32)) + /* IFLA_AMT_LINK */
nla_total_size(sizeof(__u32)) + /* IFLA_MAX_TUNNELS */
+ nla_total_size(sizeof(__u32)) + /* IFLA_AMT_MAX_GROUPS */
+ nla_total_size(sizeof(__u32)) + /* IFLA_AMT_MAX_SOURCES */
nla_total_size(sizeof(__be32)) + /* IFLA_AMT_DISCOVERY_IP */
nla_total_size(sizeof(__be32)) + /* IFLA_AMT_REMOTE_IP */
nla_total_size(sizeof(__be32)); /* IFLA_AMT_LOCAL_IP */
@@ -3804,6 +3826,10 @@ static int amt_fill_info(struct sk_buff *skb, const struct net_device *dev)
goto nla_put_failure;
if (nla_put_u32(skb, IFLA_AMT_MAX_TUNNELS, amt->max_tunnels))
goto nla_put_failure;
+ if (nla_put_u32(skb, IFLA_AMT_MAX_GROUPS, amt->max_groups))
+ goto nla_put_failure;
+ if (nla_put_u32(skb, IFLA_AMT_MAX_SOURCES, amt->max_sources))
+ goto nla_put_failure;
rcu_read_unlock();
return 0;
diff --git a/include/net/amt.h b/include/net/amt.h
index 82aaa6b..fa3a61d 100644
--- a/include/net/amt.h
+++ b/include/net/amt.h
@@ -392,6 +392,15 @@ struct amt_dev {
#define AMT_GC_KICK 2048
#define AMT_MAX_GROUP 32
#define AMT_MAX_SOURCE 128
+/* Upper bounds for IFLA_AMT_MAX_GROUPS and IFLA_AMT_MAX_SOURCES. Gateways
+ * drive these allocations: at the bounds one tunnel holds about 2 MiB of
+ * group nodes (each a kmalloc-4k object with AMT_HSIZE bucket heads) and
+ * under 1 MiB of source nodes, and max_tunnels multiplies that. The work
+ * one Membership Update may cause is bounded separately, by
+ * amt_report_budget().
+ */
+#define AMT_MAX_GROUP_LIMIT 512
+#define AMT_MAX_SOURCE_LIMIT 4096
/* Per group record, an upper bound on the passes the mode handlers plus
* amt_cleanup_srcs() make over a group's buckets and sources, and on the
* hash lookups they make per record source. The handlers need at most 5
diff --git a/include/uapi/linux/amt.h b/include/uapi/linux/amt.h
index 2dccff4..a106d7a 100644
--- a/include/uapi/linux/amt.h
+++ b/include/uapi/linux/amt.h
@@ -54,6 +54,14 @@ enum {
IFLA_AMT_DISCOVERY_IP,
/* This attribute specify number of maximum tunnel. */
IFLA_AMT_MAX_TUNNELS,
+ /* Maximum number of group records one tunnel may hold.
+ * Zero or absent means the default of 32.
+ */
+ IFLA_AMT_MAX_GROUPS,
+ /* Maximum number of source records one tunnel may hold, counted
+ * across all of its groups. Zero or absent means the default of 128.
+ */
+ IFLA_AMT_MAX_SOURCES,
__IFLA_AMT_MAX,
};
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v4 2/3] amt: bound the source-state work of one Membership Update
2026-11-24 21:05 ` [PATCH net-next v4 2/3] amt: bound the source-state work of one Membership Update Omar Ramadan
@ 2026-11-28 21:28 ` netdev-bot+sashiko
0 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 21:28 UTC (permalink / raw)
To: omar
Cc: ap420073, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, horms
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] This patch closes a CPU-exhaustion problem that a remote host can
trigger in the AMT relay, but it carries no Fixes: tag and is not…
- [Low] The new comment above AMT_REC_WALKS/AMT_REC_LOOKUPS in
include/net/amt.h (lines ~395-400) says the constants bound "the…
- [Low] amt_rec_cost() (drivers/net/amt.c:2164-2168) assumes every pass
may walk hash_buckets + nr_sources + nsrcs nodes, i.e. that…
--
amt: bound the source-state work of one Membership Update
The patch charges each IGMPv3/MLDv2 group record in a Membership Update
for the walks and lookups it causes. It stops applying records once the
total exceeds twice the cost of refreshing the tunnel's whole state.
Records for groups the tunnel has no room for are skipped and not charged.
> Found by review (Sashiko, on the limits patch); not triggered at runtime.
[Severity: Low]
Should this carry Fixes: tags and be routed through net as a bug fix?
Before this patch, amt_igmpv3_report_handler() and
amt_mldv2_report_handler() applied every record under tunnel->lock in
softirq. The only bound was ip_mc_may_pull()/ipv6_mc_may_pull().
Any host that completes the Request/Query exchange gets a valid response
MAC. It can then send a reassembled Update of up to about 64 KB with
roughly 8000 empty records naming one group. Each record makes several
full passes over the group's 256 buckets: the amt_lookup_act_srcs() passes
plus the two in amt_cleanup_srcs().
The loops date back to:
Fixes: bc54e49c140b ("amt: add multicast(IGMP) report message handler")
Fixes: b75f7095d4d4 ("amt: add mld report message handler")
Without these tags, stable kernels keep the length-only bound. The
"not triggered at runtime" line also doesn't say that the issue can be
reached remotely. The earlier patch "amt: make the A-B source walk linear"
has the same gap.
> diff --git a/drivers/net/amt.c b/drivers/net/amt.c
> index 79d68bcc7ccfd..177bc0b7cb1fd 100644
> --- a/drivers/net/amt.c
> +++ b/drivers/net/amt.c
> @@ -2157,6 +2157,30 @@ static void amt_igmpv2_leave_handler(struct amt_dev *amt, struct sk_buff *skb,
> amt_del_group(amt, gnode);
> }
>
> +/* The source-state work one group record can cause: AMT_REC_WALKS passes
> + * over the group's buckets and sources, which add_srcs may grow by nsrcs,
> + * plus AMT_REC_LOOKUPS hash lookups per record source.
> + */
> +static u64 amt_rec_cost(const struct amt_dev *amt, u32 nr_sources, u16 nsrcs)
> +{
> + return (u64)AMT_REC_WALKS * (amt->hash_buckets + nr_sources + nsrcs) +
> + (u64)AMT_REC_LOOKUPS * nsrcs;
[Severity: Low]
Does the walk term over-charge sources the relay will refuse?
The term assumes amt_add_srcs() can grow the group by the full nsrcs.
However, amt_add_srcs() stops once the tunnel is full:
drivers/net/amt.c:amt_add_srcs() {
...
for (i = 0; i < nsrcs; i++) {
if (tunnel->nr_sources >= amt->max_sources)
return;
...
}
So a walk never visits more than hash_buckets + max_sources nodes.
Refused sources already pay their lookup cost through AMT_REC_LOOKUPS.
They are also charged AMT_REC_WALKS units each for walk growth that cannot
happen.
The charge and the break run before amt_add_group(), amt_add_srcs() and
the mode handlers. At the defaults, the budget is 120320 and a new-group
record costs 1792 + 15 * nsrcs. A first record with more than about 7900
IPv4 sources therefore trips work > budget at i == 0, and none of the
Update is applied.
Smaller spreads get cut early too. For example, 32 records of 160 sources
are charged about 134k, while the real worst-case work is about 99k.
Normal hosts split reports to the MTU, so this needs MTUs above roughly
16 KB, or a sender that only damages its own state.
The commit message says "records the relay refuses cannot use up the
budget". That rule is applied to groups but not to sources. Would capping
the nsrcs inside the walk term at the remaining room
(max_sources - tunnel->nr_sources) match the growth that can actually
happen?
> +}
[ ... ]
> diff --git a/include/net/amt.h b/include/net/amt.h
> index f36efcdd92d0b..82aaa6b3070fb 100644
> --- a/include/net/amt.h
> +++ b/include/net/amt.h
> @@ -392,6 +392,14 @@ struct amt_dev {
> #define AMT_GC_KICK 2048
> #define AMT_MAX_GROUP 32
> #define AMT_MAX_SOURCE 128
> +/* Per group record, an upper bound on the passes the mode handlers plus
> + * amt_cleanup_srcs() make over a group's buckets and sources, and on the
> + * hash lookups they make per record source. The handlers need at most 5
> + * and 7 (EXCLUDE TO_IN and EXCLUDE BLOCK); the bound is rounded up so a
> + * later pass does not silently exceed it. See amt_rec_cost().
> + */
[Severity: Low]
Does the count of 7 lookups per source match the functions this comment
names?
In amt_mcast_block_handler(), the EXCLUDE branch calls
amt_lookup_act_srcs() with AMT_OPS_SUB_REV, AMT_OPS_UNI, AMT_OPS_SUB_REV
and AMT_OPS_UNI. That is 6 lookups per source. amt_cleanup_srcs() makes no
per-source lookups.
The seventh comes from amt_add_srcs(), which runs before every mode
handler:
if (amt_lookup_src(tunnel, gnode, AMT_FILTER_ALL, &src))
continue;
amt_add_srcs() is not listed here. The amt_rec_cost() comment mentions it
only as growing the source count.
The constants are still valid upper bounds today. Someone re-deriving the
bound from the listed functions would find 6 lookups and assume 2 of
headroom under AMT_REC_LOOKUPS, when the real headroom is 1. Could the
comment list amt_add_srcs() as a contributor?
> +#define AMT_REC_WALKS 7
> +#define AMT_REC_LOOKUPS 8
> #define AMT_HSIZE_SHIFT 8
> #define AMT_HSIZE (1 << AMT_HSIZE_SHIFT)
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124210501.70394-1-omar%40blockcast.net
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v4 3/3] amt: make the per-tunnel group and source limits configurable
2026-11-24 21:05 ` [PATCH net-next v4 3/3] amt: make the per-tunnel group and source limits configurable Omar Ramadan
@ 2026-11-28 21:28 ` netdev-bot+sashiko
0 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sashiko @ 2026-11-28 21:28 UTC (permalink / raw)
To: omar
Cc: ap420073, andrew+netdev, davem, edumazet, kuba, pabeni, netdev,
linux-kernel, horms
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] amt_report_budget() (drivers/net/amt.c:2191-2197) now takes
the per-Update work budget as min(2 * amt_report_cost(amt,…
- [Medium] The patch raises max_sources up to AMT_MAX_SOURCE_LIMIT (4096,
include/net/amt.h:403) but keeps the per-group source hash at…
--
amt: make the per-tunnel group and source limits configurable
This adds IFLA_AMT_MAX_GROUPS and IFLA_AMT_MAX_SOURCES. They let the
per-tunnel group and source record limits be raised when the link is
created, up to 512 and 4096. It also changes amt_report_budget() to take
the smaller of the previous bound and the cost of a report sized to the
relay device's MTU.
> diff --git a/drivers/net/amt.c b/drivers/net/amt.c
> index 177bc0b7cb1fd..fd907eb124189 100644
> --- a/drivers/net/amt.c
> +++ b/drivers/net/amt.c
> @@ -2167,18 +2167,33 @@ static u64 amt_rec_cost(const struct amt_dev *amt, u32 nr_sources, u16 nsrcs)
> (u64)AMT_REC_LOOKUPS * nsrcs;
> }
>
> -/* The most work one Membership Update may cause: twice what refreshing
> - * every group the tunnel may hold, with every source, costs. The packet
> - * length used to be the only bound, and a report that names one full
> - * group many times costs far more than one that refreshes the whole
> - * tunnel.
> +/* The work of a report naming @recs groups, each walked in full, plus two
> + * passes over every source the tunnel may hold and a lookup per source.
> + */
> +static u64 amt_report_cost(const struct amt_dev *amt, u64 recs)
> +{
> + return (u64)AMT_REC_WALKS *
> + (recs * amt->hash_buckets + 2 * (u64)amt->max_sources) +
> + (u64)AMT_REC_LOOKUPS * amt->max_sources;
> +}
> +
> +/* The most work one Membership Update may cause. The packet length used
> + * to be the only bound, and a report that names one full group many times
> + * costs far more than one that refreshes the whole tunnel.
> + *
> + * Twice what refreshing every group the tunnel may hold costs, but never
> + * more than a report as large as this device's MTU can legitimately cost:
> + * a host splits its report to the MTU (RFC 3376 s4.2.16, RFC 3810
> + * s5.2.15), so one report names at most mtu / 8 groups, IGMPv3 records
> + * being the smallest. The second bound is what limits the work at high
> + * IFLA_AMT_MAX_GROUPS; at the defaults the first is the smaller.
> */
> static u64 amt_report_budget(const struct amt_dev *amt)
> {
> - return 2 * ((u64)AMT_REC_WALKS *
> - ((u64)amt->max_groups * amt->hash_buckets +
> - 2 * amt->max_sources) +
> - (u64)AMT_REC_LOOKUPS * amt->max_sources);
> + u64 recs = READ_ONCE(amt->dev->mtu) / sizeof(struct igmpv3_grec);
> +
> + return min(2 * amt_report_cost(amt, amt->max_groups),
> + amt_report_cost(amt, recs));
> }
[Severity: Medium]
Do the defaults still keep the previous bound here? recs comes from the
relay amt device's own MTU. In relay mode, amt_newlink() lets that MTU go
as low as:
dev->min_mtu = ETH_MIN_MTU + AMT_RELAY_HLEN;
which is 108. The MTU also follows the stream device through
amt_device_event() on NETDEV_CHANGEMTU.
At the defaults (hash_buckets 256, max_sources 128, AMT_REC_WALKS 7,
AMT_REC_LOOKUPS 8), amt_report_cost(amt, recs) is 1792 * recs + 2816. The
first term of min() is 120,320, so the MTU term is the smaller one
whenever dev->mtu <= 527.
That doesn't match the comment above ("at the defaults the first is the
smaller") or the commit message ("The defaults keep the previous bound").
Below a relay MTU of 256 the budget is also smaller than a legitimate full
refresh. At MTU 200, recs is 25 and the budget is 47,616. A refresh of 32
groups with no sources costs 32 * 1792 = 57,344.
A gateway sizes its reports to its own MTU, not the relay's. So
amt_igmpv3_report_handler() would reach this on every periodic refresh:
work += amt_rec_cost(amt, gnode ? gnode->nr_sources : 0, nsrcs);
if (work > budget) {
...
break;
}
It would drop the same tail records each time. Wouldn't those groups then
time out? That is the same-tail loss the "not charged" comment in that
handler is meant to prevent.
At the new ceilings the budget is 224 * mtu + 90,112. A relay MTU below
about 1174 would then cut off the largest legitimate reports from a
gateway with a 1460-byte MTU. The commit message only covers the case of a
jumbo-MTU gateway talking to a standard-MTU relay, not a relay whose own
AMT MTU was lowered.
[ ... ]
> diff --git a/include/net/amt.h b/include/net/amt.h
> index 82aaa6b3070fb..fa3a61dfe786b 100644
> --- a/include/net/amt.h
> +++ b/include/net/amt.h
> @@ -392,6 +392,15 @@ struct amt_dev {
> #define AMT_GC_KICK 2048
> #define AMT_MAX_GROUP 32
> #define AMT_MAX_SOURCE 128
> +/* Upper bounds for IFLA_AMT_MAX_GROUPS and IFLA_AMT_MAX_SOURCES. Gateways
> + * drive these allocations: at the bounds one tunnel holds about 2 MiB of
> + * group nodes (each a kmalloc-4k object with AMT_HSIZE bucket heads) and
> + * under 1 MiB of source nodes, and max_tunnels multiplies that. The work
> + * one Membership Update may cause is bounded separately, by
> + * amt_report_budget().
> + */
> +#define AMT_MAX_GROUP_LIMIT 512
> +#define AMT_MAX_SOURCE_LIMIT 4096
[Severity: Medium]
With max_sources up to 4096 and the per-group source hash still at
AMT_HSIZE (256) buckets, a full group's chains average about 16 entries.
amt_rec_cost() still charges each per-source lookup as one unit:
return (u64)AMT_REC_WALKS * (amt->hash_buckets + nr_sources + nsrcs) +
(u64)AMT_REC_LOOKUPS * nsrcs;
But amt_lookup_src() walks the whole bucket chain on a miss:
hlist_for_each_entry_rcu(snode, &gnode->sources[hash], node)
if (amt_status_filter(snode, filter) &&
amt_addr_equal(&snode->source_addr, src))
return snode;
Does amt_report_budget() then really cap one Update at "about 416,000
visits at the ceilings", as the commit message says?
For example, a gateway that has completed the Request/Query handshake
fills one EXCLUDE-mode group with 4096 sources. It then sends a reassembled
Membership Update with one BLOCK record listing about 16,000 sources that
are not in the group. amt_update_handler() puts no length limit on the
encapsulated report.
That record is charged 7 * (256 + 4096 + 16000) + 8 * 16000, about 270K.
That is under the budget of about 416K at a relay MTU of 1460.
The tunnel is full, so amt_add_srcs() returns early. In EXCLUDE mode,
amt_mcast_block_handler() still calls amt_lookup_act_srcs() for two
SUB_REV passes (two lookups per source on a miss) and two UNI passes (one
lookup per source). That is about 6 lookups per source, each walking
about 16 nodes.
That adds up to about 6 * 16000 * 16 = 1.5M chain-node visits, in softirq
under spin_lock_bh(&tunnel->lock). This is about 4x the stated cap and
about 13x the default 120,320. At the default limits the same record is
charged about 242K and rejected.
Should the lookup charge in amt_rec_cost() include the expected chain
length once max_sources is larger than hash_buckets?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124210501.70394-1-omar%40blockcast.net
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-28 21:28 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 21:04 [PATCH net-next v4 0/3] amt: configurable per-tunnel limits, with bounded report work Omar Ramadan
2026-11-24 21:04 ` [PATCH net-next v4 1/3] amt: make the A-B source walk linear Omar Ramadan
2026-11-24 21:05 ` [PATCH net-next v4 2/3] amt: bound the source-state work of one Membership Update Omar Ramadan
2026-11-28 21:28 ` netdev-bot+sashiko
2026-11-24 21:05 ` [PATCH net-next v4 3/3] amt: make the per-tunnel group and source limits configurable Omar Ramadan
2026-11-28 21:28 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®