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 2CEF1740040 for ; Thu, 1 Feb 2024 21:32:19 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=ZXvwKMRgYLAnBKJahP2bCQG9rqDgZOttjZdn3NVK2rA=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1706823138; v=1; b=ierKWK47aZ/6mItz/AUzMvqmDsePq3sTK+a8tBr7wdYpTCqNicm/Cy21tQb/oMeDUd6HixNV owkp2MSb0iawI76LEb0TlO9lK5OguAtwl3xfkx/8GpuAVQ32xKW1DNTL0RC/M6MGkvzf6d6cO7J t9wz70LBJnv3nfY/8I7jpuiI= X-Received: by 127.0.0.2 with SMTP id 7C7sYY7687511xMp76DS7CaN; Thu, 01 Feb 2024 13:32:18 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) by mx.groups.io with SMTP id smtpd.web10.7983.1706823137198121983 for ; Thu, 01 Feb 2024 13:32:17 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="402853078" X-IronPort-AV: E=Sophos;i="6.05,236,1701158400"; d="scan'208";a="402853078" X-Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2024 13:32:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,236,1701158400"; d="scan'208";a="4505849" X-Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orviesa003.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 01 Feb 2024 13:32:16 -0800 X-Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 1 Feb 2024 13:32:15 -0800 X-Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35 via Frontend Transport; Thu, 1 Feb 2024 13:32:15 -0800 X-Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.57.40) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 1 Feb 2024 13:32:14 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gkqd8BUY6EWgq9CLn0s42lSgic2Bb4zuMEnOulMxQ9DXDBVC3/9fFzKDZB3f7wzMP5c/hThivfDi3ojgeqnH9H6BBrUHRyrkeNZACvzo1mRD1npg/50c8wQPy1C6KxQuQWSLaXKslbTuGIyoukYhsLiKau4lp26sE9rDuPwAs0C98ne5ERbwLgNYe7Td4qbey7Xyq4owF9CgFclYJLxLb1rpacxO+xpimV5VtEb5FwkQBp7FokcU0Go2k+Mh5h9QKIaTfTPQr0cc2ZOUc/gNqqPQKz/PZhODWq+y1YYT6WO/anDfC7dGB3vkX8LifvbHkOG2kxhUJIW+ZP0NLBQzfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mgqb/tV48U7LTsgaDtdZJAB6koKMYOv6FK5s/O4WuAY=; b=OEaRNyVQDd3N3c7w9M4voOUjkAQktBAzZJRnj9uaFcoXPXYIiEN5HfYgsdgiHsf42WNCLTehu3sZWb1cE5LZeAvNa6eFsiiN8+n1WaNGyYUv3zG9PfJbTrDCYmeU/O94cYdEmu+FbgIsKmO7Kzuqi+SuofHUGhzYw3VdHyCKSfCV9yUtxBKz28fkGuHiv94tDzBRjr4jvDCbpZU7BFYF8XYjwzsYqoQI9is2JNkOVggr5sUKq1c62g/ifyRbBaYLS7w/PSEJWHKHOZeR1h/TR5tyELaBie8rBojBo9xmzBTvMBC7re0HNLrltneUNA/JMhlCtFwZotJN2C69618gtQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from SN7PR11MB8281.namprd11.prod.outlook.com (2603:10b6:806:26b::20) by CH0PR11MB8236.namprd11.prod.outlook.com (2603:10b6:610:184::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.34; Thu, 1 Feb 2024 21:32:11 +0000 X-Received: from SN7PR11MB8281.namprd11.prod.outlook.com ([fe80::bf47:e473:3750:b81f]) by SN7PR11MB8281.namprd11.prod.outlook.com ([fe80::bf47:e473:3750:b81f%5]) with mapi id 15.20.7249.024; Thu, 1 Feb 2024 21:32:09 +0000 From: "Saloni Kasbekar" To: "Douglas Flick [MSFT]" , "devel@edk2.groups.io" CC: Doug Flick , "Clark-williams, Zachary" Subject: Re: [edk2-devel] [PATCH v2 11/15] NetworkPkg: UefiPxeBcDxe: SECURITY PATCH CVE-2023-45234 Unit Tests Thread-Topic: [PATCH v2 11/15] NetworkPkg: UefiPxeBcDxe: SECURITY PATCH CVE-2023-45234 Unit Tests Thread-Index: AQHaT+M1fDLV+xAf/kiAQ8Fcd9v2DLD2AP5A Date: Thu, 1 Feb 2024 21:32:09 +0000 Message-ID: References: <87dd1ac4223e2dc4e7f059db206b2954a0340234.1706219324.git.doug.edk2@gmail.com> In-Reply-To: <87dd1ac4223e2dc4e7f059db206b2954a0340234.1706219324.git.doug.edk2@gmail.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: SN7PR11MB8281:EE_|CH0PR11MB8236:EE_ x-ms-office365-filtering-correlation-id: 7da5cbab-b5e3-4d0a-fb1b-08dc236d3f3c x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: D1ML8fA3fL0zzAJQeYWx6mrETtokYEcZh2BxVRHnMdE/BwznmsT+mxT9rkCnvNB0VAZhK1lApEpmRS6ILw43oug6xoOyEpH0Antt3X8p1gm1qoiG2fhtgM1lnJ/1iilhuzt6LS1RiBPhGzTVqpuLXfmpVzc+NaInQrBjPVnoQ2I52A77uiVVzr3ijphlKrLDnnKoNCs2xHR0bjBVmFzIKXnnyN0SDd9wmc6VTCcCTW0cl1SVBhWEvW9/U4lg5GkkuIDctBM2JFdyma8wM2KEq9dJ2mLwjStdbCAEOoFndEKYAYwvAJlrBznH2UACGBz9CAJcNWCK4f13OXTjWcBeAWJFBXgFWQAraBQIx6PnPS00gkbgJkcemd8qFCUuX7/d6MA/cHgnBwAffy8lu8x2GEPx7mu0g6ip98CYpmBdga5BgzYtM0c2jKK0x4rlyL/gI20ql0aicXs8CtJT6W3SnFNasIzEuO1GFCf5JIlrlO5z5RKHObV90VVZ36HuB0pBxWoVSDG4lbv0lNo8GHGdqqjIIaQCqbDZn1LggvK96Vy27BcXJ7R+kLZQbPZYhO3bLgqMyOwsLiM1neItD6dY12+oJhr2BmXIG0UaqCNhVfBh1LdlNf9h7iTDNLv4QbyMwOjaGD4XTEL4LrkKM798fw== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?L4ESjH4MrvM5nGSF4wotjbWo4roUke2V3PJlooA+/lzIQD2oK4rdkrINvoxf?= =?us-ascii?Q?7tN+F1TrWJialt6Vd+6gyDT/jTtrYcGKwysz4codtXTNBEgP3k1YBU69mmRM?= =?us-ascii?Q?43APtXTUn2ql7HJGvMmC8gw4AyuwWMBH3tQY3vIFZDfq885+pKsR1l/BaKsT?= =?us-ascii?Q?ruNksQhsvTIq5rgZziiso3CmtZxMu2V1xQ9SLy9kCL6rUjILA+0fpQthE0Xf?= =?us-ascii?Q?MJNAOAx2hY6rZVdlooyPM+xhMizvCR0mqYnS/S4/jOP0CFeAAQHMpg9CrMlb?= =?us-ascii?Q?ZkToD7aIKIMu9oeBiEAZy8vMx8hlUezlgRsM7ayKw0ZUExfai0MATETLcWd8?= =?us-ascii?Q?K/5OuGejoQXbc4dKsc6+TK+o4zU4S3bVjbLyXK82zjzy0mvW4X9VOCKZN8w7?= =?us-ascii?Q?pkEoxsL9rgyhKiLV6a68dmkP583wUhcZoRBVgspzk+uuaIQ0vzV+X0yPHoZ9?= =?us-ascii?Q?5Kc6qePYsI5ypultTQlNjePyo8ESHHDO0VvfpBSad7PsGyHsyvqPAOvwMSYA?= =?us-ascii?Q?4B2BMq9rLXQi57tJ6OO+9EpTPhaowPb4iGjoFeyVJdI4cbFaHv371mH15+p1?= =?us-ascii?Q?eFWtvs+oNEpqyiAPHLc/um1W3SDM+NEqeF9lpo8thzmYvgMumHlrRuxLvjIa?= =?us-ascii?Q?sGt+eBsARl9sS7Xo6V3VXbuZPYGeQqG3UP/eKB5xhG33PWY1ltNJCRVsZVdg?= =?us-ascii?Q?McLYaCCK7VHRp4Lj8S8tA2zH5CAJV48D/rjwjZQLAlGImHu1mzuoR974DhWC?= =?us-ascii?Q?lTyrCqO5hNefDbXFRjCigdxZvwV+pszajDkss/QRomHhl3hQe+2K/HOWpRAr?= =?us-ascii?Q?w5K3TyQ/2DWniLHYRROM3mPCIxVpvKXtFch4J+VyH0e5Zu0V3AduWhAZbxpc?= =?us-ascii?Q?gJFfmMvaTffGSf9TbpLubMC5JSOwunPUzGvG8RDvTujGBw34tgFc8mKlHFD1?= =?us-ascii?Q?t9anAuew8JCFe2gBzD2iuy1ZpnhGCY35il4G0Hnru5DGUrPzCQ8r7UcV4Kjm?= =?us-ascii?Q?T9SsI7jnAPz+cGNN55oF+ja37o/8PUS8HNjTOB+vnaAn7Q42l3dOiM1RB2IG?= =?us-ascii?Q?orUXkzAPIwl3C9hkkO+VI9GxYPG3HqA2tdPfdyhGq3slmveNapIE2kvefTjH?= =?us-ascii?Q?8I8GcMVplPVnCEV1Ulv88d2iZ+q1iwzBwnt8oPjKC23VgRPrmcpr8nG2Cf7t?= =?us-ascii?Q?4M/AcEQ+m6MtT/br5Y+7UGtM/txqI1HzjZpubTNdsYpVFDkyK5MQGES1X1ws?= =?us-ascii?Q?3YX7TkwvVXoWPt6rJHo2Q69EFlcDZh15OW7L5R6xHpUEbR/1SaXacX0sEoHR?= =?us-ascii?Q?gODdskey90Uvkn8sbs3e2npg9LQk6k5//8lWZP11Qr+Y6Nu//4Ny7pV8CcRl?= =?us-ascii?Q?JqEiuAaq8Pk0IuBgWHGSgWMUagmm/1b0V2Fn1lnnMd2ECqpztU9uURRrXv+H?= =?us-ascii?Q?aJTYR41j/uhCvDec97hXfvlJUwtJj/sbsO9c5iHeQDS4MWyCRKFv8Kb1qVAr?= =?us-ascii?Q?Xw/3efAoWxX3CDxKB3mSDdjCeHE+UuB3KXBsNJBs4Ji8mVk+2yijnf8aGsN8?= =?us-ascii?Q?/H8myrWLyZYdksDszK9vlGXbBjr5TBXRadc413+D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN7PR11MB8281.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7da5cbab-b5e3-4d0a-fb1b-08dc236d3f3c X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Feb 2024 21:32:09.9114 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 5X3OdQU+SJET3xeR9M1v9a8UacJNZJBAq1Im+wqxWbEhhPGyi0OAVF/4yTXHDfsS1ItiInk10cijXM/LvqQzjkz9ml1rCsIczstui4srBcQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR11MB8236 X-OriginatorOrg: intel.com 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,saloni.kasbekar@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: BJYbkb8UeqD6D304I3ePisCLx7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" 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=ierKWK47; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=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; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") Reviewed-by: Saloni Kasbekar -----Original Message----- From: Douglas Flick [MSFT] =20 Sent: Thursday, January 25, 2024 1:55 PM To: devel@edk2.groups.io Cc: Doug Flick ; Kasbekar, Saloni ; Clark-williams, Zachary ; Do= ug Flick [MSFT] Subject: [PATCH v2 11/15] NetworkPkg: UefiPxeBcDxe: SECURITY PATCH CVE-2023= -45234 Unit Tests From: Doug Flick REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D4539 Unit tests to that the bug.. Buffer overflow when processing DNS Servers option in a DHCPv6 Advertise me= ssage ..has been patched This contains tests for the following functions: PxeBcHandleDhcp6Offer PxeBcCacheDnsServerAddresses Cc: Saloni Kasbekar Cc: Zachary Clark-williams Signed-off-by: Doug Flick [MSFT] --- NetworkPkg/Test/NetworkPkgHostTest.dsc | 1 + .../GoogleTest/UefiPxeBcDxeGoogleTest.inf | 48 +++ .../GoogleTest/PxeBcDhcp6GoogleTest.h | 50 +++ .../GoogleTest/PxeBcDhcp6GoogleTest.cpp | 300 ++++++++++++++++++ .../GoogleTest/UefiPxeBcDxeGoogleTest.cpp | 19 ++ 5 files changed, 418 insertions(+) create mode 100644 NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTe= st.inf create mode 100644 NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest= .h create mode 100644 NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest= .cpp create mode 100644 NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTe= st.cpp diff --git a/NetworkPkg/Test/NetworkPkgHostTest.dsc b/NetworkPkg/Test/Netwo= rkPkgHostTest.dsc index 7fa7b0f9d5be..a0273c431025 100644 --- a/NetworkPkg/Test/NetworkPkgHostTest.dsc +++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc @@ -27,6 +27,7 @@ [Components] # NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf NetworkPkg/I= p6Dxe/GoogleTest/Ip6DxeGoogleTest.inf+ NetworkPkg/UefiPxeBcDxe/GoogleTest/= UefiPxeBcDxeGoogleTest.inf # Despite these library classes being listed in= [LibraryClasses] below, they are not needed for the host-based unit tests.= [LibraryClasses]diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcD= xeGoogleTest.inf b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTes= t.inf new file mode 100644 index 000000000000..301dcdf61109 --- /dev/null +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.inf @@ -0,0 +1,48 @@ +## @file+# Unit test suite for the UefiPxeBcDxe using Google Test+#+# Copy= right (c) Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Claus= e-Patent+##+[Defines]+INF_VERSION =3D 0x00010005+BASE_NAME =3D Uefi= PxeBcDxeGoogleTest+FILE_GUID =3D 77D45C64-EC1E-4174-887B-886E89FD1EDF+= MODULE_TYPE =3D HOST_APPLICATION+VERSION_STRING =3D 1.0++#+# The followi= ng information is for reference only and not required by the build tools.+#= +# VALID_ARCHITECTURES =3D IA32 X64+#++[Sources]+ UefiPxeBcDxeG= oogleTest.cpp+ PxeBcDhcp6GoogleTest.cpp+ PxeBcDhcp6GoogleTest.h+ ../PxeB= cDhcp6.c+ ../PxeBcSupport.c++[Packages]+ MdePkg/MdePkg.dec+ MdeModulePkg= /MdeModulePkg.dec+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec+ Network= Pkg/NetworkPkg.dec++[LibraryClasses]+ GoogleTestLib+ DebugLib+ NetLib+ = PcdLib++[Protocols]+ gEfiDhcp6ServiceBindingProtocolGuid+ gEfiDns6Service= BindingProtocolGuid+ gEfiDns6ProtocolGuid++[Pcd]+ gEfiNetworkPkgTokenSpac= eGuid.PcdDhcp6UidType++[Guids]+ gZeroGuiddiff --git a/NetworkPkg/UefiPxeBc= Dxe/GoogleTest/PxeBcDhcp6GoogleTest.h b/NetworkPkg/UefiPxeBcDxe/GoogleTest/= PxeBcDhcp6GoogleTest.h new file mode 100644 index 000000000000..b17c314791c8 --- /dev/null +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.h @@ -0,0 +1,50 @@ +/** @file+ This file exposes the internal interfaces which may be unit te= sted+ for the PxeBcDhcp6Dxe driver.++ Copyright (c) Microsoft Corporation= .
+ SPDX-License-Identifier: BSD-2-Clause-Patent+**/++#ifndef PXE_BC_DH= CP6_GOOGLE_TEST_H_+#define PXE_BC_DHCP6_GOOGLE_TEST_H_++//+// Minimal inclu= des needed to compile+//+#include +#include "../PxeBcImpl.h"++/**+ = Handle the DHCPv6 offer packet.++ @param[in] Private The poi= nter to PXEBC_PRIVATE_DATA.++ @retval EFI_SUCCESS Handled th= e DHCPv6 offer packet successfully.+ @retval EFI_NO_RESPONSE No = response to the following request packet.+ @retval EFI_OUT_OF_RESOURCE= S Failed to allocate resources.+ @retval EFI_BUFFER_TOO_SMALL Can't = cache the offer pacet.++**/+EFI_STATUS+PxeBcHandleDhcp6Offer (+ IN PXEBC_P= RIVATE_DATA *Private+ );++/**+ Cache the DHCPv6 Server address++ @param= [in] Private The pointer to PXEBC_PRIVATE_DATA.+ @param[in] = Cache6 The pointer to PXEBC_DHCP6_PACKET_CACHE.++ @retval = EFI_SUCCESS Cache the DHCPv6 Server address successfully.+ @re= tval EFI_OUT_OF_RESOURCES Failed to allocate resources.+ @retval EF= I_DEVICE_ERROR Failed to cache the DHCPv6 Server address.+**/+EFI_STAT= US+PxeBcCacheDnsServerAddresses (+ IN PXEBC_PRIVATE_DATA *Private,+= IN PXEBC_DHCP6_PACKET_CACHE *Cache6+ );++#endif // PXE_BC_DHCP6_GOOGLE_= TEST_H_diff --git a/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest= .cpp b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp new file mode 100644 index 000000000000..8260eeee50dc --- /dev/null +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/PxeBcDhcp6GoogleTest.cpp @@ -0,0 +1,300 @@ +/** @file+ Host based unit test for PxeBcDhcp6.c.++ Copyright (c) Micros= oft Corporation+ SPDX-License-Identifier: BSD-2-Clause-Patent+**/+#include= ++extern "C" {+ #include + #include + #include + #include "../PxeBcImpl.h"+ #inclu= de "../PxeBcDhcp6.h"+ #include "PxeBcDhcp6GoogleTest.h"+}++///////////////= ////////////////////////////////////////////////////////////////+// Definit= ions+//////////////////////////////////////////////////////////////////////= /////////++#define PACKET_SIZE (1500)++typedef struct {+ UINT16 Option= Code; // The option code for DHCP6_OPT_SERVER_ID (e.g., 0x03)+ UINT16 = OptionLen; // The length of the option (e.g., 16 bytes)+ UINT8 Ser= verId[16]; // The 16-byte DHCPv6 Server Identifier+} DHCP6_OPTION_SERVER_ID= ;++////////////////////////////////////////////////////////////////////////= ///////+/// Symbol Definitions+////////////////////////////////////////////= ///////////////////////////////////++EFI_STATUS+MockUdpWrite (+ IN EFI_PXE= _BASE_CODE_PROTOCOL *This,+ IN UINT16 OpFlag= s,+ IN EFI_IP_ADDRESS *DestIp,+ IN EFI_PXE_BASE_CODE_UDP= _PORT *DestPort,+ IN EFI_IP_ADDRESS *GatewayIp OPT= IONAL,+ IN EFI_IP_ADDRESS *SrcIp OPTIONAL,+ IN OUT= EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,+ IN UINTN = *HeaderSize OPTIONAL,+ IN VOID *= HeaderPtr OPTIONAL,+ IN UINTN *BufferSize,+ I= N VOID *BufferPtr+ )+{+ return EFI_SUCCESS;+}+= +EFI_STATUS+MockUdpRead (+ IN EFI_PXE_BASE_CODE_PROTOCOL *This,+ IN = UINT16 OpFlags,+ IN OUT EFI_IP_ADDRESS = *DestIp OPTIONAL,+ IN OUT EFI_PXE_BASE_CODE_UDP_PORT *DestPort = OPTIONAL,+ IN OUT EFI_IP_ADDRESS *SrcIp OPTIONAL,+ IN= OUT EFI_PXE_BASE_CODE_UDP_PORT *SrcPort OPTIONAL,+ IN UINTN = *HeaderSize OPTIONAL,+ IN VOID = *HeaderPtr OPTIONAL,+ IN OUT UINTN *BufferSize,= + IN VOID *BufferPtr+ )+{+ return EFI_SUCCESS= ;+}++EFI_STATUS+MockConfigure (+ IN EFI_UDP6_PROTOCOL *This,+ IN EFI_= UDP6_CONFIG_DATA *UdpConfigData OPTIONAL+ )+{+ return EFI_SUCCESS;+}++//= Needed by PxeBcSupport+EFI_STATUS+EFIAPI+QueueDpc (+ IN EFI_TPL = DpcTpl,+ IN EFI_DPC_PROCEDURE DpcProcedure,+ IN VOID *Dp= cContext OPTIONAL+ )+{+ return EFI_SUCCESS;+}++///////////////////////= ////////////////////////////////////////////////////////+// PxeBcHandleDhcp= 6OfferTest Tests+//////////////////////////////////////////////////////////= /////////////////////++class PxeBcHandleDhcp6OfferTest : public ::testing::= Test {+public:+ PXEBC_PRIVATE_DATA Private =3D { 0 };+ EFI_UDP6_PROTOCOL = Udp6Read;+ EFI_PXE_BASE_CODE_MODE Mode =3D { 0 };++protected:+ // Add any= setup code if needed+ virtual void+ SetUp (+ )+ {+ Private.Dhcp6R= equest =3D (EFI_DHCP6_PACKET *)AllocateZeroPool (PACKET_SIZE);++ // Need= to setup the EFI_PXE_BASE_CODE_PROTOCOL+ // The function under test rea= lly only needs the following:+ // UdpWrite+ // UdpRead++ Private= .PxeBc.UdpWrite =3D (EFI_PXE_BASE_CODE_UDP_WRITE)MockUdpWrite;+ Private.= PxeBc.UdpRead =3D (EFI_PXE_BASE_CODE_UDP_READ)MockUdpRead;++ // Need to= setup EFI_UDP6_PROTOCOL+ // The function under test really only needs t= he following:+ // Configure++ Udp6Read.Configure =3D (EFI_UDP6_CONFI= GURE)MockConfigure;+ Private.Udp6Read =3D &Udp6Read;++ // Need to s= etup the EFI_PXE_BASE_CODE_MODE+ Private.PxeBc.Mode =3D &Mode;++ // f= or this test it doesn't really matter what the Dhcpv6 ack is set to+ }++ = // Add any cleanup code if needed+ virtual void+ TearDown (+ )+ {+ = if (Private.Dhcp6Request !=3D NULL) {+ FreePool (Private.Dhcp6Request= );+ }++ // Clean up any resources or variables+ }+};++// Note:+// Te= sting PxeBcHandleDhcp6Offer() is difficult because it depends on a+// prope= rly setup Private structure. Attempting to properly test this function+// w= ithout a signficant refactor is a fools errand. Instead, we will test+// th= at we can prevent an overflow in the function.+TEST_F (PxeBcHandleDhcp6Offe= rTest, BasicUsageTest) {+ PXEBC_DHCP6_PACKET_CACHE *Cache6 =3D NULL;+ EF= I_DHCP6_PACKET_OPTION Option =3D { 0 };++ Private.SelectIndex =3D 1; //= SelectIndex is 1-based+ Cache6 =3D &Private.OfferBuffer[Priv= ate.SelectIndex - 1].Dhcp6;++ Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] = =3D &Option;+ // Setup the DHCPv6 offer packet+ Cache6->OptList[PXEBC_DHC= P6_IDX_DNS_SERVER]->OpCode =3D DHCP6_OPT_SERVER_ID;+ Cache6->OptList[PXEBC= _DHCP6_IDX_DNS_SERVER]->OpLen =3D NTOHS (1337);++ ASSERT_EQ (PxeBcHandleD= hcp6Offer (&(PxeBcHandleDhcp6OfferTest::Private)), EFI_DEVICE_ERROR);+}++cl= ass PxeBcCacheDnsServerAddressesTest : public ::testing::Test {+public:+ P= XEBC_PRIVATE_DATA Private =3D { 0 };++protected:+ // Add any setup code if= needed+ virtual void+ SetUp (+ )+ {+ }++ // Add any cleanup code i= f needed+ virtual void+ TearDown (+ )+ {+ }+};++// Test Description+= // Test that we cache the DNS server address from the DHCPv6 offer packet+T= EST_F (PxeBcCacheDnsServerAddressesTest, BasicUsageTest) {+ UINT8 = SearchPattern[16] =3D { 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xB= E, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF, 0xDE, 0xAD, 0xBE, 0xEF };+ EFI_DHCP6_PACK= ET_OPTION *Option;+ PXEBC_DHCP6_PACKET_CACHE *Cache6 =3D NULL;++ Optio= n =3D (EFI_DHCP6_PACKET_OPTION *)AllocateZeroPool (sizeof (EFI_DHCP6_PACKET= _OPTION) + sizeof (SearchPattern));+ ASSERT_NE (Option, nullptr);++ Optio= n->OpCode =3D DHCP6_OPT_SERVER_ID;+ Option->OpLen =3D NTOHS (sizeof (Sear= chPattern));+ CopyMem (Option->Data, SearchPattern, sizeof (SearchPattern)= );++ Private.SelectIndex =3D 1; // SelectIndex is = 1-based+ Cache6 =3D &Private.OfferBuf= fer[Private.SelectIndex - 1].Dhcp6;+ Cache6->OptList[PXEBC_DHCP6_IDX_DNS_S= ERVER] =3D Option;++ Private.DnsServer =3D nullptr;++ ASSERT_EQ (PxeBcCac= heDnsServerAddresses (&(PxeBcCacheDnsServerAddressesTest::Private), Cache6)= , EFI_SUCCESS);+ ASSERT_NE (Private.DnsServer, nullptr);+ ASSERT_EQ (Comp= areMem (Private.DnsServer, SearchPattern, sizeof (SearchPattern)), 0);++ i= f (Private.DnsServer) {+ FreePool (Private.DnsServer);+ }++ if (Option= ) {+ FreePool (Option);+ }+}+// Test Description+// Test that we can pr= event an overflow in the function+TEST_F (PxeBcCacheDnsServerAddressesTest,= AttemptOverflowTest) {+ EFI_DHCP6_PACKET_OPTION Option =3D { 0 };+ PX= EBC_DHCP6_PACKET_CACHE *Cache6 =3D NULL;++ Private.SelectIndex = =3D 1; // SelectIndex is 1-based+ Cache6 = =3D &Private.OfferBuffer[Private.SelectIndex - 1].Dhcp6;+= Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] =3D &Option;+ // Setup the D= HCPv6 offer packet+ Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpCode = =3D DHCP6_OPT_SERVER_ID;+ Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpL= en =3D NTOHS (1337);++ Private.DnsServer =3D NULL;++ ASSERT_EQ (PxeBcCac= heDnsServerAddresses (&(PxeBcCacheDnsServerAddressesTest::Private), Cache6)= , EFI_DEVICE_ERROR);+ ASSERT_EQ (Private.DnsServer, nullptr);++ if (Priva= te.DnsServer) {+ FreePool (Private.DnsServer);+ }+}++// Test Descriptio= n+// Test that we can prevent an underflow in the function+TEST_F (PxeBcCac= heDnsServerAddressesTest, AttemptUnderflowTest) {+ EFI_DHCP6_PACKET_OPTION= Option =3D { 0 };+ PXEBC_DHCP6_PACKET_CACHE *Cache6 =3D NULL;++ Priv= ate.SelectIndex =3D 1; // SelectIndex is 1-based+ = Cache6 =3D &Private.OfferBuffer[Privat= e.SelectIndex - 1].Dhcp6;+ Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER] =3D= &Option;+ // Setup the DHCPv6 offer packet+ Cache6->OptList[PXEBC_DHCP6_= IDX_DNS_SERVER]->OpCode =3D DHCP6_OPT_SERVER_ID;+ Cache6->OptList[PXEBC_DH= CP6_IDX_DNS_SERVER]->OpLen =3D NTOHS (2);++ Private.DnsServer =3D NULL;++= ASSERT_EQ (PxeBcCacheDnsServerAddresses (&(PxeBcCacheDnsServerAddressesTe= st::Private), Cache6), EFI_DEVICE_ERROR);+ ASSERT_EQ (Private.DnsServer, n= ullptr);++ if (Private.DnsServer) {+ FreePool (Private.DnsServer);+ }+= }++// Test Description+// Test that we can handle recursive dns (multiple d= ns entries)+TEST_F (PxeBcCacheDnsServerAddressesTest, MultipleDnsEntries) {= + EFI_DHCP6_PACKET_OPTION Option =3D { 0 };+ PXEBC_DHCP6_PACKET_CACHE = *Cache6 =3D NULL;++ Private.SelectIndex =3D 1; //= SelectIndex is 1-based+ Cache6 =3D &= Private.OfferBuffer[Private.SelectIndex - 1].Dhcp6;+ Cache6->OptList[PXEBC= _DHCP6_IDX_DNS_SERVER] =3D &Option;+ // Setup the DHCPv6 offer packet+ Ca= che6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER]->OpCode =3D DHCP6_OPT_SERVER_ID;+= + EFI_IPv6_ADDRESS addresses[2] =3D {+ // 2001:db8:85a3::8a2e:370:7334= + { 0x20, 0x01, 0x0d, 0xb8, 0x85, 0xa3, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x= 2e, 0x03, 0x70, 0x73, 0x34 },+ // fe80::d478:91c3:ecd7:4ff9+ { 0xfe, = 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd4, 0x78, 0x91, 0xc3, 0xec, 0xd= 7, 0x4f, 0xf9 }+ };++ CopyMem (Cache6->OptList[PXEBC_DHCP6_IDX_DNS_SERVER= ]->Data, &addresses, sizeof (addresses));++ Cache6->OptList[PXEBC_DHCP6_ID= X_DNS_SERVER]->OpLen =3D NTOHS (sizeof (addresses));++ Private.DnsServer = =3D NULL;++ ASSERT_EQ (PxeBcCacheDnsServerAddresses (&(PxeBcCacheDnsServer= AddressesTest::Private), Cache6), EFI_SUCCESS);++ ASSERT_NE (Private.DnsSe= rver, nullptr);++ //+ // This is expected to fail until DnsServer support= s multiple DNS servers+ //+ // This is tracked in https://bugzilla.tianoc= ore.org/show_bug.cgi?id=3D1886+ //+ // Disabling:+ // ASSERT_EQ (Compare= Mem(Private.DnsServer, &addresses, sizeof(addresses)), 0);++ if (Private.D= nsServer) {+ FreePool (Private.DnsServer);+ }+}diff --git a/NetworkPkg/= UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.cpp b/NetworkPkg/UefiPxeBcDx= e/GoogleTest/UefiPxeBcDxeGoogleTest.cpp new file mode 100644 index 000000000000..cc4fdf525b62 --- /dev/null +++ b/NetworkPkg/UefiPxeBcDxe/GoogleTest/UefiPxeBcDxeGoogleTest.cpp @@ -0,0 +1,19 @@ +/** @file+ Acts as the main entry point for the tests for the UefiPxeBcDx= e module.+ Copyright (c) Microsoft Corporation+ SPDX-License-Identifier: = BSD-2-Clause-Patent+**/+#include ++/////////////////////////= ///////////////////////////////////////////////////////+// Run the tests+//= ///////////////////////////////////////////////////////////////////////////= ///+int+main (+ int argc,+ char *argv[]+ )+{+ testing::InitGoogleTes= t (&argc, argv);+ return RUN_ALL_TESTS ();+}--=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 (#114966): https://edk2.groups.io/g/devel/message/114966 Mute This Topic: https://groups.io/mt/103964987/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-