🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #17269

Re: [PATCH net-next] net: sparx5: check DT port reg against array size

#17269
From: netdev-bot+sashiko
Date: Mon, 16 Nov 2026 14:42
105 lines
11833 bytes
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

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).

- [High] The new range check in mchp_sparx5_probe()
  (drivers/net/ethernet/microchip/sparx5/sparx5_main.c:848) compares the…

--

net: sparx5: check DT port reg against array size

This patch adds a range check on the DT 'reg' value of each ethernet-port
node in mchp_sparx5_probe(). Nodes with portno >= SPX5_PORTS are now
skipped, so sparx5_create_port() can no longer index past the end of
sparx5->ports[].

> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
> index 9b67a0520907b..d975474792f9f 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
> @@ -845,6 +845,11 @@ static int mchp_sparx5_probe(struct platform_device *pdev)
>  			dev_err(sparx5->dev, "port reg property error\n");
>  			continue;
>  		}
> +		if (portno >= SPX5_PORTS) {

[Severity: High]
Should this bound be sparx5->data->consts->n_ports rather than SPX5_PORTS?

SPX5_PORTS (65) is the compile-time size of sparx5->ports[]. It matches the
front-port count on Sparx5 only. mchp_sparx5_probe() is also used for
lan969x, and its consts are smaller:

drivers/net/ethernet/microchip/sparx5/lan969x/lan969x.c:
	.n_ports             = 30,
	.n_ports_all         = 35,

drivers/net/ethernet/microchip/sparx5/lan969x/lan969x_regs.c:
	[TC_DEV2G5] = 28,
	...
	[RC_QSYS_ATOP] = 35,

On lan969x, a reg value from 30 to 64 passes this check.
lan969x_port_is_rgmii() is only true for ports 28 and 29, so such a port
just needs a phys phandle for devm_of_phy_get() to succeed. After that it
is accepted and goes through this path:

mchp_sparx5_probe()
  sparx5_create_port()
    sparx5->ports[config->portno] = spx5_port;
    sparx5_port_init()
      sparx5_port_max_tags_set()
        spx5_wr(..., DEV2G5_MAC_TAGS_CFG(port->portno));

The DEV2G5 registers resolve to regs[TARGET_DEV2G5 + portno]. The lan969x
iomap only fills TARGET_DEV2G5 + 0..27, and the sparx5 struct is
zero-allocated, so those slots are NULL. spx5_addr() warns but still
returns the address:

drivers/net/ethernet/microchip/sparx5/sparx5_main.h:spx5_addr() {
	WARN_ON((tinst) >= tcnt);
	WARN_ON((ginst) >= gcnt);
	WARN_ON((rinst) >= rcnt);
	return base[id + (tinst)] +
		gbase + ((ginst) * gwidth) +
		raddr + ((rinst) * rwidth);
}

Can this end up as an MMIO write to a near-NULL address during probe?

sparx5_port_init() also uses portno directly as the replication index for
QSYS_PAUSE_CFG(), QSYS_ATOP(), ANA_CL_CAPTURE_BPDU_CFG() and
ANA_CL_FILTER_CTRL(). With RC_QSYS_ATOP = 35 on lan969x, ports 30..34 would
reconfigure the internal CPU/VD ports, the ones sparx5_get_internal_port()
returns as n_ports + N. Ports 35..64 would go past the replication range.

If such a port survives init, sparx5_register_netdevs(),
sparx5_destroy_netdevs() and sparx5_unregister_netdevs() only walk
portno < consts->n_ports. Would its netdev then never be registered, and
its phylink never be destroyed?

The commit message describes the DT as possibly untrusted (overlay, kexec,
bootloader fixup). The binding in microchip,sparx5-switch.yaml sets no
maximum on the port reg, so this driver check is the only guard. Would
checking against the per-chip limit close the out-of-bounds case on
lan969x as well?

> +			dev_err(sparx5->dev, "port %u: reg out of range\n",
> +				portno);
> +			continue;
> +		}
>  		config = &configs[idx];
>  		conf = &config->conf;
>  		conf->speed = SPEED_UNKNOWN;

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179457014579.23820.10657909253312598784%40gmail.com
Technical Details
Message-ID: <179484015280.3136.6207275462106785238@kernel.org>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364464-linux-kernel-netdev=dewy.ru
References: <179457014579.23820.10657909253312598784@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!feeder1.feed.ams11.usenet.farm!feed.usenet.farm!feeder.usenetexpress.com!tr3.eu1.usenetexpress.com!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-364464-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next] net: sparx5: check DT port reg against array size
Date: Mon, 16 Nov 2026 14:42:32 +0000
Organization: Usenet Network
Message-ID: <179484015280.3136.6207275462106785238@kernel.org>
References: <179457014579.23820.10657909253312598784@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network; logging-data="2088939"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:jRLFe9v55eh8pECBkeiUSn4GOEg= sha256:y4Skkjw1NP6GPaE3fiE+GW8Ne0qw6wJ4rutp+164IAI= sha1:hgKPMi2+54O+RAy5IgizDR+IGvY= sha256:Fcu8NVWC7arsn7nuZCpVHZGjyY5XgB76KW1vJL1vThk=
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 4B6C0114C8C; Mon, 16 Nov 2026 17:42:50 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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, URIBL_BLOCKED=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 mNnffxItH8T3; Mon, 16 Nov 2026 17:42:46 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-364464-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 276B6114C81; Mon, 16 Nov 2026 17:42:37 +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 ADF572B3CF; Mon, 16 Nov 2026 14:42:35 +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=1794840154; b=OJeGbtfREIqFM7d1WDTEYSmA4hem7IDXI8w0ApEwDjYMcF04UdJO2fMWfZWraaWFPA8c knjxLV4DTHqSCnJ3bG0NDit9amHe+g5H2hGD0kCmxGt7Q+mA51F7HgISrCpF04MYmPTJF +IdZC0OKELJxxv3r/piVkvMdPPMIGlssr+VWQJWTZukRhmH1TrJKlJ374z3RM+ycuQ4w/ tdDk2vVAEW5b/m5/oYYtdWbmtp4vaOUn/edKHTljHXEgcWTNimK72p/COw4kjy7mhmMGX tFjy1qXgMzTt5lxVz0YeO/h7PicAb+tFX1Ht7a9BI4eDNfw+vYAxy+DpJJODQ6fNS2A==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794840154; 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=q5fTVKGrskJG4rdSydPr4XMv95Db9+O3BQWMmUFXULI=; b=PmXIrFyOmGG2ZdMl8jlM/+wqrJS/+xlL74f1bevqaRKvzJ1fxMcPL7prvrKUEtEkyuFa Fkt8flkC+/7KIaSJojfTyLw/7cQ9a2qgF4cJBCs5bn/RUoqYq3F6N0iP4C1uUiUGQhEMn 9tcPsLxLZ3Lp8VdGsTz154yylYC2doKN9xfpAY2se5qeN1RvK2gU4d6Oj/DpSLizZYwF/ GZWrEjubT+jeAtjJ6qSCc5qhe9NOxzXUJ359JcyPQkl02gTXsGxAGSRQaPJ8hdiKXpXbq 9PbBytK1iDDqbrvP4gxClT2CfLe32nQxaRSbeSWlkOPmmUI9mJW2ehT7LVjrBsAuBEQ==
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=LG7D9VlL; 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 C4104606A338; Mon, 16 Nov 2026 14:42:34 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=LG7D9VlL
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=1794840154; b=M7FC7y3f1Nck5X1qRsE6iagKyvtA8rGBTdMTUD/s+iQT5de6gWHHboS0AeGgshWm5a+t hlzVqOq0NubMIMLH2RAvNh9OagkbVeGh1l0+zIuD31DW0FtbmlTImgPud7G9eTORpsW83 2QmjqQBRwz+DPjFSTnpvKLvjRRcUWj9xJMQWPZFY0yuZEYD8LtwDfJuSyCoRSrHmyI7WJ 28F4yGcseNhAZN9VxtWmNs/WSXcgNbh8IiDmKIXzKfZyk3GmKliA7fKQKlvuvR4XcuqpV tGgMfL2hJCpgzHzfbrZUYRtSj8GYo2DocyNGf0xKdDVRdofMpqXcMXyE0pptmRdvHDg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794840154; 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=q5fTVKGrskJG4rdSydPr4XMv95Db9+O3BQWMmUFXULI=; b=h/CnNb4k6p0WTfzgzUVSjV57WTJWXZIhQfRS81S2qL3+kKEXIB81e9zYJ/vQrbOqFpXX v6L2xFye9AToUL8PIbTqfRv90CaMphkOzkQ+gjIOXt2klsUeebJ8wL7SBxVgL34KacKdC 4tAh92og+V9a80VInGybwMjtXwTOZMFMPfnjbiszwR5qdXz84k6RotimyiPD0YZLV6Iu6 SJLsz/2G7FVRt/jLm9KzdZsu36iViTOeVEXScnJn37tSFVnVixITSsdBanWtWOaP/fzLT x5z5LQcDWE5AfsT0l5LTWQbQMRSlOwtkGypTtNVKjHOf8C2V6BMRcnIfK5PZ8ylFtIw==
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=LG7D9VlL; 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 E153D606A31C; Mon, 16 Nov 2026 14:42:33 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4DD611F000C4; Mon, 16 Nov 2026 14:42:33 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794840153; bh=q5fTVKGrskJG4rdSydPr4XMv95Db9+O3BQWMmUFXULI=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=LG7D9VlL4ycHov4A3MFP0swl7FuLeK3/NWZCcN0scM6Z9FrBhWr5UHnFsuWQfeAHf +Rduaj5TAKFSzumhW2L1L+eA07I65IohhX7Eod1PstibMo8Ugm50XhzTKiAO24ppkj nQFLZUFEpj2eOuGCO8BeMqT+xcdLDDAsQEnrdqdTfqiWSS2bT4Kv7WxtKeDQlI+b2V N4s00Zd1bHU4BpvX+ttPjaZSsFm3lQ0dmFGKH5Rnl3OIM4XW/+Kc2swF1hEcyAJSwg p5q57ANVmtAlmHYzxDwO7GVNV+Y4EcB6pJluPnpYdyKp9YinMOEIBb5olYxIk7s0XQ mfGMQ4syM2fKQ==
X-Cc: Steen.Hegelund@microchip.com, daniel.machon@microchip.com, UNGLinuxDriver@microchip.com, netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kuba@kernel.org
X-In-Reply-To: <179457014579.23820.10657909253312598784@gmail.com>
X-sashiko-severity: High
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