Skip to contentSkip to conversation

mmc: host: fix potential null pointer dereference

PATCH In review Gustavo A. R. Silva 3 participants 5 messages May 23, 2017 – May 29, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: host: fix potential null pointer dereference

Null check at line 1165: if (mrq->cmd), implies that mrq->cmd might be NULL.
Add null checks before dereferencing pointer mrq->cmd in order to avoid any potential NULL pointer dereference.

Addresses-Coverity-ID: 1408740

---
 drivers/mmc/host/bcm2835.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/mmc/host/bcm2835.c +9 -3
index 1f343a4..abba9a2 100644
@@ -1172,7 +1172,10 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
 	if (mrq->data && !is_power_of_2(mrq->data->blksz)) {
 		dev_err(dev, "unsupported block size (%d bytes)\n",
 			mrq->data->blksz);
-		mrq->cmd->error = -EINVAL;
+
+		if (mrq->cmd)
+			mrq->cmd->error = -EINVAL;
+
 		mmc_request_done(mmc, mrq);
 		return;
 	}
@@ -1194,7 +1197,10 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
 			readl(host->ioaddr + SDCMD) & SDCMD_CMD_MASK,
 			edm);
 		bcm2835_dumpregs(host);
-		mrq->cmd->error = -EILSEQ;
+
+		if (mrq->cmd)
+			mrq->cmd->error = -EILSEQ;
+
 		bcm2835_finish_request(host);
 		mutex_unlock(&host->mutex);
 		return;
@@ -1207,7 +1213,7 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
 			if (!host->use_busy)
 				bcm2835_finish_command(host);
 		}
-	} else if (bcm2835_send_command(host, mrq->cmd)) {
+	} else if (mrq->cmd && bcm2835_send_command(host, mrq->cmd)) {
 		if (host->data && host->dma_desc) {
 			/* DMA transfer starts now, PIO starts after irq */
 			bcm2835_start_dma(host);
Signature · 1 line
2.5.0
Tested-by on v1 1/1
#1 lore raw

Hi Gustavo,

Quoted 10 lines

"Gustavo A. R. Silva" <[email protected]> hat am 24. Mai 2017 um 01:42 geschrieben:

Null check at line 1165: if (mrq->cmd), implies that mrq->cmd might be NULL.
Add null checks before dereferencing pointer mrq->cmd in order to avoid any potential NULL pointer dereference.

Addresses-Coverity-ID: 1408740

with a Raspberry Pi Zero.

But please change the subject to make sure it's bcm2835 related:

mmc: bcm2835: fix potential null pointer dereferences

Thanks
Stefan

#2 lore raw

Hi Stefan,

Quoting Stefan Wahren <[email protected]>:

Quoted 14 lines

Hi Gustavo,

Quoted 11 lines

"Gustavo A. R. Silva" <[email protected]> hat am 24. Mai 2017 um 01:42 geschrieben:

Null check at line 1165: if (mrq->cmd), implies that mrq->cmd might be NULL.
Add null checks before dereferencing pointer mrq->cmd in order to avoid any potential NULL pointer dereference.

Addresses-Coverity-ID: 1408740

Quoted 8 lines

with a Raspberry Pi Zero.

But please change the subject to make sure it's bcm2835 related:

mmc: bcm2835: fix potential null pointer dereferences

OK, I'll send v2 shortly.

Thank you
--
Gustavo A. R. Silva

#3 lore raw

PATCH v2 1/1 mmc: bcm2835: fix potential null pointer dereferences

Null check at line 1165: if (mrq->cmd), implies that mrq->cmd might be NULL.
Add null checks before dereferencing pointer mrq->cmd in order to avoid any potential NULL pointer dereference.

Addresses-Coverity-ID: 1408740

---
Changes in v2:
Change subject to make it clear the patch is bcm2835 related.

 drivers/mmc/host/bcm2835.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/mmc/host/bcm2835.c +9 -3
index 1f343a4..abba9a2 100644
@@ -1172,7 +1172,10 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
 	if (mrq->data && !is_power_of_2(mrq->data->blksz)) {
 		dev_err(dev, "unsupported block size (%d bytes)\n",
 			mrq->data->blksz);
-		mrq->cmd->error = -EINVAL;
+
+		if (mrq->cmd)
+			mrq->cmd->error = -EINVAL;
+
 		mmc_request_done(mmc, mrq);
 		return;
 	}
@@ -1194,7 +1197,10 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
 			readl(host->ioaddr + SDCMD) & SDCMD_CMD_MASK,
 			edm);
 		bcm2835_dumpregs(host);
-		mrq->cmd->error = -EILSEQ;
+
+		if (mrq->cmd)
+			mrq->cmd->error = -EILSEQ;
+
 		bcm2835_finish_request(host);
 		mutex_unlock(&host->mutex);
 		return;
@@ -1207,7 +1213,7 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
 			if (!host->use_busy)
 				bcm2835_finish_command(host);
 		}
-	} else if (bcm2835_send_command(host, mrq->cmd)) {
+	} else if (mrq->cmd && bcm2835_send_command(host, mrq->cmd)) {
 		if (host->data && host->dma_desc) {
 			/* DMA transfer starts now, PIO starts after irq */
 			bcm2835_start_dma(host);
Signature · 1 line
2.5.0
Applied
#4 lore raw

Re: [PATCH v2] mmc: bcm2835: fix potential null pointer dereferences

Quoted 8 lines · Gustavo A. R. Silva

Null check at line 1165: if (mrq->cmd), implies that mrq->cmd might be NULL.
Add null checks before dereferencing pointer mrq->cmd in order to avoid any potential NULL pointer dereference.

Addresses-Coverity-ID: 1408740

Thanks, applied for next!

Kind regards
Uffe

Quoted 47 lines

---
Changes in v2:
Change subject to make it clear the patch is bcm2835 related.

 drivers/mmc/host/bcm2835.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/mmc/host/bcm2835.c +9 -4
index 1f343a4..abba9a2 100644
@@ -1172,7 +1172,10 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
        if (mrq->data && !is_power_of_2(mrq->data->blksz)) {
                dev_err(dev, "unsupported block size (%d bytes)\n",
                        mrq->data->blksz);
-               mrq->cmd->error = -EINVAL;
+
+               if (mrq->cmd)
+                       mrq->cmd->error = -EINVAL;
+
                mmc_request_done(mmc, mrq);
                return;
        }
@@ -1194,7 +1197,10 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
                        readl(host->ioaddr + SDCMD) & SDCMD_CMD_MASK,
                        edm);
                bcm2835_dumpregs(host);
-               mrq->cmd->error = -EILSEQ;
+
+               if (mrq->cmd)
+                       mrq->cmd->error = -EILSEQ;
+
                bcm2835_finish_request(host);
                mutex_unlock(&host->mutex);
                return;
@@ -1207,7 +1213,7 @@ static void bcm2835_request(struct mmc_host *mmc, struct mmc_request *mrq)
                        if (!host->use_busy)
                                bcm2835_finish_command(host);
                }
-       } else if (bcm2835_send_command(host, mrq->cmd)) {
+       } else if (mrq->cmd && bcm2835_send_command(host, mrq->cmd)) {
                if (host->data && host->dma_desc) {
                        /* DMA transfer starts now, PIO starts after irq */
                        bcm2835_start_dma(host);
--

2.5.0