Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp866541pxb; Tue, 1 Feb 2022 12:03:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJw/5i7amxqW335CMRV/8xOXqbqGhVnbbDcb8cgd2zoH6B3HyPF0agAMpQXRaAFULd027y6N X-Received: by 2002:aa7:d6c5:: with SMTP id x5mr26438798edr.29.1643745834605; Tue, 01 Feb 2022 12:03:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745834; cv=none; d=google.com; s=arc-20160816; b=EqrnlG1wk0QG7faU55TugufiAFS9s8mcCqTfbTWXN0cAD19gJ5WsNiJOU+74vGZ64A FcYCQawP4VY/Mo+vGgP6v8KGoCKJFglzxuGEBRDD9RjU+neqF5JcRs54Ie45FHjbs7qw JXBgJVtrw+eUVKBZbgTJROs26broln16iP/tXEvbdPwQfzUldkwWmPZFwAV9LHBkspBH VtNtk23uMCznHr7ahaQGz1JdOcjps8iNHmGNwAlAtX8jaOBo/TJwHvKfhkHCRk+QcGVK d68RtS6vIbXJBS4hPVJfoKM5rrS9OTkVQDsREUd6ubQS8XaZmX9daMOnZLaQ0NVwyBg5 5DIQ== 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=LrWBItwsPVihanNQtVYZPW2rc2ZkJUUK4pDyi6W33rQ=; b=BePvOZE9Pdp/othuJ/8QXeZmHN9ilY6KjGDqXRj/D/AnD9R1H0BPlqU3f1u7nlZ02H VxDI2zsr/41i1+RXbQtFLMGP4DKz58OtxF9/oI3r5pv3i4JlS3POjjW4XN3aQxfLZ2g/ D2T7+rXbeTsiGx+0KjN3ftMT4LbjIRy4jcc3Ad9cJO8lBnr/LCKmHgkig189DsVOPZRN RkowgcU7Dz0VrDfhQsNkh/GSS/S7dIFwZj0wifJ77S41cLwfiehGpIxXcVLjFt2OLH8O +jDOYWg1wDUUfRc6C8RiS5BUQKRb/kZPO496qGECZfcst60QDJVjoybIGldheOYV8lGv piUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xWDc+pOi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w6si12647628edu.367.2022.02.01.12.03.28; Tue, 01 Feb 2022 12:03:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xWDc+pOi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359687AbiAaLRD (ORCPT + 99 others); Mon, 31 Jan 2022 06:17:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377216AbiAaLJs (ORCPT ); Mon, 31 Jan 2022 06:09:48 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3350CC0604D4; Mon, 31 Jan 2022 03:06:36 -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 ams.source.kernel.org (Postfix) with ESMTPS id E760BB82A5C; Mon, 31 Jan 2022 11:06:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39E48C340EF; Mon, 31 Jan 2022 11:06:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643627193; bh=fwtUg8Y8iUk8jIUE8qbO9EPXZyhnyzScNpHop/rrleU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xWDc+pOiguFC7IEfLsIlnY0PT41t7VOWSqXsmpZAlP7mURjT/svW3gjYBOeux0qjn MI9G5+24s7GL9/H+nk7a2u/hopas68UklEuQTEogN1F004v90bkIcTERe58TyT1BUT gSnXxuVYyBzFqfNhFPIXzutSEco4rPZsa4EPJTGY= 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 5.10 074/100] phylib: fix potential use-after-free Date: Mon, 31 Jan 2022 11:56:35 +0100 Message-Id: <20220131105222.910242948@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105220.424085452@linuxfoundation.org> References: <20220131105220.424085452@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 85f3cde5ffd09..d2f6d8107595a 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -1682,6 +1682,9 @@ void phy_detach(struct phy_device *phydev) phy_driver_is_genphy_10g(phydev)) 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. @@ -1693,9 +1696,6 @@ void phy_detach(struct phy_device *phydev) ndev_owner = dev->dev.parent->driver->owner; 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