๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #16544

Re: [PATCH net v7 2/6] amt: fix use-after-free when a Membership Update re-arms a freed tunnel

#16544
From: netdev-bot+sashiko
Date: Sun, 15 Nov 2026 06:07
130 lines
12601 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท 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] This patch adds a parking stage for group nodes before they
  are freed, and nothing enforces a limit on how many can be parked.

--

amt: fix use-after-free when a Membership Update re-arms a freed tunnel

This patch reworks tunnel, group and source lifetime handling in the AMT
relay to close several use-after-free and double free races. Tunnel expiry
now re-arms itself from a last_seen timestamp, and nodes are marked dead
under tunnel->lock. Deleted groups and sources are parked on global GC
lists, and once AMT_GC_KICK (2048) nodes are parked a drain is queued
immediately.

> diff --git a/drivers/net/amt.c b/drivers/net/amt.c
> index 3a703b79f2c9a..fc3900e255ca2 100644
> --- a/drivers/net/amt.c
> +++ b/drivers/net/amt.c

[ ... ]

> @@ -106,6 +120,62 @@ static void amt_source_gc_work(struct work_struct *work)
>  	spin_unlock_bh(&source_gc_lock);
>  }
>  
> +static void __amt_group_gc_work(void)
> +{

[ ... ]

> +	hlist_for_each_entry_safe(gnode, t, &gc_list, gc_node) {
> +		cancel_delayed_work_sync(&gnode->group_timer);
> +		hlist_del_init(&gnode->gc_node);
> +		kfree_rcu(gnode, rcu);
> +		cond_resched();
> +	}
> +}

[ ... ]

> +static void amt_gc_parked(void)
> +{
> +	if (++amt_gc_queued == AMT_GC_KICK)
> +		mod_delayed_work(amt_wq, &group_gc_wq, 0);
> +}

[ ... ]

> @@ -266,10 +347,11 @@ static void amt_del_group(struct amt_dev *amt, struct amt_group_node *gnode)
>  		hlist_for_each_entry_safe(snode, t, &gnode->sources[i], node)
>  			amt_destroy_source(snode);
>  
> -	/* tunnel->lock was acquired outside of amt_del_group()
> -	 * But rcu_read_lock() was acquired too so It's safe.
> -	 */
> -	kfree_rcu(gnode, rcu);
> +	WRITE_ONCE(gnode->tunnel_list, NULL);
> +	spin_lock_bh(&source_gc_lock);
> +	hlist_add_head(&gnode->gc_node, &group_gc_list);
> +	amt_gc_parked();
> +	spin_unlock_bh(&source_gc_lock);
>  }

[Severity: Medium]
Is there anything that actually limits how many groups end up on
group_gc_list?

Before this patch, amt_del_group() passed the group straight to
kfree_rcu(). Now it decrements tunnel->nr_groups and parks the group on
the module-global group_gc_list. Each parked group is sizeof(*gnode) plus
256 hlist_heads, so a kmalloc-4k object.

amt_add_group() only checks the per-tunnel count:

	if (tunnel->nr_groups >= amt->max_groups)
		return ERR_PTR(-ENOSPC);

nr_groups is decremented before the group is parked. That means an
authenticated gateway sending IGMPv2 Report/Leave pairs, or the MLDv1
equivalents, parks one group per pair and never reaches max_groups:

  amt_igmpv2_report_handler()->amt_add_group()
  amt_igmpv2_leave_handler()->amt_del_group()

amt_gc_parked() never refuses or throttles parking. It queues the drain
once, at the moment the counter equals AMT_GC_KICK. A single work item does
the draining, amt_group_gc_work()->__amt_group_gc_work(), with one
cancel_delayed_work_sync(), kfree_rcu() and cond_resched() per node. With
several tunnels (different source ports or addresses), groups can be
parked from softirq on many CPUs at once.

Can the backlog keep growing if parking outpaces that one worker? Two
examples would be RSS spreading Leave or Done floods across CPUs, or
softirq load starving the unbound kworker. The per-CPU kfree_rcu() batching
used before had a shrinker. This list has no shrinker and no high-water
mark.

The commit message says:

  the kick keeps the backlog near that instead of letting it grow for
  up to 30 seconds

Is that enforced anywhere, or does it rely on the drain keeping up?

The lists and counters are also shared by every AMT device in every
network namespace. Churn on one device grows the backlog for all of them,
and it also lengthens the __amt_group_gc_work() drains that amt_dev_stop()
runs under RTNL for other devices.

Would a hard cap on amt_gc_queued, checked in amt_add_group() where groups
are admitted, fit better here?

Later patches in the series don't seem to change this either.
amt_gc_parked(), amt_del_group() and amt_add_group() are still the same in
"amt: create relay tunnels only from authenticated Updates".

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261110210538.217936-1-omar%40blockcast.net
Technical Details
Message-ID: <179472285784.2199510.18288706993986643464@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363571-linux-kernel-netdev=dewy.ru
References: <20261110210538.217936-3-omar@blockcast.net>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363571-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v7 2/6] amt: fix use-after-free when a Membership
 Update re-arms a freed tunnel
