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:
@@ -2,7 +2,7 @@
|
||||
IpIo Library.
|
||||
|
||||
(C) Copyright 2014 Hewlett-Packard Development Company, L.P.<BR>
|
||||
Copyright (c) 2005 - 2009, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2005 - 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
|
||||
@@ -1029,42 +1029,56 @@ IpIoListenHandlerDpc (
|
||||
|
||||
if (IpIo->IpVersion == IP_VERSION_4) {
|
||||
if ((EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress) != 0) &&
|
||||
!NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), 0)) {
|
||||
//
|
||||
// The source address is not zero and it's not a unicast IP address, discard it.
|
||||
//
|
||||
goto CleanUp;
|
||||
}
|
||||
!NetIp4IsUnicast (EFI_NTOHL (((EFI_IP4_RECEIVE_DATA *) RxData)->Header->SourceAddress), 0)) {
|
||||
//
|
||||
// The source address is not zero and it's not a unicast IP address, discard it.
|
||||
//
|
||||
goto CleanUp;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a netbuffer representing IPv4 packet
|
||||
//
|
||||
Pkt = NetbufFromExt (
|
||||
(NET_FRAGMENT *) RxData->Ip4RxData.FragmentTable,
|
||||
RxData->Ip4RxData.FragmentCount,
|
||||
0,
|
||||
0,
|
||||
IpIoExtFree,
|
||||
RxData->Ip4RxData.RecycleSignal
|
||||
);
|
||||
if (NULL == Pkt) {
|
||||
goto CleanUp;
|
||||
}
|
||||
if (RxData->Ip4RxData.DataLength == 0) {
|
||||
//
|
||||
// Discard zero length data payload packet.
|
||||
//
|
||||
goto CleanUp;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a net session
|
||||
//
|
||||
Session.Source.Addr[0] = EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress);
|
||||
Session.Dest.Addr[0] = EFI_IP4 (RxData->Ip4RxData.Header->DestinationAddress);
|
||||
Session.IpHdr.Ip4Hdr = RxData->Ip4RxData.Header;
|
||||
Session.IpHdrLen = RxData->Ip4RxData.HeaderLength;
|
||||
Session.IpVersion = IP_VERSION_4;
|
||||
//
|
||||
// Create a netbuffer representing IPv4 packet
|
||||
//
|
||||
Pkt = NetbufFromExt (
|
||||
(NET_FRAGMENT *) RxData->Ip4RxData.FragmentTable,
|
||||
RxData->Ip4RxData.FragmentCount,
|
||||
0,
|
||||
0,
|
||||
IpIoExtFree,
|
||||
RxData->Ip4RxData.RecycleSignal
|
||||
);
|
||||
if (NULL == Pkt) {
|
||||
goto CleanUp;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a net session
|
||||
//
|
||||
Session.Source.Addr[0] = EFI_IP4 (RxData->Ip4RxData.Header->SourceAddress);
|
||||
Session.Dest.Addr[0] = EFI_IP4 (RxData->Ip4RxData.Header->DestinationAddress);
|
||||
Session.IpHdr.Ip4Hdr = RxData->Ip4RxData.Header;
|
||||
Session.IpHdrLen = RxData->Ip4RxData.HeaderLength;
|
||||
Session.IpVersion = IP_VERSION_4;
|
||||
} else {
|
||||
|
||||
if (!NetIp6IsValidUnicast(&RxData->Ip6RxData.Header->SourceAddress)) {
|
||||
goto CleanUp;
|
||||
}
|
||||
|
||||
if (RxData->Ip6RxData.DataLength == 0) {
|
||||
//
|
||||
// Discard zero length data payload packet.
|
||||
//
|
||||
goto CleanUp;
|
||||
}
|
||||
|
||||
//
|
||||
// Create a netbuffer representing IPv6 packet
|
||||
//
|
||||
@@ -1279,6 +1293,14 @@ IpIoOpen (
|
||||
// configure ip
|
||||
//
|
||||
if (IpVersion == IP_VERSION_4){
|
||||
//
|
||||
// RawData mode is no supported.
|
||||
//
|
||||
ASSERT (!OpenData->IpConfigData.Ip4CfgData.RawData);
|
||||
if (OpenData->IpConfigData.Ip4CfgData.RawData) {
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
Status = IpIo->Ip.Ip4->Configure (
|
||||
IpIo->Ip.Ip4,
|
||||
&OpenData->IpConfigData.Ip4CfgData
|
||||
|
Reference in New Issue
Block a user