From nobody Mon Sep 16 19:39:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+114256+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+114256+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1706073631; cv=none; d=zohomail.com; s=zohoarc; b=jrthgyU4BQQ2eTSTpByKsc72GxwfRE804xLGELwmbUe7PAjt6yxVpdxF8Let+wKPmndz0GoRN2WDxdFrzQSp0XH41aJCM9ZvGfmI+n08ShTQnkblpbcZA4S0kyHfqEL138UqVl1ZAyz6AO6OG6y0TgwmbhzK7H4mD543sjkNy7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706073631; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=dd87rJX6KX118nEshYNL+zdOg/rB1K7ZqFDKN1rmtd8=; b=Cn+Rbk7baI2/uCpSmFPetCEnmsvIrI72DLzCG5mis3Z/TSWYkQcrlLaor91cwi46sn09mwgCeLksEgkNp5v5Urv8YuntI2aHvWaZ+UTsffV7Diyt/uWPS0VHZ6mZ6XVmFVNvqQghQTUxsspCcBs34rjPbuMcqN4B4bCUH9e3irY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+114256+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1706073631391513.1199465401849; Tue, 23 Jan 2024 21:20:31 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=1LZ1I4yQmdy04PWw+HQBlZ5peWUb6QcU6RaKH9S+eDI=; 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=1706073631; v=1; b=tR+dgv+aG5lXCI6gMesD+q32pfWRlY2DF3qL4qOEzPbvpKIk/p9+bAjuIYorHeDUJBnm/Xtl ph3GDSKWxWUlLHeStSFWkGAMk6iie3YA6l5rnJ3n2kgX32qlYymg8ThQgIBNB6vjfURZKmdh1ll TolYloaGHt4y7FuhNQm3HKtE= X-Received: by 127.0.0.2 with SMTP id gNxcYY1788612xxn4asKbGlO; Tue, 23 Jan 2024 21:20:31 -0800 X-Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by mx.groups.io with SMTP id smtpd.web11.16103.1706073630477624504 for ; Tue, 23 Jan 2024 21:20:30 -0800 X-Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-5cddfe0cb64so2569410a12.0 for ; Tue, 23 Jan 2024 21:20:30 -0800 (PST) X-Gm-Message-State: ab6xUHCA4iQq2cyNlUA5l6z4x1787277AA= X-Google-Smtp-Source: AGHT+IHagWLT3iDQl+Og4ecyn7jfS13hYYJPJxdi/ZSwfyEMG+RPH/15znPGtJ4gz0uvBE0TV4u8YQ== X-Received: by 2002:a17:903:2649:b0:1d7:4ea2:3dc3 with SMTP id je9-20020a170903264900b001d74ea23dc3mr173555plb.82.1706073629503; Tue, 23 Jan 2024 21:20:29 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 21:20:29 -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 04/14] NetworkPkg: Dhcp6Dxe: SECURITY PATCH CVE-2023-45229 Unit Tests Date: Tue, 23 Jan 2024 19:33:27 -0800 Message-ID: <9cedd6b0094a541bf6a32c728feda217c0964ea4.1706062164.git.doug.edk2@gmail.com> 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-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1706073632297100012 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4534 SECURITY PATCH - Unit Tests TCBZ4534 CVE-2023-45229 CVSS 6.5 : CVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N CWE-125 Out-of-bounds Read Cc: Saloni Kasbekar Cc: Zachary Clark-williams Signed-off-by: Doug Flick [MSFT] --- NetworkPkg/Test/NetworkPkgHostTest.dsc | 1 + .../GoogleTest/Dhcp6DxeGoogleTest.inf | 1 + .../Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.h | 58 +++ NetworkPkg/Dhcp6Dxe/Dhcp6Io.c | 2 +- .../Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp | 365 +++++++++++++++++- 5 files changed, 424 insertions(+), 3 deletions(-) create mode 100644 NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.h diff --git a/NetworkPkg/Test/NetworkPkgHostTest.dsc b/NetworkPkg/Test/Netwo= rkPkgHostTest.dsc index 20bc90b1728d..24dee654df2e 100644 --- a/NetworkPkg/Test/NetworkPkgHostTest.dsc +++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc @@ -16,6 +16,7 @@ [Defines] SKUID_IDENTIFIER =3D DEFAULT =20 !include UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc + [Packages] MdePkg/MdePkg.dec UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf b/Networ= kPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf index 8e9119a37158..12532ed30cb3 100644 --- a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf @@ -18,6 +18,7 @@ [Defines] [Sources] Dhcp6DxeGoogleTest.cpp Dhcp6IoGoogleTest.cpp + Dhcp6IoGoogleTest.h ../Dhcp6Io.c ../Dhcp6Utility.c =20 diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.h b/NetworkPk= g/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.h new file mode 100644 index 000000000000..aed3b890827b --- /dev/null +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.h @@ -0,0 +1,58 @@ +/** @file + Acts as header for private functions under test in Dhcp6Io.c + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef DHCP6_IO_GOOGLE_TEST_H_ +#define DHCP6_IO_GOOGLE_TEST_H_ + +//////////////////////////////////////////////////////////////////////////= ////// +// These are the functions that are being unit tested +//////////////////////////////////////////////////////////////////////////= ////// + +#include + +/** + Seeks the Inner Options from a DHCP6 Option + + @param[in] IaType The type of the IA option. + @param[in] Option The pointer to the DHCP6 Option. + @param[in] OptionLen The length of the DHCP6 Option. + @param[out] IaInnerOpt The pointer to the IA inner option. + @param[out] IaInnerLen The length of the IA inner option. + + @retval EFI_SUCCESS Seek the inner option successfully. + @retval EFI_DEVICE_ERROR The OptionLen is invalid. +*/ +EFI_STATUS +Dhcp6SeekInnerOptionSafe ( + UINT16 IaType, + UINT8 *Option, + UINT32 OptionLen, + UINT8 **IaInnerOpt, + UINT16 *IaInnerLen + ); + +/** + Seek StatusCode Option in package. A Status Code option may appear in the + options field of a DHCP message and/or in the options field of another o= ption. + See details in section 22.13, RFC3315. + + @param[in] Instance The pointer to the Dhcp6 instance. + @param[in] Packet The pointer to reply messages. + @param[out] Option The pointer to status code option. + + @retval EFI_SUCCESS Seek status code option successfully. + @retval EFI_DEVICE_ERROR An unexpected error. + +**/ +EFI_STATUS +Dhcp6SeekStsOption ( + IN DHCP6_INSTANCE *Instance, + IN EFI_DHCP6_PACKET *Packet, + OUT UINT8 **Option + ); + +#endif // DHCP6_IO_GOOGLE_TEST_H diff --git a/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c b/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c index 89d16484a568..3b8feb4a2032 100644 --- a/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c +++ b/NetworkPkg/Dhcp6Dxe/Dhcp6Io.c @@ -816,7 +816,7 @@ Dhcp6SeekStsOption ( // IA option to the end of the DHCP6 option area, thus subtract the space // up until this option // - OptionLen =3D OptionLen - (*Option - Packet->Dhcp6.Option); + OptionLen =3D OptionLen - (UINT32)(*Option - Packet->Dhcp6.Option); =20 // // Seek the inner option diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp b/Network= Pkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp index 7ee40e4af480..7db253a7b87f 100644 --- a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp @@ -13,6 +13,7 @@ extern "C" { #include #include "../Dhcp6Impl.h" #include "../Dhcp6Utility.h" + #include "Dhcp6IoGoogleTest.h" } =20 //////////////////////////////////////////////////////////////////////// @@ -21,7 +22,35 @@ extern "C" { =20 #define DHCP6_PACKET_MAX_LEN 1500 =20 +// This definition is used by this test but is also required to compile +// by Dhcp6Io.c +#define DHCPV6_OPTION_IA_NA 3 +#define DHCPV6_OPTION_IA_TA 4 + +#define SEARCH_PATTERN 0xDEADC0DE +#define SEARCH_PATTERN_LEN sizeof(SEARCH_PATTERN) + //////////////////////////////////////////////////////////////////////// +// Test structures for IA_NA and IA_TA options +//////////////////////////////////////////////////////////////////////// +typedef struct { + UINT16 Code; + UINT16 Len; + UINT32 IAID; +} DHCPv6_OPTION; + +typedef struct { + DHCPv6_OPTION Header; + UINT32 T1; + UINT32 T2; + UINT8 InnerOptions[0]; +} DHCPv6_OPTION_IA_NA; + +typedef struct { + DHCPv6_OPTION Header; + UINT8 InnerOptions[0]; +} DHCPv6_OPTION_IA_TA; + //////////////////////////////////////////////////////////////////////// // Symbol Definitions // These functions are not directly under test - but required to compile @@ -210,7 +239,7 @@ TEST_F (Dhcp6AppendETOptionTest, InvalidDataExpectBuffe= rTooSmall) { Status =3D Dhcp6AppendETOption ( Dhcp6AppendETOptionTest::Packet, &Cursor, - &Instance, // Instance is not used in this function + &Instance, // Instance is not used in this= function &ElapsedTime ); =20 @@ -240,7 +269,7 @@ TEST_F (Dhcp6AppendETOptionTest, ValidDataExpectSuccess= ) { Status =3D Dhcp6AppendETOption ( Dhcp6AppendETOptionTest::Packet, &Cursor, - &Instance, // Instance is not used in this function + &Instance, // Instance is not used in this= function &ElapsedTime ); =20 @@ -476,3 +505,335 @@ TEST_F (Dhcp6AppendIaOptionTest, IaTaValidDataExpectS= uccess) { // verify that the status is EFI_SUCCESS ASSERT_EQ (Status, EFI_SUCCESS); } + +//////////////////////////////////////////////////////////////////////// +// Dhcp6SeekInnerOptionSafe Tests +//////////////////////////////////////////////////////////////////////// + +// Define a fixture for your tests if needed +class Dhcp6SeekInnerOptionSafeTest : public ::testing::Test { +protected: + // Add any setup code if needed + virtual void + SetUp ( + ) + { + // Initialize any resources or variables + } + + // Add any cleanup code if needed + virtual void + TearDown ( + ) + { + // Clean up any resources or variables + } +}; + +// Test Description: +// This test verifies that Dhcp6SeekInnerOptionSafe returns EFI_SUCCESS wh= en the IANA option is found. +TEST_F (Dhcp6SeekInnerOptionSafeTest, IANAValidOptionExpectSuccess) { + EFI_STATUS Result; + UINT8 Option[sizeof (DHCPv6_OPTION_IA_NA) + SEARCH_PATTER= N_LEN] =3D { 0 }; + UINT32 OptionLength = =3D sizeof (Option); + DHCPv6_OPTION_IA_NA *OptionPtr = =3D (DHCPv6_OPTION_IA_NA *)Option; + UINT32 SearchPattern = =3D SEARCH_PATTERN; + + UINTN SearchPatternLength =3D SEARCH_PATTERN_LEN; + UINT8 *InnerOptionPtr =3D NULL; + UINT16 InnerOptionLength =3D 0; + + OptionPtr->Header.Code =3D Dhcp6OptIana; + OptionPtr->Header.Len =3D HTONS (4 + 12); // Valid length has to be mor= e than 12 + OptionPtr->Header.IAID =3D 0x12345678; + OptionPtr->T1 =3D 0x11111111; + OptionPtr->T2 =3D 0x22222222; + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength); + + Result =3D Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIana, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Result, EFI_SUCCESS); + ASSERT_EQ (InnerOptionLength, 4); + ASSERT_EQ (CompareMem (InnerOptionPtr, &SearchPattern, SearchPatternLeng= th), 0); +} + +// Test Description: +// This test verifies that Dhcp6SeekInnerOptionSafe returns EFI_DEIVCE_ERR= OR when the IANA option size is invalid. +TEST_F (Dhcp6SeekInnerOptionSafeTest, IANAInvalidSizeExpectFail) { + // Lets add an inner option of bytes we expect to find + EFI_STATUS Status; + UINT8 Option[sizeof (DHCPv6_OPTION_IA_NA) + SEARCH_PATTER= N_LEN] =3D { 0 }; + UINT32 OptionLength = =3D sizeof (Option); + DHCPv6_OPTION_IA_NA *OptionPtr = =3D (DHCPv6_OPTION_IA_NA *)Option; + UINT32 SearchPattern = =3D SEARCH_PATTERN; + + UINTN SearchPatternLength =3D SEARCH_PATTERN_LEN; + UINT8 *InnerOptionPtr =3D NULL; + UINT16 InnerOptionLength =3D 0; + + OptionPtr->Header.Code =3D Dhcp6OptIana; + OptionPtr->Header.Len =3D HTONS (4); // Set the length to lower than ex= pected (12) + OptionPtr->Header.IAID =3D 0x12345678; + OptionPtr->T1 =3D 0x11111111; + OptionPtr->T2 =3D 0x22222222; + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength); + + // Set the InnerOptionLength to be less than the size of the option + Status =3D Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIana, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Status, EFI_DEVICE_ERROR); + + // Now set the OptionLength to be less than the size of the option + OptionLength =3D sizeof (DHCPv6_OPTION_IA_NA) - 1; + Status =3D Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIana, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Status, EFI_DEVICE_ERROR); +} + +// Test Description: +// This test verifies that Dhcp6SeekInnerOptionSafe returns EFI_SUCCESS wh= en the IATA option is found +TEST_F (Dhcp6SeekInnerOptionSafeTest, IATAValidOptionExpectSuccess) { + // Lets add an inner option of bytes we expect to find + EFI_STATUS Status; + UINT8 Option[sizeof (DHCPv6_OPTION_IA_TA) + SEARCH_PATTER= N_LEN] =3D { 0 }; + UINT32 OptionLength = =3D sizeof (Option); + DHCPv6_OPTION_IA_TA *OptionPtr = =3D (DHCPv6_OPTION_IA_TA *)Option; + UINT32 SearchPattern = =3D SEARCH_PATTERN; + + UINTN SearchPatternLength =3D SEARCH_PATTERN_LEN; + UINT8 *InnerOptionPtr =3D NULL; + UINT16 InnerOptionLength =3D 0; + + OptionPtr->Header.Code =3D Dhcp6OptIata; + OptionPtr->Header.Len =3D HTONS (4 + 4); // Valid length has to be more= than 4 + OptionPtr->Header.IAID =3D 0x12345678; + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength); + + Status =3D Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIata, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Status, EFI_SUCCESS); + ASSERT_EQ (InnerOptionLength, 4); + ASSERT_EQ (CompareMem (InnerOptionPtr, &SearchPattern, SearchPatternLeng= th), 0); +} + +// Test Description: +// This test verifies that Dhcp6SeekInnerOptionSafe returns EFI_SUCCESS wh= en the IATA option size is invalid. +TEST_F (Dhcp6SeekInnerOptionSafeTest, IATAInvalidSizeExpectFail) { + // Lets add an inner option of bytes we expect to find + EFI_STATUS Status; + UINT8 Option[sizeof (DHCPv6_OPTION_IA_TA) + SEARCH_PATTER= N_LEN] =3D { 0 }; + UINT32 OptionLength = =3D sizeof (Option); + DHCPv6_OPTION_IA_TA *OptionPtr = =3D (DHCPv6_OPTION_IA_TA *)Option; + UINT32 SearchPattern = =3D SEARCH_PATTERN; + + UINTN SearchPatternLength =3D SEARCH_PATTERN_LEN; + UINT8 *InnerOptionPtr =3D NULL; + UINT16 InnerOptionLength =3D 0; + + OptionPtr->Header.Code =3D Dhcp6OptIata; + OptionPtr->Header.Len =3D HTONS (2); // Set the length to lower than ex= pected (4) + OptionPtr->Header.IAID =3D 0x12345678; + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength); + + Status =3D Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIata, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Status, EFI_DEVICE_ERROR); + + // Now lets try modifying the OptionLength to be less than the size of t= he option + OptionLength =3D sizeof (DHCPv6_OPTION_IA_TA) - 1; + Status =3D Dhcp6SeekInnerOptionSafe ( + Dhcp6OptIata, + Option, + OptionLength, + &InnerOptionPtr, + &InnerOptionLength + ); + ASSERT_EQ (Status, EFI_DEVICE_ERROR); +} + +// Test Description: +// This test verifies that any other Option Type fails +TEST_F (Dhcp6SeekInnerOptionSafeTest, InvalidOption) { + // Lets add an inner option of bytes we expect to find + EFI_STATUS Result; + UINT8 Option[sizeof (DHCPv6_OPTION_IA_TA) + SEARCH_PATTER= N_LEN] =3D { 0 }; + UINT32 OptionLength = =3D sizeof (Option); + DHCPv6_OPTION_IA_TA *OptionPtr = =3D (DHCPv6_OPTION_IA_TA *)Option; + UINT32 SearchPattern = =3D SEARCH_PATTERN; + + UINTN SearchPatternLength =3D SEARCH_PATTERN_LEN; + UINT8 *InnerOptionPtr =3D NULL; + UINT16 InnerOptionLength =3D 0; + + OptionPtr->Header.Code =3D 0xC0DE; + OptionPtr->Header.Len =3D HTONS (2); // Set the length to lower than ex= pected (4) + OptionPtr->Header.IAID =3D 0x12345678; + CopyMem (OptionPtr->InnerOptions, &SearchPattern, SearchPatternLength); + + Result =3D Dhcp6SeekInnerOptionSafe (0xC0DE, Option, OptionLength, &Inne= rOptionPtr, &InnerOptionLength); + ASSERT_EQ (Result, EFI_DEVICE_ERROR); +} + +//////////////////////////////////////////////////////////////////////// +// Dhcp6SeekStsOption Tests +//////////////////////////////////////////////////////////////////////// + +#define PACKET_SIZE (1500) + +class Dhcp6SeekStsOptionTest : public ::testing::Test { +public: + DHCP6_INSTANCE Instance =3D { 0 }; + EFI_DHCP6_PACKET *Packet =3D NULL; + EFI_DHCP6_CONFIG_DATA Config =3D { 0 }; + +protected: + // Add any setup code if needed + virtual void + SetUp ( + ) + { + // Allocate a packet + Packet =3D (EFI_DHCP6_PACKET *)AllocateZeroPool (PACKET_SIZE); + ASSERT_NE (Packet, nullptr); + + // Initialize the packet + Packet->Size =3D PACKET_SIZE; + + Instance.Config =3D &Config; + } + + // Add any cleanup code if needed + virtual void + TearDown ( + ) + { + // Clean up any resources or variables + FreePool (Packet); + } +}; + +// Test Description: +// This test verifies that Dhcp6SeekStsOption returns EFI_DEVICE_ERROR whe= n the option is invalid +// This verifies that the calling function is working as expected +TEST_F (Dhcp6SeekStsOptionTest, SeekIATAOptionExpectFail) { + EFI_STATUS Status; + UINT8 *Option =3D NULL; + UINT32 SearchPattern =3D SEARCH_PATTERN; + UINT16 SearchPatternLength =3D SEARCH_PATTERN_LEN; + UINT16 *Len =3D NULL; + EFI_DHCP6_IA Ia =3D { 0 }; + + Ia.Descriptor.Type =3D DHCPV6_OPTION_IA_TA; + Ia.IaAddressCount =3D 1; + Ia.IaAddress[0].PreferredLifetime =3D 0xDEADBEEF; + Ia.IaAddress[0].ValidLifetime =3D 0xDEADAAAA; + Ia.IaAddress[0].IpAddress =3D mAllDhcpRelayAndServersAddress; + + Packet->Length =3D sizeof (EFI_DHCP6_HEADER); + + Option =3D Dhcp6SeekStsOptionTest::Packet->Dhcp6.Option; + + // Let's append the option to the packet + Status =3D Dhcp6AppendOption ( + Dhcp6SeekStsOptionTest::Packet, + &Option, + Dhcp6OptStatusCode, + SearchPatternLength, + (UINT8 *)&SearchPattern + ); + ASSERT_EQ (Status, EFI_SUCCESS); + + // Inner option length - this will be overwritten later + Len =3D (UINT16 *)(Option + 2); + + // Fill in the inner IA option + Status =3D Dhcp6AppendIaOption ( + Dhcp6SeekStsOptionTest::Packet, + &Option, + &Ia, + 0x12345678, + 0x11111111, + 0x22222222 + ); + ASSERT_EQ (Status, EFI_SUCCESS); + + // overwrite the len of inner Ia option + *Len =3D HTONS (3); + + Dhcp6SeekStsOptionTest::Instance.Config->IaDescriptor.Type =3D DHCPV6_OP= TION_IA_TA; + + Option =3D NULL; + Status =3D Dhcp6SeekStsOption (&(Dhcp6SeekStsOptionTest::Instance), Dhcp= 6SeekStsOptionTest::Packet, &Option); + + ASSERT_EQ (Status, EFI_DEVICE_ERROR); +} + +// Test Description: +// This test verifies that Dhcp6SeekInnerOptionSafe returns EFI_SUCCESS wh= en the IATA option size is invalid. +TEST_F (Dhcp6SeekStsOptionTest, SeekIANAOptionExpectSuccess) { + EFI_STATUS Status =3D EFI_NOT_FOUND; + UINT8 *Option =3D NULL; + UINT32 SearchPattern =3D SEARCH_PATTERN; + UINT16 SearchPatternLength =3D SEARCH_PATTERN_LEN; + EFI_DHCP6_IA Ia =3D { 0 }; + + Ia.Descriptor.Type =3D DHCPV6_OPTION_IA_NA; + Ia.IaAddressCount =3D 1; + Ia.IaAddress[0].PreferredLifetime =3D 0x11111111; + Ia.IaAddress[0].ValidLifetime =3D 0x22222222; + Ia.IaAddress[0].IpAddress =3D mAllDhcpRelayAndServersAddress; + Packet->Length =3D sizeof (EFI_DHCP6_HEADER); + + Option =3D Dhcp6SeekStsOptionTest::Packet->Dhcp6.Option; + + Status =3D Dhcp6AppendOption ( + Dhcp6SeekStsOptionTest::Packet, + &Option, + Dhcp6OptStatusCode, + SearchPatternLength, + (UINT8 *)&SearchPattern + ); + ASSERT_EQ (Status, EFI_SUCCESS); + + Status =3D Dhcp6AppendIaOption ( + Dhcp6SeekStsOptionTest::Packet, + &Option, + &Ia, + 0x12345678, + 0x11111111, + 0x22222222 + ); + ASSERT_EQ (Status, EFI_SUCCESS); + + Dhcp6SeekStsOptionTest::Instance.Config->IaDescriptor.Type =3D DHCPV6_OP= TION_IA_NA; + + Option =3D NULL; + Status =3D Dhcp6SeekStsOption (&(Dhcp6SeekStsOptionTest::Instance), Dhcp= 6SeekStsOptionTest::Packet, &Option); + + ASSERT_EQ (Status, EFI_SUCCESS); +} --=20 2.43.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114256): https://edk2.groups.io/g/devel/message/114256 Mute This Topic: https://groups.io/mt/103926734/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-