🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #5183

Re: [PATCH net-next v2] amt: make the per-tunnel group and source limits configurable

#5183
From: netdev-bot+sashiko
Date: Mon, 19 Oct 2026 23:20
168 lines
14211 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · 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] The new AMT_MAX_SOURCE_LIMIT ceiling (4096) multiplies the
  per-packet softirq CPU cost of an existing O(N×M) loop by up to 32x.

Pre-existing issues:
- [High] Teardown race between source-timer work and group/tunnel
  deletion causes double-destroy and use-after-free (this problem wasn't…

--

amt: make the per-tunnel group and source limits configurable

This patch adds IFLA_AMT_MAX_GROUPS and IFLA_AMT_MAX_SOURCES, so a relay
operator can raise the per-tunnel group and source record limits when the
link is created. The netlink policy caps them at 1024 groups and 4096
sources, and amt_fill_info() reports both values.

> diff --git a/drivers/net/amt.c b/drivers/net/amt.c
> index 81d26ef82cf5c..30cff8de4830f 100644
> --- a/drivers/net/amt.c
> +++ b/drivers/net/amt.c

[ ... ]

> @@ -3170,6 +3171,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]	= { .len = sizeof_field(struct iphdr, daddr) },
>  	[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),

[Severity: Medium]
The 4096 ceiling is justified by memory cost. The include/net/amt.h
comment says "Gateways drive these allocations, so keep one tunnel's worst
case to a few MiB". Could this ceiling also raise the per-packet softirq
cost of amt_lookup_act_srcs() by up to 32x?

