* [PATCH net-next v2] net: sparx5: check DT port reg against chip port count
@ 2026-11-16 13:08 Haoran Wang
2026-11-17 12:59 ` Daniel Machon
2026-11-18 6:43 ` [PATCH net-next v3] " Haoran Wang
0 siblings, 2 replies; 6+ messages in thread
From: Haoran Wang @ 2026-11-16 13:08 UTC (permalink / raw)
To: Daniel Machon, Steen Hegelund, UNGLinuxDriver
Cc: netdev, linux-arm-kernel, linux-kernel, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
mchp_sparx5_probe() reads the DT ethernet-port 'reg' property into
portno, which sparx5_create_port() later uses to index the fixed-size
sparx5->ports[] array:
sparx5->ports[config->portno] = spx5_port;
The value is never validated, so an out-of-range 'reg' (runtime overlay,
corrupted or attacker-controlled DTB, kexec-supplied or bootloader
fixed-up DT) turns probe into an out-of-bounds write.
Skip port nodes with an out-of-range 'reg', as lan966x does in
lan966x_probe_port(). The bound is the per-chip port count from the
match data (sparx5->data->consts->n_ports), so lan969x, which shares
this probe path and has only 30 ports, is bounded correctly as well.
Found by a scripted scan of of_property_read_u32() call sites used to
index fixed-size arrays, followed by manual review. Verified at runtime
on a pristine v7.4-rc2 arm64 QEMU virt machine (inline KASAN,
CONFIG_SPARX5_SWITCH=m): an out-of-tree module supplies only a
malicious DT overlay, the unmodified in-tree driver performs the store.
reg = 15839 yields a KASAN use-after-free, reg = 0x20000000 a wild
write 4 GiB out (paging oops), and reg = 65 silent in-struct corruption
with a later NULL oops. With this patch all three are skipped. The PoC
and full logs are posted in the thread. Not tested on real hardware,
QEMU virt (cortex-a57) and compile testing only.
Fixes: f3cad2611a77 ("net: sparx5: add hostmode with phylink support")
Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
---
v1 -> v2:
- Check against sparx5->data->consts->n_ports instead of SPX5_PORTS,
so that lan969x (30 ports), which goes through the same probe, is
bounded correctly as well (Daniel Machon).
- Document how the issue was found, the runtime verification and the
test setup, as requested by the patch bot.
drivers/net/ethernet/microchip/sparx5/sparx5_main.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
index 08a398a..1647067 100644
--- a/a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
+++ b/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 >= sparx5->data->consts->n_ports) {
+ dev_err(sparx5->dev, "port %u: reg out of range\n",
+ portno);
+ continue;
+ }
config = &configs[idx];
conf = &config->conf;
conf->speed = SPEED_UNKNOWN;
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH net-next v2] net: sparx5: check DT port reg against chip port count
2026-11-16 13:08 [PATCH net-next v2] net: sparx5: check DT port reg against chip port count Haoran Wang
@ 2026-11-17 12:59 ` Daniel Machon
2026-11-18 6:43 ` [PATCH net-next v3] " Haoran Wang
1 sibling, 0 replies; 6+ messages in thread
From: Daniel Machon @ 2026-11-17 12:59 UTC (permalink / raw)
To: Haoran Wang
Cc: Steen Hegelund, UNGLinuxDriver, netdev, linux-arm-kernel,
linux-kernel, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
> mchp_sparx5_probe() reads the DT ethernet-port 'reg' property into
> portno, which sparx5_create_port() later uses to index the fixed-size
> sparx5->ports[] array:
>
> sparx5->ports[config->portno] = spx5_port;
>
> The value is never validated, so an out-of-range 'reg' (runtime overlay,
> corrupted or attacker-controlled DTB, kexec-supplied or bootloader
> fixed-up DT) turns probe into an out-of-bounds write.
>
> Skip port nodes with an out-of-range 'reg', as lan966x does in
> lan966x_probe_port(). The bound is the per-chip port count from the
Actually, lan966x returns -EINVAL and fails. This patch just skips the port,
which is fine.
> match data (sparx5->data->consts->n_ports), so lan969x, which shares
> this probe path and has only 30 ports, is bounded correctly as well.
>
> Found by a scripted scan of of_property_read_u32() call sites used to
> index fixed-size arrays, followed by manual review. Verified at runtime
> on a pristine v7.4-rc2 arm64 QEMU virt machine (inline KASAN,
> CONFIG_SPARX5_SWITCH=m): an out-of-tree module supplies only a
> malicious DT overlay, the unmodified in-tree driver performs the store.
> reg = 15839 yields a KASAN use-after-free, reg = 0x20000000 a wild
> write 4 GiB out (paging oops), and reg = 65 silent in-struct corruption
> with a later NULL oops. With this patch all three are skipped. The PoC
> and full logs are posted in the thread. Not tested on real hardware,
> QEMU virt (cortex-a57) and compile testing only.
>
> Fixes: f3cad2611a77 ("net: sparx5: add hostmode with phylink support")
> Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
The in-body From: line from v1 is gone, so the author is now
haoranwangsec@gmail.com, which does not match the Signed-off-by.
checkpatch warns about this.
> ---
> v1 -> v2:
>
> - Check against sparx5->data->consts->n_ports instead of SPX5_PORTS,
> so that lan969x (30 ports), which goes through the same probe, is
> bounded correctly as well (Daniel Machon).
> - Document how the issue was found, the runtime verification and the
> test setup, as requested by the patch bot.
>
> drivers/net/ethernet/microchip/sparx5/sparx5_main.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
> index 08a398a..1647067 100644
> --- a/a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
> +++ b/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 >= sparx5->data->consts->n_ports) {
> + dev_err(sparx5->dev, "port %u: reg out of range\n",
> + portno);
> + continue;
> + }
> config = &configs[idx];
> conf = &config->conf;
> conf->speed = SPEED_UNKNOWN;
The fix looks correct, however the patch is broken and does not apply.
pw-bot: cr
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH net-next v3] net: sparx5: check DT port reg against chip port count
2026-11-16 13:08 [PATCH net-next v2] net: sparx5: check DT port reg against chip port count Haoran Wang
2026-11-17 12:59 ` Daniel Machon
@ 2026-11-18 6:43 ` Haoran Wang
2026-11-19 9:46 ` Haoran Wang
2026-11-23 15:00 ` patchwork-bot+netdevbpf
1 sibling, 2 replies; 6+ messages in thread
From: Haoran Wang @ 2026-11-18 6:43 UTC (permalink / raw)
To: Daniel Machon, Steen Hegelund, UNGLinuxDriver
Cc: netdev, linux-arm-kernel, linux-kernel, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
From: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
mchp_sparx5_probe() reads the DT ethernet-port 'reg' property into
portno, which sparx5_create_port() later uses to index the fixed-size
sparx5->ports[] array:
sparx5->ports[config->portno] = spx5_port;
The value is never validated, so an out-of-range 'reg' (runtime overlay,
corrupted or attacker-controlled DTB, kexec-supplied or bootloader
fixed-up DT) turns probe into an out-of-bounds write.
Skip port nodes with an out-of-range 'reg'. lan966x_probe_port() has
the same bounds check but fails probe with -EINVAL; skipping here keeps
the remaining valid ports working. The bound is the per-chip port count
from the match data (sparx5->data->consts->n_ports), so lan969x, which
shares this probe path and has only 30 ports, is bounded correctly as
well.
Found by a scripted scan of of_property_read_u32() call sites used to
index fixed-size arrays, followed by manual review. Verified at runtime
on a pristine v7.4-rc2 arm64 QEMU virt machine (inline KASAN,
CONFIG_SPARX5_SWITCH=m): an out-of-tree module supplies only a
malicious DT overlay, the unmodified in-tree driver performs the store.
reg = 15839 yields a KASAN use-after-free, reg = 0x20000000 a wild
write 4 GiB out (paging oops), and reg = 65 silent in-struct corruption
with a later NULL oops. With this patch all three are skipped. The PoC
and full logs are posted in the thread. Not tested on real hardware,
QEMU virt (cortex-a57) and compile testing only.
Fixes: f3cad2611a77 ("net: sparx5: add hostmode with phylink support")
Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
---
v2 -> v3:
- Fix the diff paths (a/a/ -> a/, b/b/ -> b/) so the patch applies
(Daniel Machon).
- Restore the in-body From: line so the author matches the Signed-off-by
(checkpatch author/Signed-off-by mismatch).
- Clarify that lan966x fails probe instead of skipping (Daniel Machon).
v1 -> v2:
- Check against sparx5->data->consts->n_ports instead of SPX5_PORTS,
so that lan969x (30 ports), which goes through the same probe, is
bounded correctly as well (Daniel Machon).
- Document how the issue was found, the runtime verification and the
test setup, as requested by the patch bot.
drivers/net/ethernet/microchip/sparx5/sparx5_main.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
index 08a398adf..164706745 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 >= sparx5->data->consts->n_ports) {
+ dev_err(sparx5->dev, "port %u: reg out of range\n",
+ portno);
+ continue;
+ }
config = &configs[idx];
conf = &config->conf;
conf->speed = SPEED_UNKNOWN;
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH net-next v3] net: sparx5: check DT port reg against chip port count
2026-11-18 6:43 ` [PATCH net-next v3] " Haoran Wang
@ 2026-11-19 9:46 ` Haoran Wang
2026-11-23 7:56 ` Daniel Machon
2026-11-23 15:00 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 6+ messages in thread
From: Haoran Wang @ 2026-11-19 9:46 UTC (permalink / raw)
To: Daniel Machon, Steen Hegelund, UNGLinuxDriver
Cc: netdev, linux-arm-kernel, linux-kernel, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
From: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
mchp_sparx5_probe() reads the DT ethernet-port 'reg' property into
portno, which sparx5_create_port() later uses to index the fixed-size
sparx5->ports[] array:
sparx5->ports[config->portno] = spx5_port;
The value is never validated, so an out-of-range 'reg' (runtime overlay,
corrupted or attacker-controlled DTB, kexec-supplied or bootloader
fixed-up DT) turns probe into an out-of-bounds write.
Skip port nodes with an out-of-range 'reg'. lan966x_probe_port() has
the same bounds check but fails probe with -EINVAL; skipping here keeps
the remaining valid ports working. The bound is the per-chip port count
from the match data (sparx5->data->consts->n_ports), so lan969x, which
shares this probe path and has only 30 ports, is bounded correctly as
well.
Found by a scripted scan of of_property_read_u32() call sites used to
index fixed-size arrays, followed by manual review. Verified at runtime
on a pristine v7.4-rc2 arm64 QEMU virt machine (inline KASAN,
CONFIG_SPARX5_SWITCH=m): an out-of-tree module supplies only a
malicious DT overlay, the unmodified in-tree driver performs the store.
reg = 15839 yields a KASAN use-after-free, reg = 0x20000000 a wild
write 4 GiB out (paging oops), and reg = 65 silent in-struct corruption
with a later NULL oops. With this patch all three are skipped. The PoC
and full logs are posted in the thread. Not tested on real hardware,
QEMU virt (cortex-a57) and compile testing only.
Fixes: f3cad2611a77 ("net: sparx5: add hostmode with phylink support")
Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
---
v2 -> v3:
- Fix the diff paths (a/a/ -> a/, b/b/ -> b/) so the patch applies
(Daniel Machon).
- Restore the in-body From: line so the author matches the Signed-off-by
(checkpatch author/Signed-off-by mismatch).
- Clarify that lan966x fails probe instead of skipping (Daniel Machon).
v1 -> v2:
- Check against sparx5->data->consts->n_ports instead of SPX5_PORTS,
so that lan969x (30 ports), which goes through the same probe, is
bounded correctly as well (Daniel Machon).
- Document how the issue was found, the runtime verification and the
test setup, as requested by the patch bot.
drivers/net/ethernet/microchip/sparx5/sparx5_main.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
index 08a398adf..164706745 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 >= sparx5->data->consts->n_ports) {
+ dev_err(sparx5->dev, "port %u: reg out of range\n",
+ portno);
+ continue;
+ }
config = &configs[idx];
conf = &config->conf;
conf->speed = SPEED_UNKNOWN;
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH net-next v3] net: sparx5: check DT port reg against chip port count
2026-11-19 9:46 ` Haoran Wang
@ 2026-11-23 7:56 ` Daniel Machon
0 siblings, 0 replies; 6+ messages in thread
From: Daniel Machon @ 2026-11-23 7:56 UTC (permalink / raw)
To: Haoran Wang
Cc: Steen Hegelund, UNGLinuxDriver, netdev, linux-arm-kernel,
linux-kernel, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
> From: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
>
> mchp_sparx5_probe() reads the DT ethernet-port 'reg' property into
> portno, which sparx5_create_port() later uses to index the fixed-size
> sparx5->ports[] array:
>
> sparx5->ports[config->portno] = spx5_port;
>
> The value is never validated, so an out-of-range 'reg' (runtime overlay,
> corrupted or attacker-controlled DTB, kexec-supplied or bootloader
> fixed-up DT) turns probe into an out-of-bounds write.
>
> Skip port nodes with an out-of-range 'reg'. lan966x_probe_port() has
> the same bounds check but fails probe with -EINVAL; skipping here keeps
> the remaining valid ports working. The bound is the per-chip port count
> from the match data (sparx5->data->consts->n_ports), so lan969x, which
> shares this probe path and has only 30 ports, is bounded correctly as
> well.
>
> Found by a scripted scan of of_property_read_u32() call sites used to
> index fixed-size arrays, followed by manual review. Verified at runtime
> on a pristine v7.4-rc2 arm64 QEMU virt machine (inline KASAN,
> CONFIG_SPARX5_SWITCH=m): an out-of-tree module supplies only a
> malicious DT overlay, the unmodified in-tree driver performs the store.
> reg = 15839 yields a KASAN use-after-free, reg = 0x20000000 a wild
> write 4 GiB out (paging oops), and reg = 65 silent in-struct corruption
> with a later NULL oops. With this patch all three are skipped. The PoC
> and full logs are posted in the thread. Not tested on real hardware,
> QEMU virt (cortex-a57) and compile testing only.
>
> Fixes: f3cad2611a77 ("net: sparx5: add hostmode with phylink support")
> Signed-off-by: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
> ---
> v2 -> v3:
> - Fix the diff paths (a/a/ -> a/, b/b/ -> b/) so the patch applies
> (Daniel Machon).
> - Restore the in-body From: line so the author matches the Signed-off-by
> (checkpatch author/Signed-off-by mismatch).
> - Clarify that lan966x fails probe instead of skipping (Daniel Machon).
>
> v1 -> v2:
> - Check against sparx5->data->consts->n_ports instead of SPX5_PORTS,
> so that lan969x (30 ports), which goes through the same probe, is
> bounded correctly as well (Daniel Machon).
> - Document how the issue was found, the runtime verification and the
> test setup, as requested by the patch bot.
>
> drivers/net/ethernet/microchip/sparx5/sparx5_main.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
> index 08a398adf..164706745 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 >= sparx5->data->consts->n_ports) {
> + dev_err(sparx5->dev, "port %u: reg out of range\n",
> + portno);
> + continue;
> + }
> config = &configs[idx];
> conf = &config->conf;
> conf->speed = SPEED_UNKNOWN;
>
The patch looks good to me.
However, the AI review flags a pre-existing issue, about two port nodes with the
same 'reg' leak the first port's phylink. To me, that strengthens the argument
that the device tree is considered trusted, as we would otherwise have to
validate every DT property in the driver.
That said, this patch fixes an out-of-bounds write, and other drivers do the
same check (lan966x in lan966x_probe_port(), and ocelot in ocelot_vsc7514.c,
which also skips the port). So it might still be worth having.
I am unsure here, so I'll leave it to the maintainers to decide.
Reviewed-by: Daniel Machon <daniel.machon@microchip.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net-next v3] net: sparx5: check DT port reg against chip port count
2026-11-18 6:43 ` [PATCH net-next v3] " Haoran Wang
2026-11-19 9:46 ` Haoran Wang
@ 2026-11-23 15:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-23 15:00 UTC (permalink / raw)
To: =?utf-8?b?546L5rWp54S2IDx3YW5naHIyMDI2QG1haWwuemdjbGFiLmVkdS5jbj4=?=
Cc: daniel.machon, Steen.Hegelund, UNGLinuxDriver, netdev,
linux-arm-kernel, linux-kernel, andrew+netdev, davem, edumazet,
kuba, pabeni
Hello:
This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Wed, 18 Nov 2026 14:43:07 +0800 you wrote:
> From: Haoran Wang <wanghr2026@mail.zgclab.edu.cn>
>
> mchp_sparx5_probe() reads the DT ethernet-port 'reg' property into
> portno, which sparx5_create_port() later uses to index the fixed-size
> sparx5->ports[] array:
>
> sparx5->ports[config->portno] = spx5_port;
>
> [...]
Here is the summary with links:
- [net-next,v3] net: sparx5: check DT port reg against chip port count
https://git.kernel.org/netdev/net-next/c/5a1f67933615
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-23 15:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16 13:08 [PATCH net-next v2] net: sparx5: check DT port reg against chip port count Haoran Wang
2026-11-17 12:59 ` Daniel Machon
2026-11-18 6:43 ` [PATCH net-next v3] " Haoran Wang
2026-11-19 9:46 ` Haoran Wang
2026-11-23 7:56 ` Daniel Machon
2026-11-23 15:00 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox