Skip to content

Commit 4ded22f

Browse files
Jakub Raczynskigregkh
authored andcommitted
net/mdiobus: Fix potential out-of-bounds clause 45 read/write access
[ Upstream commit 260388f ] When using publicly available tools like 'mdio-tools' to read/write data from/to network interface and its PHY via C45 (clause 45) mdiobus, there is no verification of parameters passed to the ioctl and it accepts any mdio address. Currently there is support for 32 addresses in kernel via PHY_MAX_ADDR define, but it is possible to pass higher value than that via ioctl. While read/write operation should generally fail in this case, mdiobus provides stats array, where wrong address may allow out-of-bounds read/write. Fix that by adding address verification before C45 read/write operation. While this excludes this access from any statistics, it improves security of read/write operation. Fixes: 4e4aafc ("net: mdio: Add dedicated C45 API to MDIO bus drivers") Signed-off-by: Jakub Raczynski <[email protected]> Reported-by: Wenjing Shan <[email protected]> Signed-off-by: David S. Miller <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 049af7a commit 4ded22f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/net/phy/mdio_bus.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,9 @@ int __mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum)
999999

10001000
lockdep_assert_held_once(&bus->mdio_lock);
10011001

1002+
if (addr >= PHY_MAX_ADDR)
1003+
return -ENXIO;
1004+
10021005
if (bus->read_c45)
10031006
retval = bus->read_c45(bus, addr, devad, regnum);
10041007
else
@@ -1030,6 +1033,9 @@ int __mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regnum,
10301033

10311034
lockdep_assert_held_once(&bus->mdio_lock);
10321035

1036+
if (addr >= PHY_MAX_ADDR)
1037+
return -ENXIO;
1038+
10331039
if (bus->write_c45)
10341040
err = bus->write_c45(bus, addr, devad, regnum, val);
10351041
else

0 commit comments

Comments
 (0)