Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp3764621pxt; Tue, 10 Aug 2021 10:46:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtEsVBvQ1U273lghRzhdVSOW7lI+ZW24EOkIRRR4Be6F0ejFiByFsrqD5fJ1FfaUAdGJgT X-Received: by 2002:a5d:8754:: with SMTP id k20mr119866iol.160.1628617618530; Tue, 10 Aug 2021 10:46:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628617618; cv=none; d=google.com; s=arc-20160816; b=GgT39GEAEL6yujOrDAtAkuXY6YscQ5wGglGOTqf8rlgMa059z6j39yiWwTwxBBTXND Gfv93XGYevm/bEU+xXMCeKrSMQ1UXHnc1H0qXKQYJJfEUfgIIG/QW6xFU8JZkESStlX9 e4GewhV/qME8uW8iFnwUVGoJimR+TA7k5MEBuXbY7sUAPlIZUS/5bqSkcpU+/ZJ5rPaF BD6/ULC0Tj3b/aF0uuOa78OWZK3O3t14cjI6K0Ln/mbLR5EIeiw7vvugXWuVJlwKA5aj Q117KFADHDdBc0X8+gQdT/97ekgr90mVzzMVG3pqlnP/H3tzbKRsQ482S7bBXYQdqwDk HgQg== 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=MQdUsBZ5SrB3qxRnD0h2ExwJi0guIUHH+Ii6aBHgz80=; b=XucLvXX3Jsgpqgk1fK60cM75WB2QMA1/oj75oG6by4DV77SwZOeWezDA2vOU+jNZ5R uQYyz8OPCP6bP2i45l4fRIWXbaba1182wNW/JV/Vmt9+pS4+6k708idTXYh7p1XEuiwW /DLwdWzMWRxciZtJfqxuLDHIj1oEKUAx9eeit9VMWfmXvjjUphLXCidIH27E6QOuPazb ktao8eMIpnOASL1ObLI8VNOjO7ajHNznjI27Yqx0YX0ML4J3DQxEbVyDp9MkpCjxqXPf uAyyVLDnOYadCApTBez4VoFB4imGe0UsehwB6iMqleNG13paH/d0bt53EhdKUNnOw0vy r88w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=b6wiF0PL; 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 o5si14206508iom.2.2021.08.10.10.46.45; Tue, 10 Aug 2021 10:46:58 -0700 (PDT) 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=b6wiF0PL; 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 S233301AbhHJRpV (ORCPT + 99 others); Tue, 10 Aug 2021 13:45:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:40876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234778AbhHJRlj (ORCPT ); Tue, 10 Aug 2021 13:41:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9D5166120F; Tue, 10 Aug 2021 17:38:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628617106; bh=h3W6hhQNLv3fu+R1/iMHBKXUZ+eMpz8K5au5yk05sFU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b6wiF0PLv7tJr53XRJwJZi7KpTm8tq5rT62cUgGVoqNm3JnsyFPiD7TifDat3j3a+ dZLkY62opxoP/sFU5rc05bM6mAua0bgK43oyE7tPuBc038q11jclzL6uT3DPaZus6c ti6QJnCaINjbu1RCStjg2PeIjN6z4R9rMzNx8M6I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Pavel Skripkin , Joakim Zhang , Jesse Brandeburg , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 048/135] net: fec: fix use-after-free in fec_drv_remove Date: Tue, 10 Aug 2021 19:29:42 +0200 Message-Id: <20210810172957.323499161@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810172955.660225700@linuxfoundation.org> References: <20210810172955.660225700@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: Pavel Skripkin [ Upstream commit 44712965bf12ae1758cec4de53816ed4b914ca1a ] Smatch says: drivers/net/ethernet/freescale/fec_main.c:3994 fec_drv_remove() error: Using fep after free_{netdev,candev}(ndev); drivers/net/ethernet/freescale/fec_main.c:3995 fec_drv_remove() error: Using fep after free_{netdev,candev}(ndev); Since fep pointer is netdev private data, accessing it after free_netdev() call can cause use-after-free bug. Fix it by moving free_netdev() call at the end of the function Reported-by: Dan Carpenter Fixes: a31eda65ba21 ("net: fec: fix clock count mis-match") Signed-off-by: Pavel Skripkin Reviewed-by: Joakim Zhang Reviewed-by: Jesse Brandeburg Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/freescale/fec_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 2cb73e850a32..94eb838a0176 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -3822,13 +3822,13 @@ fec_drv_remove(struct platform_device *pdev) if (of_phy_is_fixed_link(np)) of_phy_deregister_fixed_link(np); of_node_put(fep->phy_node); - free_netdev(ndev); clk_disable_unprepare(fep->clk_ahb); clk_disable_unprepare(fep->clk_ipg); pm_runtime_put_noidle(&pdev->dev); pm_runtime_disable(&pdev->dev); + free_netdev(ndev); return 0; } -- 2.30.2