Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp6074551pxb; Thu, 27 Jan 2022 06:04:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJxu/ZIgTMrm06h+SBUi3UPOsMBzHdtBEpoQQsn6qGxai75GnYehEYCVEEvjFOnsU7jb1wqA X-Received: by 2002:a05:6402:5212:: with SMTP id s18mr3726270edd.379.1643292246270; Thu, 27 Jan 2022 06:04:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643292246; cv=none; d=google.com; s=arc-20160816; b=My05HzrOVDCZBMJT55zlzkXU/y5gvBRIdBhv5K+PzUVXXL5Ww+7NNT2W34ZjGlo6QJ jaL+1RYY50Ymkp9dNJiKztHqjwd5LcXendze1ABOgyW38APcJOwTJHudkMlY+OAog5qU bnL8P99EcqdoZorJq/jpiVznfzxAkhkBw5Z97kG/2kWWX3EEp/BBhrkQjCloE1D4bIMr USTlmZ8MD4U6aeTssL02y/6JL1epGVylU6H7ENS7S6psyPOARfdlxYtYdjYzFKO1Zr+/ bLeEt0Kdak4U+8ek/0Nq+B3c7yU/Tk8ycvFmoPBijs5RctGYnKFzIUqpQXCh90tYfKbW K0ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=miaOzrx1hn1xjv+lhXODM75sR8WD1A90qVyKF8wqiEg=; b=LAZffPpwT1wQbL948UkdkWr5cPl6dXFj2x5w+jGf07vMhor6VQtoIxZaHQwq33Q09r oJ3XLpy6stXfYgyx5o+1N+liU8fg+hhEQ7oR3OEkBrKdU5Snd2HgygatJ3TXLH4154ak QGd3m/H7Dk6q62/EdDhJ3jkW86Gxo9Jz0Ss3AF1V1bCGFKfJmqy18eOLVQKRP7j/UAvz wyF74Us8Dhn0UbqemgZqgOKf5YTx4KqkyBDO3FOU9eeY5OkmI3pKdKdeYAyd5jXh25sv D2LQJu3T7Ztaf6OBFqTZfr8YJjxCWUpaMmFdGnI0aPUjH16iV8GKBPgT3P8t+EWQLOP3 MDbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uX5vERj7; 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 f22si1588962edf.623.2022.01.27.06.03.16; Thu, 27 Jan 2022 06:04:06 -0800 (PST) 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=uX5vERj7; 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 S237383AbiA0HeB (ORCPT + 99 others); Thu, 27 Jan 2022 02:34:01 -0500 Received: from sin.source.kernel.org ([145.40.73.55]:58104 "EHLO sin.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237363AbiA0HeB (ORCPT ); Thu, 27 Jan 2022 02:34:01 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 2AFB0CE2109; Thu, 27 Jan 2022 07:33:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D0A5C340E4; Thu, 27 Jan 2022 07:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643268837; bh=99uVPzaahdu2LLS3zdhU8BqoM2kwwQywXPkVSB8TZ4U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uX5vERj7n5vVUDhrDUKuIh/pvAAqh2OOLqMpocrU0vvo/JQN17hEK2U5ih2DyVGM9 Lg450e8c4w8/N+JnHiZSXRDskDWag22hq/9dqP7bUBze51SZz4mfssUJOiJYZsCvp+ zuQhdqZA7+Xow+VeWuU500xM5IdkUWxMMThs4JwY= Date: Thu, 27 Jan 2022 08:33:54 +0100 From: Greg Kroah-Hartman To: Ulf Hansson Cc: linux-kernel@vger.kernel.org, Xiyu Yang , Xin Xiong , Xin Tan , Tony Lindgren , Yang Li , linux-mmc@vger.kernel.org, stable , whitehat002 Subject: Re: [PATCH] moxart: fix potential use-after-free on remove path Message-ID: References: <20220114075934.302464-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 21, 2022 at 03:24:05PM +0100, Ulf Hansson wrote: > On Fri, 21 Jan 2022 at 14:54, Greg Kroah-Hartman > wrote: > > > > On Fri, Jan 21, 2022 at 01:41:27PM +0100, Ulf Hansson wrote: > > > On Fri, 14 Jan 2022 at 08:59, Greg Kroah-Hartman > > > wrote: > > > > > > > > It was reported that the mmc host structure could be accessed after it > > > > was freed in moxart_remove(), so fix this by saving the base register of > > > > the device and using it instead of the pointer dereference. > > > > > > > > Cc: Ulf Hansson > > > > Cc: Xiyu Yang > > > > Cc: Xin Xiong > > > > Cc: Xin Tan > > > > Cc: Tony Lindgren > > > > Cc: Yang Li > > > > Cc: linux-mmc@vger.kernel.org > > > > Cc: stable > > > > Reported-by: whitehat002 > > > > Signed-off-by: Greg Kroah-Hartman > > > > --- > > > > drivers/mmc/host/moxart-mmc.c | 9 +++++---- > > > > 1 file changed, 5 insertions(+), 4 deletions(-) > > > > > > > > diff --git a/drivers/mmc/host/moxart-mmc.c b/drivers/mmc/host/moxart-mmc.c > > > > index 16d1c7a43d33..f5d96940a9b8 100644 > > > > --- a/drivers/mmc/host/moxart-mmc.c > > > > +++ b/drivers/mmc/host/moxart-mmc.c > > > > @@ -697,6 +697,7 @@ static int moxart_remove(struct platform_device *pdev) > > > > { > > > > struct mmc_host *mmc = dev_get_drvdata(&pdev->dev); > > > > struct moxart_host *host = mmc_priv(mmc); > > > > + void __iomem *base = host->base; > > > > > > > > dev_set_drvdata(&pdev->dev, NULL); > > > > > > > > @@ -707,10 +708,10 @@ static int moxart_remove(struct platform_device *pdev) > > > > mmc_remove_host(mmc); > > > > mmc_free_host(mmc); > > > > > > > > - writel(0, host->base + REG_INTERRUPT_MASK); > > > > - writel(0, host->base + REG_POWER_CONTROL); > > > > - writel(readl(host->base + REG_CLOCK_CONTROL) | CLK_OFF, > > > > - host->base + REG_CLOCK_CONTROL); > > > > > > Rather than doing it like this, I think it would be easier to move > > > mmc_free_host() below this part. That's usually what mmc host drivers > > > do clean up things in ->remove(). > > > > > > > + writel(0, base + REG_INTERRUPT_MASK); > > > > + writel(0, base + REG_POWER_CONTROL); > > > > + writel(readl(base + REG_CLOCK_CONTROL) | CLK_OFF, > > > > + base + REG_CLOCK_CONTROL); > > > > > > > > Ok, I can do that, I didn't know if it would cause any functionality > > changes, so I was trying to preserve the same logic that the driver > > currently has. > > Yes, but it's most likely just a simple mistake that was made by the > original author. > > > > > Do you have this device to test this with? > > No, I don't. > > Although, I am confident that it should work fine too. Great, now sent v2: https://lore.kernel.org/r/20220127071638.4057899-1-gregkh@linuxfoundation.org