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 36C88941109 for ; Fri, 24 May 2024 05:45:36 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=9zS5s+qe6RvKSfMFM5uR9dUbmSqcDhGi0SIlWaZFjEo=; 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=1716529534; v=1; b=hcAqQkDFkoqupKMCpFoCQfKLsRd8bfL1UWPcmFusdpmwjCEpwPoh3Jyd9xYUna8hwkcI/x+r W/wWQf55hzM+hbeDRu87j8C3RXzxup3ZzW+DK4T9ajfNssSAONgEKGXAxMpJ3GBBz8yjFszCGCx gn0Zc4Af++yWKDlqU8riafFppaJ2M0kX7t8O7j6gBMpNOql9UI1Y7zGcLb4YD4WVZwz5SdC2V78 k3BvMJWNlJFdgb9zPn795pCqUdNuS7ii8HYLtwqZ1CyehyqBwmoW/cyWJLEB00ZU3FqV3uEi3Tj 1NUFFDjbIvuaus3B2/VgWOWHl7RO0XwHGxQ+PfdPzyFMw== X-Received: by 127.0.0.2 with SMTP id N3CDYY7687511xCBEMBKgTRP; Thu, 23 May 2024 22:45:34 -0700 X-Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by mx.groups.io with SMTP id smtpd.web10.9221.1716529528638036522 for ; Thu, 23 May 2024 22:45:28 -0700 X-Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6f4603237e0so1998381b3a.0 for ; Thu, 23 May 2024 22:45:28 -0700 (PDT) X-Gm-Message-State: YZKicqcsEiB4caBVXje4jNIax7686176AA= X-Google-Smtp-Source: AGHT+IH7xI4PKBQ06suI8lV6iu8moSp7V40JIER5qMEs6WxJ0EcIw3IvJToamEAlXLr2/7NQ6P4zfQ== X-Received: by 2002:a05:6a00:2c94:b0:6f8:c94f:578a with SMTP id d2e1a72fcca58-6f8e9fc10d2mr2129430b3a.12.1716529527835; Thu, 23 May 2024 22:45:27 -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-6f8fcfe64a4sm471919b3a.158.2024.05.23.22.45.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 May 2024 22:45:27 -0700 (PDT) From: "Doug Flick via groups.io" X-Google-Original-From: Flickdm To: devel@edk2.groups.io Cc: Saloni Kasbekar , Zachary Clark-williams Subject: [edk2-devel] [PATCH v3 13/20] NetworkPkg: Update the PxeBcDhcp6GoogleTest due to underlying changes Date: Thu, 23 May 2024 22:45:05 -0700 Message-Id: <20240524054512.523329-14-douglas.flick@microsoft.com> In-Reply-To: <20240524054512.523329-1-douglas.flick@microsoft.com> References: <20240524054512.523329-1-douglas.flick@microsoft.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: Thu, 23 May 2024 22:45:28 -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=hcAqQkDF; 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 fa301a7a52..1772afb058 100644 --- a/NetworkPkg/Test/NetworkPkgHostTest.dsc +++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc @@ -30,6 +30,7 @@ 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 301dcdf611..8b092d9291 100644 --- a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf @@ -14,7 +14,7 @@ VERSION_STRING =3D 1.0 #=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 @@ VERSION_STRING =3D 1.0 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 bd423ebadf..61736ff79e 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 (#119240): https://edk2.groups.io/g/devel/message/119240 Mute This Topic: https://groups.io/mt/106276865/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-