From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Jakub Raczynski <j.raczynski@samsung.com>,
andrew@lunn.ch, hkallweit1@gmail.com, netdev@vger.kernel.org,
Wenjing Shan <wenjing.shan@samsung.com>
Subject: Re: [PATCH 1/2] net/mdiobus: Fix potential out-of-bounds read/write access
Date: Thu, 26 Jun 2025 08:15:00 +0100 [thread overview]
Message-ID: <aFzzdP4Og_oim4-l@shell.armlinux.org.uk> (raw)
In-Reply-To: <0d51f36d-eee3-4455-a886-d6a979e8e891@sabinyo.mountain>
On Wed, Jun 25, 2025 at 10:23:17AM -0500, Dan Carpenter wrote:
> On Mon, Jun 09, 2025 at 05:31:46PM +0200, Jakub Raczynski wrote:
> > 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: 080bb352fad00 ("net: phy: Maintain MDIO device and bus statistics")
> > Signed-off-by: Jakub Raczynski <j.raczynski@samsung.com>
> > Reported-by: Wenjing Shan <wenjing.shan@samsung.com>
> > ---
> > drivers/net/phy/mdio_bus.c | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
> > index a6bcb0fee863..60fd0cd7cb9c 100644
> > --- a/drivers/net/phy/mdio_bus.c
> > +++ b/drivers/net/phy/mdio_bus.c
> > @@ -445,6 +445,9 @@ int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
> >
> > lockdep_assert_held_once(&bus->mdio_lock);
> >
> > + if (addr >= PHY_MAX_ADDR)
> > + return -ENXIO;
>
> addr is an int so Smatch wants this to be:
>
> if (addr < 0 || addr >= PHY_MAX_ADDR)
> return return -ENXIO;
>
> I think that although addr is an int, the actual values are limited to
> 0-U16_MAX?
0 to 31 inclusive.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
next prev parent reply other threads:[~2025-06-26 7:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20250609144014eucas1p2ee94d7aabff15fbadcc1af1fa64ce22d@eucas1p2.samsung.com>
2025-06-09 14:37 ` [PATCH] net/mdiobus: Fix potential out-of-bounds read/write access Jakub Raczynski
2025-06-09 14:57 ` Russell King (Oracle)
2025-06-09 15:31 ` [PATCH 1/2] " Jakub Raczynski
2025-06-09 15:31 ` [PATCH 2/2] net/mdiobus: Fix potential out-of-bounds clause 45 " Jakub Raczynski
2025-06-11 12:10 ` [PATCH 1/2] net/mdiobus: Fix potential out-of-bounds " patchwork-bot+netdevbpf
2025-06-25 15:23 ` Dan Carpenter
2025-06-25 16:38 ` Andrew Lunn
2025-06-26 7:15 ` Russell King (Oracle) [this message]
2025-06-26 8:55 ` Jakub Raczynski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aFzzdP4Og_oim4-l@shell.armlinux.org.uk \
--to=linux@armlinux.org.uk \
--cc=andrew@lunn.ch \
--cc=dan.carpenter@linaro.org \
--cc=hkallweit1@gmail.com \
--cc=j.raczynski@samsung.com \
--cc=netdev@vger.kernel.org \
--cc=wenjing.shan@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.