๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #7228

Re: [PATCH net] net: xps: bound the cleanup loop by the old map's num_tc

#7228
From: netdev-bot+sashiko
Date: Sun, 25 Oct 2026 17:32
145 lines
13367 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 1

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 commit message names the wrong trigger.
- [Low] The commit message understates the impact and does not mention a
  second behaviour change in the same line.

--

net: xps: bound the cleanup loop by the old map's num_tc

This commit changes the old-map cleanup loop in __netif_set_xps_queue().
The per-row trip count now comes from dev_maps->num_tc instead of the new
num_tc. Before the change, the trip count and the row stride could disagree
when dev->num_tc changed while an old XPS map was still installed.

> Triggering conditions
> ---------------------
> CAP_NET_ADMIN to set the XPS mask.  dev->num_tc is raised in-tree by the
> drivers that implement ndo_setup_tc (the Intel i40e/ice/ixgbe/iavf, mlx5
> and mvneta families, among others) and by the mqprio/taprio qdiscs.  The
> QEMU guest used for the reproducer has no such NIC, so the num_tc change
> was driven through a small module; the defect itself is reached in-tree
> on that hardware.

[Severity: Medium]
Can the drivers and qdiscs named here reach this loop with a stale map?

As far as I can tell, they all change num_tc through netdev_set_num_tc()
or netdev_reset_tc(). Both of those reset XPS on the whole device first:

net/core/dev.c:netdev_set_num_tc() {
    ...
#ifdef CONFIG_XPS
	netif_reset_xps_queues_gt(dev, 0);
#endif
	netdev_unbind_all_sb_channels(dev);

	WRITE_ONCE(dev->num_tc, num_tc);
    ...
}

Removing every tx queue leaves the map inactive. clean_xps_maps() then
calls reset_xps_maps(), which sets dev->xps_maps[type] to NULL. The next
__netif_set_xps_queue() sees dev_maps == NULL and takes:

	if (!dev_maps)
		goto out_no_old_maps;

So it never enters the loop this patch changes.

The in-tree paths that do seem to raise num_tc with an old map still
installed are the sfc Falcon and Siena drivers. ef4_setup_tc() and
efx_siena_setup_tc() write num_tc directly:

drivers/net/ethernet/sfc/siena/tx.c:efx_siena_setup_tc() {
    ...
	WRITE_ONCE(net_dev->num_tc, num_tc);

	return netif_set_real_num_tx_queues(net_dev,
					    max_t(int, num_tc, 1) *
					    efx->n_tx_channels);
}

netif_set_real_num_tx_queues() only resets XPS when the queue count
shrinks:

		if (disabling) {
			synchronize_net();
			qdisc_reset_all_tx_gt(dev, txq);
#ifdef CONFIG_XPS
			netif_reset_xps_queues_gt(dev, txq);
#endif
		}

For example, going from num_tc 0 to 2 leaves a live map with
dev_maps->num_tc == 1. The next XPS write then uses a trip count of 2 with
a stride of 1, and the last row overruns attr_map[].

netif_setup_tc() also writes num_tc = 0 without a full reset, but that is
the shrink direction.

Subordinate-device maps are reset using sb_dev->num_tx_queues as the
count. A macvlan offload (sb_dev) path, for example on ixgbe, might also
leave a stale map behind. That would work differently from what is
described here for the main device.

Could the trigger description be updated to name the sfc Falcon/Siena
paths? This also applies to the claim in the reproducer notes that the
module raises num_tc "the same way an in-tree driver does". Otherwise
stable and security triage will be pointed at hardware where the
described trigger does not seem to fire.

> The loop frees entries in dev_maps, so both the trip count and the stride
> must come from dev_maps->num_tc.  The map is sized
> XPS_CPU_DEV_MAPS_SIZE(old num_tc)/XPS_RXQ_DEV_MAPS_SIZE(old num_tc, ...),
> so iterating the new (larger) num_tc reads past the end.

