]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mtk-sd: Prevent memory corruption from DMA map failure
authorMasami Hiramatsu (Google) <mhiramat@kernel.org>
Thu, 12 Jun 2025 11:26:10 +0000 (20:26 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Jul 2025 16:24:58 +0000 (18:24 +0200)
[ Upstream commit f5de469990f19569627ea0dd56536ff5a13beaa3 ]

If msdc_prepare_data() fails to map the DMA region, the request is
not prepared for data receiving, but msdc_start_data() proceeds
the DMA with previous setting.
Since this will lead a memory corruption, we have to stop the
request operation soon after the msdc_prepare_data() fails to
prepare it.

Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Fixes: 208489032bdd ("mmc: mediatek: Add Mediatek MMC driver")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/174972756982.3337526.6755001617701603082.stgit@mhiramat.tok.corp.google.com
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/mmc/host/mtk-sd.c

index 5d330f2a3faae51006a018d3f72ea849ef081ce6..dbe3478cc2308edb0da0cf69cf5fe5ea253cd8f2 100644 (file)
@@ -686,6 +686,11 @@ static void msdc_prepare_data(struct msdc_host *host, struct mmc_data *data)
        }
 }
 
+static bool msdc_data_prepared(struct mmc_data *data)
+{
+       return data->host_cookie & MSDC_PREPARE_FLAG;
+}
+
 static void msdc_unprepare_data(struct msdc_host *host, struct mmc_data *data)
 {
        if (data->host_cookie & MSDC_ASYNC_FLAG)
@@ -1198,8 +1203,18 @@ static void msdc_ops_request(struct mmc_host *mmc, struct mmc_request *mrq)
        WARN_ON(host->mrq);
        host->mrq = mrq;
 
-       if (mrq->data)
+       if (mrq->data) {
                msdc_prepare_data(host, mrq->data);
+               if (!msdc_data_prepared(mrq->data)) {
+                       /*
+                        * Failed to prepare DMA area, fail fast before
+                        * starting any commands.
+                        */
+                       mrq->cmd->error = -ENOSPC;
+                       mmc_request_done(mmc_from_priv(host), mrq);
+                       return;
+               }
+       }
 
        /* if SBC is required, we have HW option and SW option.
         * if HW option is enabled, and SBC does not have "special" flags,