Due to its design the MDIO driver needs to set up a port to bus/address mapping during probing. The "ethernet-ports" subnodes are scanned and from the "phy-handle" property the MDIO nodes are looked up. In case of a malformed device tree the driver might produce out-of-bounds accesses. The PHY address is not checked against the maximum supported address. Add a sanity check. Do not use the existing (unused) MAX_SMI_ADDR define but drop it in favour of PHY_MAX_ADDR. Signed-off-by: Markus Stockhausen --- drivers/net/mdio/mdio-realtek-rtl9300.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index 381c45e0597b..517b01115f34 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -78,7 +78,6 @@ #define MAX_PORTS 28 #define MAX_SMI_BUSSES 4 -#define MAX_SMI_ADDR 0x1f #define RAW_PAGE(priv) ((priv)->info->num_pages - 1) @@ -495,6 +494,9 @@ static int otto_emdio_map_ports(struct device *dev) if (err) return err; + if (addr >= PHY_MAX_ADDR) + return dev_err_probe(dev, -EINVAL, "illegal smi address %d\n", addr); + __set_bit(pn, priv->valid_ports); priv->smi_bus[pn] = bus; priv->smi_addr[pn] = addr; -- 2.54.0