[Severity: Low]
Is "reads past the end" the full impact here? In the old loop body, each
slot visited is dereferenced, cleared and freed:

			RCU_INIT_POINTER(dev_maps->attr_map[tci], NULL);
			kfree_rcu(map, rcu);

copy is always false when num_tc != dev_maps->num_tc, so the
map == new_map skip never applies. Suppose an out-of-bounds slot holds a
non-NULL value. The old code then writes NULL past the end of
attr_map[]. kfree_rcu() also writes an rcu_head into whatever that
pointer points to, and frees it later.

When the neighbouring slab data is non-zero, that is an out-of-bounds
write plus a free of an arbitrary pointer, not only a read.

The patch also changes behaviour in the other direction, where the new
num_tc is smaller than dev_maps->num_tc. The old loop only visited the
first num_tc slots of each old row, so the xps_map objects in the
remaining slots were never freed.

The later "removes tx-queue from unused" loop walks the new map with
old_dev_maps passed as NULL. kfree_rcu(old_dev_maps, rcu) only frees the
container, so those xps_map objects leaked.

One way to reach this is mqprio in software mode with TC offsets that are
not in ascending order. mqprio_validate_queue_counts() only rejects
overlap, so TC0 can sit at a higher offset than TC1.

Shrinking the channel count then makes netif_setup_tc() set num_tc = 0.
Meanwhile netif_reset_xps_queues_gt(dev, txq) leaves the lower-indexed
TC1 queues mapped.

