Skip to content

Commit 3419bc6

Browse files
mhiramatgregkh
authored andcommitted
mtk-sd: Prevent memory corruption from DMA map failure
commit f5de469 upstream. 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) <[email protected]> Fixes: 2084890 ("mmc: mediatek: Add Mediatek MMC driver") Cc: [email protected] Link: https://lore.kernel.org/r/174972756982.3337526.6755001617701603082.stgit@mhiramat.tok.corp.google.com Signed-off-by: Ulf Hansson <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent cfbdcab commit 3419bc6

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

drivers/mmc/host/mtk-sd.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,11 @@ static void msdc_prepare_data(struct msdc_host *host, struct mmc_data *data)
783783
}
784784
}
785785

786+
static bool msdc_data_prepared(struct mmc_data *data)
787+
{
788+
return data->host_cookie & MSDC_PREPARE_FLAG;
789+
}
790+
786791
static void msdc_unprepare_data(struct msdc_host *host, struct mmc_data *data)
787792
{
788793
if (data->host_cookie & MSDC_ASYNC_FLAG)
@@ -1346,8 +1351,18 @@ static void msdc_ops_request(struct mmc_host *mmc, struct mmc_request *mrq)
13461351
WARN_ON(host->mrq);
13471352
host->mrq = mrq;
13481353

1349-
if (mrq->data)
1354+
if (mrq->data) {
13501355
msdc_prepare_data(host, mrq->data);
1356+
if (!msdc_data_prepared(mrq->data)) {
1357+
/*
1358+
* Failed to prepare DMA area, fail fast before
1359+
* starting any commands.
1360+
*/
1361+
mrq->cmd->error = -ENOSPC;
1362+
mmc_request_done(mmc_from_priv(host), mrq);
1363+
return;
1364+
}
1365+
}
13511366

13521367
/* if SBC is required, we have HW option and SW option.
13531368
* if HW option is enabled, and SBC does not have "special" flags,

0 commit comments

Comments
 (0)