dmaengine Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] dma: mv_xor: Fix a possible null-pointer dereference in mv_xor_prep_dma_xor()
@ 2019-07-27  9:30 Jia-Ju Bai
  2019-08-08 13:21 ` Vinod Koul
  0 siblings, 1 reply; 2+ messages in thread
From: Jia-Ju Bai @ 2019-07-27  9:30 UTC (permalink / raw)
  To: vkoul, dan.j.williams; +Cc: dmaengine, linux-kernel, Jia-Ju Bai

In mv_xor_prep_dma_xor(), there is an if statement on line 577 to check
whether sw_desc is NULL:
    if (sw_desc)

When sw_desc is NULL, it is used on line 594:
    dev_dbg(..., sw_desc, &sw_desc->async_tx);

Thus, a possible null-pointer dereference may occur.

To fix this bug, sw_desc is checked before being used.

This bug is found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 drivers/dma/mv_xor.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
index 0ac8e7b34e12..08c0b2a9eb32 100644
--- a/drivers/dma/mv_xor.c
+++ b/drivers/dma/mv_xor.c
@@ -589,9 +589,11 @@ mv_xor_prep_dma_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
 		}
 	}
 
-	dev_dbg(mv_chan_to_devp(mv_chan),
-		"%s sw_desc %p async_tx %p \n",
-		__func__, sw_desc, &sw_desc->async_tx);
+	if (sw_desc) {
+		dev_dbg(mv_chan_to_devp(mv_chan),
+			"%s sw_desc %p async_tx %p \n",
+			__func__, sw_desc, &sw_desc->async_tx);
+	}
 	return sw_desc ? &sw_desc->async_tx : NULL;
 }
 
-- 
2.17.0


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

* Re: [PATCH] dma: mv_xor: Fix a possible null-pointer dereference in mv_xor_prep_dma_xor()
  2019-07-27  9:30 [PATCH] dma: mv_xor: Fix a possible null-pointer dereference in mv_xor_prep_dma_xor() Jia-Ju Bai
@ 2019-08-08 13:21 ` Vinod Koul
  0 siblings, 0 replies; 2+ messages in thread
From: Vinod Koul @ 2019-08-08 13:21 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: dan.j.williams, dmaengine, linux-kernel

On 27-07-19, 17:30, Jia-Ju Bai wrote:
> In mv_xor_prep_dma_xor(), there is an if statement on line 577 to check
> whether sw_desc is NULL:
>     if (sw_desc)
> 
> When sw_desc is NULL, it is used on line 594:
>     dev_dbg(..., sw_desc, &sw_desc->async_tx);
> 
> Thus, a possible null-pointer dereference may occur.
> 
> To fix this bug, sw_desc is checked before being used.
> 
> This bug is found by a static analysis tool STCheck written by us.
> 
> Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
> ---
>  drivers/dma/mv_xor.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
> index 0ac8e7b34e12..08c0b2a9eb32 100644
> --- a/drivers/dma/mv_xor.c
> +++ b/drivers/dma/mv_xor.c
> @@ -589,9 +589,11 @@ mv_xor_prep_dma_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
>  		}
>  	}
>  
> -	dev_dbg(mv_chan_to_devp(mv_chan),
> -		"%s sw_desc %p async_tx %p \n",
> -		__func__, sw_desc, &sw_desc->async_tx);
> +	if (sw_desc) {
> +		dev_dbg(mv_chan_to_devp(mv_chan),
> +			"%s sw_desc %p async_tx %p \n",
> +			__func__, sw_desc, &sw_desc->async_tx);
> +	}

why not move this into the preceeding if condition?

>  	return sw_desc ? &sw_desc->async_tx : NULL;
>  }
>  
> -- 
> 2.17.0

-- 
~Vinod

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-27  9:30 [PATCH] dma: mv_xor: Fix a possible null-pointer dereference in mv_xor_prep_dma_xor() Jia-Ju Bai
2019-08-08 13:21 ` Vinod Koul

dmaengine Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/dmaengine/0 dmaengine/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dmaengine dmaengine/ https://lore.kernel.org/dmaengine \
		dmaengine@vger.kernel.org dmaengine@archiver.kernel.org
	public-inbox-index dmaengine


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.dmaengine


AGPL code for this site: git clone https://public-inbox.org/ public-inbox