mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiaming Zhang <r772577952@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org
Cc: Simon Horman <horms@kernel.org>,
	Cong Wang <cong.wang@bytedance.com>,
	Peilin Ye <peilin.ye@bytedance.com>,
	linux-kernel@vger.kernel.org,
	Jiaming Zhang <r772577952@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] netdevsim: bound port_count and num_queues in new_device_store()
Date: Sun,  6 Dec 2026 22:11:44 +0800	[thread overview]
Message-ID: <20261206141144.713822-1-r772577952@gmail.com> (raw)

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


             reply	other threads:[~2026-12-06 14:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06 14:11 Jiaming Zhang [this message]
2026-12-06 14:17 ` netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261206141144.713822-1-r772577952@gmail.com \
    --to=r772577952@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=cong.wang@bytedance.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=peilin.ye@bytedance.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®