[edk2] [Patch] MdeModulePkg/DxeNetLib: Check the actual packet size before trim data from Nbuf.

Fu Siyuan posted 1 patch 7 years, 3 months ago
Failed in applying to current master (apply log)
MdeModulePkg/Library/DxeNetLib/NetBuffer.c | 4 ++++
1 file changed, 4 insertions(+)
[edk2] [Patch] MdeModulePkg/DxeNetLib: Check the actual packet size before trim data from Nbuf.
Posted by Fu Siyuan 7 years, 3 months ago
In NetbufTrim() function, the NetBuf TotalSize should be checked with 0 before
making the trim operation, otherwise the function will fall into infinite loop.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Michael Turner <Michael.Turner@microsoft.com>
---
 MdeModulePkg/Library/DxeNetLib/NetBuffer.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
index 95cb71714b..25fc78e49e 100644
--- a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
+++ b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
@@ -1175,6 +1175,10 @@ NetbufTrim (
 
   NET_CHECK_SIGNATURE (Nbuf, NET_BUF_SIGNATURE);
 
+  if (Nbuf->TotalSize == 0) {
+    return 0;
+  }
+
   if (Len > Nbuf->TotalSize) {
     Len = Nbuf->TotalSize;
   }
-- 
2.13.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] MdeModulePkg/DxeNetLib: Check the actual packet size before trim data from Nbuf.
Posted by Wu, Jiaxin 7 years, 3 months ago
Hi Siyuan,

Maybe we can add more check for the Len to return directly, what do you think?

  if (Len == 0) {
    return 0;
  }

> +  if (Nbuf->TotalSize == 0) {
> +    return 0;
> +  }

Thanks,
Jiaxin


> -----Original Message-----
> From: Fu, Siyuan
> Sent: Wednesday, September 20, 2017 11:24 AM
> To: edk2-devel@lists.01.org
> Cc: Wu, Jiaxin <jiaxin.wu@intel.com>; Ye, Ting <ting.ye@intel.com>; Michael
> Turner <Michael.Turner@microsoft.com>
> Subject: [Patch] MdeModulePkg/DxeNetLib: Check the actual packet size
> before trim data from Nbuf.
> 
> In NetbufTrim() function, the NetBuf TotalSize should be checked with 0
> before
> making the trim operation, otherwise the function will fall into infinite loop.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
> Cc: Wu Jiaxin <jiaxin.wu@intel.com>
> Cc: Ye Ting <ting.ye@intel.com>
> Cc: Michael Turner <Michael.Turner@microsoft.com>
> ---
>  MdeModulePkg/Library/DxeNetLib/NetBuffer.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
> b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
> index 95cb71714b..25fc78e49e 100644
> --- a/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
> +++ b/MdeModulePkg/Library/DxeNetLib/NetBuffer.c
> @@ -1175,6 +1175,10 @@ NetbufTrim (
> 
>    NET_CHECK_SIGNATURE (Nbuf, NET_BUF_SIGNATURE);
> 
> +  if (Nbuf->TotalSize == 0) {
> +    return 0;
> +  }
> +
>    if (Len > Nbuf->TotalSize) {
>      Len = Nbuf->TotalSize;
>    }
> --
> 2.13.0.windows.1

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