Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3939884pxj; Mon, 21 Jun 2021 09:48:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyW/com9RVKQ/aW2kXP4SEMdcDVlGH0lC6r74LVafFn6KfDlfEn0KJSkTRhaxz3FdWymMa6 X-Received: by 2002:a17:907:62a5:: with SMTP id nd37mr25619633ejc.148.1624294132305; Mon, 21 Jun 2021 09:48:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624294132; cv=none; d=google.com; s=arc-20160816; b=XH7CbT8V/1In6XFLLnVXqnguHToXu6PaTzpPlI+mkS70SQMoVuoB3cha7Rv0+VH876 xab3jcHve0n4EYlYZRDaq3DGMYA4x0ZBV81g87KR4ZZcmJpCfd3j5aJybfcmDMYnR4GS ISgOi7OM/jlDElkviNXPy4ousV1Tn9eeb3OMa6pXpYBfxtMKIEygOQtmmnqPo9gcMK81 WaDdkZYmPPmFRYQMvOG7P+OX2M4q769z1ygMC7haX9AuHOm9xxOaQEFw2NZmMTWapyci bEuV7z/5B1c/CI+od6awhrEnfDwXtqWSHNZ7xnFkX/eDydHmh8ydDLOXIwEOGhHxsMb2 CfnQ== 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=C15nEWinP818Qrt6nUAR5bXnLVlPCxxtJpk9d+QK4yI=; b=JJOmCqi86SMFPXMs8RApB0w/DwQb2vtKYR9yeXssTCSlHOtoyDwbNEBJ5auj4FHWhq TaBs3rgQ7cmyHuHLV5/M/nThxO6VoEDSE2dU9iHpqOYBJ3iy9FHuteY3sRe+0geuz1+U vaka4WAeSL9kzGY9SVaXil+ysY454RPOr9/jY9P0nCbBbdKoRkH7UtiuwKeGjzizFiJK tApoZQXvrEPzLmDU0xb+qX2BjMjA75w11dnCOQ+mwk6B1/SyvogrjAN8hoKXN13LylG8 tmX+7EKxX/qyTz2HewUdHRh8UZ98dFLg7JDXh5AtmM193bqDphyVIyxyyUCmBBPl7I42 22mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t4hT1p1I; 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 el21si1504929ejc.33.2021.06.21.09.48.25; Mon, 21 Jun 2021 09:48:52 -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=t4hT1p1I; 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 S230102AbhFUQrH (ORCPT + 99 others); Mon, 21 Jun 2021 12:47:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:33540 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233065AbhFUQl7 (ORCPT ); Mon, 21 Jun 2021 12:41:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 10BDE613FA; Mon, 21 Jun 2021 16:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624293073; bh=GPZlmCmG5Ozv64hMj2PJFVS6AWHaoBhOPRTJYmhJWpc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t4hT1p1ITPhjQW8B58ecr+0T3ppxqXjgeQ32mBgwawhevsdXZFWNkrr0SoJ2ws0OM yDigHdtGswYl5KiiYWRqpD9tbP1LQ5yyif9CcJQjKbqsKolS9olJDEgJ/orlgWoO/Q Ab+1uXu53Iz+W9TBZHtau5eaHdLWAZc8gLrXMxmc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Skripkin , "David S. Miller" , Sasha Levin Subject: [PATCH 5.12 087/178] net: ethernet: fix potential use-after-free in ec_bhf_remove Date: Mon, 21 Jun 2021 18:15:01 +0200 Message-Id: <20210621154925.632311036@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154921.212599475@linuxfoundation.org> References: <20210621154921.212599475@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 9cca0c2d70149160407bda9a9446ce0c29b6e6c6 ] static void ec_bhf_remove(struct pci_dev *dev) { ... struct ec_bhf_priv *priv = netdev_priv(net_dev); unregister_netdev(net_dev); free_netdev(net_dev); pci_iounmap(dev, priv->dma_io); pci_iounmap(dev, priv->io); ... } priv is netdev private data, but it is used after free_netdev(). It can cause use-after-free when accessing priv pointer. So, fix it by moving free_netdev() after pci_iounmap() calls. Fixes: 6af55ff52b02 ("Driver for Beckhoff CX5020 EtherCAT master module.") Signed-off-by: Pavel Skripkin Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/ec_bhf.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/ec_bhf.c b/drivers/net/ethernet/ec_bhf.c index 46b0dbab8aad..7c992172933b 100644 --- a/drivers/net/ethernet/ec_bhf.c +++ b/drivers/net/ethernet/ec_bhf.c @@ -576,10 +576,12 @@ static void ec_bhf_remove(struct pci_dev *dev) struct ec_bhf_priv *priv = netdev_priv(net_dev); unregister_netdev(net_dev); - free_netdev(net_dev); pci_iounmap(dev, priv->dma_io); pci_iounmap(dev, priv->io); + + free_netdev(net_dev); + pci_release_regions(dev); pci_clear_master(dev); pci_disable_device(dev); -- 2.30.2