From nobody Wed Dec 17 12:18:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21F55C4167B for ; Sun, 26 Nov 2023 14:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229888AbjKZOOw (ORCPT ); Sun, 26 Nov 2023 09:14:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229996AbjKZOKs (ORCPT ); Sun, 26 Nov 2023 09:10:48 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38725FC for ; Sun, 26 Nov 2023 06:10:53 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-549070a04baso4579344a12.3 for ; Sun, 26 Nov 2023 06:10:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1701007851; x=1701612651; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Vf3BBbGgK38KEJry5f+skZG4ReehlnPep5PbY6SoWGQ=; b=CFYFTrSxcrA8TfeWR3G1Y5sOoDm20rR8R3NFf7ESSCc1n4ILNyrT7g0Y6sTs38NX3S jUW8ttrPG+5UZ4PbQKYpoESwyo5BSFnVjZSMrCiS3iD6nd/Ys41qcLD2deUV0fVNz/9X wGjcLv2FrQiB9qz7albIHwfi51Rr/dBofveH27wAjBhFmi4iCzkuTSjgBDl+zc4FTJT3 9f/PiDwuLdQxMKvLL9r2djR9lY5Ad8cucSlmk8SZwQSSKSfiUvHc56mnOKp/LbRsLWqJ 1nDqoLj1CNesd3K+MAl3vzxIoVh53/xip0H+gwRNY4x+0v8esbFbCKYBPM5aa9O/0TnP w2Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701007851; x=1701612651; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Vf3BBbGgK38KEJry5f+skZG4ReehlnPep5PbY6SoWGQ=; b=WuZaBt4KGPcc/NIMAw1eqKfPBKRnubGFT7aJx+7VwyyYbAjNzfu/yk4rZ0LSLw4NPt ruimV3Nwq9yVB6UuJt0n4qpDe91fB0qlXkzQXHJE4ccYJSzxG8ar1sjwndMZFMrGHAOv BfWRoj05z3LNPnccPI/OlATfHZ0kx692nXDESDe1mNnJhmy9r4+UpKRSTTuBHAdNoD86 QQsctPj3iDRHU0RHWlI7Spk4J6GMoqnR/B/uqS5cbay2Nd5ZBBa4lo+m2usOSgem0MEA BN2NFGWNCIV47DlVb/+2QSq5x2/DIy1XgxX+lyDh/G0BA11sh/LXY2mZdYZaYGGRLsua 2kSA== X-Gm-Message-State: AOJu0YxxSnbwWM5YFXNThpEcack5bxv+CjptqY/ji9HPfShF3xnGx5A4 okhDv5UMENiosoaEbgO34q2Gsw== X-Google-Smtp-Source: AGHT+IFQxU7KH05yMJU+q5DjIE3FNct1n5ReGHCv7CyKkjdrnTGipQuhi7GpiH5b23rMBzVDJj8YEQ== X-Received: by 2002:a17:906:4e:b0:a0d:a567:b92a with SMTP id 14-20020a170906004e00b00a0da567b92amr1525873ejg.39.1701007851676; Sun, 26 Nov 2023 06:10:51 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.125]) by smtp.gmail.com with ESMTPSA id mb22-20020a170906eb1600b009fc0c42098csm4603423ejb.173.2023.11.26.06.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 06:10:51 -0800 (PST) From: Claudiu Beznea To: nicolas.ferre@microchip.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, jgarzik@pobox.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Claudiu Beznea Subject: [PATCH 1/2] net: phy: Check phydev->drv before dereferencing it Date: Sun, 26 Nov 2023 16:10:45 +0200 Message-Id: <20231126141046.3505343-2-claudiu.beznea@tuxon.dev> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231126141046.3505343-1-claudiu.beznea@tuxon.dev> References: <20231126141046.3505343-1-claudiu.beznea@tuxon.dev> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The macb driver calls mdiobus_unregister() and mdiobus_free() in its remove function before calling unregister_netdev(). unregister_netdev() calls the driver-specific struct net_device_ops::ndo_stop function (macb_close()), and macb_close() calls phylink_disconnect_phy(). This, in turn, will call: phy_disconnect() -> phy_free_interrupt() -> phy_disable_interrupts() -> phy_config_interrupt() which dereference phydev->drv, which was already freed by: mdiobus_unregister() -> phy_mdio_device_remove() -> device_del() -> bus_remove_device() -> device_release_driver_internal() -> phy_remove() from macb_close(). Although the sequence in the macb driver is not correct, check phydev->drv = =C2=A0 =C2=A0 =C2=A0 before dereferencing it in phy_config_interrupt() to avoid scenarios like the one described. Fixes: 00db8189d984 ("This patch adds a PHY Abstraction Layer to the Linux = Kernel") Signed-off-by: Claudiu Beznea --- drivers/net/phy/phy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index a5fa077650e8..dd98a4b3ef81 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -165,7 +165,7 @@ EXPORT_SYMBOL_GPL(phy_get_rate_matching); static int phy_config_interrupt(struct phy_device *phydev, bool interrupts) { phydev->interrupts =3D interrupts ? 1 : 0; - if (phydev->drv->config_intr) + if (phydev->drv && phydev->drv->config_intr) return phydev->drv->config_intr(phydev); =20 return 0; --=20 2.39.2 From nobody Wed Dec 17 12:18:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 629B8C07D5A for ; Sun, 26 Nov 2023 14:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229935AbjKZOOy (ORCPT ); Sun, 26 Nov 2023 09:14:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230024AbjKZOKt (ORCPT ); Sun, 26 Nov 2023 09:10:49 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7842C102 for ; Sun, 26 Nov 2023 06:10:54 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-549070a04baso4579356a12.3 for ; Sun, 26 Nov 2023 06:10:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1701007853; x=1701612653; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=G30K0Y0szZ7FUxHtENoJCMPPG9CnH+Xt3mCwLqz9nTs=; b=R0MX3P5LKjKuWKFRvvhT4ZhtCc0A76L6j7srJtLOFr4VpkDDxABcnOCbS3IMDtAjsU 5lhC4La+Jnp26BQT/2WynYmzyHKY0+LVBATBCT8hWyXDpZDl4umD5LBJgF1zNxdn5z7T qQx2FMIu5Z3ySuqZj5TPTCBhe0OksBcfNJxm17K7VGYQ281TRLEVD5mCJJGvO+Dsdau8 68Rs//BWrI6PDntJU1oUFdWfIHYBJbXhozuVBIaw2WJFwB2pipzPGceFTEIja9KUgCsK +fpPJgabDHuQauXLlIuuD3AoJW1Af3ngyZ0+eTgjk3q93y5vdkESaH7G8/n3WjENvTxr o5jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701007853; x=1701612653; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G30K0Y0szZ7FUxHtENoJCMPPG9CnH+Xt3mCwLqz9nTs=; b=NUQoPOY9d6sc5D08UUDEVDEeZBnC+rhdc7gJuN+yrIBaelTNMl3MMOxjy5IpxmFQa8 eApgNFxT8joN++pDv+EUfx4LZ+pAgnJfawX0wvIH05/3RkDbS+ThGtV5+nbh/XEIWy52 W4nfDXpCQCkA4FEyb4q/VzA3iT5sM+y7VE6uUPtsc0ta3LenpUdE1S7HGeZhvoaCiM4e uyndG9oozmH9tDdXYr4sebY1gFy1beyn5eXMkHsi/OYZjY+5jfdH/OiDXlxihnDz5dMw MmfnU5L0zAdlbAyM2uQxcYbJkGzDO5uNLz6THsCe8GHlNMEl0LcgPUTKeqS9OGibTUxG F0Mw== X-Gm-Message-State: AOJu0YxMeaWZdWqLbgcPC/nIzKCE2W0DoH/YPYCrXq+u0bHQgCgznV8x Rx8ax7vPy85/0RmQXo9YfY4BXw== X-Google-Smtp-Source: AGHT+IHchuuV9GIsfhQWjw/7BZ/J4Ph2nLVq3ar7gUWKPuajHEh5h7gDvjAB7XKvfY1lncPbjEnouw== X-Received: by 2002:a17:906:10d7:b0:a0c:87e4:8097 with SMTP id v23-20020a17090610d700b00a0c87e48097mr2048227ejv.66.1701007853102; Sun, 26 Nov 2023 06:10:53 -0800 (PST) Received: from claudiu-X670E-Pro-RS.. ([82.78.167.125]) by smtp.gmail.com with ESMTPSA id mb22-20020a170906eb1600b009fc0c42098csm4603423ejb.173.2023.11.26.06.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 06:10:52 -0800 (PST) From: Claudiu Beznea To: nicolas.ferre@microchip.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk, jgarzik@pobox.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Claudiu Beznea Subject: [PATCH 2/2] net: macb: Unregister nedev before MDIO bus in remove Date: Sun, 26 Nov 2023 16:10:46 +0200 Message-Id: <20231126141046.3505343-3-claudiu.beznea@tuxon.dev> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231126141046.3505343-1-claudiu.beznea@tuxon.dev> References: <20231126141046.3505343-1-claudiu.beznea@tuxon.dev> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" unregister_netdev() calls the struct net_device_ops::ndo_stop function, which in the case of the macb driver is macb_close(). macb_close() calls, in turn, PHY-specific APIs (e.g., phy_detach()). The call trace is as follows: macb_close() -> phylink_disconnect_phy() -> phy_disconnect() -> phy_detach() phy_detach() will remove associated sysfs files by calling kernfs_remove_by_name_ns(), which will hit "kernfs: cannot remove 'attached_dev', no directory" WARN(), which will throw a stack trace too. To avoid this, call unregiser_netdev() before mdiobus_unregister() and mdiobus_free(). Fixes: 7897b071ac3b ("net: macb: convert to phylink") Signed-off-by: Claudiu Beznea Reviewed-by: Russell King (Oracle) --- drivers/net/ethernet/cadence/macb_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/etherne= t/cadence/macb_main.c index cebae0f418f2..73d041af3de1 100644 --- a/drivers/net/ethernet/cadence/macb_main.c +++ b/drivers/net/ethernet/cadence/macb_main.c @@ -5165,11 +5165,11 @@ static void macb_remove(struct platform_device *pde= v) =20 if (dev) { bp =3D netdev_priv(dev); + unregister_netdev(dev); phy_exit(bp->sgmii_phy); mdiobus_unregister(bp->mii_bus); mdiobus_free(bp->mii_bus); =20 - unregister_netdev(dev); tasklet_kill(&bp->hresp_err_tasklet); pm_runtime_disable(&pdev->dev); pm_runtime_dont_use_autosuspend(&pdev->dev); --=20 2.39.2