Skip to content

Commit f5de469

Browse files
mhiramatstorulf
authored andcommitted
mtk-sd: Prevent memory corruption from DMA map failure
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]>
1 parent 539d805 commit f5de469

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
@@ -853,6 +853,11 @@ static void msdc_prepare_data(struct msdc_host *host, struct mmc_data *data)
853853
}
854854
}
855855

856+
static bool msdc_data_prepared(struct mmc_data *data)
857+
{
858+
return data->host_cookie & MSDC_PREPARE_FLAG;
859+
}
860+
856861
static void msdc_unprepare_data(struct msdc_host *host, struct mmc_data *data)
857862
{
858863
if (data->host_cookie & MSDC_ASYNC_FLAG)
@@ -1484,8 +1489,18 @@ static void msdc_ops_request(struct mmc_host *mmc, struct mmc_request *mrq)
14841489
WARN_ON(!host->hsq_en && host->mrq);
14851490
host->mrq = mrq;
14861491

1487-
if (mrq->data)
1492+
if (mrq->data) {
14881493
msdc_prepare_data(host, mrq->data);
1494+
if (!msdc_data_prepared(mrq->data)) {
1495+
/*
1496+
* Failed to prepare DMA area, fail fast before
1497+
* starting any commands.
1498+
*/
1499+
mrq->cmd->error = -ENOSPC;
1500+
mmc_request_done(mmc_from_priv(host), mrq);
1501+
return;
1502+
}
1503+
}
14891504

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

0 commit comments

Comments
 (0)