Would it make sense for the commit message to say that this also fixes a
leak of xps_map objects, and that the overrun includes a write and a free?

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261021155538.67867-1-phx0fer%40gmail.com
Technical Details
Message-ID: <179294952071.3134.18316640480877653854@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-351589-linux-kernel-netdev=dewy.ru
References: <20261021155538.67867-1-phx0fer@gmail.com>

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-351589-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net] net: xps: bound the cleanup loop by the old map's num_tc
Date: Sun, 25 Oct 2026 17:32:00 +0000
Organization: Usenet Network
Message-ID: <179294952071.3134.18316640480877653854@kernel.org>
References: <20261021155538.67867-1-phx0fer@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1076141"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:3JGYoUUEOE1M6WeFgYCBQbP3J7c= sha256:GnAg38H7iAdQNDYa5pimPQTFNGjcyXRP6S7vz0PeNtU=
	sha1:7FPvDC+ZmNygisFEpanB307bswM= sha256:eDrGSAZxZG2OivZzlusd6IM/TVPWMxs+skje3sCmTSY=
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 1B172125B42; Sun, 25 Oct 2026 20:32:44 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.739
X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, 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 nx13A805I2nB;
	Sun, 25 Oct 2026 20:32:40 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-351589-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 E892C125B40; Sun, 25 Oct 2026 20:32: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 DF66C3B6EF; Sun, 25 Oct 2026 17:32:03 +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=1792949523;
	b=waJ0tIBOTfGmtTbGCPTTp1FGtNbgY8IZ4reH/d4tB2V1Y97tl0ThHHYFi+fSBNG4ik68
	 b6uaXuS7G0d2amExZKsEjSTlegdK8iQuehYvAlhnXWx8iiMfYkHU35lmUL0Gvp/MN6kve
	 bAi5DzAswOMyq5MrXFAM7P9823qLYIbyljX/gzKoAZ6lQ8RN3zWzVw3qS4jRKvg4zZ4fF
	 xcUNEB+0VxHc8NKle3v4Up6HnCUph32k4N2oXiaNejqiuBwMhOK4nx3lyrmmrJDVbFQHO
	 WXi2vUDzdCbC8Gbr36c3B5nd/dbYmS6jr216fs1AywOmj7RUFOqXCG5OpqrlRvdLi+g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792949523;
	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=5L6kzLQOGVMgTtlJiH4iYz/6kCVz0ZcYrdnOvzrMyAU=;
	b=Akc0MCGZw/tbvyBqdfA1WXDCuNMCAKPscLhumfahglRbjWzm3maPjBBzteC4DvcnNKJA
	 h7JxETmvqO+3w6Qwl54rzRe599yeYRahcpBfAdWEiPEAk+jk+HxNp2gKnVh15Q3oRtGSu
	 kxIDxwDJczJj2iQQJntg6VAA1xGy5Cn44cRe8XRNKtSOmfa2yVCvOoLKc1wZCe2wpl4O3
	 ElkGZOs/15TJVRAEkD026IYHtmYVFlynMVP+CfhMI1t53yoIDwigDV58NklU7lBnTzEFX
	 VsRcOv7iFcm7jAM7DLmDwvR7gU9FMjTXRivr1iKTOj/j6TxngAcfgTLi7b7qMos0j1w==
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=ZWigPjKz;
	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 29651606A332;
	Sun, 25 Oct 2026 17:32:03 +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=ZWigPjKz
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=1792949522;
	b=YcVPlImyWToOhcAuj8D2igthlySBVm7TVHmJhmaR56gRqGlRbZ7+GZWPH38sViZtB8G8
	 2kWPNYWVTa5HTCOT7WDcJ9U7woTUGaoZmyMFG0YQzVDV5qYfPAkcMLhz0f5vOumPLQIq7
	 bd/clU4Fnhcc1CLyDElFo0iOp3HTgkF75rZ+phX0LQwbOKRQrnzYpRbxkQYhMZXsC0cX2
	 442IXVzDORkU2+aOGHPqG14uBTDFXTCzFUCwUoKrCRaAoJhTkJ3H9rYuVd0tkhPi4PG0X
	 c0A5Pqma190XpvEnz4Z53nq2lnvjJxpIowyYyPb72C23x6FagzxTd00PFam5GRNFD9A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1792949522;
	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=5L6kzLQOGVMgTtlJiH4iYz/6kCVz0ZcYrdnOvzrMyAU=;
	b=RjgNsfVn+dvguk4V8ZdDYoX2iOiQellTgVVXXLZAaWF0WD3AZjtyD5x2fl3iF87nDfbJ
	 Njmf0Lb7Wf0kvnqXx+7XfTcmPlMek3WUBFD1CPaLR1FAenYIhmEIVldruN0QMnyxINu/X
	 IRH1HouHT40s4wIYlawqWYQ87G1Rjsd6Z4eZgaNH4qEanG4Rnt+vD7RDHgu/yFlgQpQCw
	 GVYgJJgglLhjmR1FvKBbk7s4u3lVdVbC4kgf2DELcPM+RRcu0FXgFQwg9vKW6t/U+jk6B
	 lObwoy7R7XZ6GpiDmBcc86gVMrlEAAZSZszYIPA0iJPfm681xtDqKJ7OP5f0DYLz3lw==
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=ZWigPjKz;
	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 F35E2606A326
	for <netdev@vger.kernel.org>; Sun, 25 Oct 2026 17:32:01 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FC4E1F031E1;
	Sun, 25 Oct 2026 17:32:01 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1792949521;
	bh=5L6kzLQOGVMgTtlJiH4iYz/6kCVz0ZcYrdnOvzrMyAU=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=ZWigPjKzScUQdcGfKkKtQMX09JM3q7gFn/tQwWhNGLjQfzGMX2benw7kAeYVIKJ5l
	 g8NskabuuR+LYq8R4NhUVMjBBGLlyuy38mzGxWkeosyjG0aZBDye1jDleclVEyMKqP
	 7S1tNkYBfAhfbyMeYkbWrIdUJPHJKCIWteuYJyjbqOXidpzqzqnD0uzAh9SdU0PYmo
	 coiBT/v3cnEuj5SRQvOp1OQuVad7+X9x9PzJniXBKSSKVUpLDMBvR94gdnQ5G4hbHP
	 ePMwbkwzbIZrCw9nIimW7Rg18drFcUQj0HIr2VJhP5M9LdFb2+qONf34sMTc2RxVIe
	 cQ5stldiVmSkA==
X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
 pabeni@redhat.com, netdev@vger.kernel.org
X-In-Reply-To: <20261021155538.67867-1-phx0fer@gmail.com>
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