public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 1/2] NetworkPkg/HttpDxe: fix read memory access overflow in HTTPBoot.
  2018-09-25  8:24 [PATCH 0/2] fix read memory access overflow in HTTPBoot Songpeng Li
@ 2018-09-25  8:24 ` Songpeng Li
  0 siblings, 0 replies; 6+ messages in thread
From: Songpeng Li @ 2018-09-25  8:24 UTC (permalink / raw)
  To: edk2-devel; +Cc: Fu Siyuan, Wu Jiaxin

The input param String of AsciiStrStr() requires a pointer to
 Null-terminated string, however in HttpTcpReceiveHeader(),
 the Buffersize before AllocateZeroPool() is equal to the size
 of TCP header, after the CopyMem(), it might not end with
 Null-terminator. It might cause memory access overflow.

Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1204
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Songpeng Li <songpeng.li@intel.com>
---
 NetworkPkg/HttpDxe/HttpProto.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c
index 94f89f5665..7d69429be7 100644
--- a/NetworkPkg/HttpDxe/HttpProto.c
+++ b/NetworkPkg/HttpDxe/HttpProto.c
@@ -1914,10 +1914,10 @@ HttpTcpReceiveHeader (
       }
 
       //
-      // Append the response string.
+      // Append the response string along with a Null-terminator.
       //
       *BufferSize = *SizeofHeaders + Fragment.Len;
-      Buffer      = AllocateZeroPool (*BufferSize);
+      Buffer      = AllocatePool (*BufferSize + 1);
       if (Buffer == NULL) {
         Status = EFI_OUT_OF_RESOURCES;
         return Status;
@@ -1933,6 +1933,7 @@ HttpTcpReceiveHeader (
         Fragment.Bulk,
         Fragment.Len
         );
+      *(Buffer + *BufferSize) = '\0';
       *HttpHeaders   = Buffer;
       *SizeofHeaders = *BufferSize;
 
@@ -2013,10 +2014,10 @@ HttpTcpReceiveHeader (
       }
 
       //
-      // Append the response string.
+      // Append the response string along with a Null-terminator.
       //
       *BufferSize = *SizeofHeaders + Fragment.Len;
-      Buffer      = AllocateZeroPool (*BufferSize);
+      Buffer      = AllocatePool (*BufferSize + 1);
       if (Buffer == NULL) {
         Status = EFI_OUT_OF_RESOURCES;
         return Status;
@@ -2032,6 +2033,7 @@ HttpTcpReceiveHeader (
         Fragment.Bulk,
         Fragment.Len
         );
+      *(Buffer + *BufferSize) = '\0';
       *HttpHeaders   = Buffer;
       *SizeofHeaders = *BufferSize;
 
-- 
2.18.0.windows.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 0/2] fix read memory access overflow in HTTPBoot.
@ 2018-09-28  1:57 Songpeng Li
  2018-09-28  1:57 ` [PATCH 1/2] NetworkPkg/HttpDxe: " Songpeng Li
  2018-09-28  1:57 ` [PATCH 2/2] NetworkPkg/HttpUtilitiesDxe: fix read memory access overflow Songpeng Li
  0 siblings, 2 replies; 6+ messages in thread
From: Songpeng Li @ 2018-09-28  1:57 UTC (permalink / raw)
  To: edk2-devel

The input param String of AsciiStrStr() requires a pointer to
 Null-terminated string, however in HttpTcpReceiveHeader() and
 HttpUtilitiesParse(), the Buffersize before AllocateZeroPool()
 is equal to the size of TCP header, after the CopyMem(), it
 might not end with Null-terminator. It might cause memory
 access overflow.

Songpeng Li (2):
  NetworkPkg/HttpDxe: fix read memory access overflow in HTTPBoot.
  NetworkPkg/HttpUtilitiesDxe: fix read memory access overflow.

 NetworkPkg/HttpDxe/HttpProto.c                      | 10 ++++++----
 NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c |  8 +++++++-
 2 files changed, 13 insertions(+), 5 deletions(-)

-- 
2.18.0.windows.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] NetworkPkg/HttpDxe: fix read memory access overflow in HTTPBoot.
  2018-09-28  1:57 [PATCH 0/2] fix read memory access overflow in HTTPBoot Songpeng Li
@ 2018-09-28  1:57 ` Songpeng Li
  2018-09-28  2:32   ` Fu, Siyuan
  2018-09-28  1:57 ` [PATCH 2/2] NetworkPkg/HttpUtilitiesDxe: fix read memory access overflow Songpeng Li
  1 sibling, 1 reply; 6+ messages in thread
