Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1396808pxb; Fri, 21 Jan 2022 17:36:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwg4dSA6HaU14/3RIoQUL1bv+0sexWDz5irHMR7e43l/YhAF+QLaUBJ331SYZthhHlRkypB X-Received: by 2002:a17:903:234c:b0:14b:1632:9267 with SMTP id c12-20020a170903234c00b0014b16329267mr6472742plh.45.1642815413269; Fri, 21 Jan 2022 17:36:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642815413; cv=none; d=google.com; s=arc-20160816; b=Vap0Ia6bXUp0Z4RfQZV3gfJLyrlfErSNpeBRAbgRiUG3zfnxnKG/h+dAC33IgRUM0h atpLT3qmPJYxqnUrqW4HKltyptEPDrc7E/BmX6twMStPuadO/iCRqOiaM3gfk89yzb54 34Zd6m0jKFxR/zuSDukXXSECX+6ThtdP4a99xTs9f7ctu2rAmkjQOB7ns9eXU73iwdVc GcTyj1l0qnBZoOoDI77uoioe4ekyTmt/91TiIFpbedl03PcYITcnzF+Mu6VVeZnVX+m/ 1pup/AKQwQM1MArVZKS87AFmfzXnQbAqtU/ewcTrA5EgIsFfzGVtbtfN/SHoYQj5xsUg /CJQ== 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=ezjSQdZS9GGReiFXmIjI6Bl0ClJ4WFKKFKT9bwkf1/4=; b=cEorLost6nNO1DaBb+mUYqI29+E3IeDx7zRPZb/GI8DKVljKl0vURwRKsN9+35fkVp AXr9CZDqzEzLqrSGI7gHuiMvOF5+sXYVjTUZxxuPrMAdOefc5YVD4o/Vv8B0YknrQubi +61mAa5a1c1O6ucRNuWOLGtSN+hcJ8v7QgWN3ul4UeMjjqOnBcCLzPNu7CeymxAbh9Qi bhTi/ixHt+HXxPonTXP52DCeRtrw6NzZLulzbEWim77GfLeiWnpV+UOiPff/X29zOWYF 9NYTlEtik6w6MOEsTf6kMMH1dvTxnZMyjOURpC7Bz+NY++lChpNfYq5oGv9CQn54/9YP t5eQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g91iKuk5; 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 oj10si15481991pjb.39.2022.01.21.17.36.41; Fri, 21 Jan 2022 17:36:53 -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=g91iKuk5; 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 S1380791AbiAUNyv (ORCPT + 99 others); Fri, 21 Jan 2022 08:54:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350341AbiAUNyt (ORCPT ); Fri, 21 Jan 2022 08:54:49 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72924C061574; Fri, 21 Jan 2022 05:54:49 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 59A84616F0; Fri, 21 Jan 2022 13:54:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B912C340E1; Fri, 21 Jan 2022 13:54:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1642773287; bh=MsGTfQONatWIvmB+ivBn7GztIxbSTJkJ4CdpKN2PPh8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=g91iKuk5lY+J2J7MmuPExW4S7EYjj/FcXwJYf7QI9502AbYrToyaXIblqIXbeHsaT gHBa5SHiFz2fP5gEiIbEE0WgIN1kpgLj2uK2m3cc/+fXBS/6kDB420Ow1mL1jmVknt ieKCl7zu846j+LYjAz+1qU+wBOSeVEmPq8gGpFqs= Date: Fri, 21 Jan 2022 14:54:39 +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 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. Do you have this device to test this with? thanks, greg k-h