From: netdev-bot+sashiko@kernel.org
To: haoranwangsec@gmail.com
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
Subject: Re: [PATCH net-next] net: sparx5: check DT port reg against array size
Date: Mon, 16 Nov 2026 14:42:32 +0000 [thread overview]
Message-ID: <179484015280.3136.6207275462106785238@kernel.org> (raw)
In-Reply-To: <179457014579.23820.10657909253312598784@gmail.com>
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
prev parent reply other threads:[~2026-11-16 14:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 11:42 Haoran Wang
2026-11-13 11:42 ` Haoran Wang
2026-11-13 11:47 ` netdev-bot+sinfo
2026-11-15 22:13 ` Daniel Machon
2026-11-16 11:56 ` Wang Haoran
2026-11-16 14:42 ` netdev-bot+sashiko [this message]
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=179484015280.3136.6207275462106785238@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=Steen.Hegelund@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=daniel.machon@microchip.com \
--cc=haoranwangsec@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@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®