mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] netdevsim: bound port_count and num_queues in new_device_store()
@ 2026-12-06 14:11 Jiaming Zhang
  2026-12-06 14:17 ` netdev-bot+sinfo
  0 siblings, 1 reply; 2+ messages in thread
From: Jiaming Zhang @ 2026-12-06 14:11 UTC (permalink / raw)
  To: Jakub Kicinski, Andrew Lunn, David S. Miller, Eric Dumazet,
	Paolo Abeni, netdev
  Cc: Simon Horman, Cong Wang, Peilin Ye, linux-kernel, Jiaming Zhang, stable

Writing "id port_count num_queues" to /sys/bus/netdevsim/new_device
creates a simulated device and registers one network device per port.
new_device_store() checks only id before passing the parsed counts into
device creation:

	if (id > INT_MAX) {
		pr_err("Value of \"id\" is too big.\n");
		return -EINVAL;
	}

Since commit d4861fc6be58 ("netdevsim: Add multi-queue support"),
num_queues goes straight to alloc_netdev_mq(), which accepts up to
65535 queues in netif_alloc_netdev_queues().  Unlike rtnl_create_link(),
which caps TX and RX queues to 1..4096, netdevsim leaves both
port_count and num_queues unbounded.

With an oversized num_queues, both register_netdevice() during probe
and ETHTOOL_SCHANNELS updates in nsim_set_channels() hold rtnl_lock()
while creating or tearing down tens of thousands of rx-* and tx-* sysfs
queue kobjects.  An unbounded port_count likewise loops in
nsim_dev_port_add_all() under bus and devlink locks.

Chained channel toggles or large registrations hold rtnl_mutex long
enough to stall concurrent network namespace cleanup (ops_undo_list() ->
ops_exit_rtnl_list()) and netlink queries past the default hung-task
timeout.  Triggering this requires root write access to sysfs on a
kernel with netdevsim enabled.

Define NSIM_BUS_DEV_MAX_PORTS (256) and NSIM_BUS_DEV_MAX_QUEUES (4096,
matching rtnl_create_link()) and reject out-of-range values in
new_device_store().  Allow port_count == 0 so existing devlink trap
selftests continue to work, while requiring num_queues >= 1 because
ports can be added later through new_port_store().

Fixes: d4861fc6be58 ("netdevsim: Add multi-queue support")
Closes: https://lore.kernel.org/lkml/CANypQFb9VpwKA2ipZ32fddoehVvn5fBKqMYGOwXPjNQ7j3N_RA@mail.gmail.com/
Cc: stable@vger.kernel.org
Assisted-by: Antigravity:Gemini
Signed-off-by: Jiaming Zhang <r772577952@gmail.com>
---
 drivers/net/netdevsim/bus.c       | 8 ++++++++
 drivers/net/netdevsim/netdevsim.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c
index b792ee10b1c1..39bcca0cd2b9 100644
--- a/drivers/net/netdevsim/bus.c
+++ b/drivers/net/netdevsim/bus.c
@@ -175,6 +175,14 @@ new_device_store(const struct bus_type *bus, const char *buf, size_t count)
 			pr_err("Value of \"id\" is too big.\n");
 			return -EINVAL;
 		}
+		if (port_count > NSIM_BUS_DEV_MAX_PORTS) {
+			pr_err("Value of \"port_count\" is too big.\n");
+			return -EINVAL;
+		}
+		if (num_queues < 1 || num_queues > NSIM_BUS_DEV_MAX_QUEUES) {
+			pr_err("Value of \"num_queues\" is out of range.\n");
+			return -EINVAL;
+		}
 		break;
 	default:
 		pr_err("Format for adding new device is \"id port_count num_queues\" (uint uint uint).\n");
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index fd5599cd3bb9..550681106290 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -474,6 +474,8 @@ int nsim_setup_tc(struct net_device *dev, enum tc_setup_type type,
 		  void *type_data);
 
 #define NSIM_BUS_DEV_MAX_VFS 4
+#define NSIM_BUS_DEV_MAX_PORTS 256
+#define NSIM_BUS_DEV_MAX_QUEUES 4096
 struct nsim_bus_dev {
 	struct device dev;
 	struct list_head list;

base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
-- 
2.43.0


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

end of thread, other threads:[~2026-12-06 14:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-06 14:11 [PATCH] netdevsim: bound port_count and num_queues in new_device_store() Jiaming Zhang
2026-12-06 14:17 ` netdev-bot+sinfo

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®