linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Chandra Gorentla <csgorentla@gmail.com>
Cc: gregkh@linuxfoundation.org, rachel.kim@atmel.com,
	dean.lee@atmel.com, chris.park@atmel.com,
	devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org,
	johnny.kim@atmel.com, linux-kernel@vger.kernel.org,
	sudipm.mukherjee@gmail.com
Subject: Re: [PATCH] staging: wilc100: Remove pointer and integer comparision
Date: Mon, 10 Aug 2015 19:27:13 +0300	[thread overview]
Message-ID: <20150810155614.GK5096@mwanda> (raw)
In-Reply-To: <20150810152943.GA12993@gcs-HP-Compaq-nx6320>

On Mon, Aug 10, 2015 at 08:59:43PM +0530, Chandra Gorentla wrote:
> I agree with your suggestion
> that we need to take a broader look.  Please help in understanding
> how does that broader look is suggesting that the patch is not
> addressing a right problem.  The gcc version I am using is - 4.8.2.
> 
> In the later part of your reply - you felt that there may be a
> case in which more than the allocated number of bytes may be
> copied in to the memory pointed to by 'pu8CurrByte' and memory
> may get corrupted.  From the code in the function I am not seeing
> that happening.  In the beginning of the function, this pointer
> variable is assigned a block of memory whose size is
> '->u32HeadLen' + '->u32TailLen' + 16.
> 
> The function is copying 16 individual bytes to this memory;
> a smaller block of memory of size '->u32HeadLen' is being copied;
> and an another smaller block of memory of size '->u32TailLen' may
> be copied based on a condition.  After this last copy, the
> function increments the pointer by '->u32TailLen' irrespective
> of last copy takes place or not.  Hence I am not seeing any
> corruption of the memory.

It is an integer overflow.  Try the test.c file I'll include below.

> 
> It looks like that the last increment is just an operation that
> does no harm.  In addition to this the pointer variable
> 'pu8CurrByte' is just a local variable and it is not being used
> after the last increment operation of the pointer.

It's a pointer to allocated memory.  We call WILC_MALLOC().

This function allocates a buffer, then it copies memory over with the
memcpy().  The "*pu8CurrByte++ = " statements are copying memory but
doing endian conversion as well.  (This is not the correct way to do
endian conversion).

> 
> After making the change in this patch I just did a 'make'.
> I do not have the hardware which this driver supports.  So at
> this point of time, I cannot test your suggestions on wilc1000
> hardware.  Is there any way I can test this driver code on a
> old notebook computer?

Don't worry too much about testing this.  Just write small test programs
to help you understand as much as possible.  We are good at reviewing so
you aren't going to break the code.

#include <stdio.h>

int main(void)
{
	unsigned int u32HeadLen;
	unsigned int u32TailLen;
	int s32ValueSize;

	u32HeadLen = 1000;
	u32TailLen = -1U - 500 - 16 + 1;
	s32ValueSize = u32HeadLen + u32TailLen + 16;

	printf("Allocating %d bytes.\n", s32ValueSize);
	printf("Copying %u bytes into a %d byte buffer will corrupt memory.\n",
		u32HeadLen, s32ValueSize);

	return 0;
}

regards,
dan carpenter

  reply	other threads:[~2015-08-10 16:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-09 15:20 [PATCH] staging: wilc100: Remove pointer and integer comparision Chandra S Gorentla
2015-08-10  9:39 ` Dan Carpenter
2015-08-10 15:29   ` Chandra Gorentla
2015-08-10 16:27     ` Dan Carpenter [this message]
2015-08-10 17:40       ` Chandra Gorentla
2015-08-10 18:38         ` Dan Carpenter
2015-08-11 15:07           ` Chandra Gorentla

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=20150810155614.GK5096@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=chris.park@atmel.com \
    --cc=csgorentla@gmail.com \
    --cc=dean.lee@atmel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=johnny.kim@atmel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=rachel.kim@atmel.com \
    --cc=sudipm.mukherjee@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).