* [PATCH] niu: validate num_ports against NIU_MAX_PORTS
@ 2026-08-25 9:42 Yang Zi
2026-08-27 19:14 ` Jakub Kicinski
0 siblings, 1 reply; 2+ messages in thread
From: Yang Zi @ 2026-08-25 9:42 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: linux-kernel, netdev
niu_get_and_validate_port() obtains parent->num_ports from hardware
(nr64(ESPC_NUM_PORTS_MACS) & ESPC_NUM_PORTS_MACS_VAL), an 8-bit value that
can range from 0 to 255, with no upper-bound check. The driver's per-port
arrays (rxchan_per_port[], txchan_per_port[], rdc_group_cfg[]) are only
NIU_MAX_PORTS (4) entries, so niu_divide_channels() and
niu_divide_rdc_groups() iterate num_ports times and write out of bounds
whenever num_ports is greater than 4.
Reject num_ports > NIU_MAX_PORTS with -EINVAL so the probe aborts before any
of these arrays are written.
Covers fuzzing bug IDs 321, 322, 323 and 324 (same root cause).
Signed-off-by: Yang Zi <2959243019@qq.com>
---
diff --git a/drivers/net/ethernet/sun/niu.c b/drivers/net/ethernet/sun/niu.c
index 54dd7281191d..d33c87489bd9 100644
--- a/drivers/net/ethernet/sun/niu.c
+++ b/drivers/net/ethernet/sun/niu.c
@@ -8586,6 +8586,14 @@ static int niu_get_and_validate_port(struct niu *np)
}
}
+ /* num_ports may come from an 8-bit hardware field (ESPC_NUM_PORTS_MACS),
+ * so validate it against the fixed per-port array sizes (NIU_MAX_PORTS)
+ * to avoid out-of-bounds accesses in niu_divide_channels() and
+ * niu_divide_rdc_groups().
+ */
+ if (parent->num_ports > NIU_MAX_PORTS)
+ return -EINVAL;
+
if (np->port >= parent->num_ports)
return -ENODEV;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] niu: validate num_ports against NIU_MAX_PORTS
2026-08-25 9:42 [PATCH] niu: validate num_ports against NIU_MAX_PORTS Yang Zi
@ 2026-08-27 19:14 ` Jakub Kicinski
0 siblings, 0 replies; 2+ messages in thread
From: Jakub Kicinski @ 2026-08-27 19:14 UTC (permalink / raw)
To: Yang Zi; +Cc: David S. Miller, Eric Dumazet, Paolo Abeni, linux-kernel, netdev
On Tue, 25 Aug 2026 17:42:42 +0800 Yang Zi wrote:
> niu_get_and_validate_port() obtains parent->num_ports from hardware
> (nr64(ESPC_NUM_PORTS_MACS) & ESPC_NUM_PORTS_MACS_VAL), an 8-bit value that
> can range from 0 to 255, with no upper-bound check. The driver's per-port
> arrays (rxchan_per_port[], txchan_per_port[], rdc_group_cfg[]) are only
> NIU_MAX_PORTS (4) entries, so niu_divide_channels() and
> niu_divide_rdc_groups() iterate num_ports times and write out of bounds
> whenever num_ports is greater than 4.
>
> Reject num_ports > NIU_MAX_PORTS with -EINVAL so the probe aborts before any
> of these arrays are written.
>
> Covers fuzzing bug IDs 321, 322, 323 and 324 (same root cause).
>
> Signed-off-by: Yang Zi <2959243019@qq.com>
this is a waste of time, please don't send any more patches to linux
networking this year
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-08-27 19:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-25 9:42 [PATCH] niu: validate num_ports against NIU_MAX_PORTS Yang Zi
2026-08-27 19:14 ` Jakub Kicinski
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®