All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	Colin King <colin.king@canonical.com>
Cc: devel@driverdev.osuosl.org,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: ks7010_sdio: fix NULL pointer dereference and memory leak
Date: Thu, 12 Apr 2018 18:08:25 +0300	[thread overview]
Message-ID: <20180412150825.ckyvcmw2shvdbwvs@mwanda> (raw)
In-Reply-To: <20180412143009.GA31998@embeddedor.com>

I added Colin to the Cc list.

On Thu, Apr 12, 2018 at 09:30:09AM -0500, Gustavo A. R. Silva wrote:
> priv is being dereferenced when it is still null, hence there is an
> explicit null pointer dereference at line 935: free_netdev(priv->net_dev)
> 
> Also, memory allocated for netdev at line 854:
> netdev = alloc_etherdev(sizeof(*priv));
> is not being free'd, hence there is a memory leak.
> 
> Fix this by null checking priv before dererefencing it and free netdev
> before return.
> 
> Addresses-Coverity-ID: 1467844 ("Explicit null dereferenced")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  drivers/staging/ks7010/ks7010_sdio.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/ks7010/ks7010_sdio.c b/drivers/staging/ks7010/ks7010_sdio.c
> index b8f55a1..f5d4c62 100644
> --- a/drivers/staging/ks7010/ks7010_sdio.c
> +++ b/drivers/staging/ks7010/ks7010_sdio.c
> @@ -932,8 +932,12 @@ static int ks7010_sdio_probe(struct sdio_func *func,
>  	return 0;
>  
>   err_free_netdev:
> -	free_netdev(priv->net_dev);
> -	card->priv = NULL;
> +	if (priv) {
> +		free_netdev(priv->net_dev);
> +		card->priv = NULL;

This isn't required because the next thing we do to card is kfree(card).

> +	} else {
> +		free_netdev(netdev);
> +	}


That's too complicated.  Just do:

err_free_netdev:
	free_netdev(net_dev);

err_release_irq:
	...

Please send a v2 patch.

regards,
dan carpenter


_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  reply	other threads:[~2018-04-12 15:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-12 14:30 [PATCH] staging: ks7010_sdio: fix NULL pointer dereference and memory leak Gustavo A. R. Silva
2018-04-12 15:08 ` Dan Carpenter [this message]
2018-04-12 15:14   ` Gustavo A. R. Silva

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=20180412150825.ckyvcmw2shvdbwvs@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=colin.king@canonical.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavo@embeddedor.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.