Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2838126rdh; Sun, 26 Nov 2023 23:11:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFCxOF0ZSemCZQP0dyrhQSEh+RjwmXBuf5VMWUub2yUc90G0sItsP6qEFwgwxbmEsQ1Pg/4 X-Received: by 2002:a05:6a21:3989:b0:187:a581:cc4e with SMTP id ad9-20020a056a21398900b00187a581cc4emr12026876pzc.29.1701069060075; Sun, 26 Nov 2023 23:11:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701069060; cv=none; d=google.com; s=arc-20160816; b=Qpjz0mq7KKURNsPrm4fUKFxoqENAkRdCx+pnxavX95G9AwbgfFZp0DKoXByIXsYYxO YRJ9z299kQhF7Ur9FWzZOv4JEeVmitv0LlCjC/pTHkSgj8MZ6Hqkvw8TbTYPGeATbmYk ncWud1RYiQIsQLkqt2tZouAtf+QWk1axEPi0T6TAmLVYEROns4VtmAV4IyYGZV1YoYzU dAycC/3DoOST9GylhHPgetBEOBaq0QSvEa+mYCK5dtovsl0BeaA3mBrnckVL3Ku/JnJA Xy1oQpuA+tWCbITLJ+uYfgKDNW1SHcLjlRZKTw+oOoUXHbMD7Y3+BAM+C99Rpynod8zD 01ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Vf3BBbGgK38KEJry5f+skZG4ReehlnPep5PbY6SoWGQ=; fh=LFcv2OHzfpz/VcIjGaAV3U9+3Y1V0RaOGvgbSTwNd8g=; b=WEATYYLKLD00UQ480mG60Zlt0SwgOas2HYVuaeKvDpYXUf2a+cjS0pVGsz1LtZexL7 c0eYoZfvxnUGrVc4SEM1q3kHc4c3ExxwIZNYwYm9fDc3K6Iyg0YL9PWovXNHVYHF+Yr4 KbTlhqdyfdtrkYmHKMj4E3oeq9FxUcZ2t4ANsDaLkaUU6FrZR1po9huUDomzh1dBvSZv A58X9lKe5LNOlOpiH/roGTx8W29mJblv1UrwvoZ30F+yo5fKNB2KnWmFl0Jo8yHMzxoA rgjToALavPf4VAZX4EKwlHbZsE99zmoY8oxv6GWIz8O0MXrTaQ7AlgQCaSJCNjq+6B9f vMBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tuxon.dev header.s=google header.b=CFYFTrSx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id a1-20020a170902ee8100b001cfa8f0e6dfsi6266785pld.496.2023.11.26.23.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Nov 2023 23:11:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@tuxon.dev header.s=google header.b=CFYFTrSx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 5EFE080811D2; Sun, 26 Nov 2023 06:15:06 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229843AbjKZOOv (ORCPT + 99 others); Sun, 26 Nov 2023 09:14:51 -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-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: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sun, 26 Nov 2023 06:15:06 -0800 (PST) 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       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 = interrupts ? 1 : 0; - if (phydev->drv->config_intr) + if (phydev->drv && phydev->drv->config_intr) return phydev->drv->config_intr(phydev); return 0; -- 2.39.2