net/mdiobus: Fix potential out-of-bounds clause 45 read/write access
authorJakub Raczynski <j.raczynski@samsung.com>
Mon, 9 Jun 2025 15:31:47 +0000 (17:31 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 11 Jun 2025 11:49:03 +0000 (12:49 +0100)
commit260388f79e94fb3026c419a208ece8358bb7b555
treed98917e9ad787c32108ec2458cd2567857bdba1a
parent0e629694126ca388916f059453a1c36adde219c4
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: 4e4aafcddbbf ("net: mdio: Add dedicated C45 API to MDIO bus drivers")
Signed-off-by: Jakub Raczynski <j.raczynski@samsung.com>
Reported-by: Wenjing Shan <wenjing.shan@samsung.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/mdio_bus.c