summaryrefslogtreecommitdiffstats
path: root/NetworkPkg/TcpDxe
diff options
context:
space:
mode:
authorFu Siyuan <siyuan.fu@intel.com>2016-03-28 11:01:03 +0800
committerFu Siyuan <siyuan.fu@intel.com>2016-04-01 13:30:23 +0800
commit37b680116dcd4a3517cb87794c33fc84beea8dd2 (patch)
tree72595ee118afd97ef259b1a5eb5a54e5d3850188 /NetworkPkg/TcpDxe
parent1b31acb66c026f2791c959a4ec9b55c04d583c22 (diff)
downloadedk2-37b680116dcd4a3517cb87794c33fc84beea8dd2.tar.gz
edk2-37b680116dcd4a3517cb87794c33fc84beea8dd2.tar.bz2
edk2-37b680116dcd4a3517cb87794c33fc84beea8dd2.zip
NetworkPkg: Check received packet size before use it.
Arbitrary length of packet may be received from network, including the packets with zero payload data or malformed protocol header. So the code much check the actually received data size before using it. For example, in current edk2 network stack, an zero payload UDP packet may cause the platform ASSERT in NetbufFromExt() because of the zero fragment number. This patch update the IpIoLib and UdpIoLib to check and discard the zero payload data packet to avoid above assert. Some other network drivers are also updated to check the packet size to guarantee the minimum length of protocol header is received from upper layer driver. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Fu Siyuan <siyuan.fu@intel.com> Reviewed-by: Sriram Subramanian <sriram-s@hpe.com> Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
Diffstat (limited to 'NetworkPkg/TcpDxe')
-rw-r--r--NetworkPkg/TcpDxe/TcpInput.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/NetworkPkg/TcpDxe/TcpInput.c b/NetworkPkg/TcpDxe/TcpInput.c
index d0118f1d88..745ee4cc6e 100644
--- a/NetworkPkg/TcpDxe/TcpInput.c
+++ b/NetworkPkg/TcpDxe/TcpInput.c
@@ -1,7 +1,7 @@
/** @file
TCP input process routines.
- Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2016 Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -748,11 +748,18 @@ TcpInput (
Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL);
ASSERT (Head != NULL);
+
+ if (Nbuf->TotalSize < sizeof (TCP_HEAD)) {
+ DEBUG ((EFI_D_INFO, "TcpInput: received a malformed packet\n"));
+ goto DISCARD;
+ }
+
Len = Nbuf->TotalSize - (Head->HeadLen << 2);
if ((Head->HeadLen < 5) || (Len < 0)) {
DEBUG ((EFI_D_INFO, "TcpInput: received a malformed packet\n"));
+
goto DISCARD;
}
@@ -1560,6 +1567,10 @@ TcpIcmpInput (
BOOLEAN IcmpErrIsHard;
BOOLEAN IcmpErrNotify;
+ if (Nbuf->TotalSize < sizeof (TCP_HEAD)) {
+ goto CLEAN_EXIT;
+ }
+
Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL);
ASSERT (Head != NULL);