* [PATCH net-next] net: mdio_bus: validate "addr" for mdiobus_is_registered_device()
@ 2023-07-24 15:57 Russell King (Oracle)
2023-07-25 21:23 ` Andrew Lunn
2023-07-26 3:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Russell King (Oracle) @ 2023-07-24 15:57 UTC (permalink / raw)
To: Andrew Lunn, Heiner Kallweit
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
netdev
mdiobus_is_registered_device() doesn't checking that "addr" was valid
before dereferencing bus->mdio_map[]. Extract the code that checks
this from mdiobus_get_phy(), and use it here as well.
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
---
I've had this patch kicking about for a while - probably a good idea?
It shouldn't cause a regression, but if it does it means we're already
dereferencing the arrray outside its bounds in
mdiobus_is_registered_device().
drivers/net/phy/mdio_bus.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index bc04048de2fa..25dcaa49ab8b 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -107,16 +107,21 @@ int mdiobus_unregister_device(struct mdio_device *mdiodev)
}
EXPORT_SYMBOL(mdiobus_unregister_device);
-struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
+static struct mdio_device *mdiobus_find_device(struct mii_bus *bus, int addr)
{
bool addr_valid = addr >= 0 && addr < ARRAY_SIZE(bus->mdio_map);
- struct mdio_device *mdiodev;
if (WARN_ONCE(!addr_valid, "addr %d out of range\n", addr))
return NULL;
- mdiodev = bus->mdio_map[addr];
+ return bus->mdio_map[addr];
+}
+struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
+{
+ struct mdio_device *mdiodev;
+
+ mdiodev = mdiobus_find_device(bus, addr);
if (!mdiodev)
return NULL;
@@ -129,7 +134,7 @@ EXPORT_SYMBOL(mdiobus_get_phy);
bool mdiobus_is_registered_device(struct mii_bus *bus, int addr)
{
- return bus->mdio_map[addr];
+ return mdiobus_find_device(bus, addr) != NULL;
}
EXPORT_SYMBOL(mdiobus_is_registered_device);
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: mdio_bus: validate "addr" for mdiobus_is_registered_device()
2023-07-24 15:57 [PATCH net-next] net: mdio_bus: validate "addr" for mdiobus_is_registered_device() Russell King (Oracle)
@ 2023-07-25 21:23 ` Andrew Lunn
2023-07-26 3:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2023-07-25 21:23 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: Heiner Kallweit, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, netdev
On Mon, Jul 24, 2023 at 04:57:14PM +0100, Russell King (Oracle) wrote:
> mdiobus_is_registered_device() doesn't checking that "addr" was valid
> before dereferencing bus->mdio_map[]. Extract the code that checks
> this from mdiobus_get_phy(), and use it here as well.
>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] net: mdio_bus: validate "addr" for mdiobus_is_registered_device()
2023-07-24 15:57 [PATCH net-next] net: mdio_bus: validate "addr" for mdiobus_is_registered_device() Russell King (Oracle)
2023-07-25 21:23 ` Andrew Lunn
@ 2023-07-26 3:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-07-26 3:20 UTC (permalink / raw)
To: Russell King; +Cc: andrew, hkallweit1, davem, edumazet, kuba, pabeni, netdev
Hello:
This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Mon, 24 Jul 2023 16:57:14 +0100 you wrote:
> mdiobus_is_registered_device() doesn't checking that "addr" was valid
> before dereferencing bus->mdio_map[]. Extract the code that checks
> this from mdiobus_get_phy(), and use it here as well.
>
> Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
> ---
> I've had this patch kicking about for a while - probably a good idea?
> It shouldn't cause a regression, but if it does it means we're already
> dereferencing the arrray outside its bounds in
> mdiobus_is_registered_device().
>
> [...]
Here is the summary with links:
- [net-next] net: mdio_bus: validate "addr" for mdiobus_is_registered_device()
https://git.kernel.org/netdev/net-next/c/09bd2d7ddaed
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-07-26 3:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-24 15:57 [PATCH net-next] net: mdio_bus: validate "addr" for mdiobus_is_registered_device() Russell King (Oracle)
2023-07-25 21:23 ` Andrew Lunn
2023-07-26 3:20 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).