2022-11-17 12:53:10

by Anastasia Belova

[permalink] [raw]
Subject: [PATCH] mmc: sh_mmcif: Add check for NULL for host->chan_yx and host->chan_rx in sh_mmcif_end_cmd

Without these checks NULL-pointer may be dereferenced in
sh_mmcif_end_cmd parameters inside if (data->flags & MMC_DATA_READ).

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: eae309836509 ("mmc: sh_mmcif: Terminate DMA transactions when detecting timeout or error")
Signed-off-by: Anastasia Belova <[email protected]>
---
drivers/mmc/host/sh_mmcif.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/mmc/host/sh_mmcif.c b/drivers/mmc/host/sh_mmcif.c
index 0fd4c9d644dd..f35694acafcc 100644
--- a/drivers/mmc/host/sh_mmcif.c
+++ b/drivers/mmc/host/sh_mmcif.c
@@ -1136,14 +1136,17 @@ static bool sh_mmcif_end_cmd(struct sh_mmcif_host *host)
time = wait_for_completion_interruptible_timeout(&host->dma_complete,
host->timeout);

- if (data->flags & MMC_DATA_READ)
- dma_unmap_sg(host->chan_rx->device->dev,
- data->sg, data->sg_len,
- DMA_FROM_DEVICE);
- else
- dma_unmap_sg(host->chan_tx->device->dev,
- data->sg, data->sg_len,
- DMA_TO_DEVICE);
+ if (data->flags & MMC_DATA_READ) {
+ if (host->chan_rx)
+ sh_mmcif_end_cmd(host->chan_rx->device->dev,
+ data->sg, data->sg_len,
+ DMA_FROM_DEVICE);
+ } else {
+ if (host->chan_tx)
+ dma_unmap_sg(host->chan_tx->device->dev,
+ data->sg, data->sg_len,
+ DMA_TO_DEVICE);
+ }

if (host->sd_error) {
dev_err(host->mmc->parent,
--
2.30.2



2022-11-17 14:25:48

by Wolfram Sang

[permalink] [raw]
Subject: Re: [PATCH] mmc: sh_mmcif: Add check for NULL for host->chan_yx and host->chan_rx in sh_mmcif_end_cmd

On Thu, Nov 17, 2022 at 03:30:07PM +0300, Anastasia Belova wrote:
> Without these checks NULL-pointer may be dereferenced in
> sh_mmcif_end_cmd parameters inside if (data->flags & MMC_DATA_READ).
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.

Is there a code path actually triggering it? I wonder because it seems
to me the check for valid channels is already done a little above when
DMA is started. And I'd assume once DMA has been started we can take for
granted that we have a valid channel when unmapping. But maybe I am
missing some error codepath?


Attachments:
(No filename) (593.00 B)
signature.asc (849.00 B)
Download all attachments