From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.181 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796566318; b=INge5BHndedX4aUVh5tT4ZR9tdZau1YvIl0M66S26bDR9nvMa2scZ5dHaP21h7W8Zy6k 296eE1GDpgQAxC8kW5OdD6eE0XJ3+7EmMZ6n1Nsae7aMsLeQPrVaRwkvUSaECxT+outuU vggM79aUo0yY190VNk18Z9hl0ktnuLwYZr8oo7fKulqPL7i/wbSCOzJxO9aRofH65uK3I Ecey+7HBPuehaCfDuMydfzs403D91VMt3IPoQN5geG4GQvdjFl6ENRCq114OBBwXHJeVM 1fsZP/TyN6Fog7fES2Y/8rN8qTH2NTw5aaJdZ/3W9yG/221lRaZBfrwB4yFJ/T/Q8bA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796566318; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=FvNb/0S2kL5sf0otB1LvDsDTlvJyxyCXr8Sm4S5+w2A=; b=p3jigdTb4EQeA43DxYTcylCCqZgGAE/vwT+fm3lIcp0l63QfX+4MKufFLh0cq1QPDEBz Y7pTo+cHgDD/KbetoYoAD4W9lKpXaSIuij16eHhRziTDi/QwB8k88QZmFe0tM4X2tUe1g egJWrMaMSC8YfdoI38+4NbrWsvLYCDiQln57mFDIzxlMA45MJON4LTHxg62AUPmmeHnhr 88ZV4d5/X6OrIT0WyN/s5Wv1FVSpby6BELePpQpS4QepnF84tHBg1EgCkAdXb9Jys1qAq j+bW+sips4XUMBdJy9mkzD4ddQBK6mL5OV/RLmllErfZI71Wr7+0mlXVKWcNWo/whnw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=puEd6Afm; arc=none smtp.remote-ip=209.85.215.181 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BD7E606A321 for ; Sun, 6 Dec 2026 14:11:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4BD7E606A321 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=puEd6Afm Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-ce14f644f55so38521a12.3 for ; Sun, 06 Dec 2026 06:11:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796566318; x=1797171118; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=FvNb/0S2kL5sf0otB1LvDsDTlvJyxyCXr8Sm4S5+w2A=; b=puEd6AfmOsxTXvcI4LdOH6U/cqDEJvPIFaehuobFxJdzMrqg7ab/w3Zy5ERJwTk58c oPUId2OXCzC7ZPU/pZ1Qutm3cKdkJbcPW1IhfguZ2p3gELTWwZKfqkqK4fGavDEV1piU VKk3///Dkyb7F758a+/6BaXW1y+JztDrkGTIuaPbOTNXv8gV58EC++mZhycguWTBp9CG dqCOKoMK/nmgSDqJPuNfmLAM/7fupdd7DPTdC0M0MKTFM7szV4P/aD2ye4sI+bdKZE7M zHpj7pUa2ITqqWoY9o83Gzw2NU8WEMYoqCoR+9DPf02M/97mCdhn+elIyxZl5g3+Z6J+ jc+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796566318; x=1797171118; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=FvNb/0S2kL5sf0otB1LvDsDTlvJyxyCXr8Sm4S5+w2A=; b=rclL6TN14PvVaF8g6dVEC5ima4uNN28lTPluDy4BmqsSwQLch4V3He2cIXLe2OBM/C pqIrCzFUwQyXPk77pyctt4EF++/UxPA1vMNVfjUMdrNnlALsOYlDbGkC/eitTmc7t7nD OHKgkAdCHEvLMOUuueAW3MN1ObANlf+ZjXjo2xBBSeurV36sqOP5Fh4NZgZFqW35hIL0 wNsVYLFkCRdnudwaml3GRghgJf9X5dQKeyOPdbhAyHToNNfds5W+1JDHpa5wOSMVLCDU WlMOuJ5iboaePvjSHT4e9j8ls9LWACD/i8kB05PjebEpIn32hSn6xiXnU3FlJ8htHtip MB/w== X-Forwarded-Encrypted: i=1; AL+hErHW8GgvFXZdVQij5QsF41nDRQDjiJYETIr75pq93FJ5QeK+KFcgLWwkqwkKPKTCm51c8vz8AsPt2V3aZp8=@vger.kernel.org X-Gm-Message-State: AB4q+uHthvQqD9v2EelnynSyrWJ0zYyqvcYkKn4uh6ddhJTw7u1ENHwq qcFk+DfbgnMvo1hsytpd4znDK1PcXw4HcMJWM/acxcSBnKu/ASjANdRC X-Gm-Gg: AZFdTZdiPFX5MQ73n8kk4ZTY2ZBROMpg1O6MjLoENNC6WXncFImYBTkc+7pjvQH4r76 Azy+TptAuPp+Em2QOUIgUCrsrgQi3/kxaCQBqIj7P9NiV1b98hUXVKKNxXgb78r/CgWRAaxs7oi AeSooytg+LzZXLcVnVZdL1Tng4QzOe76JlPj23KZVErghx6cux3ZhE9DG1+EWoN9HHf8XrFmgLX wEMn8mlHkb4JCiB0kTijbYFrg4d2clZW4yzZ89adp0zPt7f0HXZEmVuHsUqR2gESjK+OlJXzoRt OCjtv+MYneLlvs39eLTI8AjutMREXO9Ye90cUg6ygHiyMko8ie9so1Carlfb5/sgi0cHve34dFH PuENHSZfp43HiXN1Aado8JJJqqIv6NTHKOsL928ZkaOqYIhL4LTmPg4A0SGAOUaRIihrCwhtoay o2bKEmKsvBgYzDMefIQLtJW0VjltrE8XadUGwLfXuzaYYItrhtBegu5qLWqksiln5lBqG/uV3Ni bKC/R/pnQIwNfk2tn7tIwAhk6GeulHIxrr5N/Zvue/Cbb41vGz6X8r//kTL6++JfYbltC8W8D6q HkCTGrBnU9B1jGdjSJaqfi7thWzcKBy+FIM0M6Ch2g== X-Received: by 2002:a17:90a:e18b:b0:3b1:2d60:66cc with SMTP id 98e67ed59e1d1-3b5e054af04mr7503071a91.8.1796566317562; Sun, 06 Dec 2026 06:11:57 -0800 (PST) Received: from ustb520lab-MS-7E07.. ([115.25.44.221]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5ddc37998sm12750231a91.10.2026.12.06.06.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2026 06:11:57 -0800 (PST) From: Jiaming Zhang To: Jakub Kicinski , Andrew Lunn , "David S. Miller" , Eric Dumazet , Paolo Abeni , netdev@vger.kernel.org Cc: Simon Horman , Cong Wang , Peilin Ye , linux-kernel@vger.kernel.org, Jiaming Zhang , 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 Message-ID: <20261206141144.713822-1-r772577952@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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