Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3920522pxj; Mon, 21 Jun 2021 09:23:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyqljr51TTn+nP+sGJj+VCDVl7K00lCWo//xb3RCCtU7sonsdX3QlLcVrMhmaVqsrqWOY4 X-Received: by 2002:a50:ef12:: with SMTP id m18mr22911629eds.285.1624292625055; Mon, 21 Jun 2021 09:23:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292625; cv=none; d=google.com; s=arc-20160816; b=Vg77929wgM9aqYuHsiRjHV8NFcv1nWcqOY+SEiGegJXyG8qSk3Z2dqQKY0lJXr2Mnv Sri09TkNm4M2eU4xmKZeq0H33iekpIQTDqauBTi+qJ54nAnYWdlMZiWKgHQdPyeH6Mp1 T2HCqkldZ4xh7T/RRBeFgKyqPcze3NlJp2OlikC8qTLxjIcErVCq/j8UeFCCWmiuP6zI W9TekI2o2RHDgdaqdPtmwt403/+hzJ8KlyNE8txxSG6VTxHm6snzegsviXlsfCm+WiFc mjhEc6CVsrRHB11mLVig7YKPfSIOwSG1HKQ4Fzxssa+/mCESpt3Wx24Iq2BHhnpalSS6 nPSQ== 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=OWk3VFMCCAbriJaqyEmzUNeKf93j8GjSl7nCZMJp4YNpfpeRvP4+EXDiOeyl8MmNc9 RX36D8X+PBzjJ0z6SWWwAcHIn7TPjiJEEzWQrRa5yPtGOzQudM8ww9kX2Yt7YTcVlUj5 U6Cs7uerFd0dBPVojU3Bds0+fJ63zCMT8sjIZ463T83UmFI+tF2takHOhP1yWkFM3k4/ 2Uqt+288gIW1wKd3wVl4/eFMy6DF1YFlAilvzXoZp2whAW2erh/b8owlx4IViHM45EmG PVQGP6SDwAooSkz1AGWq0nPZ9ApADEJTBB8UfZj0Tn/GHob5PP4pxczI7svVnVI+r8x0 BOww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HSUjtk7L; 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 w7si16821479edx.534.2021.06.21.09.23.22; Mon, 21 Jun 2021 09:23:45 -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=HSUjtk7L; 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 S231723AbhFUQX6 (ORCPT + 99 others); Mon, 21 Jun 2021 12:23:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:40508 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231597AbhFUQW0 (ORCPT ); Mon, 21 Jun 2021 12:22:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3CC31611C1; Mon, 21 Jun 2021 16:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292398; bh=GPZlmCmG5Ozv64hMj2PJFVS6AWHaoBhOPRTJYmhJWpc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HSUjtk7LLZgJYHbGnPHxVYv2iEB3Pi2eTLxCoOfFGJeNlSsG7+5M7jHVI7fL00HsM 4PQ95m+AmhT9Bq9hAEH4GcKiTgityLd/M6kCbVNCARqkXwUOsiw1o4heLlw24r4JuZ Bbe3qvCpRuTizZn8Xp0DdHTMmkiJMUdfbMsZ6Xqk= 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.4 42/90] net: ethernet: fix potential use-after-free in ec_bhf_remove Date: Mon, 21 Jun 2021 18:15:17 +0200 Message-Id: <20210621154905.542318900@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154904.159672728@linuxfoundation.org> References: <20210621154904.159672728@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