Thread View: linux.kernel.netdev
5 messages
5 total messages
Started by Ziheng Wei
Sun, 15 Nov 2026 16:18
[PATCH net] net: phy: reject non-PHY mdio devices in phy_connect()
Author: Ziheng Wei
Date: Sun, 15 Nov 2026 16:18
Date: Sun, 15 Nov 2026 16:18
68 lines
10980 bytes
10980 bytes
phy_connect() resolves the PHY by name using bus_find_device_by_name()
and then casts the result to struct phy_device without verifying that
it actually is one.
Every mdio device is registered with the same name format (PHY_ID_FMT,
bus id and address), whether it is a struct phy_device or a bare
struct mdio_device. A DT node under an MDIO bus with a compatible
string that is not an ethernet-phy-* string is registered as a bare
mdio_device, which is the normal way to describe switches and PCS
devices on the same bus.
If such a device sits at the address a MAC driver passes to
phy_connect(), the name lookup succeeds and to_phy_device() derives a
struct phy_device pointer from a smaller struct mdio_device. Accessing
any field past the embedded mdio_device then reads out of bounds.
With a test module that registers a bare mdio_device and calls
phy_connect() on its bus id (QEMU, KASAN, v7.3.1):
BUG: KASAN: slab-out-of-bounds in phy_connect+0x196/0x200 [libphy]
Read of size 4 at addr ffff88801b270f2c by task insmod/162
Call Trace:
phy_connect+0x196/0x200 [libphy]
The same problem was fixed for of_phy_find_device() in commit
6ed742363b9c ("of: of_mdio: Ensure mdio device is a PHY"), and
fwnode_phy_find_device() in this file performs the check as well.
phy_connect() was left without it. Check MDIO_DEVICE_FLAG_PHY before
calling to_phy_device() and return -ENODEV for a non-PHY device.
Found by LLM-assisted source review. Reproduced only with the synthetic
test module above; no board is known to hit this. The fix was build
tested only; it was not run against the test module, selftests or
hardware.
Fixes: a9049e0c513c ("mdio: Add support for mdio drivers.")
Cc: stable@vger.kernel.org
Signed-off-by: Ziheng Wei <zihengw03@163.com>
---
Notes:
The changelog was drafted with an AI assistant from my analysis;
I have reviewed the code, the fix and the text.
drivers/net/phy/phy_device.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index b39e945ce..4f8f9cbc3 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1184,6 +1184,11 @@ struct phy_device *phy_connect(struct net_device *dev, const char *bus_id,
pr_err("PHY %s not found\n", bus_id);
return ERR_PTR(-ENODEV);
}
+ if (!(to_mdio_device(d)->flags & MDIO_DEVICE_FLAG_PHY)) {
+ pr_err("MDIO device %s is not a PHY\n", bus_id);
+ put_device(d);
+ return ERR_PTR(-ENODEV);
+ }
phydev = to_phy_device(d);
rc = phy_connect_direct(dev, phydev, handler, interface);
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
--
2.43.0
Re: [PATCH net] net: phy: reject non-PHY mdio devices in phy_connect()
Author: Andrew Lunn
Date: Sun, 15 Nov 2026 16:30
Date: Sun, 15 Nov 2026 16:30
7 lines
8354 bytes
8354 bytes
> Fixes: a9049e0c513c ("mdio: Add support for mdio drivers.")
> Cc: stable@vger.kernel.org
Who does this bother?
Andrew
Re: [PATCH net] net: phy: reject non-PHY mdio devices in phy_connect()
Author: Ziheng Wei
Date: Sun, 15 Nov 2026 16:42
Date: Sun, 15 Nov 2026 16:42
18 lines
9062 bytes
9062 bytes
On Sun, Nov 15, 2026 at 05:30:15PM +0100, Andrew Lunn wrote:
> > Fixes: a9049e0c513c ("mdio: Add support for mdio drivers.")
> > Cc: stable@vger.kernel.org
>
> Who does this bother?
Nobody that I know of. I found it by reading the code and could only
trigger it with a test module that registers a bare mdio_device at the
address passed to phy_connect(). I am not aware of a board or driver
that does this, so it does not belong in net or stable.
If you think the check is still worth having as hardening, I can send
it to net-next without the Fixes and stable tags. Otherwise please
drop it.
Thanks,
Ziheng
Re: [PATCH net] net: phy: reject non-PHY mdio devices in phy_connect()
Author: Andrew Lunn
Date: Sun, 15 Nov 2026 16:53
Date: Sun, 15 Nov 2026 16:53
22 lines
8909 bytes
8909 bytes
On Mon, Nov 16, 2026 at 12:42:33AM +0800, Ziheng Wei wrote:
> On Sun, Nov 15, 2026 at 05:30:15PM +0100, Andrew Lunn wrote:
> > > Fixes: a9049e0c513c ("mdio: Add support for mdio drivers.")
> > > Cc: stable@vger.kernel.org
> >
> > Who does this bother?
>
> Nobody that I know of.
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
> If you think the check is still worth having as hardening, I can send
> it to net-next without the Fixes and stable tags. Otherwise please
> drop it.
You have to defend your own patch. Do you think it is worth having?
Andrew
---
pw-bot: cr
Re: [PATCH net] net: phy: reject non-PHY mdio devices in phy_connect()
Author: Ziheng Wei
Date: Sun, 15 Nov 2026 17:03
Date: Sun, 15 Nov 2026 17:03
8 lines
8808 bytes
8808 bytes
On Sun, Nov 15, 2026 at 05:53PM +0100, Andrew Lunn wrote: > You have to defend your own patch. Do you think it is worth having? No. Without a real user hitting it, I don't think it is worth the churn. Please drop it, and thanks for the review. Ziheng
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads