Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1826297pxb; Wed, 9 Feb 2022 05:25:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJwO45OZ/uOwTrwB1ZTJQQsE2P66MrDxN7rsqLzx/29MvAO+w7k/sIQ46fiztZF0/dYqE4z1 X-Received: by 2002:aa7:87c7:: with SMTP id i7mr2307293pfo.83.1644413146077; Wed, 09 Feb 2022 05:25:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644413146; cv=none; d=google.com; s=arc-20160816; b=SmUyVcu4FuajCe0/eFg382utHzEo8V0jPrNlEeCGeOba5KGrKyeMDRB8EiSAxB4vmO 63xTBiEHzW9+nVfvIAcKykcaX1Nb1fuin9Zwe/CE2JiZyzGhZdl0xhlwWijItZunXLrE 5nKa2+CygnuYQ0cc0lxEojOlkSwlAj9hu1nCXT8WotBHSO1qZD8MUPTJXWXSxdovn+ij pXTw0/FjX2uLd6/qx/SCZsACtegsOKLHrR3gm4n2qkMVsIHi9nHbf5/CvDIBh39sWRpR rkqOEOkV6nsUA1SBurjI2wbk0IQg4rHeRHYQWWeOP8cnP+gCWRjHWpbV4/baE0e4Hc3v UAEw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=b7dImjafTki12SZZZ/+gQQZrjVZZ5aUBhdnzJ2H1ATY=; b=rSibU6Egja2HDGxmeg9qCRgZRuSVzOZ6I5kHya6NGjHokGbfOFD+sHuhZXq9JV1Hgr TY/unRqaCnkT8wK6LI6wNr4FtnuozHEYE59Sj7uDP1EZq4wOQJ0v6Obl9qipTThXu0NC 6dG8bA25OrOHtKF3GUGYhHm3PUo80NixisFQ6zVYEEnh3QV8hF0y/Xqt/bfs/Uh156x2 fnLFIcybLs7f7sRx03fklQD0E9sVJoCzuGA2WPn6GEKidzPJgt04EwaqOA+oMO6Dyg06 aY0zVEXzNreRSG34ul+hKEosnAiswImUBFWc0mYl/P1LNgK69h8VzkRqwpXjeIPTOO4B oN0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sBBVUiQI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id l17si8229182plg.143.2022.02.09.05.25.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 05:25:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sBBVUiQI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 23A99E088FD6; Wed, 9 Feb 2022 02:11:25 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382953AbiBGLVO (ORCPT + 99 others); Mon, 7 Feb 2022 06:21:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378393AbiBGLPu (ORCPT ); Mon, 7 Feb 2022 06:15:50 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E3BCC03FEE8; Mon, 7 Feb 2022 03:15:31 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DCA0C6113B; Mon, 7 Feb 2022 11:15:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2460C004E1; Mon, 7 Feb 2022 11:15:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232530; bh=2OOCeYXrVO5I2xFEe1arKQB7R0jBUJ86hcpONKyUaUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sBBVUiQIBmGhpxNd1dSxkMMFxIEwbxJWPhH286x66Qhhz3D+JTOmZnxqm/ZcpO/wM IxsxryPQIGTtEBlTufbDLj4r6L4MIrKawdQ++zVqQR9lEdmU5gs1HNmHzQHL7VmGIH 4D4inhjXVhBRn0sZ6iAxZX/PdBXxHJP0x56OtBA8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Marek=20Beh=C3=BAn?= , Andrew Lunn , Jakub Kicinski , Sasha Levin Subject: [PATCH 4.19 40/86] phylib: fix potential use-after-free Date: Mon, 7 Feb 2022 12:06:03 +0100 Message-Id: <20220207103758.845485398@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.550973048@linuxfoundation.org> References: <20220207103757.550973048@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marek BehĂșn [ Upstream commit cbda1b16687580d5beee38273f6241ae3725960c ] Commit bafbdd527d56 ("phylib: Add device reset GPIO support") added call to phy_device_reset(phydev) after the put_device() call in phy_detach(). The comment before the put_device() call says that the phydev might go away with put_device(). Fix potential use-after-free by calling phy_device_reset() before put_device(). Fixes: bafbdd527d56 ("phylib: Add device reset GPIO support") Signed-off-by: Marek BehĂșn Reviewed-by: Andrew Lunn Link: https://lore.kernel.org/r/20220119162748.32418-1-kabel@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/phy/phy_device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index b884b681d5c52..a03d0627efb06 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1166,6 +1166,9 @@ void phy_detach(struct phy_device *phydev) phydev->mdio.dev.driver == &genphy_driver.mdiodrv.driver) device_release_driver(&phydev->mdio.dev); + /* Assert the reset signal */ + phy_device_reset(phydev, 1); + /* * The phydev might go away on the put_device() below, so avoid * a use-after-free bug by reading the underlying bus first. @@ -1175,9 +1178,6 @@ void phy_detach(struct phy_device *phydev) put_device(&phydev->mdio.dev); if (ndev_owner != bus->owner) module_put(bus->owner); - - /* Assert the reset signal */ - phy_device_reset(phydev, 1); } EXPORT_SYMBOL(phy_detach); -- 2.34.1