Skip to content

Commit 049af7a

Browse files
Jakub Raczynskigregkh
authored andcommitted
net/mdiobus: Fix potential out-of-bounds read/write access
[ Upstream commit 0e62969 ] When using publicly available tools like 'mdio-tools' to read/write data from/to network interface and its PHY via 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 read/write operation. While this excludes this access from any statistics, it improves security of read/write operation. Fixes: 080bb35 ("net: phy: Maintain MDIO device and bus statistics") 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 7a4b2ff commit 049af7a

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
@@ -903,6 +903,9 @@ int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
903903

904904
lockdep_assert_held_once(&bus->mdio_lock);
905905

906+
if (addr >= PHY_MAX_ADDR)
907+
return -ENXIO;
908+
906909
if (bus->read)
907910
retval = bus->read(bus, addr, regnum);
908911
else
@@ -932,6 +935,9 @@ int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
932935

933936
lockdep_assert_held_once(&bus->mdio_lock);
934937

938+
if (addr >= PHY_MAX_ADDR)
939+
return -ENXIO;
940+
935941
if (bus->write)
936942
err = bus->write(bus, addr, regnum, val);
937943
else

0 commit comments

Comments
 (0)