linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: host: fix potential null pointer dereference
@ 2017-05-23 23:42 Gustavo A. R. Silva
  2017-05-25  9:12 ` Stefan Wahren
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo A. R. Silva @ 2017-05-23 23:42 UTC (permalink / raw)
  To: linux-arm-kernel

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
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/mmc/host/bcm2835.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/bcm2835.c b/drivers/mmc/host/bcm2835.c
index 1f343a4..abba9a2 100644
--- a/drivers/mmc/host/bcm2835.c
+++ b/drivers/mmc/host/bcm2835.c
@@ -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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] mmc: host: fix potential null pointer dereference
  2017-05-23 23:42 [PATCH] mmc: host: fix potential null pointer dereference Gustavo A. R. Silva
@ 2017-05-25  9:12 ` Stefan Wahren
  2017-05-25 16:46   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Wahren @ 2017-05-25  9:12 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Gustavo,

> "Gustavo A. R. Silva" <garsilva@embeddedor.com> 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
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>

Tested-by: Stefan Wahren <stefan.wahren@i2se.com>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] mmc: host: fix potential null pointer dereference
  2017-05-25  9:12 ` Stefan Wahren
@ 2017-05-25 16:46   ` Gustavo A. R. Silva
  2017-05-25 17:04     ` [PATCH v2] mmc: bcm2835: fix potential null pointer dereferences Gustavo A. R. Silva
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo A. R. Silva @ 2017-05-25 16:46 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Stefan,

Quoting Stefan Wahren <stefan.wahren@i2se.com>:

> Hi Gustavo,
>
>> "Gustavo A. R. Silva" <garsilva@embeddedor.com> 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
>> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
>
> Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
>
> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] mmc: bcm2835: fix potential null pointer dereferences
  2017-05-25 16:46   ` Gustavo A. R. Silva
@ 2017-05-25 17:04     ` Gustavo A. R. Silva
  2017-05-29 14:42       ` Ulf Hansson
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo A. R. Silva @ 2017-05-25 17:04 UTC (permalink / raw)
  To: linux-arm-kernel

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
Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
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(-)

diff --git a/drivers/mmc/host/bcm2835.c b/drivers/mmc/host/bcm2835.c
index 1f343a4..abba9a2 100644
--- a/drivers/mmc/host/bcm2835.c
+++ b/drivers/mmc/host/bcm2835.c
@@ -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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] mmc: bcm2835: fix potential null pointer dereferences
  2017-05-25 17:04     ` [PATCH v2] mmc: bcm2835: fix potential null pointer dereferences Gustavo A. R. Silva
@ 2017-05-29 14:42       ` Ulf Hansson
  0 siblings, 0 replies; 5+ messages in thread
From: Ulf Hansson @ 2017-05-29 14:42 UTC (permalink / raw)
  To: linux-arm-kernel

On 25 May 2017 at 19:04, Gustavo A. R. Silva <garsilva@embeddedor.com> wrote:
> 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
> Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>

Thanks, applied for next!

Kind regards
Uffe

> ---
> 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(-)
>
> diff --git a/drivers/mmc/host/bcm2835.c b/drivers/mmc/host/bcm2835.c
> index 1f343a4..abba9a2 100644
> --- a/drivers/mmc/host/bcm2835.c
> +++ b/drivers/mmc/host/bcm2835.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-05-29 14:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-23 23:42 [PATCH] mmc: host: fix potential null pointer dereference Gustavo A. R. Silva
2017-05-25  9:12 ` Stefan Wahren
2017-05-25 16:46   ` Gustavo A. R. Silva
2017-05-25 17:04     ` [PATCH v2] mmc: bcm2835: fix potential null pointer dereferences Gustavo A. R. Silva
2017-05-29 14:42       ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).