Skip to content

Commit

Permalink
net: mdio: validate parameter addr in mdiobus_get_phy()
Browse files Browse the repository at this point in the history
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 <hkallweit1@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://lore.kernel.org/r/cdf664ea-3312-e915-73f8-021678d08887@gmail.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
hkallweit authored and Paolo Abeni committed Jan 17, 2023
1 parent ecf7cf8 commit 867dbe7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drivers/net/phy/mdio_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ EXPORT_SYMBOL(mdiobus_unregister_device);

struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
{
struct mdio_device *mdiodev = bus->mdio_map[addr];
struct mdio_device *mdiodev;

if (addr < 0 || addr >= ARRAY_SIZE(bus->mdio_map))
return NULL;

mdiodev = bus->mdio_map[addr];

if (!mdiodev)
return NULL;
Expand Down

0 comments on commit 867dbe7

Please sign in to comment.