From: FUJITA Tomonori 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 --- 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