From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail05.groups.io (mail05.groups.io [45.79.224.7]) by spool.mail.gandi.net (Postfix) with ESMTPS id AB4CE7803D0 for ; Thu, 9 May 2024 05:56:52 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=nPESuxgW/7tFCFmGCTwWf79bsJajdaNTMezsS4o6VhA=; 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:Resent-Date:Resent-From:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20240206; t=1715234211; v=1; b=pz+/lIHyEnHgSSBZqDxEqwh+9r87lFu+BxuCflJz+IbTE7V5RdWfhrZGbxNhlXEoYTNOk2UL FcC9u0YZAJ1hZbgkM5wx0nPCZTNPdon8S0O2exqhK9qgwFrYVLL9wdNxQRlDkMPnQnR7735kWgt vHsrBa+W7B3Y+/eUNHhjuWinPCzLx0O2xen0tNyoWKlz69ts5ocBfXv1DwSyVOk3pRRp+Tiyyue dwxLtH0cH9ADT4wgIrl0fQPvfBEcdeqYIhlSdAj5Bd/LC+ToEwLYNbVdcxvK+X7p3KM+cT/R2jG Y/G53OGNBM4ZcnhnWRaHPezIi9psKuG+Mtl3Zt0euIzOw== X-Received: by 127.0.0.2 with SMTP id l4XLYY7687511xQCKE6c5Q62; Wed, 08 May 2024 22:56:51 -0700 X-Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) by mx.groups.io with SMTP id smtpd.web10.3661.1715234208614967706 for ; Wed, 08 May 2024 22:56:48 -0700 X-Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3c974a0647bso353044b6e.2 for ; Wed, 08 May 2024 22:56:48 -0700 (PDT) X-Gm-Message-State: rV36KIV9eCRrfzNAccl5D1ejx7686176AA= X-Google-Smtp-Source: AGHT+IGp9A03wXtHDRMHHaoKScud3VuYQqZjLC31mY+TEdRmdwBA2HLxJPBlTa01jpAuP4Tt0ddhJQ== X-Received: by 2002:a05:6808:1201:b0:3c9:65af:1935 with SMTP id 5614622812f47-3c9852c5c4cmr5073113b6e.29.1715234206732; Wed, 08 May 2024 22:56:46 -0700 (PDT) X-Received: from localhost.localdomain (c-67-160-15-86.hsd1.wa.comcast.net. [67.160.15.86]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2b26cf5sm525611b3a.195.2024.05.08.22.56.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 May 2024 22:56:46 -0700 (PDT) From: "Doug Flick via groups.io" To: devel@edk2.groups.io Cc: Saloni Kasbekar , Zachary Clark-williams Subject: [edk2-devel] [PATCH v2 13/13] NetworkPkg: Update the PxeBcDhcp6GoogleTest due to underlying changes Date: Wed, 8 May 2024 22:56:33 -0700 Message-Id: <20240509055633.828642-14-doug.edk2@gmail.com> In-Reply-To: <20240509055633.828642-1-doug.edk2@gmail.com> References: <20240509055633.828642-1-doug.edk2@gmail.com> 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 Resent-Date: Wed, 08 May 2024 22:56:48 -0700 Resent-From: dougflick@microsoft.com 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=20240206 header.b="pz+/lIHy"; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 45.79.224.7 as permitted sender) smtp.mailfrom=bounce@groups.io From: Doug Flick This patch updates the PxeBcDhcp6GoogleTest due to the changes in the underlying code. The changes are as follows: - Random now comes from the RngLib Protocol - The TCP ISN is now generated by the hash function Cc: Saloni Kasbekar Cc: Zachary Clark-williams Signed-off-by: Doug Flick [MSFT] --- NetworkPkg/Test/NetworkPkgHostTest.dsc | 1 + NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf | 3 +- NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp | 102 ++++++= +++++++++++++- 3 files changed, 100 insertions(+), 6 deletions(-) diff --git a/NetworkPkg/Test/NetworkPkgHostTest.dsc b/NetworkPkg/Test/Netwo= rkPkgHostTest.dsc index fa301a7a52ab..1772afb05815 100644 --- a/NetworkPkg/Test/NetworkPkgHostTest.dsc +++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc @@ -30,6 +30,7 @@ [Components] NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf {=0D =0D UefiRuntimeServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/Mock= UefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf=0D + UefiBootServicesTableLib|MdePkg/Test/Mock/Library/GoogleTest/MockUef= iBootServicesTableLib/MockUefiBootServicesTableLib.inf=0D }=0D =0D # Despite these library classes being listed in [LibraryClasses] below, th= ey are not needed for the host-based unit tests.=0D diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf = b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf index 301dcdf61109..8b092d9291d4 100644 --- a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf @@ -14,7 +14,7 @@ [Defines] #=0D # The following information is for reference only and not required by the = build tools.=0D #=0D -# VALID_ARCHITECTURES =3D IA32 X64=0D +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64=0D #=0D =0D [Sources]=0D @@ -23,6 +23,7 @@ [Sources] PxeBcDhcp6GoogleTest.h=0D ../PxeBcDhcp6.c=0D ../PxeBcSupport.c=0D + ../../../MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockRng.cpp=0D =0D [Packages]=0D MdePkg/MdePkg.dec=0D diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp b/= NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp index bd423ebadfce..61736ff79e83 100644 --- a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp @@ -7,6 +7,8 @@ #include =0D #include =0D #include =0D +#include =0D +#include =0D =0D extern "C" {=0D #include =0D @@ -165,7 +167,7 @@ protected: // Note:=0D // Testing PxeBcHandleDhcp6Offer() is difficult because it depends on a=0D // properly setup Private structure. Attempting to properly test this func= tion=0D -// without a signficant refactor is a fools errand. Instead, we will test= =0D +// without a significant refactor is a fools errand. Instead, we will test= =0D // that we can prevent an overflow in the function.=0D TEST_F (PxeBcHandleDhcp6OfferTest, BasicUsageTest) {=0D PXEBC_DHCP6_PACKET_CACHE *Cache6 =3D NULL;=0D @@ -238,6 +240,7 @@ TEST_F (PxeBcCacheDnsServerAddressesTest, BasicUsageTes= t) { FreePool (Option);=0D }=0D }=0D +=0D // Test Description=0D // Test that we can prevent an overflow in the function=0D TEST_F (PxeBcCacheDnsServerAddressesTest, AttemptOverflowTest) {=0D @@ -470,10 +473,15 @@ TEST_F (PxeBcRequestBootServiceTest, AttemptRequestOv= erFlowExpectFailure) { class PxeBcDhcp6DiscoverTest : public ::testing::Test {=0D public:=0D PXEBC_PRIVATE_DATA Private =3D { 0 };=0D + // create a mock md5 hash=0D + UINT8 Md5Hash[16] =3D { 0 };=0D +=0D EFI_UDP6_PROTOCOL Udp6Read;=0D =0D protected:=0D MockUefiRuntimeServicesTableLib RtServicesMock;=0D + MockUefiBootServicesTableLib BsMock;=0D + MockRng RngMock;=0D =0D // Add any setup code if needed=0D virtual void=0D @@ -527,8 +535,21 @@ TEST_F (PxeBcDhcp6DiscoverTest, BasicOverflowTest) { =0D Private.Dhcp6Request->Length =3D (UINT16)(Cursor - (UINT8 *)Private.Dhcp= 6Request);=0D =0D - EXPECT_CALL (RtServicesMock, gRT_GetTime)=0D - .WillOnce (::testing::Return (0));=0D + EXPECT_CALL (BsMock, gBS_LocateProtocol)=0D + .WillOnce (=0D + ::testing::DoAll (=0D + ::testing::SetArgPointee<2> (::testing::ByRef (gRngPro= tocol)),=0D + ::testing::Return (EFI_SUCCESS)=0D + )=0D + );=0D +=0D + EXPECT_CALL (RngMock, GetRng)=0D + .WillOnce (=0D + ::testing::DoAll (=0D + ::testing::SetArgPointee<3> (::testing::ByRef (Md5Hash= [0])),=0D + ::testing::Return (EFI_SUCCESS)=0D + )=0D + );=0D =0D ASSERT_EQ (=0D PxeBcDhcp6Discover (=0D @@ -558,8 +579,21 @@ TEST_F (PxeBcDhcp6DiscoverTest, BasicUsageTest) { =0D Private.Dhcp6Request->Length =3D (UINT16)(Cursor - (UINT8 *)Private.Dhcp= 6Request);=0D =0D - EXPECT_CALL (RtServicesMock, gRT_GetTime)=0D - .WillOnce (::testing::Return (0));=0D + EXPECT_CALL (BsMock, gBS_LocateProtocol)=0D + .WillOnce (=0D + ::testing::DoAll (=0D + ::testing::SetArgPointee<2> (::testing::ByRef (gRngPro= tocol)),=0D + ::testing::Return (EFI_SUCCESS)=0D + )=0D + );=0D +=0D + EXPECT_CALL (RngMock, GetRng)=0D + .WillOnce (=0D + ::testing::DoAll (=0D + ::testing::SetArgPointee<3> (::testing::ByRef (Md5Hash= [0])),=0D + ::testing::Return (EFI_SUCCESS)=0D + )=0D + );=0D =0D ASSERT_EQ (=0D PxeBcDhcp6Discover (=0D @@ -572,3 +606,61 @@ TEST_F (PxeBcDhcp6DiscoverTest, BasicUsageTest) { EFI_SUCCESS=0D );=0D }=0D +=0D +TEST_F (PxeBcDhcp6DiscoverTest, MultipleRequestsAttemptOverflow) {=0D + EFI_IPv6_ADDRESS DestIp =3D { 0 };=0D + EFI_DHCP6_PACKET_OPTION RequestOpt =3D { 0 }; // the data section doesn= 't really matter=0D +=0D + RequestOpt.OpCode =3D HTONS (0x1337);=0D + RequestOpt.OpLen =3D HTONS (REQUEST_OPTION_LENGTH); // this length woul= d overflow without a check=0D + UINT8 RequestOptBuffer[REQUEST_OPTION_LENGTH] =3D { 0 };=0D +=0D + // make sure we have enough space for 10 of these options=0D + ASSERT_TRUE (REQUEST_OPTION_LENGTH * 10 <=3D PACKET_SIZE);=0D +=0D + UINT8 Index =3D 0;=0D + EFI_DHCP6_PACKET *Packet =3D (EFI_DHCP6_PACKET *)&Private.Dhcp6Request[= Index];=0D + UINT8 *Cursor =3D (UINT8 *)(Packet->Dhcp6.Option);=0D +=0D + // let's add 10 of these options - this should overflow=0D + for (UINT8 i =3D 0; i < 10; i++) {=0D + CopyMem (Cursor, &RequestOpt, sizeof (RequestOpt));=0D + Cursor +=3D sizeof (RequestOpt) - 1;=0D + CopyMem (Cursor, RequestOptBuffer, REQUEST_OPTION_LENGTH);=0D + Cursor +=3D REQUEST_OPTION_LENGTH;=0D + }=0D +=0D + // Update the packet length=0D + Packet->Length =3D (UINT16)(Cursor - (UINT8 *)Packet);=0D + Packet->Size =3D PACKET_SIZE;=0D +=0D + // Make sure we're larger than the buffer we're trying to write into=0D + ASSERT_TRUE (Packet->Length > sizeof (EFI_PXE_BASE_CODE_DHCPV6_PACKET));= =0D +=0D + EXPECT_CALL (BsMock, gBS_LocateProtocol)=0D + .WillOnce (=0D + ::testing::DoAll (=0D + ::testing::SetArgPointee<2> (::testing::ByRef (gRngPro= tocol)),=0D + ::testing::Return (EFI_SUCCESS)=0D + )=0D + );=0D +=0D + EXPECT_CALL (RngMock, GetRng)=0D + .WillOnce (=0D + ::testing::DoAll (=0D + ::testing::SetArgPointee<3> (::testing::ByRef (Md5Hash= [0])),=0D + ::testing::Return (EFI_SUCCESS)=0D + )=0D + );=0D +=0D + ASSERT_EQ (=0D + PxeBcDhcp6Discover (=0D + &(PxeBcDhcp6DiscoverTest::Private),=0D + 0,=0D + NULL,=0D + FALSE,=0D + (EFI_IP_ADDRESS *)&DestIp=0D + ),=0D + EFI_OUT_OF_RESOURCES=0D + );=0D +}=0D --=20 2.34.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#118728): https://edk2.groups.io/g/devel/message/118728 Mute This Topic: https://groups.io/mt/105996592/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-