From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 00A1AAC0C3E for ; Wed, 24 Jan 2024 05:20:30 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=k4Xx8OPedQmqQLZKpmtbCOjmOimfny8B4d2OpngHkQY=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1706073629; v=1; b=RzuCq+japMSWppevRto2xBAQtknf3ulda3yLRJlBGPtgXQ0hlriRe7yvwQoEd6Z/4WBLtujK nsylCGkJSExkrrnNKj7QT9djs+6+9O8SoHOHfxNRpUJNrMvKPgA+9yoLTnxqOYEyDMguaTiGFiy WXoIizwsDDktZ8jRs3swNygE= X-Received: by 127.0.0.2 with SMTP id Ri96YY7687511xZughqs11US; Tue, 23 Jan 2024 21:20:29 -0800 X-Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mx.groups.io with SMTP id smtpd.web11.16102.1706073628781303782 for ; Tue, 23 Jan 2024 21:20:28 -0800 X-Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1d780a392fdso3803085ad.3 for ; Tue, 23 Jan 2024 21:20:28 -0800 (PST) X-Gm-Message-State: ebaDFvNDwIBuLKwHCTLGWodJx7686176AA= X-Google-Smtp-Source: AGHT+IF5De8vvOyL0gQQiLVCbwpeNgzZGSME2kaZ642Q8BtyMQybV8oU2uXH1MKuUUB+lujDk4puyA== X-Received: by 2002:a17:902:ec81:b0:1d7:6c3f:78e6 with SMTP id x1-20020a170902ec8100b001d76c3f78e6mr426594plg.48.1706073627796; Tue, 23 Jan 2024 21:20:27 -0800 (PST) X-Received: from localhost.localdomain ([24.17.138.83]) by smtp.gmail.com with ESMTPSA id w2-20020a170902c78200b001d71f10aa42sm7831709pla.11.2024.01.23.21.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 21:20:27 -0800 (PST) From: "Doug Flick via groups.io" To: devel@edk2.groups.io Cc: "Douglas Flick [MSFT]" , Saloni Kasbekar , Zachary Clark-williams Subject: [edk2-devel] [PATCH 02/14] NetworkPkg: Dhcp6Dxe: SECURITY PATCH CVE-2023-45230 Unit Tests Date: Tue, 23 Jan 2024 19:33:25 -0800 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,dougflick@microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=RzuCq+ja; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4535 SECURITY PATCH - Unit Tests TCBZ4535 CVE-2023-45230 CVSS 8.3 : CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:H CWE-119 Improper Restriction of Operations within the Bounds of a Memory Buffer Cc: Saloni Kasbekar Cc: Zachary Clark-williams Signed-off-by: Doug Flick [MSFT] --- NetworkPkg/Test/NetworkPkgHostTest.dsc | 99 ++++ .../GoogleTest/Dhcp6DxeGoogleTest.inf | 43 ++ .../GoogleTest/Dhcp6DxeGoogleTest.cpp | 20 + .../Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp | 478 ++++++++++++++++++ NetworkPkg/NetworkPkg.ci.yaml | 118 ++--- 5 files changed, 695 insertions(+), 63 deletions(-) create mode 100644 NetworkPkg/Test/NetworkPkgHostTest.dsc create mode 100644 NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf create mode 100644 NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.cpp create mode 100644 NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp diff --git a/NetworkPkg/Test/NetworkPkgHostTest.dsc b/NetworkPkg/Test/Netwo= rkPkgHostTest.dsc new file mode 100644 index 000000000000..20bc90b1728d --- /dev/null +++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc @@ -0,0 +1,99 @@ +## @file=0D +# NetworkPkgHostTest DSC file used to build host-based unit tests.=0D +#=0D +# Copyright (c) Microsoft Corporation.
=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +##=0D +[Defines]=0D + PLATFORM_NAME =3D NetworkPkgHostTest=0D + PLATFORM_GUID =3D 3b68324e-fc07-4d49-9520-9347ede65879=0D + PLATFORM_VERSION =3D 0.1=0D + DSC_SPECIFICATION =3D 0x00010005=0D + OUTPUT_DIRECTORY =3D Build/NetworkPkg/HostTest=0D + SUPPORTED_ARCHITECTURES =3D IA32|X64|AARCH64=0D + BUILD_TARGETS =3D NOOPT=0D + SKUID_IDENTIFIER =3D DEFAULT=0D +=0D +!include UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec=0D +=0D +[Components]=0D + #=0D + # Build HOST_APPLICATION that tests NetworkPkg=0D + #=0D + NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf=0D +=0D +# Despite these library classes being listed in [LibraryClasses] below, th= ey are not needed for the host-based unit tests.=0D +[LibraryClasses]=0D + NetLib|NetworkPkg/Library/DxeNetLib/DxeNetLib.inf=0D + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf=0D + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf=0D + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf=0D + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf=0D + HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf=0D + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAll= ocationLib.inf=0D + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf=0D + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf=0D + UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntry= Point.inf=0D + UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiA= pplicationEntryPoint.inf=0D + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBoo= tServicesTableLib.inf=0D + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf=0D + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/U= efiRuntimeServicesTableLib.inf=0D + UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServic= esLib.inf=0D + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManag= erLib.inf=0D + TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplat= e.inf=0D + PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibN= ull.inf=0D + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeC= offGetEntryPointLib.inf=0D + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf=0D + DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableL= ib.inf=0D + SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf=0D + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf=0D + VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/Var= iablePolicyHelperLib.inf=0D +!ifdef CONTINUOUS_INTEGRATION=0D + BaseCryptLib|CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf=0D + TlsLib|CryptoPkg/Library/TlsLibNull/TlsLibNull.inf=0D +!else=0D + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf=0D + OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf=0D + TlsLib|CryptoPkg/Library/TlsLib/TlsLib.inf=0D +!endif=0D + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseD= ebugPrintErrorLevelLib.inf=0D + FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf=0D + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf= =0D + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf=0D + IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf=0D +=0D +!if $(TOOL_CHAIN_TAG) =3D=3D VS2019 or $(TOOL_CHAIN_TAG) =3D=3D VS2022=0D +[LibraryClasses.X64]=0D + # Provide StackCookie support lib so that we can link to /GS exports for= VS builds=0D + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf=0D +!endif=0D +=0D +[LibraryClasses.common.UEFI_DRIVER]=0D + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf=0D + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRepor= tStatusCodeLib.inf=0D + DebugLib|MdePkg/Library/UefiDebugLibConOut/UefiDebugLibConOut.inf=0D +[LibraryClasses.common.UEFI_APPLICATION]=0D + DebugLib|MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf=0D + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf=0D +[LibraryClasses.ARM, LibraryClasses.AARCH64]=0D + #=0D + # It is not possible to prevent ARM compiler calls to generic intrinsic = functions.=0D + # This library provides the instrinsic functions generated by a given co= mpiler.=0D + # [LibraryClasses.ARM] and NULL mean link this library into all ARM imag= es.=0D + #=0D +!if $(TOOL_CHAIN_TAG) !=3D VS2017 and $(TOOL_CHAIN_TAG) !=3D VS2015 and $(= TOOL_CHAIN_TAG) !=3D VS2019=0D + NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf=0D +!endif=0D + NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf=0D +[LibraryClasses.ARM]=0D + RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf=0D +[LibraryClasses.RISCV64]=0D + RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf=0D +=0D +[PcdsFixedAtBuild]=0D + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2=0D + gEfiNetworkPkgTokenSpaceGuid.PcdDhcp6UidType|0x4=0D diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf b/Networ= kPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf new file mode 100644 index 000000000000..8e9119a37158 --- /dev/null +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf @@ -0,0 +1,43 @@ +## @file=0D +# Unit test suite for the Dhcp6Dxe using Google Test=0D +#=0D +# Copyright (c) Microsoft Corporation.
=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +##=0D +[Defines]=0D + INF_VERSION =3D 0x00010017=0D + BASE_NAME =3D Dhcp6DxeGoogleTest=0D + FILE_GUID =3D 1D2A4C65-38C8-4C2F-BB60-B5FA49625AA9=0D + VERSION_STRING =3D 1.0=0D + MODULE_TYPE =3D HOST_APPLICATION=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64=0D +#=0D +[Sources]=0D + Dhcp6DxeGoogleTest.cpp=0D + Dhcp6IoGoogleTest.cpp=0D + ../Dhcp6Io.c=0D + ../Dhcp6Utility.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec=0D + NetworkPkg/NetworkPkg.dec=0D +=0D +[LibraryClasses]=0D + GoogleTestLib=0D + DebugLib=0D + NetLib=0D + PcdLib=0D +=0D +[Protocols]=0D + gEfiDhcp6ServiceBindingProtocolGuid=0D +=0D +[Pcd]=0D + gEfiNetworkPkgTokenSpaceGuid.PcdDhcp6UidType=0D +=0D +[Guids]=0D + gZeroGuid=0D diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.cpp b/Networ= kPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.cpp new file mode 100644 index 000000000000..9aeced2f9156 --- /dev/null +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.cpp @@ -0,0 +1,20 @@ +/** @file=0D + Acts as the main entry point for the tests for the Dhcp6Dxe module.=0D +=0D + Copyright (c) Microsoft Corporation=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +#include =0D +=0D +//////////////////////////////////////////////////////////////////////////= //////=0D +// Run the tests=0D +//////////////////////////////////////////////////////////////////////////= //////=0D +int=0D +main (=0D + int argc,=0D + char *argv[]=0D + )=0D +{=0D + testing::InitGoogleTest (&argc, argv);=0D + return RUN_ALL_TESTS ();=0D +}=0D diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp b/Network= Pkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp new file mode 100644 index 000000000000..7ee40e4af480 --- /dev/null +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp @@ -0,0 +1,478 @@ +/** @file=0D + Tests for Dhcp6Io.c.=0D +=0D + Copyright (c) Microsoft Corporation=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +#include =0D +=0D +extern "C" {=0D + #include =0D + #include =0D + #include =0D + #include =0D + #include "../Dhcp6Impl.h"=0D + #include "../Dhcp6Utility.h"=0D +}=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +// Defines=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +#define DHCP6_PACKET_MAX_LEN 1500=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +////////////////////////////////////////////////////////////////////////=0D +// Symbol Definitions=0D +// These functions are not directly under test - but required to compile=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +// This definition is used by this test but is also required to compile=0D +// by Dhcp6Io.c=0D +EFI_IPv6_ADDRESS mAllDhcpRelayAndServersAddress =3D {=0D + { 0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2 }=0D +};=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +UdpIoSendDatagram (=0D + IN UDP_IO *UdpIo,=0D + IN NET_BUF *Packet,=0D + IN UDP_END_POINT *EndPoint OPTIONAL,=0D + IN EFI_IP_ADDRESS *Gateway OPTIONAL,=0D + IN UDP_IO_CALLBACK CallBack,=0D + IN VOID *Context=0D + )=0D +{=0D + return EFI_SUCCESS;=0D +}=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +UdpIoRecvDatagram (=0D + IN UDP_IO *UdpIo,=0D + IN UDP_IO_CALLBACK CallBack,=0D + IN VOID *Context,=0D + IN UINT32 HeadLen=0D + )=0D +{=0D + return EFI_SUCCESS;=0D +}=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +// Dhcp6AppendOptionTest Tests=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +class Dhcp6AppendOptionTest : public ::testing::Test {=0D +public:=0D + UINT8 *Buffer =3D NULL;=0D + EFI_DHCP6_PACKET *Packet;=0D +=0D +protected:=0D + // Add any setup code if needed=0D + virtual void=0D + SetUp (=0D + )=0D + {=0D + // Initialize any resources or variables=0D + Buffer =3D (UINT8 *)AllocateZeroPool (DHCP6_PACKET_MAX_LEN);=0D + ASSERT_NE (Buffer, (UINT8 *)NULL);=0D +=0D + Packet =3D (EFI_DHCP6_PACKET *)Buffer;=0D + Packet->Size =3D DHCP6_PACKET_MAX_LEN;=0D + }=0D +=0D + // Add any cleanup code if needed=0D + virtual void=0D + TearDown (=0D + )=0D + {=0D + // Clean up any resources or variables=0D + if (Buffer !=3D NULL) {=0D + FreePool (Buffer);=0D + }=0D + }=0D +};=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that is too small by a duid tha= t is too large=0D +TEST_F (Dhcp6AppendOptionTest, InvalidDataExpectBufferTooSmall) {=0D + UINT8 *Cursor;=0D + EFI_DHCP6_DUID *UntrustedDuid;=0D + EFI_STATUS Status;=0D +=0D + UntrustedDuid =3D (EFI_DHCP6_DUID *)AllocateZeroPool (sizeof (EFI_DHCP6_= DUID));=0D + ASSERT_NE (UntrustedDuid, (EFI_DHCP6_DUID *)NULL);=0D +=0D + UntrustedDuid->Length =3D NTOHS (0xFFFF);=0D +=0D + Cursor =3D Dhcp6AppendOptionTest::Packet->Dhcp6.Option;=0D +=0D + Status =3D Dhcp6AppendOption (=0D + Dhcp6AppendOptionTest::Packet,=0D + &Cursor,=0D + HTONS (Dhcp6OptServerId),=0D + UntrustedDuid->Length,=0D + UntrustedDuid->Duid=0D + );=0D +=0D + ASSERT_EQ (Status, EFI_BUFFER_TOO_SMALL);=0D +}=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that is large enough=0D +TEST_F (Dhcp6AppendOptionTest, ValidDataExpectSuccess) {=0D + UINT8 *Cursor;=0D + EFI_DHCP6_DUID *UntrustedDuid;=0D + EFI_STATUS Status;=0D + UINTN OriginalLength;=0D +=0D + UINT8 Duid[6] =3D { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };=0D +=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D + OriginalLength =3D Packet->Length;=0D +=0D + UntrustedDuid =3D (EFI_DHCP6_DUID *)AllocateZeroPool (sizeof (EFI_DHCP6_= DUID));=0D + ASSERT_NE (UntrustedDuid, (EFI_DHCP6_DUID *)NULL);=0D +=0D + UntrustedDuid->Length =3D NTOHS (sizeof (Duid));=0D + CopyMem (UntrustedDuid->Duid, Duid, sizeof (Duid));=0D +=0D + Cursor =3D Dhcp6AppendOptionTest::Packet->Dhcp6.Option;=0D +=0D + Status =3D Dhcp6AppendOption (=0D + Dhcp6AppendOptionTest::Packet,=0D + &Cursor,=0D + HTONS (Dhcp6OptServerId),=0D + UntrustedDuid->Length,=0D + UntrustedDuid->Duid=0D + );=0D +=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +=0D + // verify that the pointer to cursor moved by the expected amount=0D + ASSERT_EQ (Cursor, (UINT8 *)Dhcp6AppendOptionTest::Packet->Dhcp6.Option = + sizeof (Duid) + 4);=0D +=0D + // verify that the length of the packet is now the expected amount=0D + ASSERT_EQ (Dhcp6AppendOptionTest::Packet->Length, OriginalLength + sizeo= f (Duid) + 4);=0D +}=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +// Dhcp6AppendETOption Tests=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +class Dhcp6AppendETOptionTest : public ::testing::Test {=0D +public:=0D + UINT8 *Buffer =3D NULL;=0D + EFI_DHCP6_PACKET *Packet;=0D +=0D +protected:=0D + // Add any setup code if needed=0D + virtual void=0D + SetUp (=0D + )=0D + {=0D + // Initialize any resources or variables=0D + Buffer =3D (UINT8 *)AllocateZeroPool (DHCP6_PACKET_MAX_LEN);=0D + ASSERT_NE (Buffer, (UINT8 *)NULL);=0D +=0D + Packet =3D (EFI_DHCP6_PACKET *)Buffer;=0D + Packet->Size =3D DHCP6_PACKET_MAX_LEN;=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D + }=0D +=0D + // Add any cleanup code if needed=0D + virtual void=0D + TearDown (=0D + )=0D + {=0D + // Clean up any resources or variables=0D + if (Buffer !=3D NULL) {=0D + FreePool (Buffer);=0D + }=0D + }=0D +};=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that is too small by a duid tha= t is too large=0D +TEST_F (Dhcp6AppendETOptionTest, InvalidDataExpectBufferTooSmall) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D + DHCP6_INSTANCE Instance;=0D + UINT16 ElapsedTimeVal;=0D + UINT16 *ElapsedTime;=0D +=0D + Cursor =3D Dhcp6AppendETOptionTest::Packet->Dhcp6.Option;=0D + ElapsedTime =3D &ElapsedTimeVal;=0D +=0D + Packet->Length =3D Packet->Size - 2;=0D +=0D + Status =3D Dhcp6AppendETOption (=0D + Dhcp6AppendETOptionTest::Packet,=0D + &Cursor,=0D + &Instance, // Instance is not used in this function=0D + &ElapsedTime=0D + );=0D +=0D + // verify that we error out because the packet is too small for the opti= on header=0D + ASSERT_EQ (Status, EFI_BUFFER_TOO_SMALL);=0D +=0D + // reset the length=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D +}=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that is large enough=0D +TEST_F (Dhcp6AppendETOptionTest, ValidDataExpectSuccess) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D + DHCP6_INSTANCE Instance;=0D + UINT16 ElapsedTimeVal;=0D + UINT16 *ElapsedTime;=0D + UINTN ExpectedSize;=0D + UINTN OriginalLength;=0D +=0D + Cursor =3D Dhcp6AppendETOptionTest::Packet->Dhcp6.Option;=0D + ElapsedTime =3D &ElapsedTimeVal;=0D + ExpectedSize =3D 6;=0D + OriginalLength =3D Packet->Length;=0D +=0D + Status =3D Dhcp6AppendETOption (=0D + Dhcp6AppendETOptionTest::Packet,=0D + &Cursor,=0D + &Instance, // Instance is not used in this function=0D + &ElapsedTime=0D + );=0D +=0D + // verify that the status is EFI_SUCCESS=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +=0D + // verify that the pointer to cursor moved by the expected amount=0D + ASSERT_EQ (Cursor, (UINT8 *)Dhcp6AppendETOptionTest::Packet->Dhcp6.Optio= n + ExpectedSize);=0D +=0D + // verify that the length of the packet is now the expected amount=0D + ASSERT_EQ (Dhcp6AppendETOptionTest::Packet->Length, OriginalLength + Exp= ectedSize);=0D +}=0D +=0D +////////////////////////////////////////////////////////////////////////=0D +// Dhcp6AppendIaOption Tests=0D +////////////////////////////////////////////////////////////////////////=0D +=0D +class Dhcp6AppendIaOptionTest : public ::testing::Test {=0D +public:=0D + UINT8 *Buffer =3D NULL;=0D + EFI_DHCP6_PACKET *Packet;=0D + EFI_DHCP6_IA *Ia;=0D +=0D +protected:=0D + // Add any setup code if needed=0D + virtual void=0D + SetUp (=0D + )=0D + {=0D + // Initialize any resources or variables=0D + Buffer =3D (UINT8 *)AllocateZeroPool (DHCP6_PACKET_MAX_LEN);=0D + ASSERT_NE (Buffer, (UINT8 *)NULL);=0D +=0D + Packet =3D (EFI_DHCP6_PACKET *)Buffer;=0D + Packet->Size =3D DHCP6_PACKET_MAX_LEN;=0D +=0D + Ia =3D (EFI_DHCP6_IA *)AllocateZeroPool (sizeof (EFI_DHCP6_IA) + sizeo= f (EFI_DHCP6_IA_ADDRESS) * 2);=0D + ASSERT_NE (Ia, (EFI_DHCP6_IA *)NULL);=0D +=0D + CopyMem (Ia->IaAddress, mAllDhcpRelayAndServersAddress.Addr, sizeof (E= FI_IPv6_ADDRESS));=0D + CopyMem (Ia->IaAddress + 1, mAllDhcpRelayAndServersAddress.Addr, sizeo= f (EFI_IPv6_ADDRESS));=0D +=0D + Ia->IaAddressCount =3D 2;=0D + }=0D +=0D + // Add any cleanup code if needed=0D + virtual void=0D + TearDown (=0D + )=0D + {=0D + // Clean up any resources or variables=0D + if (Buffer !=3D NULL) {=0D + FreePool (Buffer);=0D + }=0D +=0D + if (Ia !=3D NULL) {=0D + FreePool (Ia);=0D + }=0D + }=0D +};=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that doesn't have enough space= =0D +// for the option header=0D +TEST_F (Dhcp6AppendIaOptionTest, IaNaInvalidDataExpectBufferTooSmall) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D +=0D + Packet->Length =3D Packet->Size - 2;=0D +=0D + Ia->Descriptor.Type =3D Dhcp6OptIana;=0D + Ia->Descriptor.IaId =3D 0x12345678;=0D +=0D + Cursor =3D Dhcp6AppendIaOptionTest::Packet->Dhcp6.Option;=0D +=0D + Status =3D Dhcp6AppendIaOption (=0D + Dhcp6AppendIaOptionTest::Packet,=0D + &Cursor,=0D + Ia,=0D + 0x12345678,=0D + 0x11111111,=0D + Dhcp6OptIana=0D + );=0D +=0D + // verify that we error out because the packet is too small for the opti= on header=0D + ASSERT_EQ (Status, EFI_BUFFER_TOO_SMALL);=0D +=0D + // reset the length=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D +}=0D +=0D +// Test Description:=0D +// Attempt to append an option to a packet that doesn't have enough space= =0D +// for the option header=0D +TEST_F (Dhcp6AppendIaOptionTest, IaTaInvalidDataExpectBufferTooSmall) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D +=0D + // Use up nearly all the space in the packet=0D + Packet->Length =3D Packet->Size - 2;=0D +=0D + Ia->Descriptor.Type =3D Dhcp6OptIata;=0D + Ia->Descriptor.IaId =3D 0x12345678;=0D +=0D + Cursor =3D Dhcp6AppendIaOptionTest::Packet->Dhcp6.Option;=0D +=0D + Status =3D Dhcp6AppendIaOption (=0D + Dhcp6AppendIaOptionTest::Packet,=0D + &Cursor,=0D + Ia,=0D + 0,=0D + 0,=0D + Dhcp6OptIata=0D + );=0D +=0D + // verify that we error out because the packet is too small for the opti= on header=0D + ASSERT_EQ (Status, EFI_BUFFER_TOO_SMALL);=0D +=0D + // reset the length=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D +}=0D +=0D +TEST_F (Dhcp6AppendIaOptionTest, IaNaValidDataExpectSuccess) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D + UINTN ExpectedSize;=0D + UINTN OriginalLength;=0D +=0D + //=0D + // 2 bytes for the option header type=0D + //=0D + ExpectedSize =3D 2;=0D + //=0D + // 2 bytes for the option header length=0D + //=0D + ExpectedSize +=3D 2;=0D + //=0D + // 4 bytes for the IAID=0D + //=0D + ExpectedSize +=3D 4;=0D + //=0D + // + 4 bytes for the T1=0D + //=0D + ExpectedSize +=3D 4;=0D + //=0D + // + 4 bytes for the T2=0D + //=0D + ExpectedSize +=3D 4;=0D + //=0D + // + (4 + sizeof (EFI_DHCP6_IA_ADDRESS)) * 2;=0D + // + 2 bytes for the option header type=0D + // + 2 bytes for the option header length=0D + // + sizeof (EFI_DHCP6_IA_ADDRESS) for the IA Address=0D + //=0D + ExpectedSize +=3D (4 + sizeof (EFI_DHCP6_IA_ADDRESS)) * 2;=0D +=0D + Cursor =3D Dhcp6AppendIaOptionTest::Packet->Dhcp6.Option;=0D +=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D + OriginalLength =3D Packet->Length;=0D +=0D + Ia->Descriptor.Type =3D Dhcp6OptIana;=0D + Ia->Descriptor.IaId =3D 0x12345678;=0D +=0D + Status =3D Dhcp6AppendIaOption (=0D + Dhcp6AppendIaOptionTest::Packet,=0D + &Cursor,=0D + Ia,=0D + 0x12345678,=0D + 0x12345678,=0D + Dhcp6OptIana=0D + );=0D +=0D + // verify that the pointer to cursor moved by the expected amount=0D + ASSERT_EQ (Cursor, (UINT8 *)Dhcp6AppendIaOptionTest::Packet->Dhcp6.Optio= n + ExpectedSize);=0D +=0D + // verify that the length of the packet is now the expected amount=0D + ASSERT_EQ (Dhcp6AppendIaOptionTest::Packet->Length, OriginalLength + Exp= ectedSize);=0D +=0D + // verify that the status is EFI_SUCCESS=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +}=0D +=0D +TEST_F (Dhcp6AppendIaOptionTest, IaTaValidDataExpectSuccess) {=0D + UINT8 *Cursor;=0D + EFI_STATUS Status;=0D + UINTN ExpectedSize;=0D + UINTN OriginalLength;=0D +=0D + //=0D + // 2 bytes for the option header type=0D + //=0D + ExpectedSize =3D 2;=0D + //=0D + // 2 bytes for the option header length=0D + //=0D + ExpectedSize +=3D 2;=0D + //=0D + // 4 bytes for the IAID=0D + //=0D + ExpectedSize +=3D 4;=0D + //=0D + // + (4 + sizeof (EFI_DHCP6_IA_ADDRESS)) * 2;=0D + // + 2 bytes for the option header type=0D + // + 2 bytes for the option header length=0D + // + sizeof (EFI_DHCP6_IA_ADDRESS) for the IA Address=0D + //=0D + ExpectedSize +=3D (4 + sizeof (EFI_DHCP6_IA_ADDRESS)) * 2;=0D +=0D + Cursor =3D Dhcp6AppendIaOptionTest::Packet->Dhcp6.Option;=0D +=0D + Packet->Length =3D sizeof (EFI_DHCP6_HEADER);=0D + OriginalLength =3D Packet->Length;=0D +=0D + Ia->Descriptor.Type =3D Dhcp6OptIata;=0D + Ia->Descriptor.IaId =3D 0x12345678;=0D +=0D + Status =3D Dhcp6AppendIaOption (=0D + Dhcp6AppendIaOptionTest::Packet,=0D + &Cursor,=0D + Ia,=0D + 0,=0D + 0,=0D + Dhcp6OptIata=0D + );=0D +=0D + // verify that the pointer to cursor moved by the expected amount=0D + ASSERT_EQ (Cursor, (UINT8 *)Dhcp6AppendIaOptionTest::Packet->Dhcp6.Optio= n + ExpectedSize);=0D +=0D + // verify that the length of the packet is now the expected amount=0D + ASSERT_EQ (Dhcp6AppendIaOptionTest::Packet->Length, OriginalLength + Exp= ectedSize);=0D +=0D + // verify that the status is EFI_SUCCESS=0D + ASSERT_EQ (Status, EFI_SUCCESS);=0D +}=0D diff --git a/NetworkPkg/NetworkPkg.ci.yaml b/NetworkPkg/NetworkPkg.ci.yaml index 07dc7abd6938..0060f7a2cb8f 100644 --- a/NetworkPkg/NetworkPkg.ci.yaml +++ b/NetworkPkg/NetworkPkg.ci.yaml @@ -7,73 +7,65 @@ # SPDX-License-Identifier: BSD-2-Clause-Patent=0D ##=0D {=0D - "LicenseCheck": {=0D - "IgnoreFiles": []=0D - },=0D + "LicenseCheck": { "IgnoreFiles": [] },=0D "EccCheck": {=0D - ## Exception sample looks like below:=0D - ## "ExceptionList": [=0D - ## "", ""=0D - ## ]=0D - "ExceptionList": [=0D - ],=0D - ## Both file path and directory path are accepted.=0D - "IgnoreFiles": [=0D - ]=0D - },=0D - "CompilerPlugin": {=0D - "DscPath": "NetworkPkg.dsc"=0D - },=0D - "CharEncodingCheck": {=0D - "IgnoreFiles": []=0D - },=0D + ## Exception sample looks like below:=0D + ## "ExceptionList": [=0D + ## "", ""=0D + ## ]=0D + "ExceptionList": [],=0D + ## Both file path and directory path are accepted.=0D + "IgnoreFiles": [],=0D + },=0D + "CompilerPlugin": { "DscPath": "NetworkPkg.dsc" },=0D + "HostUnitTestCompilerPlugin": { "DscPath": "Test/NetworkPkgHostTest.ds= c" },=0D + "CharEncodingCheck": { "IgnoreFiles": [] },=0D "DependencyCheck": {=0D - "AcceptableDependencies": [=0D - "MdePkg/MdePkg.dec",=0D - "MdeModulePkg/MdeModulePkg.dec",=0D - "NetworkPkg/NetworkPkg.dec",=0D - "CryptoPkg/CryptoPkg.dec"=0D - ],=0D - # For host based unit tests=0D - "AcceptableDependencies-HOST_APPLICATION":[],=0D - # For UEFI shell based apps=0D - "AcceptableDependencies-UEFI_APPLICATION":[=0D - "ShellPkg/ShellPkg.dec"=0D - ],=0D - "IgnoreInf": []=0D - },=0D - "DscCompleteCheck": {=0D - "DscPath": "NetworkPkg.dsc",=0D - "IgnoreInf": []=0D - },=0D - "GuidCheck": {=0D - "IgnoreGuidName": [],=0D - "IgnoreGuidValue": [],=0D - "IgnoreFoldersAndFiles": []=0D - },=0D - "LibraryClassCheck": {=0D - "IgnoreHeaderFile": []=0D - },=0D + "AcceptableDependencies":=0D + [=0D + "MdePkg/MdePkg.dec",=0D + "MdeModulePkg/MdeModulePkg.dec",=0D + "NetworkPkg/NetworkPkg.dec",=0D + "CryptoPkg/CryptoPkg.dec",=0D + ],=0D + # For host based unit tests=0D + "AcceptableDependencies-HOST_APPLICATION": [=0D + "UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec"=0D + ],=0D + # For UEFI shell based apps=0D + "AcceptableDependencies-UEFI_APPLICATION":=0D + ["ShellPkg/ShellPkg.dec"],=0D + "IgnoreInf": [],=0D + },=0D + "DscCompleteCheck": { "DscPath": "NetworkPkg.dsc", "IgnoreInf": [] },= =0D + "GuidCheck":=0D + {=0D + "IgnoreGuidName": [],=0D + "IgnoreGuidValue": [],=0D + "IgnoreFoldersAndFiles": [],=0D + },=0D + "LibraryClassCheck": { "IgnoreHeaderFile": [] },=0D =0D ## options defined ci/Plugin/SpellCheck=0D "SpellCheck": {=0D - "AuditOnly": True, # Fails test but run in AuditOnly mod= e to collect log=0D - "IgnoreFiles": [], # use gitignore syntax to ignore erro= rs in matching files=0D - "ExtendWords": [], # words to extend to the dictionary f= or this package=0D - "IgnoreStandardPaths": [], # Standard Plugin defined paths that = should be ignore=0D - "AdditionalIncludePaths": [] # Additional paths to spell check (wi= ldcards supported)=0D - },=0D + "AuditOnly": True, # Fails test but run in AuditOnly mode to c= ollect log=0D + "IgnoreFiles": [], # use gitignore syntax to ignore errors in = matching files=0D + "ExtendWords": [], # words to extend to the dictionary for thi= s package=0D + "IgnoreStandardPaths": [], # Standard Plugin defined paths tha= t should be ignore=0D + "AdditionalIncludePaths": [], # Additional paths to spell chec= k (wildcards supported)=0D + },=0D =0D - "Defines": {=0D - "BLD_*_CONTINUOUS_INTEGRATION": "TRUE",=0D - "BLD_*_NETWORK_ENABLE": "TRUE",=0D - "BLD_*_NETWORK_SNP_ENABLE": "TRUE",=0D - "BLD_*_NETWORK_VLAN_ENABLE": "TRUE",=0D - "BLD_*_NETWORK_IP4_ENABLE": "TRUE",=0D - "BLD_*_NETWORK_IP6_ENABLE": "TRUE",=0D - "BLD_*_NETWORK_TLS_ENABLE": "TRUE",=0D - "BLD_*_NETWORK_HTTP_ENABLE": "FALSE",=0D - "BLD_*_NETWORK_HTTP_BOOT_ENABLE": "TRUE",=0D - "BLD_*_NETWORK_ISCSI_ENABLE": "TRUE",=0D - }=0D + "Defines":=0D + {=0D + "BLD_*_CONTINUOUS_INTEGRATION": "TRUE",=0D + "BLD_*_NETWORK_ENABLE": "TRUE",=0D + "BLD_*_NETWORK_SNP_ENABLE": "TRUE",=0D + "BLD_*_NETWORK_VLAN_ENABLE": "TRUE",=0D + "BLD_*_NETWORK_IP4_ENABLE": "TRUE",=0D + "BLD_*_NETWORK_IP6_ENABLE": "TRUE",=0D + "BLD_*_NETWORK_TLS_ENABLE": "TRUE",=0D + "BLD_*_NETWORK_HTTP_ENABLE": "FALSE",=0D + "BLD_*_NETWORK_HTTP_BOOT_ENABLE": "TRUE",=0D + "BLD_*_NETWORK_ISCSI_ENABLE": "TRUE",=0D + },=0D }=0D --=20 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114254): https://edk2.groups.io/g/devel/message/114254 Mute This Topic: https://groups.io/mt/103926732/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-