MdeModulePkg: 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>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/** @file
|
||||
The implementation of the ARP protocol.
|
||||
|
||||
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2006 - 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
|
||||
which accompanies this distribution. The full text of the license may be found at<BR>
|
||||
@@ -112,15 +112,28 @@ ArpOnFrameRcvdDpc (
|
||||
// Status is EFI_SUCCESS, process the received frame.
|
||||
//
|
||||
RxData = RxToken->Packet.RxData;
|
||||
Head = (ARP_HEAD *) RxData->PacketData;
|
||||
//
|
||||
// Sanity check.
|
||||
//
|
||||
if (RxData->DataLength < sizeof (ARP_HEAD)) {
|
||||
//
|
||||
// Restart the receiving if packet size is not correct.
|
||||
//
|
||||
goto RESTART_RECEIVE;
|
||||
}
|
||||
|
||||
//
|
||||
// Convert the byte order of the multi-byte fields.
|
||||
//
|
||||
Head = (ARP_HEAD *) RxData->PacketData;
|
||||
Head->HwType = NTOHS (Head->HwType);
|
||||
Head->ProtoType = NTOHS (Head->ProtoType);
|
||||
Head->OpCode = NTOHS (Head->OpCode);
|
||||
|
||||
if (RxData->DataLength < (sizeof (ARP_HEAD) + 2 * Head->HwAddrLen + 2 * Head->ProtoAddrLen)) {
|
||||
goto RESTART_RECEIVE;
|
||||
}
|
||||
|
||||
if ((Head->HwType != ArpService->SnpMode.IfType) ||
|
||||
(Head->HwAddrLen != ArpService->SnpMode.HwAddressSize) ||
|
||||
(RxData->ProtocolType != ARP_ETHER_PROTO_TYPE)) {
|
||||
|
Reference in New Issue
Block a user