All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vadim.Lomovtsev@caviumnetworks.com (Vadim Lomovtsev)
To: linux-arm-kernel@lists.infradead.org
Subject: [v2] net: thunderx: nicvf_main: Fix potential NULL pointer dereferences
Date: Thu, 5 Apr 2018 05:38:13 -0700	[thread overview]
Message-ID: <20180405123813.GA11841@localhost.localdomain> (raw)
In-Reply-To: <20180403220423.GA718@embeddedor.com>

Hi guys,

Please give me couple days to workout solution for this.
I'll post patch for this as soon as I done with my testing.

WBR,
Vadim

On Tue, Apr 03, 2018 at 05:04:23PM -0500, Gustavo A. R. Silva wrote:
> Add null check on kmalloc() return value in order to prevent
> a null pointer dereference.
> 
> Addresses-Coverity-ID: 1467429 ("Dereference null return value")
> Fixes: 37c3347eb247 ("net: thunderx: add ndo_set_rx_mode callback implementation for VF")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
> Changes in v2:
>  - Add a null check on a second kmalloc a few lines below. Thanks to
>    Eric Dumazet for pointing this out.
> 
>  drivers/net/ethernet/cavium/thunder/nicvf_main.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
> index 1e9a31f..f7b5ca5 100644
> --- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c
> +++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
> @@ -1999,10 +1999,14 @@ static void nicvf_set_rx_mode(struct net_device *netdev)
>  				struct xcast_addr *xaddr;
>  
>  				mc_list = kmalloc(sizeof(*mc_list), GFP_ATOMIC);
> +				if (unlikely(!mc_list))
> +					return;
>  				INIT_LIST_HEAD(&mc_list->list);
>  				netdev_hw_addr_list_for_each(ha, &netdev->mc) {
>  					xaddr = kmalloc(sizeof(*xaddr),
>  							GFP_ATOMIC);
> +					if (unlikely(!xaddr))
> +						return;
>  					xaddr->addr =
>  						ether_addr_to_u64(ha->addr);
>  					list_add_tail(&xaddr->list,

WARNING: multiple messages have this Message-ID (diff)
From: Vadim Lomovtsev <Vadim.Lomovtsev@caviumnetworks.com>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>
Cc: Eric Dumazet <eric.dumazet@gmail.com>,
	Sunil Goutham <sgoutham@cavium.com>,
	Robert Richter <rric@kernel.org>,
	linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [v2] net: thunderx: nicvf_main: Fix potential NULL pointer dereferences
Date: Thu, 5 Apr 2018 05:38:13 -0700	[thread overview]
Message-ID: <20180405123813.GA11841@localhost.localdomain> (raw)
In-Reply-To: <20180403220423.GA718@embeddedor.com>

Hi guys,

Please give me couple days to workout solution for this.
I'll post patch for this as soon as I done with my testing.

WBR,
Vadim

On Tue, Apr 03, 2018 at 05:04:23PM -0500, Gustavo A. R. Silva wrote:
> Add null check on kmalloc() return value in order to prevent
> a null pointer dereference.
> 
> Addresses-Coverity-ID: 1467429 ("Dereference null return value")
> Fixes: 37c3347eb247 ("net: thunderx: add ndo_set_rx_mode callback implementation for VF")
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
> Changes in v2:
>  - Add a null check on a second kmalloc a few lines below. Thanks to
>    Eric Dumazet for pointing this out.
> 
>  drivers/net/ethernet/cavium/thunder/nicvf_main.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ethernet/cavium/thunder/nicvf_main.c b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
> index 1e9a31f..f7b5ca5 100644
> --- a/drivers/net/ethernet/cavium/thunder/nicvf_main.c
> +++ b/drivers/net/ethernet/cavium/thunder/nicvf_main.c
> @@ -1999,10 +1999,14 @@ static void nicvf_set_rx_mode(struct net_device *netdev)
>  				struct xcast_addr *xaddr;
>  
>  				mc_list = kmalloc(sizeof(*mc_list), GFP_ATOMIC);
> +				if (unlikely(!mc_list))
> +					return;
>  				INIT_LIST_HEAD(&mc_list->list);
>  				netdev_hw_addr_list_for_each(ha, &netdev->mc) {
>  					xaddr = kmalloc(sizeof(*xaddr),
>  							GFP_ATOMIC);
> +					if (unlikely(!xaddr))
> +						return;
>  					xaddr->addr =
>  						ether_addr_to_u64(ha->addr);
>  					list_add_tail(&xaddr->list,

  parent reply	other threads:[~2018-04-05 12:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-03 22:04 [PATCH v2] net: thunderx: nicvf_main: Fix potential NULL pointer dereferences Gustavo A. R. Silva
2018-04-03 22:04 ` Gustavo A. R. Silva
2018-04-04  6:36 ` Eric Dumazet
2018-04-04  6:36   ` Eric Dumazet
2018-04-04  6:41   ` Gustavo A. R. Silva
2018-04-04  6:41     ` Gustavo A. R. Silva
2018-04-05 12:38 ` Vadim Lomovtsev [this message]
2018-04-05 12:38   ` [v2] " Vadim Lomovtsev

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=20180405123813.GA11841@localhost.localdomain \
    --to=vadim.lomovtsev@caviumnetworks.com \
    --cc=linux-arm-kernel@lists.infradead.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.