[edk2] [Patch] NetworkPkg/HttpDxe: Fix HTTP download OS image over 4G size failure

Jiaxin Wu posted 1 patch 7 years, 6 months ago
Failed in applying to current master (apply log)
NetworkPkg/HttpDxe/HttpProto.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
[edk2] [Patch] NetworkPkg/HttpDxe: Fix HTTP download OS image over 4G size failure
Posted by Jiaxin Wu 7 years, 6 months ago
UINT32 integer overflow will happen once the download OS image over
4G size. This patch is to fix this issue.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Zhang Lubo <lubo.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/HttpDxe/HttpProto.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c
index 3d61ba2..3fda294 100644
--- a/NetworkPkg/HttpDxe/HttpProto.c
+++ b/NetworkPkg/HttpDxe/HttpProto.c
@@ -2029,24 +2029,24 @@ HttpTcpReceiveBody (
     ASSERT (Tcp4 != NULL);
   }
   
   if (HttpInstance->LocalAddressIsIPv6) {
     Rx6Token = &Wrap->TcpWrap.Rx6Token;
-    Rx6Token ->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;
-    Rx6Token ->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;
+    Rx6Token ->Packet.RxData->DataLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
+    Rx6Token ->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
     Rx6Token ->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;
     Rx6Token->CompletionToken.Status = EFI_NOT_READY;
 
     Status = Tcp6->Receive (Tcp6, Rx6Token);
     if (EFI_ERROR (Status)) {
       DEBUG ((EFI_D_ERROR, "Tcp6 receive failed: %r\n", Status));
       return Status;
     }
   } else {
     Rx4Token = &Wrap->TcpWrap.Rx4Token;
-    Rx4Token->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;
-    Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;
+    Rx4Token->Packet.RxData->DataLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
+    Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
     Rx4Token->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;
     
     Rx4Token->CompletionToken.Status = EFI_NOT_READY;
     Status = Tcp4->Receive (Tcp4, Rx4Token);
     if (EFI_ERROR (Status)) {
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] NetworkPkg/HttpDxe: Fix HTTP download OS image over 4G size failure
Posted by Fu, Siyuan 7 years, 6 months ago
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>


-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jiaxin Wu
Sent: 2017年4月13日 18:37
To: edk2-devel@lists.01.org
Cc: Ye, Ting <ting.ye@intel.com>; Zhang, Lubo <lubo.zhang@intel.com>; Fu, Siyuan <siyuan.fu@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
Subject: [edk2] [Patch] NetworkPkg/HttpDxe: Fix HTTP download OS image over 4G size failure

UINT32 integer overflow will happen once the download OS image over 4G size. This patch is to fix this issue.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Zhang Lubo <lubo.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/HttpDxe/HttpProto.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c index 3d61ba2..3fda294 100644
--- a/NetworkPkg/HttpDxe/HttpProto.c
+++ b/NetworkPkg/HttpDxe/HttpProto.c
@@ -2029,24 +2029,24 @@ HttpTcpReceiveBody (
     ASSERT (Tcp4 != NULL);
   }
   
   if (HttpInstance->LocalAddressIsIPv6) {
     Rx6Token = &Wrap->TcpWrap.Rx6Token;
-    Rx6Token ->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;
-    Rx6Token ->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;
+    Rx6Token ->Packet.RxData->DataLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
+    Rx6Token ->Packet.RxData->FragmentTable[0].FragmentLength = 
+ (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
     Rx6Token ->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;
     Rx6Token->CompletionToken.Status = EFI_NOT_READY;
 
     Status = Tcp6->Receive (Tcp6, Rx6Token);
     if (EFI_ERROR (Status)) {
       DEBUG ((EFI_D_ERROR, "Tcp6 receive failed: %r\n", Status));
       return Status;
     }
   } else {
     Rx4Token = &Wrap->TcpWrap.Rx4Token;
-    Rx4Token->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;
-    Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;
+    Rx4Token->Packet.RxData->DataLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
+    Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) 
+ MIN (MAX_UINT32, HttpMsg->BodyLength);
     Rx4Token->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;
     
     Rx4Token->CompletionToken.Status = EFI_NOT_READY;
     Status = Tcp4->Receive (Tcp4, Rx4Token);
     if (EFI_ERROR (Status)) {
--
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] NetworkPkg/HttpDxe: Fix HTTP download OS image over 4G size failure
Posted by Ye, Ting 7 years, 6 months ago
Reviewed-by: Ye Ting <ting.ye@intel.com> 

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jiaxin Wu
Sent: Thursday, April 13, 2017 6:37 PM
To: edk2-devel@lists.01.org
Cc: Ye, Ting <ting.ye@intel.com>; Zhang, Lubo <lubo.zhang@intel.com>; Fu, Siyuan <siyuan.fu@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
Subject: [edk2] [Patch] NetworkPkg/HttpDxe: Fix HTTP download OS image over 4G size failure

UINT32 integer overflow will happen once the download OS image over 4G size. This patch is to fix this issue.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Zhang Lubo <lubo.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/HttpDxe/HttpProto.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c index 3d61ba2..3fda294 100644
--- a/NetworkPkg/HttpDxe/HttpProto.c
+++ b/NetworkPkg/HttpDxe/HttpProto.c
@@ -2029,24 +2029,24 @@ HttpTcpReceiveBody (
     ASSERT (Tcp4 != NULL);
   }
   
   if (HttpInstance->LocalAddressIsIPv6) {
     Rx6Token = &Wrap->TcpWrap.Rx6Token;
-    Rx6Token ->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;
-    Rx6Token ->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;
+    Rx6Token ->Packet.RxData->DataLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
+    Rx6Token ->Packet.RxData->FragmentTable[0].FragmentLength = 
+ (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
     Rx6Token ->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;
     Rx6Token->CompletionToken.Status = EFI_NOT_READY;
 
     Status = Tcp6->Receive (Tcp6, Rx6Token);
     if (EFI_ERROR (Status)) {
       DEBUG ((EFI_D_ERROR, "Tcp6 receive failed: %r\n", Status));
       return Status;
     }
   } else {
     Rx4Token = &Wrap->TcpWrap.Rx4Token;
-    Rx4Token->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;
-    Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;
+    Rx4Token->Packet.RxData->DataLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
+    Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) 
+ MIN (MAX_UINT32, HttpMsg->BodyLength);
     Rx4Token->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;
     
     Rx4Token->CompletionToken.Status = EFI_NOT_READY;
     Status = Tcp4->Receive (Tcp4, Rx4Token);
     if (EFI_ERROR (Status)) {
--
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] NetworkPkg/HttpDxe: Fix HTTP download OS image over 4G size failure
Posted by Subramanian, Sriram 7 years, 6 months ago
Reviewed-by: Sriram Subramanian <sriram-s@hpe.com>

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jiaxin Wu
Sent: Thursday, April 13, 2017 4:07 PM
To: edk2-devel@lists.01.org
Cc: Ye Ting <ting.ye@intel.com>; Zhang Lubo <lubo.zhang@intel.com>; Fu Siyuan <siyuan.fu@intel.com>; Wu Jiaxin <jiaxin.wu@intel.com>
Subject: [edk2] [Patch] NetworkPkg/HttpDxe: Fix HTTP download OS image over 4G size failure

UINT32 integer overflow will happen once the download OS image over
4G size. This patch is to fix this issue.

Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Cc: Zhang Lubo <lubo.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/HttpDxe/HttpProto.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c
index 3d61ba2..3fda294 100644
--- a/NetworkPkg/HttpDxe/HttpProto.c
+++ b/NetworkPkg/HttpDxe/HttpProto.c
@@ -2029,24 +2029,24 @@ HttpTcpReceiveBody (
     ASSERT (Tcp4 != NULL);
   }
   
   if (HttpInstance->LocalAddressIsIPv6) {
     Rx6Token = &Wrap->TcpWrap.Rx6Token;
-    Rx6Token ->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;
-    Rx6Token ->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;
+    Rx6Token ->Packet.RxData->DataLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
+    Rx6Token ->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
     Rx6Token ->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;
     Rx6Token->CompletionToken.Status = EFI_NOT_READY;
 
     Status = Tcp6->Receive (Tcp6, Rx6Token);
     if (EFI_ERROR (Status)) {
       DEBUG ((EFI_D_ERROR, "Tcp6 receive failed: %r\n", Status));
       return Status;
     }
   } else {
     Rx4Token = &Wrap->TcpWrap.Rx4Token;
-    Rx4Token->Packet.RxData->DataLength = (UINT32) HttpMsg->BodyLength;
-    Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) HttpMsg->BodyLength;
+    Rx4Token->Packet.RxData->DataLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
+    Rx4Token->Packet.RxData->FragmentTable[0].FragmentLength = (UINT32) MIN (MAX_UINT32, HttpMsg->BodyLength);
     Rx4Token->Packet.RxData->FragmentTable[0].FragmentBuffer = (VOID *) HttpMsg->Body;
     
     Rx4Token->CompletionToken.Status = EFI_NOT_READY;
     Status = Tcp4->Receive (Tcp4, Rx4Token);
     if (EFI_ERROR (Status)) {
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel