[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1a20853b-3c08-d6dc-4f1e-9f38fb197a37@gmail.com>
Date: Tue, 17 Jan 2023 21:43:08 +0100
From: Heiner Kallweit <hkallweit1@...il.com>
To: Paolo Abeni <pabeni@...hat.com>, Andrew Lunn <andrew@...n.ch>,
Russell King - ARM Linux <linux@...linux.org.uk>,
David Miller <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Eric Dumazet <edumazet@...gle.com>
Cc: "netdev@...r.kernel.org" <netdev@...r.kernel.org>
Subject: Re: [PATCH net] net: mdio: validate parameter addr in
mdiobus_get_phy()
On 17.01.2023 12:31, Paolo Abeni wrote:
> On Sun, 2023-01-15 at 11:54 +0100, Heiner Kallweit wrote:
>> The caller may pass any value as addr, what may result in an out-of-bounds
>> access to array mdio_map. One existing case is stmmac_init_phy() that
>> may pass -1 as addr. Therefore validate addr before using it.
>>
>> Fixes: 7f854420fbfe ("phy: Add API for {un}registering an mdio device to a bus.")
>> Signed-off-by: Heiner Kallweit <hkallweit1@...il.com>
>> ---
>> drivers/net/phy/mdio_bus.c | 7 ++++++-
>> 1 file changed, 6 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
>> index 902e1c88e..132dd1f90 100644
>> --- a/drivers/net/phy/mdio_bus.c
>> +++ b/drivers/net/phy/mdio_bus.c
>> @@ -108,7 +108,12 @@ EXPORT_SYMBOL(mdiobus_unregister_device);
>>
>> struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
>> {
>> - struct mdio_device *mdiodev = bus->mdio_map[addr];
>> + struct mdio_device *mdiodev;
>> +
>> + if (addr < 0 || addr >= ARRAY_SIZE(bus->mdio_map))
>> + return NULL;
>
> Speaking of possible follow-ups, would it make sense to add a
> WARN_ON_ONCE() or similar on the above condition?
>
Yes, I think that's a good idea.
I'll send a follow-up patch.
> Thanks!
>
> Paolo
>>
>
Powered by blists - more mailing lists