All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ajay Singh <ajay.kathat@microchip.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: <linux-wireless@vger.kernel.org>, <devel@driverdev.osuosl.org>,
	<venkateswara.kaja@microchip.com>, <gregkh@linuxfoundation.org>,
	<ganesh.krishna@microchip.com>, <adham.abozaeid@microchip.com>,
	<aditya.shankar@microchip.com>
Subject: Re: [PATCH 01/11] staging: wilc1000: refactor scan() to free kmalloc memory on failure cases
Date: Wed, 21 Mar 2018 10:35:41 +0530	[thread overview]
Message-ID: <20180321103541.53c399c0@ajaysk-VirtualBox> (raw)
In-Reply-To: <20180320194632.2dwmzdx5h4mvnksk@mwanda>

Hi Dan,

Thanks for your detailed review comments.

On Tue, 20 Mar 2018 22:46:32 +0300
Dan Carpenter <dan.carpenter@oracle.com> wrote:

> On Tue, Mar 20, 2018 at 10:25:34PM +0530, Ajay Singh wrote:
> > Added changes to free the allocated memory in scan() for error condition.
> > Also added 'NULL' check validation before accessing allocated memory.
> > 
> > Signed-off-by: Ajay Singh <ajay.kathat@microchip.com>

> Don't put a blank line between the alloc and the check.  They're as
> connected as can be.  I hate "goto out;" but that is a personal
> preference which I would never push on to other developers...
> 

I will modify the code to address the review comments and will send the
updated patch.

> > +
> > +	ntwk->n_ssids = request->n_ssids;
> > +
> > +	for (i = 0; i < request->n_ssids; i++) {
> > +		if (request->ssids[i].ssid_len > 0) {
> > +			struct hidden_net_info *info = &ntwk->net_info[i];
> > +
> > +			info->ssid = kmemdup(request->ssids[i].ssid,
> > +					     request->ssids[i].ssid_len,
> > +					     GFP_KERNEL);
> > +
> > +			if (!info->ssid)
> > +				goto out_free;
> > +
> > +			info->ssid_len = request->ssids[i].ssid_len;
> > +		} else {
> > +			ntwk->n_ssids -= 1;
> > +		}  
> 
> You didn't introduce the problem, but this loop seems kind of buggy.  We
> should have two iterators, one for request->ssids[i] and one for
> ntwk->net_info[i].  Otherwise we're copying the array information but
> we're leaving holes in the destination array.  Which would be fine
> except we're not saving the totaly number of elements in the destination
> array, we're saving the number of elements with stuff in them.
> 
> So imagine that we have a request->n_ssids == 10 but only the last
> three elements have request->ssids[i].ssid_len > 0.  Then we record that
> ntwk->n_ssids is 3 but wthose elements are all holes.  So that can't
> work.  See handle_scan():
> 
> 	for (i = 0; i < hidden_net->n_ssids; i++)
> 		valuesize += ((hidden_net->net_info[i].ssid_len) + 1);
> 
> "valuesize" is wrong because it's looking at holes.

While testing, I found that the last element in request->ssids the
ssid_len is zero. For in between elements the values has some valid
length. I only tested for 'connect with AP' and 'iw scan' operation.
The scenario you have mention can occur for some instance. So, I will
modify the code to not have holes in allocated array at the time of
filling the data.
I will include these changes and send updated v2 patch set.

> 
> > +	}
> > +	return true;
> > +
> > +out_free:
> > +
> > +	for (; i >= 0 ; i--)
> > +		kfree(ntwk->net_info[i].ssid);  
> 
> The first kfree(ntwk->net_info[i].ssid); is a no-op.  You could write
> this like:
> 
> 	while (--i >= 0)
> 		kfree(ntwk->net_info[i].ssid);
> 

I will include these changes and send the updated patch.



Regards,
Ajay

  reply	other threads:[~2018-03-21  5:05 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-20 16:55 [PATCH 00/11] staging: wilc1000: fix for checkpatch and handled malloc memory properly Ajay Singh
2018-03-20 16:55 ` [PATCH 01/11] staging: wilc1000: refactor scan() to free kmalloc memory on failure cases Ajay Singh
2018-03-20 19:46   ` Dan Carpenter
2018-03-21  5:05     ` Ajay Singh [this message]
2018-03-20 16:55 ` [PATCH 02/11] staging: wilc1000: removed unused global variables for gtk and ptk information Ajay Singh
2018-03-20 16:55 ` [PATCH 03/11] staging: wilc1000: remove line over 80 char warnings in set_wiphy_params() Ajay Singh
2018-03-20 16:55 ` [PATCH 04/11] staging: wilc1000: refactor WILC_WFI_p2p_rx() to avoid line over 80 char Ajay Singh
2018-03-21  7:13   ` Dan Carpenter
2018-03-21 13:55   ` Claudiu Beznea
2018-03-20 16:55 ` [PATCH 05/11] staging: wilc1000: rename WILC_WFI_p2p_rx & s32Freq to avoid camelCase Ajay Singh
2018-03-20 16:55 ` [PATCH 06/11] staging: wilc1000: refactor mgmt_tx to fix line over 80 chars Ajay Singh
2018-03-21  7:40   ` Dan Carpenter
2018-03-21 13:59   ` Claudiu Beznea
2018-03-20 16:55 ` [PATCH 07/11] staging: wilc1000: rename hAgingTimer to avoid camelCase issue Ajay Singh
2018-03-20 16:55 ` [PATCH 08/11] staging: wilc1000: fix line over 80 char issue in clear_shadow_scan() Ajay Singh
2018-03-20 16:55 ` [PATCH 09/11] staging: wilc1000: remove line over 80 char in cfg_connect_result() Ajay Singh
2018-03-21  7:49   ` Dan Carpenter
2018-03-20 16:55 ` [PATCH 10/11] staging: wilc1000: remove unused 'struct add_key_params' Ajay Singh
2018-03-20 16:55 ` [PATCH 11/11] staging: wilc1000: remove line over 80 char warning in few functions Ajay Singh
2018-03-21  7:51 ` [PATCH 00/11] staging: wilc1000: fix for checkpatch and handled malloc memory properly Dan Carpenter
2018-03-21  9:20   ` Ajay Singh
2018-03-21 14:04     ` Claudiu Beznea
2018-03-27  7:22       ` Ajay Singh
2018-03-27  8:55         ` Claudiu Beznea
2018-03-27 13:16           ` Ajay Singh
2018-03-28 11:31         ` Greg KH
2018-04-04  5:15           ` Ajay Singh
2018-04-23 13:43             ` Greg KH

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=20180321103541.53c399c0@ajaysk-VirtualBox \
    --to=ajay.kathat@microchip.com \
    --cc=adham.abozaeid@microchip.com \
    --cc=aditya.shankar@microchip.com \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=ganesh.krishna@microchip.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=venkateswara.kaja@microchip.com \
    /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.