public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Wu, Jiaxin" <jiaxin.wu@intel.com>
To: Santhapur Naveen <naveens@amiindia.co.in>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: Array out of bounds write
Date: Tue, 11 Apr 2017 11:53:28 +0000	[thread overview]
Message-ID: <895558F6EA4E3B41AC93A00D163B7274162BF6B4@SHSMSX103.ccr.corp.intel.com> (raw)
In-Reply-To: <625A2455CC232F40B0F38F05ACED6D97C867892F@Venus2.in.megatrends.com>

Hi Naveen,

Please feel free for the below coding, the array should never over bound since the buffer has been allocated before using it.

 	 FragCount = (HeaderSize != NULL) ? 2 : 1;
  	TxLength  = sizeof (EFI_UDP6_TRANSMIT_DATA) + (FragCount - 1) * sizeof (EFI_UDP6_FRAGMENT_DATA);
  	TxData    = (EFI_UDP6_TRANSMIT_DATA *) AllocateZeroPool (TxLength);

Actually, you can treat it as pointer, and the allocated memory would be lost since we have defined the FragmentCount.

Thanks,
Jiaxin

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Santhapur Naveen
> Sent: Tuesday, April 11, 2017 4:06 PM
> To: edk2-devel@lists.01.org
> Subject: [edk2] Array out of bounds write
> Importance: High
> 
> Hello all,
> 
>             In the file PxeBcSupport.c of NetworkPkg there is
> 
> EFI_STATUS
> PxeBcUdp4Write (
> {
>             ...
>             //
>             // Arrange one fragment buffer for data, and another fragment buffer
> for header if has.
>             //
>             FragCount = (HeaderSize != NULL) ? 2 : 1;
>             ...
>             TxData->FragmentTable[FragCount - 1].FragmentLength = (UINT32)
> *BufferSize;
>             ...
> }
> 
> And similarly in
> 
> EFI_STATUS
> PxeBcUdp6Write (
> {
>             ...
>             //
>             // Arrange one fragment buffer for data, and another fragment buffer
> for header if has.
>             //
>             FragCount = (HeaderSize != NULL) ? 2 : 1;
>             ...
>             TxData->FragmentTable[FragCount - 1].FragmentLength = (UINT32)
> *BufferSize;
>             ...
> }
> 
> If HeaderSize is not NULL, then there is a chance of writing array over bounds
> since FragmentTable is of single element.
> 
> ///
>   /// Array of fragment descriptors.
>   ///
>   EFI_UDP6_FRAGMENT_DATA    FragmentTable[1];
> 
> Shouldn't we be taking care of this?
> 
> 
> Regards,
> Naveen
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


      reply	other threads:[~2017-04-11 11:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-11  8:05 Array out of bounds write Santhapur Naveen
2017-04-11 11:53 ` Wu, Jiaxin [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-list 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=895558F6EA4E3B41AC93A00D163B7274162BF6B4@SHSMSX103.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /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