Date: Sun, 15 Nov 2026 06:07:37 +0000
Organization: Usenet Network
Message-ID: <179472285784.2199510.18288706993986643464@kernel.org>
References: <20261110210538.217936-3-omar@blockcast.net>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1738980"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:ryOmevGdV70UOH9Q8B1ksnVRLMs= sha256:2gR6ZQUZfydCDVgy5MMhgHPHKRdx0radkj/F28uKvAc=
	sha1:KDfBmo0/eOdF7D7tdwoG7RJxn2s= sha256:gfcsf8GR2W58D7btw6yxXjGpF4HfCpVlhwliXz8Iozg=
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 E7F89125D3A; Sun, 15 Nov 2026 09:08:11 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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 LO7ZpRlAAY8d;
	Sun, 15 Nov 2026 09:08:03 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-363571-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 96F8D125D3D; Sun, 15 Nov 2026 09:07:55 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id AAD1237636; Sun, 15 Nov 2026 06:07:49 +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=1794722865;
	b=ZO003eUsEr2zmzAmggiFFvcLed/CQF/TzSjfiLYCIqmM2AscLIMoRA/+dtFe73lfZg1q
	 DdQtgI/FO1DZvkQIPenk9S52+siSv5OmaAkS+F5NiOppzoUpahaLgviXGAyWNXb8SOEOg
	 1eT1dvedBj+GmEivrLVYU+U2RdJanbOuYAtdCNzQhUFCu6ksZcWwig68BJGCJHFlkVfx0
	 y/cVA3Y0B1A5/qypi3peiten/vCfgy7Rq3d+38jP4D1vUBxi6tVVyx6a37hNi55fY8Yf4
	 D0wrqHnBkTWHQwYq/3Lz8LQbzhjljb4JLQWsuK+EYrX60qnV3IpB9kVZV4mqbtA47YQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794722865;
	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=ZdGWU1xDsfsW7sNtgyXBAi046XdVD06gOAW+d954Fvw=;
	b=xbcbgImOweiFz54QYXajSnDQmN8UTnvkRbhq12rn8lzXfYVkbwiRlAVZk5Zh8iLW7xuZ
	 nAoe58rNyxwMeRjgnrOjQ1ryVByRP3enyY5V2rL7CyCZ3gUln9vAukbxqT5aTbNNZNMqy
	 Mbox35k39RNu95OwQqbG3CUh+GtNRcikKQBK2HYenUmFHkJmrBpbPK23pWoXPNsmjt0AI
	 FRFKFuPGnzAeFq+cerafVLPEl9zHxTujxRCcXL8k05qR3LtxVVY4M/LiT48EWaxUdpTSB
	 8qMjGrTXl+funp3feZ8dGkuE23Ny7tG5iWaBhXIH4fWJIA7Q4I7cuwbMxq3FXl7/oBA==
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="fCicJp5/";
	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 6AAD2606A331;
	Sun, 15 Nov 2026 06:07:45 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fCicJp5/
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=1794722859;
	b=i+BvhvgqjGlclKe4B4ebHIMTanvepI9Z3KyNApFBfftygSFTqtc5i2SITXZVs6n0TWba
	 fgBTOlNTrJ91bkMR/xVvgYRc4BIL/5OQwsFPobO1r9OY1gfZBxFtx2PSejSu71ZJ52hkh
	 Q71l9nvY+wNqgjWUaoA7bOIcHDAO9j6cYXj2ix8jjwrYnNClXFTrcQDY1w7F7qPvR1ku2
	 BGGaTHED2o8EnXk6Zg1chVRZQ7xZ/xaUgjt9sSDA2avulqJGXoX4cwZCdksKflTHwqd6Q
	 9QqN1eEMy7FnCzTr8NDsZ9hkeofbsi+BQyng3aPNJUjXrhBcTl1LnEUTB0bbqmksZqw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794722859;
	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=ZdGWU1xDsfsW7sNtgyXBAi046XdVD06gOAW+d954Fvw=;
	b=N+grmT/N/kPI43+8gTUYHZs18XijYmDFQ+qZNNTNeUVCyV7Bi+OLeRC0ZCpjJTXBkO4L
	 T0VLtB+ooTPZXZ56aI8JHIPfRvaX5SGckJDQYQbVzQY8Uai8F/5pNAL8NOjIMhVYxwtgt
	 ISiKMOwH7F4MV5YArF9os7Ip5FSvTQf4YDhm7q87Yt+RFmj14PYeoqCR7e56y23n8qc5g
	 ZwBx508F1puPt5wn4N31w4Jm1fvIh36hjhS3Gs1h9B+lsyTm8LJyg9u/IME3k33Ji7HbM
	 CtOTSQPwHzYsGlxRtGfDI84SJGBEZ2fsIpKZ5JZ9LPw4+HDhSV8FnnzU/nL4dl8RibA==
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="fCicJp5/";
	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 85348606A323;
	Sun, 15 Nov 2026 06:07:39 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FAF21F000C4;
	Sun, 15 Nov 2026 06:07:38 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1794722859;
	bh=ZdGWU1xDsfsW7sNtgyXBAi046XdVD06gOAW+d954Fvw=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=fCicJp5/S2leanAXVxExUMcrj2N5Jxq4uTRUvLk5AzCcWAZj7kuFBAki1wK0Da31R
	 N0fKdPUvXAd++kMWpNZWOQe+qBeUN2JYsH58kO6g/L46VsLlVSv3N5BPmo97oOc3PE
	 sKrPfXwqv00+sd/1+KPngdbe9mBkIbN2BAA+PjNomsOUD6dix4d6V055o9hzYIom4/
	 v7ELF20lNQInUR26YgIRUMPr72Ir0+A559rJKNfpXIxW888pHNi2R3tQeE/mMZlsVL
	 B4l10C++BGzMkwQyGR3Aue3+uQVFiYRcWt/36JA8Ie63R9WilunVyQlUecshF//t8v
	 imT91m0bxLqOQ==
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,
 bigeasy@linutronix.de, clrkwllms@kernel.org, rostedt@goodmis.org,
 linux-rt-devel@lists.linux.dev, kuniyu@google.com
X-In-Reply-To: <20261110210538.217936-3-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