Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp854288rdb; Fri, 19 Jan 2024 00:21:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IEZFf0gzklPb0EuGf7qAti8GpbC1ACdFcJRvt8UypWjg6Ls7cS7LG8ZTbkbitrQxhfXzCO9 X-Received: by 2002:a17:906:6298:b0:a2d:87a:7192 with SMTP id sn24-20020a170906629800b00a2d087a7192mr888261ejc.167.1705652491602; Fri, 19 Jan 2024 00:21:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705652491; cv=pass; d=google.com; s=arc-20160816; b=N9ro4D7tCTr+sO9a7S17gBFqQ7Q9fUPrWbFViQEenPWSAmBxnLCpsfXcpxibVsN5NE yQlgl5eWenYHl1qZCmtKqrLIiMYyPkkaJXoQ0A/JCWr73N1x10p05WUyGa0gK7XcwcP3 bM6M2/9m0t994o30wEOwHrar4MaffvNJrbbKy8Q61JLfi4GK9bQ1JAEhyNd0WmB9L+Xd o0y5zS/qOMnk470RJ9q+hG03iF+7whxK4oq7byWogdiPmAzMeJPmU6eTmKmEyhMEDqRl EccW6JYfY+P09r7DvEFpHrZTeb4x3K+8Kj/9mKfrt0ZynR8j6B+UzX4xnbM3Tm23GGm7 FNkw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=W1CmZY6zUMYoc6lrSx/QZoh9XWk0/+lUqVLxN/JvKZ8=; fh=iXruHf+o8BQRSia4f73k582TsAIuDvjYMi5Sr5saCKI=; b=N9Gfo0/0SQVCmDreuRa+KGI9U4SDOmK4dCb0Jr9kDKcEBtVHnTQZXobo+MW6MoydJY c8i44RqdWvGKUg0xCHSxZ8jzuBUzKUYy0g0mK3accrAKL/fAz49dApyhsleOZWQ1t7go UqegFoSbPzaisism/FJGI+s7zEExxp15CxyMzywplOLsIFTzBrAvoAYFhKhejWbp+Cyb Cw9TD6qA2rbt6aMJNtmlpKTFoX+4ee6lWTx+5cKd+E5s51vxnQf3R4HW/bMmIRmvI2uh sh6OYAskvWk3e7RjWHTAmZdsFxeVuK7oIOmjhlmTf7BKqXDQshxz7KqawhTJ2itT/hfP MKCA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kYTYHsAM; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-30893-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30893-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a24-20020a1709062b1800b00a2e875de90bsi3248478ejg.120.2024.01.19.00.21.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jan 2024 00:21:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30893-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kYTYHsAM; arc=pass (i=1 dkim=pass dkdomain=linuxfoundation.org); spf=pass (google.com: domain of linux-kernel+bounces-30893-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30893-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9CA471F21E45 for ; Fri, 19 Jan 2024 08:21:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 690CD208AE; Fri, 19 Jan 2024 08:21:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="kYTYHsAM" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 526E96AA0; Fri, 19 Jan 2024 08:21:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705652463; cv=none; b=giYBxXH3/YzJwozds+gUnf+h4uqnSIRVHrG7jKcfv6mBulUGGawN1oTRRQuko5Aext3DuJt5bF4pGYItr6n5sHjAopJc7L0Vz0IBLgkF2RqZNBX1PL1Mb9o2m4dAz0f3YBvQnQ/IFFXUSKsMf39Qm5rIYniTQu80bgyFGdJIqUY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705652463; c=relaxed/simple; bh=VN3W5znShoWe5oBeYGybruQe/c44tyaC01yxzyq2waw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=T8pAh0BzdD/3dmpa/3sLbS3LcLMTK6cUmuxW6sQCsn5eWKxJ8vsXuPHMi5KGIpesv7a58VxwQkhfVa/JcwXPY7hleueAImvTNnZnWU59vI8iawE9ObtS5aBMZv/t2hF4EIihK1tRvsO7kIdpVsc1uZGNSD3TNm8Ab+/q+oyB5gQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=kYTYHsAM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44155C433F1; Fri, 19 Jan 2024 08:21:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1705652461; bh=VN3W5znShoWe5oBeYGybruQe/c44tyaC01yxzyq2waw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kYTYHsAM1iECuefu1ZuF4y+7PSu+rg4407HYxsFREPBuJgLsOIVBqZgKiaaLvq0lv 1DA2e5q7gPsLyPQSmRp9SPd7GU3/3Psu1lwg2hgj81skjrygs85zXirppBHv2XuZJt 1s9qmfC8iUOyJheshudhWTm6E9t6uX8xPeDS1NRw= Date: Fri, 19 Jan 2024 09:20:59 +0100 From: Greg KH To: Seunghui Lee Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, avri.altman@wdc.com, grant.jung@samsung.com, jt77.jang@samsung.com, dh0421.hwang@samsung.com, junwoo80.lee@samsung.com, jangsub.yi@samsung.com, cw9316.lee@samsung.com, sh8267.baek@samsung.com, wkon.kim@samsung.com Subject: Re: [PATCH] mmc: core: Fix null pointer dereference in bus_shutdown Message-ID: <2024011945-studio-smitten-300e@gregkh> References: <20240119073247.7441-1-sh043.lee@samsung.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240119073247.7441-1-sh043.lee@samsung.com> On Fri, Jan 19, 2024 at 04:32:47PM +0900, Seunghui Lee wrote: > When shutting down removable device, > it can be occurred null pointer dereference. How? And please wrap your lines properly. > To prevent null pointer dereference, > At first, check null pointer. > Next, block rescan worker to scan removable device during shutdown. Why do two things? > > Signed-off-by: Seunghui Lee > --- > drivers/mmc/core/bus.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c > index 0af96548e7da..4f370a6577aa 100644 > --- a/drivers/mmc/core/bus.c > +++ b/drivers/mmc/core/bus.c > @@ -143,9 +143,17 @@ static void mmc_bus_shutdown(struct device *dev) > { > struct mmc_driver *drv = to_mmc_driver(dev->driver); > struct mmc_card *card = mmc_dev_to_card(dev); > - struct mmc_host *host = card->host; > + struct mmc_host *host; > int ret; > > + if (!drv || !card) { > + pr_debug("%s: drv or card is NULL.\n", dev_name(dev)); What is this going to help with? And why not use dev_dbg()? How can drv ever be NULL? That looks impossible to me based on just the code shown here. > + return; > + } > + > + host = card->host; Why is this change needed? This line can go back to the top just fine, right? > + host->rescan_disable = 1; Shouldn't this be a separate change? And what happens if the check for this is right before you set it? Where is the locking to prevent the issue you are attempting to solve? thanks, greg k-h