mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vinod Koul <vkoul@kernel.org>
To: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: dan.j.williams@intel.com, dmaengine@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] dma: mv_xor: Fix a possible null-pointer dereference in mv_xor_prep_dma_xor()
Date: Thu, 8 Aug 2019 18:51:40 +0530	[thread overview]
Message-ID: <20190808132140.GZ12733@vkoul-mobl.Dlink> (raw)
In-Reply-To: <20190727093027.11781-1-baijiaju1990@gmail.com>

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

      reply	other threads:[~2019-08-08 13:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-27  9:30 Jia-Ju Bai
2019-08-08 13:21 ` Vinod Koul [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190808132140.GZ12733@vkoul-mobl.Dlink \
    --to=vkoul@kernel.org \
    --cc=baijiaju1990@gmail.com \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®