Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3813523pxv; Mon, 28 Jun 2021 13:35:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxw2raAMTbXBwmunRX02VW+6GHJaLJuMXTYeikHpmmCmwufl2oZzAok9jDviXlkXwOIIuW2 X-Received: by 2002:a92:ddd1:: with SMTP id d17mr18225539ilr.46.1624912534995; Mon, 28 Jun 2021 13:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624912534; cv=none; d=google.com; s=arc-20160816; b=v5Qilyq8kLDxz+Mw6sT4RLymekozpg7Hw+8wX7DkdiuAKPGDFu1KoncLYCoCaAWLTF YiwCT26e5PUnG14sUhOpOuhjQJ2MiZopQg7DoErCikkaHtuV6HwfihNYk1uWUUAVEWEn FGvYkq40A13yBaNQ2r8qNu8AhHPu9BHaJ5NGH0sH4agd8JD47u+RbmzDsIQE5VZWbPJb kESYztEt+xcdj4IQAYrRE7PBWSRykMZpfWjsgumB0nEUk93admT6IE+TKleW1Glt5lvL 64Nrgy5xfTIoeVqtibXciDMltP602/RQfXlxVAkxyj4kMvhPMDjDdaX+dgob6Rn311Mv DLRA== 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=ZbSFTaBaRllhdkuu8+j2jEUgRF9tb5z/eiW4DCc0csY=; b=dgtLg1aOU8jsgnrZwvcayaCJ7WF8wL5vYBAnhWY2dKzM4kTw4wxQvNj+AazE4kcpsI gACGHA4ePVA4XIF/OrV05byEYUDbbP7RLs0phiRn6Kk76fOuBkQkEBP8slHMryZEFblR dwnhnK2rZpRNVUVggTCtkZP7yGfU9bCLI4Id7KGKu4C+M42dbf6aTWu+8/n2urhoFXre ReDDrAbQfwBcUiChHZFqyRF9fRKo4KwkhpkXRDIEWbEirGzj98m7Yv4Ua2f1V66cyjb8 QnXPElZuZ/hzb7wkE+aHz4oTYswDxUzJBSekLEUkma6EzJEHL+kOtJV2+NdOALYX50VC 7Etw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mUdlpCdW; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n6si17871384ilj.66.2021.06.28.13.35.22; Mon, 28 Jun 2021 13:35:34 -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=@kernel.org header.s=k20201202 header.b=mUdlpCdW; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235042AbhF1PLb (ORCPT + 99 others); Mon, 28 Jun 2021 11:11:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:54460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235523AbhF1Ou5 (ORCPT ); Mon, 28 Jun 2021 10:50:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EFDCD61CB7; Mon, 28 Jun 2021 14:37:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624891025; bh=4xaNqH5xgORiyWdDNFdZbt2jNtVSIyBiQhbjriEm0Ak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mUdlpCdWwB9yUE7EN/6dhqPAmDRBn7hoSksslBiGBOLXp4SzbZ7rU2md7/Y7RZygY NNRh0Rfzv3HtJcPZ27GAquP7Gri0+HzZqstXQwN2cFI51NZ+1iiXYIASB3nptJtS9M EOnsCMWUkWk1YZD0nNTUB59eACgakwihxW5+9LIao8YuAiEfoOajLUZ0Gi18hghjj4 5d6ev3IRsh8nMKYG6zvqWe3jPKUh1Wff3L2rufOTpBX9ygE+SMZGLPQN2Xmj+AHY94 2f0kc7/KXRkB0NKQjWSV9kf2qXn09AF6sBPHmkLKaS0nQVT6l5yBeEYA29Fb4Pkkxw fdQWYbtp5zh2g== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Pavel Skripkin , "David S . Miller" , Sasha Levin Subject: [PATCH 4.14 40/88] net: ethernet: fix potential use-after-free in ec_bhf_remove Date: Mon, 28 Jun 2021 10:35:40 -0400 Message-Id: <20210628143628.33342-41-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143628.33342-1-sashal@kernel.org> References: <20210628143628.33342-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.14.238-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.14.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.14.238-rc1 X-KernelTest-Deadline: 2021-06-30T14:36+00:00 X-stable: review X-Patchwork-Hint: Ignore 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 1b79a6defd56..5561dd295324 100644 --- a/drivers/net/ethernet/ec_bhf.c +++ b/drivers/net/ethernet/ec_bhf.c @@ -585,10 +585,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