amt_add_srcs() only checks the tunnel-wide count:

	for (i = 0; i < nsrcs; i++) {
		if (tunnel->nr_sources >= amt->max_sources)
			return;

So all max_sources records can sit in a single group. The AMT_OPS_SUB
branch of amt_lookup_act_srcs() then walks every source in that group and
compares each one against every source in the incoming record:

	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++) {

This loop runs from amt_update_handler()->amt_mcast_is_in_handler() and
from the EXCLUDE-mode handler. It runs in softirq with
spin_lock_bh(&tunnel->lock) held.

In amt_igmpv3_report_handler(), only ip_mc_may_pull() bounds nsrcs. A
reassembled datagram can therefore carry about 16K IPv4 sources in one
record. That is about 2M address compares per record at 128 sources, and
about 67M at 4096, all with BHs disabled.

Can a remote gateway that has completed the request/query exchange use
this to cause soft lockups or RCU stalls on a relay that raised
IFLA_AMT_MAX_SOURCES?

One step is not confirmed: whether a gateway can keep thousands of one
group's sources in D_FWD/OLD state, so that they pass
amt_status_filter().

>  };
>  
>  static int amt_validate(struct nlattr *tb[], struct nlattr *data[],
> @@ -3235,8 +3238,10 @@ static int amt_newlink(struct net_device *dev,
>  		amt->max_tunnels = AMT_MAX_TUNNELS;
>  
>  	spin_lock_init(&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;

[Severity: High]
This is a pre-existing issue and was not introduced by this patch. This
patch lets a tunnel hold more groups and sources, though. Is source timer
teardown in amt_destroy_source() safe against an amt_source_work() that is
already running?

amt_destroy_source() uses the non-synchronous cancel:

	cancel_delayed_work(&snode->source_timer);
	hlist_del_init_rcu(&snode->node);
	tunnel->nr_sources--;
	gnode->nr_sources--;
	spin_lock_bh(&source_gc_lock);
	hlist_add_head_rcu(&snode->node, &source_gc_list);
	spin_unlock_bh(&source_gc_lock);

amt_source_work() reads snode->gnode and gnode->tunnel_list before it
takes any lock or rcu_read_lock(). It also never checks whether snode has
already been unhashed:

	struct amt_group_node *gnode = snode->gnode;
	...
	tunnel = gnode->tunnel_list;
	spin_lock_bh(&tunnel->lock);
	rcu_read_lock();
	if (gnode->filter_mode == MCAST_INCLUDE) {
		amt_destroy_source(snode);

amt_wq is WQ_UNBOUND. Consider amt_source_work() spinning on tunnel->lock
on one CPU while another CPU handles an IGMPv2 leave from the gateway:

CPU B (softirq, tunnel->lock held)
amt_update_handler()
  amt_igmpv2_leave_handler()
    amt_del_group()
      amt_destroy_source(snode)    /* cancel returns false */
      kfree_rcu(gnode, rcu)

CPU A
amt_source_work()
  spin_lock_bh(&tunnel->lock)     /* acquired after CPU B */
  amt_destroy_source(snode)       /* second time */

The second amt_destroy_source() call then does three things:

- It calls hlist_del_init_rcu() on a node that is now on source_gc_list,
  without holding source_gc_lock.
- It decrements the u32 tunnel->nr_sources and gnode->nr_sources again.
  They wrap, and amt_add_srcs() then refuses every further source for
  that tunnel.
- It adds snode to source_gc_list again, so __amt_source_gc_work() can
  kfree_rcu() it twice.

With CONFIG_PREEMPT, the worker can also be preempted after it reads
gnode and tunnel but before spin_lock_bh(). The group, or the whole tunnel
through amt_tunnel_expire()->amt_clear_groups()->kfree_rcu(tunnel, rcu),
can be freed after a grace period. When the worker resumes, it takes
tunnel->lock and reads gnode->filter_mode from freed memory.

The MLDv1 done handler, amt_group_work() and amt_tunnel_expire() reach the
same deletion paths.

>  	amt->hash_buckets = AMT_HSIZE;
>  	amt->nr_tunnels = 0;
>  	get_random_bytes(&amt->hash_seed, sizeof(amt->hash_seed));

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261015231825.2852054-1-omar%40blockcast.net
Technical Details
Message-ID: <179245202637.3135.11251208496046654130@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348890-linux-kernel-netdev=dewy.ru
References: <20261015231825.2852054-1-omar@blockcast.net>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-348890-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v2] amt: make the per-tunnel group and source
 limits configurable
Date: Mon, 19 Oct 2026 23:20:26 +0000
Organization: Usenet Network
Message-ID: <179245202637.3135.11251208496046654130@kernel.org>
References: <20261015231825.2852054-1-omar@blockcast.net>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3737532"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/ARChsLzidr5eBqqLe+Sq6RU+tE= sha256:eledumLKokOCuv7sBr09s17nayLGR4ify9pdZn6hJMk=
	sha1:jsxMpnkF1vdOYGkvUk9caI+ykCs= sha256:wXJFSBzeNJF0m9P6tJVItGb/3rwyDR78/iTQl5vK6eQ=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id A4B1F110B6F; Tue, 20 Oct 2026 02:22:42 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.729
X-Spam-Status: No, score=-3.729 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.329, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 6Lz_9VQDXQ37;
	Tue, 20 Oct 2026 02:22:39 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-348890-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 29CC5110B3F; Tue, 20 Oct 2026 02:22:31 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 625FD608B5; Mon, 19 Oct 2026 23:20:46 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1792452045;
	b=m/MMZBM3Sg6rEGHZXXzp/MGnvBL+ChxCWZLN6vTHZEJ27sp4S35UVMmohtFajEUYfV2/
	 WNZGQTU/EbQ5FGTiY36NCJekyyDhJDP2ibtrajiAhXz1Nc+uOWnXnnVv5nPx+J0XxIT/7
	 SEkWnd8zER8zi6gPIWczmxHAeQES+oGFqS2sK0DC7elLtw3tv4nrbi9t3HARqElYNSoiR
	 Aoad8LWMlEq2BXcwG21+vf7cIaSFTgBFmG6GL7plXwnm2YZu561GsHkT7w3MesEgTy1Ev
	 TNI550suz8RNsXwtRVySbV0Wqm1qQ29kBE3n4vr6kpbEjT12QddjpN1T+ZH5FbtcKNQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792452045;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=dXkUXwQG+10POwpnoEARoMLh2opBDrQrGq9cD0ZkTdk=;
	b=yxeTqBKjHXGSDG4qqlZmYsmXxO7e1b9OlsYOTjsoI/o3dRo1l5Ijp1EXuZTZdNHUe1i9
	 GkT6VpcrZ/tQdga1+NlpM7Q1Jd4pRM1tvXs64+4rl7qJf7eCRkIb7ysW/jT4QbsSrtk1N
	 lR4l9ZLyLO06sqfbl4TxUnUYREprryy3C2wxGcU2MWFp/UM7jLO82lragVDFlL33+/HVr
	 dw/hd+fmdZOIfzY4JSOooOSm0l9/39hJCnndAZI3aSsco/Qo06cowinOd9SxaQ8dwPvpm
	 8kf2A+dArqpNfkYJ5kFaUChEv1q5NEJjPAzBCzRhSMG3on0lvuSxgOmGV4M7hfhAoKQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bnzQBHwC;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 66B62606A31C;
	Mon, 19 Oct 2026 23:20:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bnzQBHwC
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1792452028;
	b=eyfRixr2pGc78CwC8+LkwPPiPTSw8FrtRKNSwnYiTK/eooIv66qShq+7/Vm88/UCEn/d
	 gmmpN07RWsDjc+ZBKRdWJvICSUnXgjr+4XSuXpVQ0yZ//4jbi6Uqe20ExzfbQ9CnUaaKk
	 khby1PgBo769qx3CjSEZvT9C7JMbjX0F5Ouw9iMfmL73aGveY2yvtpXONjAZtv+o+EkZy
	 X35GpU6tsGqqGrVebKZw+O961hO5MOjdHrNyjRb5AVq1BX698oRml7HbHrjVaKvk/17qW
	 eyAeclH65z7rrCNWDmOp+2mHR2nE9FP21hJt9PiCzVIL7QPA3MFqNcHrVtNBW2SNM7w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792452028;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=dXkUXwQG+10POwpnoEARoMLh2opBDrQrGq9cD0ZkTdk=;
	b=KA5SkqUF4bdO16LGGlARUFdvWs6qPJ2XH/yZ7SYyDlR+WwbSi2/MpeVQVHKbW54bd8Sz
	 NOA0lvUEe1+LC1akY7Ksv6bUMh7RWR0c6jmOn0BzHlNfq6mMTDLWBFlHpSRTZY3IQIR52
	 IJh0IqUy6ALzCbayu9PMhf1mBIEN3ZkOhs+Q8ISyBQWGZOsCLHvVXyJuhdpUU6lpVoyqE
	 ht27V+a6ybTM/yFj+1dgMr1YPzkD1F/NY+v6PDcQeEqlM1aHSZzCR4Grh83MsL03eJ9fO
	 Hlq8rguZ3zgE9YC2287J9ZdOo9WX3DxxBPUO9qEaRnwk0kJsMxgZrDQcXlH9U/KbySg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bnzQBHwC;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id BD11D606A323;
	Mon, 19 Oct 2026 23:20:27 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAAFE1F000C8;
	Mon, 19 Oct 2026 23:20:26 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1792452027;
	bh=dXkUXwQG+10POwpnoEARoMLh2opBDrQrGq9cD0ZkTdk=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=bnzQBHwC06rY1eNXq0YdNC3lvvUBT8VavXzWoxG980plAwQX4UEZkVM355E0A2M7q
	 nJDNm/sgLyh7C+iEbuxQngIsBspFQS8R1vUmFT6/sAC/R/n/9TG0RbLkUUb2JVZroA
	 GO9FWtvlobjenmLJFuRV2vS21aqSnbY8C5M//VpqpqcyCEnzwyYuP33vl4ZoBr4s4K
	 PhvQM77wCLKyqOYPlhTAKAHuAcPMbJ0PReEK/XvLDjLNrxCdIv00gxqv/pczWHXXCR
	 4MnoumcC6d44smYPVO74FNrCuD/DwbFNTe72omQd/IOLHd+1IJYWWUixJVACNbnNpI
	 f2ZgFqVHqEtQw==
X-Cc: ap420073@gmail.com, andrew+netdev@lunn.ch, davem@davemloft.net,
 edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
 netdev@vger.kernel.org, linux-kernel@vger.kernel.org, horms@kernel.org
X-In-Reply-To: <20261015231825.2852054-1-omar@blockcast.net>
X-sashiko-severity: Medium
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list