From mboxrd@z Thu Jan 1 00:00:00 1970 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 7BAFC13F452; Thu, 11 Apr 2024 10:16:09 +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=1712830569; cv=none; b=tuB6x77SbwXMhQty55xnAXPXiZHBdd/8n6lMR6fmOk3dt5uisFl8X4ONfASQHHkrrW+jE0UpIhe0Q8IJQMFP9/v0uloFPk4gbkHJCR8TjEtCy0XTY4dbeZxdMlUKAeGtakvSkfQZyaPu66zvbkntQQ0KURQz9iiG8exadvxW2k4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712830569; c=relaxed/simple; bh=Gvp2cFPviIBC3fbhlkw/9Tc6F1roQNdcACQVCmf4Iqc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Fpz+Zxtp7D5//VsT6nasV9oOt5Lyz6rkM+eiMI4ojvzSHSjhl9adu3ARtNNHDNzpt8vrtRFumA4OCPcZCVq8tD/dRtgp08gDeEbZQd3685F0dYmt9gh52RqZwhPaZ2S0UQQNLF2DDtaPhu02DvXVoVeqdk0Qi6cX2kFbOQDNnww= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=m2OAvBxS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="m2OAvBxS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF38EC433C7; Thu, 11 Apr 2024 10:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712830569; bh=Gvp2cFPviIBC3fbhlkw/9Tc6F1roQNdcACQVCmf4Iqc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m2OAvBxS77y22yDwQVFroaPGug6EO/QaqdfAedVTeuxnbwIHCO1uDeIO/mhpbazfz ORvmxtAj6lPSTVIcfVItR0EgXJJHIJZNFN81klC/etkqnGEqA+5cHWueg3hd+t3W1x wH4NXhzN9JGhRc23J7wsB+W7QUMEzgW2BMjz00hM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dirk Behme , Wolfram Sang , Ulf Hansson , Sasha Levin Subject: [PATCH 5.4 044/215] mmc: tmio: avoid concurrent runs of mmc_request_done() Date: Thu, 11 Apr 2024 11:54:13 +0200 Message-ID: <20240411095426.218845167@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240411095424.875421572@linuxfoundation.org> References: <20240411095424.875421572@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wolfram Sang [ Upstream commit e8d1b41e69d72c62865bebe8f441163ec00b3d44 ] With the to-be-fixed commit, the reset_work handler cleared 'host->mrq' outside of the spinlock protected critical section. That leaves a small race window during execution of 'tmio_mmc_reset()' where the done_work handler could grab a pointer to the now invalid 'host->mrq'. Both would use it to call mmc_request_done() causing problems (see link below). However, 'host->mrq' cannot simply be cleared earlier inside the critical section. That would allow new mrqs to come in asynchronously while the actual reset of the controller still needs to be done. So, like 'tmio_mmc_set_ios()', an ERR_PTR is used to prevent new mrqs from coming in but still avoiding concurrency between work handlers. Reported-by: Dirk Behme Closes: https://lore.kernel.org/all/20240220061356.3001761-1-dirk.behme@de.bosch.com/ Fixes: df3ef2d3c92c ("mmc: protect the tmio_mmc driver against a theoretical race") Signed-off-by: Wolfram Sang Tested-by: Dirk Behme Reviewed-by: Dirk Behme Cc: stable@vger.kernel.org # 3.0+ Link: https://lore.kernel.org/r/20240305104423.3177-2-wsa+renesas@sang-engineering.com Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin --- drivers/mmc/host/tmio_mmc_core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/mmc/host/tmio_mmc_core.c b/drivers/mmc/host/tmio_mmc_core.c index 25083f010a7ad..e21907b92cf11 100644 --- a/drivers/mmc/host/tmio_mmc_core.c +++ b/drivers/mmc/host/tmio_mmc_core.c @@ -217,6 +217,8 @@ static void tmio_mmc_reset_work(struct work_struct *work) else mrq->cmd->error = -ETIMEDOUT; + /* No new calls yet, but disallow concurrent tmio_mmc_done_work() */ + host->mrq = ERR_PTR(-EBUSY); host->cmd = NULL; host->data = NULL; -- 2.43.0