Skip to content

Commit 0e62969

Browse files
Jakub Raczynskidavem330
authored andcommitted
net/mdiobus: Fix potential out-of-bounds read/write access
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]>
1 parent d9816ec commit 0e62969

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

446446
lockdep_assert_held_once(&bus->mdio_lock);
447447

448+
if (addr >= PHY_MAX_ADDR)
449+
return -ENXIO;
450+
448451
if (bus->read)
449452
retval = bus->read(bus, addr, regnum);
450453
else
@@ -474,6 +477,9 @@ int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
474477

475478
lockdep_assert_held_once(&bus->mdio_lock);
476479

480+
if (addr >= PHY_MAX_ADDR)
481+
return -ENXIO;
482+
477483
if (bus->write)
478484
err = bus->write(bus, addr, regnum, val);
479485
else

0 commit comments

Comments
 (0)