Netdev List
 help / color / mirror / Atom feed
From: YueHaibing <yuehaibing@huawei.com>
To: <davem@davemloft.net>
Cc: <netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next] net: fddi: fix a possible null-ptr-deref
Date: Tue, 5 Jun 2018 21:08:14 +0800	[thread overview]
Message-ID: <d1dc0497-7b03-111a-9c58-594eeb9c67fc@huawei.com> (raw)
In-Reply-To: <20180605100627.16184-1-yuehaibing@huawei.com>

On 2018/6/5 18:06, YueHaibing wrote:
> bp->SharedMemAddr is set to NULL while bp->SharedMemSize less than 0,
> then memset will trigger null-ptr-deref.
> 
> Fix it use pci_zalloc_consistent when bp->SharedMemSize is greater than 0.
> 
> Signed-off-by: YueHaibing <yuehaibing@huawei.com>
> ---
>  drivers/net/fddi/skfp/skfddi.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/fddi/skfp/skfddi.c b/drivers/net/fddi/skfp/skfddi.c
> index 2414f1d..90164e0 100644
> --- a/drivers/net/fddi/skfp/skfddi.c
> +++ b/drivers/net/fddi/skfp/skfddi.c
> @@ -407,23 +407,21 @@ static  int skfp_driver_init(struct net_device *dev)
>  	if (bp->SharedMemSize > 0) {
>  		bp->SharedMemSize += 16;	// for descriptor alignment
>  
> -		bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev,
> -							 bp->SharedMemSize,
> -							 &bp->SharedMemDMA);
> +		bp->SharedMemAddr = pci_zalloc_consistent(&bp->pdev,
> +							  bp->SharedMemSize,
> +							  &bp->SharedMemDMA);

This also need move from pci_dma* to dma_*, will send v2

>  		if (!bp->SharedMemAddr) {
>  			printk("could not allocate mem for ");
>  			printk("hardware module: %ld byte\n",
>  			       bp->SharedMemSize);
>  			goto fail;
>  		}
> -		bp->SharedMemHeap = 0;	// Nothing used yet.
>  
>  	} else {
>  		bp->SharedMemAddr = NULL;
> -		bp->SharedMemHeap = 0;
>  	}			// SharedMemSize > 0
>  
> -	memset(bp->SharedMemAddr, 0, bp->SharedMemSize);
> +	bp->SharedMemHeap = 0;
>  
>  	card_stop(smc);		// Reset adapter.
>  
> 

      reply	other threads:[~2018-06-05 13:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05 10:06 [PATCH net-next] net: fddi: fix a possible null-ptr-deref YueHaibing
2018-06-05 13:08 ` YueHaibing [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=d1dc0497-7b03-111a-9c58-594eeb9c67fc@huawei.com \
    --to=yuehaibing@huawei.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@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