Skip to content

Commit 260388f

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

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
@@ -541,6 +541,9 @@ int __mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum)
541541

542542
lockdep_assert_held_once(&bus->mdio_lock);
543543

544+
if (addr >= PHY_MAX_ADDR)
545+
return -ENXIO;
546+
544547
if (bus->read_c45)
545548
retval = bus->read_c45(bus, addr, devad, regnum);
546549
else
@@ -572,6 +575,9 @@ int __mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regnum,
572575

573576
lockdep_assert_held_once(&bus->mdio_lock);
574577

578+
if (addr >= PHY_MAX_ADDR)
579+
return -ENXIO;
580+
575581
if (bus->write_c45)
576582
err = bus->write_c45(bus, addr, devad, regnum, val);
577583
else

0 commit comments

Comments
 (0)