summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHeiner Kallweit <hkallweit1@gmail.com>2023-01-15 11:54:06 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-02-06 07:49:39 +0100
commitc431a3d642593bbdb99e8a9e3eed608b730db6f8 (patch)
tree750adeb5145ab177082bee9b53d15468293a7810 /drivers
parenta264cc6ded2d404f5e93642e39731972cd67b7df (diff)
downloadlinux-stable-c431a3d642593bbdb99e8a9e3eed608b730db6f8.tar.gz
linux-stable-c431a3d642593bbdb99e8a9e3eed608b730db6f8.tar.bz2
linux-stable-c431a3d642593bbdb99e8a9e3eed608b730db6f8.zip
net: mdio: validate parameter addr in mdiobus_get_phy()
[ Upstream commit 867dbe784c5010a466f00a7d1467c1c5ea569c75 ] 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: 7f854420fbfe ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/phy/mdio_bus.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 1d1fbd7bd6fc..550806351049 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -103,7 +103,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;