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;
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
© 2016 - 2026 Red Hat, Inc.