All of lore.kernel.org
 help / color / mirror / Atom feed
From: FUJITA Tomonori <tomo@flapping.org>
To: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com
Cc: hfdevel@gmx.net, johan@kernel.org, netdev@vger.kernel.org,
	FUJITA Tomonori <fujita.tomonori@gmail.com>
Subject: [PATCH net] net: tn40xx: terminate the PHY software node property array
Date: Tue, 24 Nov 2026 16:26:46 +0900	[thread overview]
Message-ID: <20261124072646.3438910-1-tomo@flapping.org> (raw)

From: FUJITA Tomonori <fujita.tomonori@gmail.com>

The PHY software node uses phy_props[] as its property array. The array
has three entries and no empty entry at the end. Property lookups walk
the array until they find an entry with a NULL name, so they read past
the end of phy_props[].

This happens on every probe of a TN9510 card. When the AQR105 PHY is
registered, mdio_device_register_reset() looks up "reset-gpios" and
"reset-assert-us", and the PHY node has neither of them.

On 32-bit kernels, the walk reads napi.weight in struct tn40_priv as a
name pointer. napi.weight is 64 at this point, so strcmp()
dereferences address 0x40 and the kernel crashes.

On 64-bit kernels, there is no crash only because of the struct
layout: the NULL entry at the end of group[] happens to be at the
offset of a name field, so the walk stops there.

All the properties are constant. Define them in a static const array
with an empty entry at the end, which is the usual way to define
software node properties.

Found by code inspection. The 32-bit crash was reproduced in QEMU with
a test module that sets up the software nodes in struct tn40_priv in
the same way as the driver. The fix was tested on a TN9510 card on
x86_64.

Fixes: 25b6a6d29d40 ("net: tn40xx: create swnode for mdio and aqr105 phy and add to mdiobus")
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
 drivers/net/ethernet/tehuti/tn40.h      |  1 -
 drivers/net/ethernet/tehuti/tn40_mdio.c | 14 ++++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/tehuti/tn40.h b/drivers/net/ethernet/tehuti/tn40.h
index 25da8686d469..73c81cb3e23e 100644
--- a/drivers/net/ethernet/tehuti/tn40.h
+++ b/drivers/net/ethernet/tehuti/tn40.h
@@ -127,7 +127,6 @@ enum tn40_swnodes {
 struct tn40_nodes {
 	char phy_name[32];
 	char mdio_name[32];
-	struct property_entry phy_props[3];
 	struct software_node swnodes[SWNODE_MAX];
 	const struct software_node *group[SWNODE_MAX + 1];
 };
diff --git a/drivers/net/ethernet/tehuti/tn40_mdio.c b/drivers/net/ethernet/tehuti/tn40_mdio.c
index fb1a4a2e4dbc..c6139f92c23e 100644
--- a/drivers/net/ethernet/tehuti/tn40_mdio.c
+++ b/drivers/net/ethernet/tehuti/tn40_mdio.c
@@ -113,6 +113,13 @@ static int tn40_mdio_write_c45(struct mii_bus *mii_bus, int addr, int devnum,
 	return  tn40_mdio_write(mii_bus->priv, addr, devnum, regnum, val);
 }
 
+static const struct property_entry tn40_phy_props[] = {
+	PROPERTY_ENTRY_STRING("compatible", "ethernet-phy-id03a1.b4a3"),
+	PROPERTY_ENTRY_U32("reg", 1),
+	PROPERTY_ENTRY_STRING("firmware-name", AQR105_FIRMWARE),
+	{ }
+};
+
 /* registers an mdio node and an aqr105 PHY at address 1
  * tn40_mdio-%id {
  *	ethernet-phy@1 {
@@ -139,14 +146,9 @@ static int tn40_swnodes_register(struct tn40_priv *priv)
 
 	swnodes[SWNODE_MDIO] = NODE_PROP(nodes->mdio_name, NULL);
 
-	nodes->phy_props[0] = PROPERTY_ENTRY_STRING("compatible",
-						    "ethernet-phy-id03a1.b4a3");
-	nodes->phy_props[1] = PROPERTY_ENTRY_U32("reg", 1);
-	nodes->phy_props[2] = PROPERTY_ENTRY_STRING("firmware-name",
-						    AQR105_FIRMWARE);
 	swnodes[SWNODE_PHY] = NODE_PAR_PROP(nodes->phy_name,
 					    &swnodes[SWNODE_MDIO],
-					    nodes->phy_props);
+					    tn40_phy_props);
 
 	nodes->group[SWNODE_PHY] = &swnodes[SWNODE_PHY];
 	nodes->group[SWNODE_MDIO] = &swnodes[SWNODE_MDIO];

base-commit: 4392bb809812ac79449cd0cf1f5e00469ee102d1
-- 
2.43.0


             reply	other threads:[~2026-11-24  7:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  7:26 FUJITA Tomonori [this message]
2026-11-25 16:57 ` [PATCH net] net: tn40xx: terminate the PHY software node property array Andrew Lunn
2026-11-25 22:21   ` FUJITA Tomonori
2026-11-30  3:50 ` patchwork-bot+netdevbpf

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=20261124072646.3438910-1-tomo@flapping.org \
    --to=tomo@flapping.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=fujita.tomonori@gmail.com \
    --cc=hfdevel@gmx.net \
    --cc=johan@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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.