From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796032266; b=ywyT5DljFS57Rh30CH5OW/5Xyl5sYyZIhS5EkWOHZtTjgxNDnZuiUdlSZOJuiGnDR9vi gEW3Kb5rj/oLaRA0iA6WDFgYHkvaMx/+YBinjxTSnWGEFOO15gRS/LvG18aP146bUL/rp Ds1nQlcNRSaV9y87iYItprljyN2wlachll+XADYilkXtSLTouWnEawuoItQE3n7F+HvuH A1JBGVQUrCPO0jRKNqB5EENj0KcGhfD1oP3ckDdcvRbn2XyVbUCn2NKktdQ61jKOYdGsR Z0AwV6nRYhSa5qHC+ozzrho3poeTfnNi/wvVrigCWq6sakTmANARKHZfwUMz0sC3iQQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796032266; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=TOxDWdA5O1cOnQxd3M9/+J3EyDkUDCIaRm1MwXWoP4U=; b=FOcOw2NM/x6K4xpgxjQSqeTGEvBTkRMC9K7afY/339+sZBUaJV/p334DPugJqIyFiu/F Epn8sRr0z5mT1gkB4L7fDTHON5C5PDqfzfbZipcgK6wXNii2QOapSque6jOVYAWXDIWJC k6iU1w9GpADu1YdIU2+GMDrWsXQRd0nBySfr/fuFVKaK05MleTbxOgtnm6ab/Wbd5tTyM Su3jGK4R4zE52RT03tno5JrN8gn4FnqfEohOL+Cly/i6zDJcR/XJJtyRxDjctmxxUYQC9 mHeV3cfxX/j6aIh8PGkpSOQgwOhU5maFbSa5ee5d90n/MfYHR7SRcf07n7wsdTd04pw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=blockcast.net; spf=pass smtp.mailfrom=blockcast.net; dkim=pass header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=gf5VXGMa; arc=none smtp.remote-ip=74.125.82.41 Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 898E960A260A for ; Mon, 30 Nov 2026 09:51:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 898E960A260A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=blockcast.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=blockcast.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=blockcast.net header.i=@blockcast.net header.a=rsa-sha256 header.s=google header.b=gf5VXGMa Received: by mail-dl1-f41.google.com with SMTP id a92af1059eb24-1b3b4944a0eso7352793c88.0 for ; Mon, 30 Nov 2026 01:51:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blockcast.net; s=google; t=1796032265; x=1796637065; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TOxDWdA5O1cOnQxd3M9/+J3EyDkUDCIaRm1MwXWoP4U=; b=gf5VXGMajd3/7+507JCeiaHiA79C5UipBHCT7NSIGT2+c3z8SjKvbITSOvc27RaMMi K/vfNFYGvxJ5cEMNAeG/2yNd2ugYicrrCIY/Uk/N0yCHI8KE2xMsKNZuedwtlE/em6jD jIHpnj98rf9aIoPsWxnjtHO8/tP0TjKx/rtSjTeZCxAjbtMx4+amx+NhoZLwn7Wg8Jlo NPP/FZXzospJAQBRJXM2XN/9cvR7wTopBk73KcheLmm+z/mBzgdAHlNCNLVUr1VTXf2n WD3VDTcjIz7QLxkdu2u3h//oPJTnZL2Wz+ZavqvGDBPeztDeHeHe9AFsV9CsW8DD+jii 1nwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796032265; x=1796637065; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=TOxDWdA5O1cOnQxd3M9/+J3EyDkUDCIaRm1MwXWoP4U=; b=DVsFBjhZvkaI8C4nlgjfSPMcdIK0MavW14VQs4LPMZxjKVnwvcgEiQLjap3I+S3Hw+ an/skO96dZfQ+4mWzbpPylkubpPzhEh/HQViAKys5Q4CXuaCSAF9Cmj7JVQS5dc+ri1m 6Y6bQaBklBP0YCuSPrs8ukJJ51c2SHoeUwMMnAIas9Bzyei9cGIWh4d6fUquGbny4+4j zIhRT6cVgm6fO1CtVsIpYZT2XujZTq9Dezf6GZf03xdifcsqaJIXXmE87t0iS9ZtXKoK 2/rfwOo8qF9TVLE0oSOvgpEdV+sePIlwAFCJU30+CMx9lO1fc4o96AEUrwac7LvOfq2V nOmQ== X-Forwarded-Encrypted: i=1; AL+hErFFmR4nX2XCE7NlNColLDoWqs4kJsTWG6PsPccl6o3U5yModsGkdThmTyO5MZvXxxtY0w/gdwzD2QkuGyY=@vger.kernel.org X-Gm-Message-State: APuU4Z/bX29wwtOZdScgyVfWgMJ89j4g458HrNN8s1u5X/nuQSZUeMfU qrW5UKbziiNYPT1cJWqqbvKBTSh2QYJkezk9n6ugZ5YbVoxGi6qnq7BhitBqonFD/mg= X-Gm-Gg: AZFdTZeX2iVdDcP6e5vhXceWg9QScqCxc6i01Xq0aE/aBFAWUFtbaVWM2Yvzt4YGgNn N2F3o3qmo9amCDDg22ZuLVtTiECS3D4M8IcjWJ20q/joxPk5FL9EJ/rAbduXeuu3wURBy1IRJw4 dSdVOl9jA/rcFL4aQC60fCJEPCGKwpbz65syChJloZLbtiCU/JgQqQ22V8UQk6tQvtSqYS57YEP rlm3Rh36kfNNlChPU4njpIRBrjPqTIg/YToL83AqoxzipBS7rLZJRieaLRj6XH7D0EWgYtFGKuQ 7QTIcrwjH4+0a5FINp3U42BfGLhyU/Udin2uNXr3Zo0e9N4atAFXS40tM5vo9mb4DZ3IMmwh9lw TZpWFwVxwCVKtTsLuWYNb2hYsqHL9bz3flzJUsDxrJkhedRkBBPGU3PDqB77V/qXqnleGtDE4jV A88HPlmucB9R5ccW0uJZOr1d8w3KXOjeXEAn8pekRapaIgZzpTnwb5ceDQQ6up5wAN1/CP+ARQF M7f1FYvN4ad0kPt35zmoWuzBKyzwNcpRy62RSM5EAAarpusgpuarl+NaPUS/ZAC8eWI70kocr4V tlRj90fF1ljxkpoSEg7uxKx/t9RmsqbHr/nmi4OKRUi/4jrO3InosfB15UP7lV2Pi5Ea+hZnb00 F++m5N5xiAgrU5ipHWbzF4INIMR1D X-Received: by 2002:a05:701b:20ce:20b0:1b5:709f:d57a with SMTP id a92af1059eb24-1b5709fd6e6mr23965131c88.31.1796032264540; Mon, 30 Nov 2026 01:51:04 -0800 (PST) Received: from devbox.ts.blockcast.net ([2602:f74d:1::32]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b562a82b3fsm93595422c88.5.2026.11.30.01.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 01:51:03 -0800 (PST) From: Omar Ramadan To: Taehee Yoo , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Horman , Willem de Bruijn Subject: [PATCH net-next v5 2/3] amt: bound the source-state work of one Membership Update Date: Mon, 30 Nov 2026 09:50:58 +0000 Message-ID: <20261130095059.1301582-3-omar@blockcast.net> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130095059.1301582-1-omar@blockcast.net> References: <20261130095059.1301582-1-omar@blockcast.net> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 of the group and is charged only for the lookup that found no group, at most max_groups chain entries. Records the relay refuses therefore cannot use up the budget and truncate the same records from every report, and a report of them cannot repeat that lookup thousands of times uncharged. Found by review (Sashiko, on the limits patch), not seen at runtime. A gateway that completes the Request and Query exchange can send such an Update, so the cost is reachable from the network. Assisted-by: LLM Signed-off-by: Omar Ramadan --- drivers/net/amt.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++ include/net/amt.h | 10 +++++++ 2 files changed, 80 insertions(+) diff --git a/drivers/net/amt.c b/drivers/net/amt.c index 79d68bcc7..125db76e0 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,8 +2191,10 @@ 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; + bool full; int i; saddr = ip_hdr(skb)->saddr; @@ -2194,6 +2220,27 @@ 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 of the group, so it is charged only for the lookup + * above, which visits at most max_groups entries of a + * chain. Charging it a walk would let a host joined to more + * than max_groups groups lose the same tail records from + * every report; charging it nothing would let one report of + * such records, all naming one group, repeat that lookup + * thousands of times. + */ + full = !gnode && tunnel->nr_groups >= amt->max_groups; + work += full ? amt->max_groups : + 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 (full) + continue; if (!gnode) { gnode = amt_add_group(amt, tunnel, &group, &host, false); @@ -2335,8 +2382,10 @@ 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; + bool full; int i; saddr = ipv6_hdr(skb)->saddr; @@ -2362,6 +2411,27 @@ 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 of the group, so it is charged only for the lookup + * above, which visits at most max_groups entries of a + * chain. Charging it a walk would let a host joined to more + * than max_groups groups lose the same tail records from + * every report; charging it nothing would let one report of + * such records, all naming one group, repeat that lookup + * thousands of times. + */ + full = !gnode && tunnel->nr_groups >= amt->max_groups; + work += full ? amt->max_groups : + 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 (full) + continue; 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 f36efcdd9..f4ccc871c 100644 --- a/include/net/amt.h +++ b/include/net/amt.h @@ -392,6 +392,16 @@ 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 + * passes and 6 lookups (EXCLUDE TO_IN and EXCLUDE BLOCK), and amt_add_srcs(), + * which runs before every handler, adds one more lookup; 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)