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 3A78D7C0AB; Mon, 8 Apr 2024 13:04:26 +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=1712581466; cv=none; b=CwwYxEiOuBUbuPH78lvdIBoakdEAUhZfvpTXigusYChGtGCeuY5fooV2pl9+gdH6VkzRkHttVDW4qJ2pj3oEY8ZWm7lnxYfwkvkltAXMWFBfZve6dR0epaXfUUKrFng5OfvjsvTS8fJVl51oiihkXHwXijIATjn+uFzyG+L5oYo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712581466; c=relaxed/simple; bh=GT9Kvt6/z1+7/Xpl2+cosILDoOcIZyYtUaXOIhzG+ro=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DesRr72pCF9Q+hO7Rse2s7Lc++b4HoNU9nWS271jXgw75W2Num7oeqyMr+8uMGzrLnzEEOu4yt7DtFhDscOsS0angLDs8EPC05DNyIvZRhpH0eGK77xUjckOAbkqNuD/ZJmkgIIbT+vKwG8RbNGgNrf8EIFuteUGbA+XJa9DAXg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=y9j9lWFr; 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="y9j9lWFr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B68DFC433F1; Mon, 8 Apr 2024 13:04:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1712581466; bh=GT9Kvt6/z1+7/Xpl2+cosILDoOcIZyYtUaXOIhzG+ro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y9j9lWFrNF7UqVvYWxXgEv0d2yivom7TMh5d3GjO3iaC73NcTiZMfW/jftxBoJ2jJ t/G9EakTMpKs1EVZph8PBC61Abc+0t47MsDLYY8JdemR4qAMyRgpW4daoG7p3jK/jS GR/KxNcealSfQWMtHW01Mlewuelme9vWWfWs8DtU= 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.15 053/690] mmc: tmio: avoid concurrent runs of mmc_request_done() Date: Mon, 8 Apr 2024 14:48:39 +0200 Message-ID: <20240408125401.442230827@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408125359.506372836@linuxfoundation.org> References: <20240408125359.506372836@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.15-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 437048bb80273..5024cae411d3a 100644 --- a/drivers/mmc/host/tmio_mmc_core.c +++ b/drivers/mmc/host/tmio_mmc_core.c @@ -259,6 +259,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