mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v3] net: xps: reject an out of range traffic class
@ 2026-09-21 15:03 Norbert Szetei
  2026-09-24  2:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Norbert Szetei @ 2026-09-21 15:03 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Kees Cook, Kuniyuki Iwashima, Alexander Duyck,
	linux-kernel

Only the entries below dev->num_tc are valid in dev->tc_to_txq[], and
dev->prio_tc_map[] may only name classes below it. netdev_set_num_tc()
lowers dev->num_tc without touching either array.

netdev_txq_to_tc() walks all TC_MAX_QUEUE slots and
netdev_get_prio_tc_map() returns the entry as it stands, so a leftover
entry is handed out as a traffic class >= dev->num_tc. Taking that
class from netdev_txq_to_tc(), __netif_set_xps_queue() rejects only a
negative one and indexes an XPS map sized for dev->num_tc classes:

	tci = j * num_tc + tc;
	RCU_INIT_POINTER(new_dev_maps->attr_map[tci], map);

attr_map[] holds nr_ids * num_tc entries and j runs over the ids named
in the mask, so a class that is not below num_tc pushes tci past the end
of the map for the last ids and the store overruns it.

Any caller that lowers num_tc leaves such entries behind, and
mqprio_destroy() tears down with netdev_set_num_tc(dev, 0) rather than
netdev_reset_tc(). After mqprio with 8 classes then 1, tc_to_txq[1..7]
still describe txq 1..7. The splat is from an XPS write to txq 2 on a
veth with 8 rx queues: attr_map[] has 8 * 1 entries, tci = j + 2, and
j == 6 stores one past the end of the 88-byte map:

  BUG: KASAN: slab-out-of-bounds in __netif_set_xps_queue (net/core/dev.c:2954)
  Write of size 8 at addr ffff88813016bc58 by task xps_oob/634
   __netif_set_xps_queue (net/core/dev.c:2954)
   xps_rxqs_store (net/core/net-sysfs.c:1880)
   netdev_queue_attr_store (net/core/net-sysfs.c:1390)
  Allocated by task 634:
   __kmalloc_noprof (mm/slub.c:5439)
   __netif_set_xps_queue (net/core/dev.c:2937)
  The buggy address is located 0 bytes to the right of
   allocated 88-byte region [ffff88813016bc00, ffff88813016bc58)

Reject a class the map has no room for.

Fixes: 184c449f91fe ("net: Add support for XPS with QoS via traffic classes")
Assisted-by: LLM
Signed-off-by: Norbert Szetei <norbert@doyensec.com>
---
v3:
  - stack trace decoded with scripts/decode_stacktrace.sh and the changelog
    now says how attr_map[] is overrun (Simon Horman)
  - no code change from v2
  - v2: https://lore.kernel.org/netdev/CE030A45-D573-4310-8761-01431156F0D6@doyensec.com/

v2:
  - bound the class in __netif_set_xps_queue() instead of clearing
    dev->tc_to_txq[]/dev->prio_tc_map[] in netdev_set_num_tc(), per the
    Sashiko review of v1
  - dropped the memory-ordering claim from the changelog
  - retitled
  - v1: https://lore.kernel.org/netdev/16E3A318-5532-4B5E-8D03-86D21B463A2D@doyensec.com/

 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index c67900354fa6..0292a16e16c2 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -2901,7 +2901,7 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask,
 		dev = netdev_get_tx_queue(dev, index)->sb_dev ? : dev;
 
 		tc = netdev_txq_to_tc(dev, index);
-		if (tc < 0)
+		if (tc < 0 || tc >= num_tc)
 			return -EINVAL;
 	}
 
-- 
2.55.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net v3] net: xps: reject an out of range traffic class
  2026-09-21 15:03 [PATCH net v3] net: xps: reject an out of range traffic class Norbert Szetei
@ 2026-09-24  2:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-24  2:50 UTC (permalink / raw)
  To: Norbert Szetei
  Cc: netdev, davem, edumazet, kuba, pabeni, horms, kees, kuniyu,
	alexander.duyck, linux-kernel

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 21 Sep 2026 17:03:57 +0200 you wrote:
> Only the entries below dev->num_tc are valid in dev->tc_to_txq[], and
> dev->prio_tc_map[] may only name classes below it. netdev_set_num_tc()
> lowers dev->num_tc without touching either array.
> 
> netdev_txq_to_tc() walks all TC_MAX_QUEUE slots and
> netdev_get_prio_tc_map() returns the entry as it stands, so a leftover
> entry is handed out as a traffic class >= dev->num_tc. Taking that
> class from netdev_txq_to_tc(), __netif_set_xps_queue() rejects only a
> negative one and indexes an XPS map sized for dev->num_tc classes:
> 
> [...]

Here is the summary with links:
  - [net,v3] net: xps: reject an out of range traffic class
    https://git.kernel.org/netdev/net/c/4da3b7b8b50f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-24  2:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-21 15:03 [PATCH net v3] net: xps: reject an out of range traffic class Norbert Szetei
2026-09-24  2:50 ` patchwork-bot+netdevbpf

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®