Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3425682pxf; Mon, 29 Mar 2021 01:44:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxDglg21Y/It4GBdgkLgGFXN/8Q/fAeH8CPUxcZHzK78XjC/YH106laoLVr9IKpm3gTcW0 X-Received: by 2002:a17:907:9482:: with SMTP id dm2mr1232211ejc.303.1617007441941; Mon, 29 Mar 2021 01:44:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617007441; cv=none; d=google.com; s=arc-20160816; b=GfOTB3zonI2EmcRC7js2EVuJRYV1pV44baTcBrBZQ9MzuKOZO9SonO7cL3Dah/8bTj pnCKUxls67bq4NRBwMnaCUH+p5Uur2/1XbtxdK2BPp8qiv/Ke0HPdZTCKFGL6J9svGCx fN6SdgobmxiPXw3ed9z34nju8SRIndAremM2cuw89zXv5Z3B9zYy8SIyvvxYRSvQQV81 m6UIYJkXCvPqecqxfaD7SCUtUAvP0Bn5er72X2doltrrld6cT1o+1BrC6uSDeHrWP2/3 dlnK6B0Aqr0pdnySZgEvGcWsndwrtJ5vNduQu7n8wEtdpN/pxTJeuJU+QN2dwe8077dQ usFA== 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=pIzOL6bMu6RJNa2zYuiox47FrYxH+KjIkzVOCEImPiHl80GKGpzA4sbknoSMMzg3KK qaKEw5PhDcPYSdnn7KmCZC8gD0GpOtvALpzyLeTlp+8ug2CJXINI3EpdyM1dPyQiH6TL kbGe8enfNHeEW1mDxH0BnWTheZ3eKSCJq/yZxpN8SK65K5EmZFIOZsJPz+01z+hjEJ9K Mb+K3QVjEGMC+sbZ0LadW65cMZHX5lqbkqq4KjTG8zJQ9UJ87FFg2UgqkasGGJZt8JXI AdGSuoDudidaYcnF1R8ueJLTM0Gq/X/AnchDpaNM3/sLkGetJtgothhKQGNCgQG5xU98 EEKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=B+mJaCZx; 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 m24si12404540edp.422.2021.03.29.01.43.38; Mon, 29 Mar 2021 01:44:01 -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=B+mJaCZx; 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 S232906AbhC2Ile (ORCPT + 99 others); Mon, 29 Mar 2021 04:41:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:38360 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233712AbhC2IWO (ORCPT ); Mon, 29 Mar 2021 04:22:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 94B3B61481; Mon, 29 Mar 2021 08:22:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1617006134; bh=JqQYKn1ZTnx1pruKnmZr2f/O7Y9btMH/+S13rtg3ZGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B+mJaCZxtshPEzpOPiV9chIfhQWH9fcVAQJM26TI5lcag1cJuSZDKy3RNuWwm3Nqa aaX/uqAYlp2CUwyc7FO0Q6nIbFQwL8kHBEV0SzLNJqDErDA6uXwWs4d9AyZYr87UFI BqLojjuXhfNzJQ6GzGP/P1HX2sf7syohyIVQRwVs= 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.10 129/221] can: c_can_pci: c_can_pci_remove(): fix use-after-free Date: Mon, 29 Mar 2021 09:57:40 +0200 Message-Id: <20210329075633.503752924@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210329075629.172032742@linuxfoundation.org> References: <20210329075629.172032742@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