From: Songpeng Li @ 2018-09-28  1:57 UTC (permalink / raw)
  To: edk2-devel; +Cc: Fu Siyuan, Wu Jiaxin

The input param String of AsciiStrStr() requires a pointer to
 Null-terminated string, however in HttpTcpReceiveHeader(),
 the Buffersize before AllocateZeroPool() is equal to the size
 of TCP header, after the CopyMem(), it might not end with
 Null-terminator. It might cause memory access overflow.

Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1204
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Songpeng Li <songpeng.li@intel.com>
---
 NetworkPkg/HttpDxe/HttpProto.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c
index 94f89f5665..7d69429be7 100644
--- a/NetworkPkg/HttpDxe/HttpProto.c
+++ b/NetworkPkg/HttpDxe/HttpProto.c
@@ -1914,10 +1914,10 @@ HttpTcpReceiveHeader (
       }
 
       //
-      // Append the response string.
+      // Append the response string along with a Null-terminator.
       //
       *BufferSize = *SizeofHeaders + Fragment.Len;
-      Buffer      = AllocateZeroPool (*BufferSize);
+      Buffer      = AllocatePool (*BufferSize + 1);
       if (Buffer == NULL) {
         Status = EFI_OUT_OF_RESOURCES;
         return Status;
@@ -1933,6 +1933,7 @@ HttpTcpReceiveHeader (
         Fragment.Bulk,
         Fragment.Len
         );
+      *(Buffer + *BufferSize) = '\0';
       *HttpHeaders   = Buffer;
       *SizeofHeaders = *BufferSize;
 
@@ -2013,10 +2014,10 @@ HttpTcpReceiveHeader (
       }
 
       //
-      // Append the response string.
+      // Append the response string along with a Null-terminator.
       //
       *BufferSize = *SizeofHeaders + Fragment.Len;
-      Buffer      = AllocateZeroPool (*BufferSize);
+      Buffer      = AllocatePool (*BufferSize + 1);
       if (Buffer == NULL) {
         Status = EFI_OUT_OF_RESOURCES;
         return Status;
@@ -2032,6 +2033,7 @@ HttpTcpReceiveHeader (
         Fragment.Bulk,
         Fragment.Len
         );
+      *(Buffer + *BufferSize) = '\0';
       *HttpHeaders   = Buffer;
       *SizeofHeaders = *BufferSize;
 
-- 
2.18.0.windows.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] NetworkPkg/HttpUtilitiesDxe: fix read memory access overflow.
  2018-09-28  1:57 [PATCH 0/2] fix read memory access overflow in HTTPBoot Songpeng Li
  2018-09-28  1:57 ` [PATCH 1/2] NetworkPkg/HttpDxe: " Songpeng Li
@ 2018-09-28  1:57 ` Songpeng Li
  2018-09-28  2:32   ` Fu, Siyuan
  1 sibling, 1 reply; 6+ messages in thread
From: Songpeng Li @ 2018-09-28  1:57 UTC (permalink / raw)
  To: edk2-devel; +Cc: Fu Siyuan, Wu Jiaxin

The input param String of AsciiStrStr() requires a pointer to
 Null-terminated string, however in HttpUtilitiesParse(),
 the Buffersize before AllocateZeroPool() is equal to the size
 of TCP header, after the CopyMem(), it might not end with
 Null-terminator. It might cause memory access overflow.

Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1204
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Songpeng Li <songpeng.li@intel.com>
---
 NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c
index a9a1c7c586..b0e3e7f081 100644
--- a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c
+++ b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c
@@ -298,6 +298,7 @@ HttpUtilitiesParse (
   CHAR8                     *FieldName;
   CHAR8                     *FieldValue;
   UINTN                     Index;
+  UINTN                     HttpBufferSize;
 
   Status          = EFI_SUCCESS;
   TempHttpMessage = NULL;
@@ -311,12 +312,17 @@ HttpUtilitiesParse (
     return EFI_INVALID_PARAMETER;
   }
 
-  TempHttpMessage = AllocateZeroPool (HttpMessageSize);
+  //
+  // Append the http response string along with a Null-terminator.
+  //
+  HttpBufferSize = HttpMessageSize + 1;
+  TempHttpMessage = AllocatePool (HttpBufferSize);
   if (TempHttpMessage == NULL) {
     return EFI_OUT_OF_RESOURCES;
   }
 
   CopyMem (TempHttpMessage, HttpMessage, HttpMessageSize);
+  *(TempHttpMessage + HttpMessageSize) = '\0';
 
   //
   // Get header number
-- 
2.18.0.windows.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] NetworkPkg/HttpDxe: fix read memory access overflow in HTTPBoot.
  2018-09-28  1:57 ` [PATCH 1/2] NetworkPkg/HttpDxe: " Songpeng Li
@ 2018-09-28  2:32   ` Fu, Siyuan
  0 siblings, 0 replies; 6+ messages in thread
From: Fu, Siyuan @ 2018-09-28  2:32 UTC (permalink / raw)
  To: Li, Songpeng, edk2-devel@lists.01.org; +Cc: Wu, Jiaxin

Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Songpeng Li
> Sent: Friday, September 28, 2018 9:57 AM
> To: edk2-devel@lists.01.org
> Cc: Fu, Siyuan <siyuan.fu@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [edk2] [PATCH 1/2] NetworkPkg/HttpDxe: fix read memory access
> overflow in HTTPBoot.
> 
> The input param String of AsciiStrStr() requires a pointer to
>  Null-terminated string, however in HttpTcpReceiveHeader(),
>  the Buffersize before AllocateZeroPool() is equal to the size
>  of TCP header, after the CopyMem(), it might not end with
>  Null-terminator. It might cause memory access overflow.
> 
> Cc: Fu Siyuan <siyuan.fu@intel.com>
> Cc: Wu Jiaxin <jiaxin.wu@intel.com>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1204
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Songpeng Li <songpeng.li@intel.com>
> ---
>  NetworkPkg/HttpDxe/HttpProto.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/NetworkPkg/HttpDxe/HttpProto.c
> b/NetworkPkg/HttpDxe/HttpProto.c
> index 94f89f5665..7d69429be7 100644
> --- a/NetworkPkg/HttpDxe/HttpProto.c
> +++ b/NetworkPkg/HttpDxe/HttpProto.c
> @@ -1914,10 +1914,10 @@ HttpTcpReceiveHeader (
>        }
> 
>        //
> -      // Append the response string.
> +      // Append the response string along with a Null-terminator.
>        //
>        *BufferSize = *SizeofHeaders + Fragment.Len;
> -      Buffer      = AllocateZeroPool (*BufferSize);
> +      Buffer      = AllocatePool (*BufferSize + 1);
>        if (Buffer == NULL) {
>          Status = EFI_OUT_OF_RESOURCES;
>          return Status;
> @@ -1933,6 +1933,7 @@ HttpTcpReceiveHeader (
>          Fragment.Bulk,
>          Fragment.Len
>          );
> +      *(Buffer + *BufferSize) = '\0';
>        *HttpHeaders   = Buffer;
>        *SizeofHeaders = *BufferSize;
> 
> @@ -2013,10 +2014,10 @@ HttpTcpReceiveHeader (
>        }
> 
>        //
> -      // Append the response string.
> +      // Append the response string along with a Null-terminator.
>        //
>        *BufferSize = *SizeofHeaders + Fragment.Len;
> -      Buffer      = AllocateZeroPool (*BufferSize);
> +      Buffer      = AllocatePool (*BufferSize + 1);
>        if (Buffer == NULL) {
>          Status = EFI_OUT_OF_RESOURCES;
>          return Status;
> @@ -2032,6 +2033,7 @@ HttpTcpReceiveHeader (
>          Fragment.Bulk,
>          Fragment.Len
>          );
> +      *(Buffer + *BufferSize) = '\0';
>        *HttpHeaders   = Buffer;
>        *SizeofHeaders = *BufferSize;
> 
> --
> 2.18.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] NetworkPkg/HttpUtilitiesDxe: fix read memory access overflow.
  2018-09-28  1:57 ` [PATCH 2/2] NetworkPkg/HttpUtilitiesDxe: fix read memory access overflow Songpeng Li
@ 2018-09-28  2:32   ` Fu, Siyuan
  0 siblings, 0 replies; 6+ messages in thread
From: Fu, Siyuan @ 2018-09-28  2:32 UTC (permalink / raw)
  To: Li, Songpeng, edk2-devel@lists.01.org; +Cc: Wu, Jiaxin

Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>



> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Songpeng Li
> Sent: Friday, September 28, 2018 9:57 AM
> To: edk2-devel@lists.01.org
> Cc: Fu, Siyuan <siyuan.fu@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [edk2] [PATCH 2/2] NetworkPkg/HttpUtilitiesDxe: fix read memory
> access overflow.
> 
> The input param String of AsciiStrStr() requires a pointer to
>  Null-terminated string, however in HttpUtilitiesParse(),
>  the Buffersize before AllocateZeroPool() is equal to the size
>  of TCP header, after the CopyMem(), it might not end with
>  Null-terminator. It might cause memory access overflow.
> 
> Cc: Fu Siyuan <siyuan.fu@intel.com>
> Cc: Wu Jiaxin <jiaxin.wu@intel.com>
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1204
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Songpeng Li <songpeng.li@intel.com>
> ---
>  NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c
> b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c
> index a9a1c7c586..b0e3e7f081 100644
> --- a/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c
> +++ b/NetworkPkg/HttpUtilitiesDxe/HttpUtilitiesProtocol.c
> @@ -298,6 +298,7 @@ HttpUtilitiesParse (
>    CHAR8                     *FieldName;
>    CHAR8                     *FieldValue;
>    UINTN                     Index;
> +  UINTN                     HttpBufferSize;
> 
>    Status          = EFI_SUCCESS;
>    TempHttpMessage = NULL;
> @@ -311,12 +312,17 @@ HttpUtilitiesParse (
>      return EFI_INVALID_PARAMETER;
>    }
> 
> -  TempHttpMessage = AllocateZeroPool (HttpMessageSize);
> +  //
> +  // Append the http response string along with a Null-terminator.
> +  //
> +  HttpBufferSize = HttpMessageSize + 1;
> +  TempHttpMessage = AllocatePool (HttpBufferSize);
>    if (TempHttpMessage == NULL) {
>      return EFI_OUT_OF_RESOURCES;
>    }
> 
>    CopyMem (TempHttpMessage, HttpMessage, HttpMessageSize);
> +  *(TempHttpMessage + HttpMessageSize) = '\0';
> 
>    //
>    // Get header number
> --
> 2.18.0.windows.1
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-09-28  2:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-28  1:57 [PATCH 0/2] fix read memory access overflow in HTTPBoot Songpeng Li
2018-09-28  1:57 ` [PATCH 1/2] NetworkPkg/HttpDxe: " Songpeng Li
2018-09-28  2:32   ` Fu, Siyuan
2018-09-28  1:57 ` [PATCH 2/2] NetworkPkg/HttpUtilitiesDxe: fix read memory access overflow Songpeng Li
2018-09-28  2:32   ` Fu, Siyuan
  -- strict thread matches above, loose matches on Subject: below --
2018-09-25  8:24 [PATCH 0/2] fix read memory access overflow in HTTPBoot Songpeng Li
2018-09-25  8:24 ` [PATCH 1/2] NetworkPkg/HttpDxe: " Songpeng Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox