Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3417367pxf; Mon, 29 Mar 2021 01:26:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxD87I15iZtYGRRHO7elfYTuliQ7Zjc/H21uRcqItUc1EPEyLki1bW/pgDU/yZExjaZr6/ X-Received: by 2002:a17:906:ae88:: with SMTP id md8mr26515790ejb.264.1617006374563; Mon, 29 Mar 2021 01:26:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617006374; cv=none; d=google.com; s=arc-20160816; b=OvcZNnLaVMZkr8TTZCsvNFgUYRLTV0HbxY0rk+/OppDjOietfxgLA3gc2mDPlD/qTc k7J/qLfaNvS96tYoPhJRmehu/f+3ZhjELXEBc7YTHeKTLn4RWXyqzk3hgFl3ulvr29id /8O/191Za1EqhJEwMTRRqKhwTAaRynYBEVuyPjmrGVh6SEh5CNUShixN895etsrYftNF trrpmFJNYj0RLyf3HNbTUGo4Va2JD+piWWUMMEBf7m3o6EB9mGLsl23rnJGNiBkfqKhT yjgiN0l0c9eLgOPGDvffocsGzd3gpAoayWxS2qFlV506OaLm+r/eSCkgyUtbKWCec2Fm PPCQ== 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=RyL6fe6QHEOhrBhhLmUzKMX+SoLx0vgPzCE+VG9iprM=; b=jgm+/qLFaL4zpj2tgoXQylK9hCFByE6y5dmnCPteUhsXt1UREqF9n7qXfCJDY6akPx RbsGmRlnFCacYF9CQyEszeH4Xafbzoe2rdHRu8ZNsbCGkQy1xlhYP6BZXG4AX+6HXaU9 nkNR5VdlWtqGB0pdQEYcO81dUz7yiks3a4Fwn/1SU9jLmXVb56P/VmQzR9ccEpSoM6F5 uxujTgHN6abAmOON4P/i5h/StayYsqLiC3l4qEwtmmk1P46CHRx4uQvPsN/p7M8g1//+ B7y+eS8i8sEDpgOFHe+VhBvtwf44W0OzszhkypFaFzfnxTxqvUru3d99Ri0MvJJfs/vL Dq1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xhUA+wtQ; 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 x21si13394162ejb.180.2021.03.29.01.25.51; Mon, 29 Mar 2021 01:26:14 -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=xhUA+wtQ; 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 S233428AbhC2IZJ (ORCPT + 99 others); Mon, 29 Mar 2021 04:25:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:58450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232677AbhC2IQg (ORCPT ); Mon, 29 Mar 2021 04:16:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C6B08619BA; Mon, 29 Mar 2021 08:16:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617005763; bh=JqQYKn1ZTnx1pruKnmZr2f/O7Y9btMH/+S13rtg3ZGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xhUA+wtQ+wC4UZr0lVZqvjHLHFnYIMyT+gxAoK6bSmfHWzZdytG3J/L7LktdwZ8Bo tuILadCqPHyi1WfyHWztLB1hVhl61utq74x9Y5S3YZqRUl3TUVP9r9e71zSIn5I700 +NvhdOTC66LfpCbvkEVsDTD1Ts5ATDL0mlZHr5GM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tong Zhang , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 5.4 073/111] can: c_can_pci: c_can_pci_remove(): fix use-after-free Date: Mon, 29 Mar 2021 09:58:21 +0200 Message-Id: <20210329075617.643637506@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075615.186199980@linuxfoundation.org> References: <20210329075615.186199980@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: Tong Zhang [ Upstream commit 0429d6d89f97ebff4f17f13f5b5069c66bde8138 ] There is a UAF in c_can_pci_remove(). dev is released by free_c_can_dev() and is used by pci_iounmap(pdev, priv->base) later. To fix this issue, save the mmio address before releasing dev. Fixes: 5b92da0443c2 ("c_can_pci: generic module for C_CAN/D_CAN on PCI") Link: https://lore.kernel.org/r/20210301024512.539039-1-ztong0001@gmail.com Signed-off-by: Tong Zhang Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- drivers/net/can/c_can/c_can_pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/c_can/c_can_pci.c b/drivers/net/can/c_can/c_can_pci.c index 406b4847e5dc..7efb60b50876 100644 --- a/drivers/net/can/c_can/c_can_pci.c +++ b/drivers/net/can/c_can/c_can_pci.c @@ -239,12 +239,13 @@ static void c_can_pci_remove(struct pci_dev *pdev) { struct net_device *dev = pci_get_drvdata(pdev); struct c_can_priv *priv = netdev_priv(dev); + void __iomem *addr = priv->base; unregister_c_can_dev(dev); free_c_can_dev(dev); - pci_iounmap(pdev, priv->base); + pci_iounmap(pdev, addr); pci_disable_msi(pdev); pci_clear_master(pdev); pci_release_regions(pdev); -- 2.30.1