Skip to content

Commit 867dbe7

Browse files
hkallweitPaolo Abeni
authored andcommitted
net: mdio: validate parameter addr in mdiobus_get_phy()
The caller may pass any value as addr, what may result in an out-of-bounds access to array mdio_map. One existing case is stmmac_init_phy() that may pass -1 as addr. Therefore validate addr before using it. Fixes: 7f85442 ("phy: Add API for {un}registering an mdio device to a bus.") Signed-off-by: Heiner Kallweit <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent ecf7cf8 commit 867dbe7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/net/phy/mdio_bus.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,12 @@ EXPORT_SYMBOL(mdiobus_unregister_device);
108108

109109
struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
110110
{
111-
struct mdio_device *mdiodev = bus->mdio_map[addr];
111+
struct mdio_device *mdiodev;
112+
113+
if (addr < 0 || addr >= ARRAY_SIZE(bus->mdio_map))
114+
return NULL;
115+
116+
mdiodev = bus->mdio_map[addr];
112117

113118
if (!mdiodev)
114119
return NULL;

0 commit comments

Comments
 (0)