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 450EA7803D0 for ; Thu, 1 Feb 2024 19:40:50 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=O7owvnw5le0hrWdbZ+2swu4QrX/KBPjDc7p2SWdrGuY=; 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=1706816449; v=1; b=IBmlz+G5uLPFQUBwfKoPop4b6F+4eOZIJ+ckPgeBFi2Ygm2vrdL/jNPKZjuUD5u+5AmguGd5 pcEXc0H3z/xOgelWi0SQh21rP7TH2VGlWQj4yp2bp9nRxIIyAjX2tvCwU4qHogcNVQye15FTXt2 UBgEiFdzuJCfjqVUW2oxEbFE= X-Received: by 127.0.0.2 with SMTP id xtZ8YY7687511x16JCuWVng0; Thu, 01 Feb 2024 11:40:49 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by mx.groups.io with SMTP id smtpd.web10.5083.1706816448378794411 for ; Thu, 01 Feb 2024 11:40:48 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10971"; a="10612353" X-IronPort-AV: E=Sophos;i="6.05,236,1701158400"; d="scan'208";a="10612353" X-Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2024 11:40:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,236,1701158400"; d="scan'208";a="193430" X-Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orviesa008.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 01 Feb 2024 11:40:48 -0800 X-Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) 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 11:40:46 -0800 X-Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx610.amr.corp.intel.com (10.18.126.90) 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 11:40:46 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.41) by edgegateway.intel.com (192.55.55.68) 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 11:40:46 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aWAk01YWr3LBh/LeVGVvNvURITMTuM0nfg7IaQw/PYo8Dwz3i5Al3TKKNIRncpxJH+5ivvcc6dS8AdO+14qmk0h0uI5mOrwyzukNYRMQyk/+OcducNwgvarPWy9N4Tg0F4cHy0Bwxev9J/A0uX6adhimrrm9bKD8DdR5btH3JWkb6f6Xd2p14BHPlCtapZwhHDcsCpj7WXnsLgDOonIskp7mDelw8q1nMXcM8FchjudEOSO6uR2u8/PbJY/2at+gBEJuSi74qdQCEunESC8o4ObWNeytOYfk7SnRaAgyixEL6tBcEbalhlVRtsaoXSQ1qFLp92wpg1U00Bi+gQHt8Q== 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=p0wVRAiL1FgQOfC3yd6eIIkc/OVkIzjleNU4ilcBFd0=; b=Os5jsj/DE2K9w3uazgYVKdL9Fqc27OZk5E2VP7OdGMLmiHL/l1xC3doMxycUmaG/IhcMOQXmpMgb1TaOLzIYOvsjqv1yS1R/DcQcKUZLBK/b++H8PBa/UPGJzgCWC6HFgJlOWSIwxUZNKfAuvecHzqMudbeGdPNB6xvE3A/D+3psF/wKE/7AMwuCtjod/7a1hJmkUV3CEnPEDo9LAlePnD/iWD8B57e2m6uRcCgu1RRN61l8swU1jo13rWWc8cD7d8q3Aq1vZ17LhLlTnP5CbSCtxy2Rr3ZYuaBhwZDAzbAACZKq6fbOtLM1nqZv4YtbBa2vjtg4caLqso4ISJOXPw== 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 SN7PR11MB6874.namprd11.prod.outlook.com (2603:10b6:806:2a5::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.26; Thu, 1 Feb 2024 19:40:43 +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 19:40:43 +0000 From: "Saloni Kasbekar" To: "Douglas Flick [MSFT]" , "devel@edk2.groups.io" CC: "Clark-williams, Zachary" Subject: Re: [edk2-devel] [PATCH v2 03/15] NetworkPkg: Dhcp6Dxe: SECURITY PATCH CVE-2023-45230 Unit Tests Thread-Topic: [PATCH v2 03/15] NetworkPkg: Dhcp6Dxe: SECURITY PATCH CVE-2023-45230 Unit Tests Thread-Index: AQHaT+MvRtIOrkv0u0m6hVM+7tNY5bD17Hqg Date: Thu, 1 Feb 2024 19:40:43 +0000 Message-ID: References: <4c33819343179a2cbdde07be55ac125c59f41f26.1706219324.git.doug.edk2@gmail.com> In-Reply-To: <4c33819343179a2cbdde07be55ac125c59f41f26.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_|SN7PR11MB6874:EE_ x-ms-office365-filtering-correlation-id: d7c31b3b-8fd8-4f9d-78dc-08dc235dadf8 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: tq+FOGfu1qGtpWH+jTH0TxvAB+8s+KhZpxYkTEoeruTEzIRNiZ9zSbYOUG+xHjINBsOtOefIIZwl3tQ9E3HUyZzXeEn2JTe9jRcfig+04dWOHO/Lxt/Z6If0AtFKoNxs+2o122mBVn8X7oQ52zY44C+hHSWVauGHPUoPbu74Y5YJe5Lw/MXBUHKMtrFB0dOe1wMUUy7yMIALzPBwf6SQIEPDeSg1+pZaGwCChVpx2jK49z4MggNssozyXCTXcJ+X8Ev1iDMzuKh4fQyx2pLscM+FQF/iHMVjNB7SAc+dinXQ5Vn7cORH/Cd2I9QYW8qS6G8xOIfmCbAY2kG8I+m9j2YhAU+wW8BJu9od9kucy597KvyN4z2zNcgKg4d3MEsA42fcVq5W1RqpoWuyfKsEJLkYVA/5HlPrfrJaXNiBb1as/a46BMP5qck/V36MngwipocYQwBal36+q6D59W1liIjnTp+5LgH07ai2jpHtnGHyO+u//y8Je+j1CDXhE4Tmfs/ZaepZ5rQMaCcEip/EJaCRHQZ8A+r/f5PEbx7tOpnk9OLkzo1xatdu608sag7ShAu6aDPbphHzqJwM2rIX4LTr1fHseCJwoG5geAgvth6oD6qNQ7h9j2fneiGkiWzp x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?+N9gWppNvrABCu8saXK2tohFUW/aVt50cXystZk/VmYYD+EAVppVxLugzT7w?= =?us-ascii?Q?YoS4HmigMoZ+Z38jzDQ5KqMHEIMDuF4AdPag4/IQ2466fhoctdK7GZdmPL6A?= =?us-ascii?Q?N+Tm4NkEPGj8FLN6XEKQRhVOkrQ0Hpo5T+pC3uDE6Wa/ltTVNPxyf4HGyJ18?= =?us-ascii?Q?kJRLGfPIjRb8DokR/+G4evdpTUFgzz1Wf3uTaonWqnv+pPmulqjjlQwr8Cb0?= =?us-ascii?Q?z9aRNAsl8bVS20BVtH7ZWcW5RWIYAXrmpjEfYVFAk1Aaf20rTpEuMRia7Rf2?= =?us-ascii?Q?i65H3jNyWuQ0wYh9oB4xrltQ6A6kHKGSYr6mR4VnocI0fgXh6xdrh71EGF09?= =?us-ascii?Q?aVS5/uH2zWQX1cPtu4RSLtcG03USpFYk9M4PEoXceCRNRx/QaqozFzrFkJZP?= =?us-ascii?Q?ci87igpbnwxRcHFJNBV2Tcc7GFYZQF7cbpQFc8jaX/xPI47yM8McJEayT9F1?= =?us-ascii?Q?HVkqkKNV9Ds2qhtsgzyRtvee6ijqE+hu/QiWxgFo+3z643z2n3O1bqLSGfg+?= =?us-ascii?Q?tMjUWH2DgfEouMD/V/XecjsRzqKAuw0xmAhPc4QMao8z0qlDjIKuaJXcDxwg?= =?us-ascii?Q?RcUCmadhC+Ddojy/UoYDj7bP2cxD2rdXNAZngphOSGIZYX46Mop5WLL1qcCa?= =?us-ascii?Q?ZIt1T9b0/Vcp8FtBXqhUEUP6nA6xMEXEsztyFdnAIMxmESMBK4fMu238d7mx?= =?us-ascii?Q?WsfTNvZeUhdfN4ciwS5cTtBdskvQcKLmu2ukTmERs3Tm3DSussBVxmngD8/m?= =?us-ascii?Q?zKMHwWuyJyjHEr/AXKV4mJVmWtivZQY3mF9ofVlah37cq9hfh8u1LK+JV5yt?= =?us-ascii?Q?Msbedvx1JIs5Xh8GWNYLkP+y2W6g7Ze8g8UowcMys/Ilcy/x45NQ8HRX+y2s?= =?us-ascii?Q?Ctb9jF/82Il8LGlpiz7XIZnd+bvOoaC6QxpeOev8YLEMZquf04WZe/RVwd0v?= =?us-ascii?Q?NuZb1iNQktGbvHbL5Jd0f7DowM8bsMb85Ztu9YeJVSA69gNFCFyfSxQsLKuH?= =?us-ascii?Q?G5/dzkAD0nlz/9O9qHqK/eb3wMLDJ2yAo9pU5Br4jVfZ4zXw6m1l7h9ohNzd?= =?us-ascii?Q?/T2DAEM3yIgczlr0N6gG0DSeMJCmZYTxE3qtYcyJXjd+I4P4bNs49KZ/HaMg?= =?us-ascii?Q?3DoVsqjdtmkGW7AgS05VRVxf0+LD8yRfnG6JOL7bArEPUJYra0Y2QTS6zo/W?= =?us-ascii?Q?gDn4U6I/JLy3QxXW8VbWMK9qcoDzAnz2P3c8RAIHSK5c1fuZ10CBp2spUQD7?= =?us-ascii?Q?VWsKe7uJEhN6a3U3VMwNrxE7d73npEy/QzICphKWTBaQHfny2J1pQg1Y2aT4?= =?us-ascii?Q?PDy9/clJg4s8JP6grNodeGvZuDa4z1o5uDeOqiZ52JW/TQwVnKy4OiULZg4h?= =?us-ascii?Q?+o6wOVNEAD6nMIzuaRWivybEkvcXKllISL4EL6hUnhT+YK1+W8508Jh/luiJ?= =?us-ascii?Q?tttqjU05sZ/zqOE78Fov6D66e5tcdgdDSgZCUcNRjyNxcPWTDTb7GZdm9yOe?= =?us-ascii?Q?SzyTSgoQe0FHfQpL3OJGD5xfJB9HQ6fyaSDJ0OGvZICB9DLCSoyOyPjAlNoP?= =?us-ascii?Q?ibICgCVtIaRKn9TTNb3IMw/LBKyFHBVFvJe91vfO?= 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: d7c31b3b-8fd8-4f9d-78dc-08dc235dadf8 X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Feb 2024 19:40:43.7295 (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: pVGxJr5vAidrjCS/0Rd+zxeLypEjTh1DaW6CBV54tlRVqGHQaLksF8M45TOiW9TJQ/ae/39RM3XctHUSdRv6o2XgAa7gNUIO3pRq74akAxQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR11MB6874 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: jz1H62TypO3ltLZlW2l6DLWXx7686176AA= 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=IBmlz+G5; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); 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 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: Douglas Flick [MSFT] ; Kasbekar, Saloni ; Clark-williams, Zachary Subject: [PATCH v2 03/15] NetworkPkg: Dhcp6Dxe: SECURITY PATCH CVE-2023-452= 30 Unit Tests REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4535 Confirms that reported issue... "Buffer overflow in the DHCPv6 client via a long Server ID option" ..has been corrected by the provided patch. Tests the following functions to ensure they appropriately handle untrusted= data (either too long or too small) to prevent a buffer overflow: Dhcp6AppendOption Dhcp6AppendETOption Dhcp6AppendIaOption Cc: Saloni Kasbekar Cc: Zachary Clark-williams Signed-off-by: Doug Flick [MSFT] --- NetworkPkg/Test/NetworkPkgHostTest.dsc | 1 + .../GoogleTest/Dhcp6DxeGoogleTest.inf | 43 ++ .../GoogleTest/Dhcp6DxeGoogleTest.cpp | 20 + .../Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp | 478 ++++++++++++++++++ 4 files changed, 542 insertions(+) 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 index 1aeca5c5b353..20bc90b1728d 100644 --- a/NetworkPkg/Test/NetworkPkgHostTest.dsc +++ b/NetworkPkg/Test/NetworkPkgHostTest.dsc @@ -24,6 +24,7 @@ [Components] # # Build HOST_APPLICATION that tests NetworkPkg #+ NetworkPkg/Dhcp= 6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf # Despite these library classes bei= ng listed in [LibraryClasses] below, they are not needed for the host-based= unit tests. [LibraryClasses]diff --git a/NetworkPkg/Dhcp6Dxe/GoogleTest/Dh= cp6DxeGoogleTest.inf b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.in= f new file mode 100644 index 000000000000..8e9119a37158 --- /dev/null +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.inf @@ -0,0 +1,43 @@ +## @file+# Unit test suite for the Dhcp6Dxe using Google Test+#+# Copyrigh= t (c) Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Pa= tent+##+[Defines]+ INF_VERSION =3D 0x00010017+ BASE_NAME = =3D Dhcp6DxeGoogleTest+ FILE_GUID =3D 1D2A4C65-38C8-4C2F-BB60-= B5FA49625AA9+ VERSION_STRING =3D 1.0+ MODULE_TYPE =3D HOST_A= PPLICATION+#+# The following information is for reference only and not requ= ired by the build tools.+#+# VALID_ARCHITECTURES =3D IA32 X64 AA= RCH64+#+[Sources]+ Dhcp6DxeGoogleTest.cpp+ Dhcp6IoGoogleTest.cpp+ ../Dhc= p6Io.c+ ../Dhcp6Utility.c++[Packages]+ MdePkg/MdePkg.dec+ MdeModulePkg/M= deModulePkg.dec+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec+ NetworkPk= g/NetworkPkg.dec++[LibraryClasses]+ GoogleTestLib+ DebugLib+ NetLib+ Pc= dLib++[Protocols]+ gEfiDhcp6ServiceBindingProtocolGuid++[Pcd]+ gEfiNetwor= kPkgTokenSpaceGuid.PcdDhcp6UidType++[Guids]+ gZeroGuiddiff --git a/Network= Pkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.cpp b/NetworkPkg/Dhcp6Dxe/Google= Test/Dhcp6DxeGoogleTest.cpp new file mode 100644 index 000000000000..9aeced2f9156 --- /dev/null +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6DxeGoogleTest.cpp @@ -0,0 +1,20 @@ +/** @file+ Acts as the main entry point for the tests for the Dhcp6Dxe mo= dule.++ Copyright (c) Microsoft Corporation+ SPDX-License-Identifier: BSD= -2-Clause-Patent+**/+#include ++////////////////////////////= ////////////////////////////////////////////////////+// Run the tests+/////= ///////////////////////////////////////////////////////////////////////////= +int+main (+ int argc,+ char *argv[]+ )+{+ testing::InitGoogleTest (= &argc, argv);+ return RUN_ALL_TESTS ();+}diff --git a/NetworkPkg/Dhcp6Dxe/= GoogleTest/Dhcp6IoGoogleTest.cpp b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGo= ogleTest.cpp new file mode 100644 index 000000000000..7ee40e4af480 --- /dev/null +++ b/NetworkPkg/Dhcp6Dxe/GoogleTest/Dhcp6IoGoogleTest.cpp @@ -0,0 +1,478 @@ +/** @file+ Tests for Dhcp6Io.c.++ Copyright (c) Microsoft Corporation+ = SPDX-License-Identifier: BSD-2-Clause-Patent+**/+#include ++= extern "C" {+ #include + #include + #include = + #include + #include "../Dh= cp6Impl.h"+ #include "../Dhcp6Utility.h"+}++//////////////////////////////= //////////////////////////////////////////+// Defines+/////////////////////= ///////////////////////////////////////////////////++#define DHCP6_PACKET_M= AX_LEN 1500++/////////////////////////////////////////////////////////////= ///////////+///////////////////////////////////////////////////////////////= /////////+// Symbol Definitions+// These functions are not directly under t= est - but required to compile+/////////////////////////////////////////////= ///////////////////////////++// This definition is used by this test but is= also required to compile+// by Dhcp6Io.c+EFI_IPv6_ADDRESS mAllDhcpRelayAn= dServersAddress =3D {+ { 0xFF, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2= }+};++EFI_STATUS+EFIAPI+UdpIoSendDatagram (+ IN UDP_IO *UdpIo,= + IN NET_BUF *Packet,+ IN UDP_END_POINT *EndPoint OPTIONAL,= + IN EFI_IP_ADDRESS *Gateway OPTIONAL,+ IN UDP_IO_CALLBACK CallBack= ,+ IN VOID *Context+ )+{+ return EFI_SUCCESS;+}++EFI_STATUS= +EFIAPI+UdpIoRecvDatagram (+ IN UDP_IO *UdpIo,+ IN UDP_IO_CAL= LBACK CallBack,+ IN VOID *Context,+ IN UINT32 He= adLen+ )+{+ return EFI_SUCCESS;+}++//////////////////////////////////////= //////////////////////////////////+// Dhcp6AppendOptionTest Tests+/////////= ///////////////////////////////////////////////////////////////++class Dhcp= 6AppendOptionTest : public ::testing::Test {+public:+ UINT8 *Buffer =3D NU= LL;+ EFI_DHCP6_PACKET *Packet;++protected:+ // Add any setup code if need= ed+ virtual void+ SetUp (+ )+ {+ // Initialize any resources or va= riables+ Buffer =3D (UINT8 *)AllocateZeroPool (DHCP6_PACKET_MAX_LEN);+ = ASSERT_NE (Buffer, (UINT8 *)NULL);++ Packet =3D (EFI_DHCP6_PACKE= T *)Buffer;+ Packet->Size =3D DHCP6_PACKET_MAX_LEN;+ }++ // Add any cl= eanup code if needed+ virtual void+ TearDown (+ )+ {+ // Clean up = any resources or variables+ if (Buffer !=3D NULL) {+ FreePool (Buff= er);+ }+ }+};++// Test Description:+// Attempt to append an option to a= packet that is too small by a duid that is too large+TEST_F (Dhcp6AppendOp= tionTest, InvalidDataExpectBufferTooSmall) {+ UINT8 *Cursor;+ E= FI_DHCP6_DUID *UntrustedDuid;+ EFI_STATUS Status;++ UntrustedDuid = =3D (EFI_DHCP6_DUID *)AllocateZeroPool (sizeof (EFI_DHCP6_DUID));+ ASSERT_= NE (UntrustedDuid, (EFI_DHCP6_DUID *)NULL);++ UntrustedDuid->Length =3D NT= OHS (0xFFFF);++ Cursor =3D Dhcp6AppendOptionTest::Packet->Dhcp6.Option;++ = Status =3D Dhcp6AppendOption (+ Dhcp6AppendOptionTest::Packet,= + &Cursor,+ HTONS (Dhcp6OptServerId),+ = UntrustedDuid->Length,+ UntrustedDuid->Duid+ );++ = ASSERT_EQ (Status, EFI_BUFFER_TOO_SMALL);+}++// Test Description:+// Attemp= t to append an option to a packet that is large enough+TEST_F (Dhcp6AppendO= ptionTest, ValidDataExpectSuccess) {+ UINT8 *Cursor;+ EFI_DHCP6= _DUID *UntrustedDuid;+ EFI_STATUS Status;+ UINTN Original= Length;++ UINT8 Duid[6] =3D { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };++ Pa= cket->Length =3D sizeof (EFI_DHCP6_HEADER);+ OriginalLength =3D Packet->Le= ngth;++ UntrustedDuid =3D (EFI_DHCP6_DUID *)AllocateZeroPool (sizeof (EFI_= DHCP6_DUID));+ ASSERT_NE (UntrustedDuid, (EFI_DHCP6_DUID *)NULL);++ Untru= stedDuid->Length =3D NTOHS (sizeof (Duid));+ CopyMem (UntrustedDuid->Duid,= Duid, sizeof (Duid));++ Cursor =3D Dhcp6AppendOptionTest::Packet->Dhcp6.O= ption;++ Status =3D Dhcp6AppendOption (+ Dhcp6AppendOptionTest= ::Packet,+ &Cursor,+ HTONS (Dhcp6OptServerId),+ = UntrustedDuid->Length,+ UntrustedDuid->Duid+ = );++ ASSERT_EQ (Status, EFI_SUCCESS);++ // verify that the pointer to = cursor moved by the expected amount+ ASSERT_EQ (Cursor, (UINT8 *)Dhcp6Appe= ndOptionTest::Packet->Dhcp6.Option + sizeof (Duid) + 4);++ // verify that = the length of the packet is now the expected amount+ ASSERT_EQ (Dhcp6Appen= dOptionTest::Packet->Length, OriginalLength + sizeof (Duid) + 4);+}++//////= //////////////////////////////////////////////////////////////////+// Dhcp6= AppendETOption Tests+//////////////////////////////////////////////////////= //////////////////++class Dhcp6AppendETOptionTest : public ::testing::Test = {+public:+ UINT8 *Buffer =3D NULL;+ EFI_DHCP6_PACKET *Packet;++protected:= + // Add any setup code if needed+ virtual void+ SetUp (+ )+ {+ /= / Initialize any resources or variables+ Buffer =3D (UINT8 *)AllocateZer= oPool (DHCP6_PACKET_MAX_LEN);+ ASSERT_NE (Buffer, (UINT8 *)NULL);++ P= acket =3D (EFI_DHCP6_PACKET *)Buffer;+ Packet->Size =3D DHCP6_= PACKET_MAX_LEN;+ Packet->Length =3D sizeof (EFI_DHCP6_HEADER);+ }++ //= Add any cleanup code if needed+ virtual void+ TearDown (+ )+ {+ /= / Clean up any resources or variables+ if (Buffer !=3D NULL) {+ Fre= ePool (Buffer);+ }+ }+};++// Test Description:+// Attempt to append an = option to a packet that is too small by a duid that is too large+TEST_F (Dh= cp6AppendETOptionTest, InvalidDataExpectBufferTooSmall) {+ UINT8 = *Cursor;+ EFI_STATUS Status;+ DHCP6_INSTANCE Instance;+ UINT16 = ElapsedTimeVal;+ UINT16 *ElapsedTime;++ Cursor =3D D= hcp6AppendETOptionTest::Packet->Dhcp6.Option;+ ElapsedTime =3D &ElapsedTim= eVal;++ Packet->Length =3D Packet->Size - 2;++ Status =3D Dhcp6AppendETOp= tion (+ Dhcp6AppendETOptionTest::Packet,+ &Cursor,+= &Instance, // Instance is not used in this function+ = &ElapsedTime+ );++ // verify that we error out because the = packet is too small for the option header+ ASSERT_EQ (Status, EFI_BUFFER_T= OO_SMALL);++ // reset the length+ Packet->Length =3D sizeof (EFI_DHCP6_HE= ADER);+}++// Test Description:+// Attempt to append an option to a packet t= hat is large enough+TEST_F (Dhcp6AppendETOptionTest, ValidDataExpectSuccess= ) {+ UINT8 *Cursor;+ EFI_STATUS Status;+ DHCP6_INSTANCE = Instance;+ UINT16 ElapsedTimeVal;+ UINT16 *ElapsedTime;= + UINTN ExpectedSize;+ UINTN OriginalLength;++ Curso= r =3D Dhcp6AppendETOptionTest::Packet->Dhcp6.Option;+ ElapsedTime = =3D &ElapsedTimeVal;+ ExpectedSize =3D 6;+ OriginalLength =3D Packet= ->Length;++ Status =3D Dhcp6AppendETOption (+ Dhcp6AppendETOpt= ionTest::Packet,+ &Cursor,+ &Instance, // Instance = is not used in this function+ &ElapsedTime+ );++ /= / verify that the status is EFI_SUCCESS+ ASSERT_EQ (Status, EFI_SUCCESS);+= + // verify that the pointer to cursor moved by the expected amount+ ASSE= RT_EQ (Cursor, (UINT8 *)Dhcp6AppendETOptionTest::Packet->Dhcp6.Option + Exp= ectedSize);++ // verify that the length of the packet is now the expected = amount+ ASSERT_EQ (Dhcp6AppendETOptionTest::Packet->Length, OriginalLength= + ExpectedSize);+}++//////////////////////////////////////////////////////= //////////////////+// Dhcp6AppendIaOption Tests+///////////////////////////= /////////////////////////////////////////////++class Dhcp6AppendIaOptionTes= t : public ::testing::Test {+public:+ UINT8 *Buffer =3D NULL;+ EFI_DHCP6_= PACKET *Packet;+ EFI_DHCP6_IA *Ia;++protected:+ // Add any setup code if = needed+ virtual void+ SetUp (+ )+ {+ // Initialize any resources o= r variables+ Buffer =3D (UINT8 *)AllocateZeroPool (DHCP6_PACKET_MAX_LEN)= ;+ ASSERT_NE (Buffer, (UINT8 *)NULL);++ Packet =3D (EFI_DHCP6_P= ACKET *)Buffer;+ Packet->Size =3D DHCP6_PACKET_MAX_LEN;++ Ia =3D (EFI= _DHCP6_IA *)AllocateZeroPool (sizeof (EFI_DHCP6_IA) + sizeof (EFI_DHCP6_IA_= ADDRESS) * 2);+ ASSERT_NE (Ia, (EFI_DHCP6_IA *)NULL);++ CopyMem (Ia->= IaAddress, mAllDhcpRelayAndServersAddress.Addr, sizeof (EFI_IPv6_ADDRESS));= + CopyMem (Ia->IaAddress + 1, mAllDhcpRelayAndServersAddress.Addr, sizeo= f (EFI_IPv6_ADDRESS));++ Ia->IaAddressCount =3D 2;+ }++ // Add any cle= anup code if needed+ virtual void+ TearDown (+ )+ {+ // Clean up a= ny resources or variables+ if (Buffer !=3D NULL) {+ FreePool (Buffe= r);+ }++ if (Ia !=3D NULL) {+ FreePool (Ia);+ }+ }+};++// Te= st Description:+// Attempt to append an option to a packet that doesn't hav= e enough space+// for the option header+TEST_F (Dhcp6AppendIaOptionTest, Ia= NaInvalidDataExpectBufferTooSmall) {+ UINT8 *Cursor;+ EFI_STATUS S= tatus;++ Packet->Length =3D Packet->Size - 2;++ Ia->Descriptor.Type =3D D= hcp6OptIana;+ Ia->Descriptor.IaId =3D 0x12345678;++ Cursor =3D Dhcp6Appen= dIaOptionTest::Packet->Dhcp6.Option;++ Status =3D Dhcp6AppendIaOption (+ = Dhcp6AppendIaOptionTest::Packet,+ &Cursor,+ = Ia,+ 0x12345678,+ 0x11111111,+ Dhcp= 6OptIana+ );++ // verify that we error out because the packet = is too small for the option header+ ASSERT_EQ (Status, EFI_BUFFER_TOO_SMAL= L);++ // reset the length+ Packet->Length =3D sizeof (EFI_DHCP6_HEADER);+= }++// Test Description:+// Attempt to append an option to a packet that doe= sn't have enough space+// for the option header+TEST_F (Dhcp6AppendIaOption= Test, IaTaInvalidDataExpectBufferTooSmall) {+ UINT8 *Cursor;+ EFI_S= TATUS Status;++ // Use up nearly all the space in the packet+ Packet->Le= ngth =3D Packet->Size - 2;++ Ia->Descriptor.Type =3D Dhcp6OptIata;+ Ia->D= escriptor.IaId =3D 0x12345678;++ Cursor =3D Dhcp6AppendIaOptionTest::Packe= t->Dhcp6.Option;++ Status =3D Dhcp6AppendIaOption (+ Dhcp6Appe= ndIaOptionTest::Packet,+ &Cursor,+ Ia,+ = 0,+ 0,+ Dhcp6OptIata+ );++ // verify = that we error out because the packet is too small for the option header+ A= SSERT_EQ (Status, EFI_BUFFER_TOO_SMALL);++ // reset the length+ Packet->L= ength =3D sizeof (EFI_DHCP6_HEADER);+}++TEST_F (Dhcp6AppendIaOptionTest, Ia= NaValidDataExpectSuccess) {+ UINT8 *Cursor;+ EFI_STATUS Status;+ = UINTN ExpectedSize;+ UINTN OriginalLength;++ //+ // 2 bytes = for the option header type+ //+ ExpectedSize =3D 2;+ //+ // 2 bytes for= the option header length+ //+ ExpectedSize +=3D 2;+ //+ // 4 bytes for= the IAID+ //+ ExpectedSize +=3D 4;+ //+ // + 4 bytes for the T1+ //+ = ExpectedSize +=3D 4;+ //+ // + 4 bytes for the T2+ //+ ExpectedSize += =3D 4;+ //+ // + (4 + sizeof (EFI_DHCP6_IA_ADDRESS)) * 2;+ // + 2 byte= s for the option header type+ // + 2 bytes for the option header length+= // + sizeof (EFI_DHCP6_IA_ADDRESS) for the IA Address+ //+ ExpectedSi= ze +=3D (4 + sizeof (EFI_DHCP6_IA_ADDRESS)) * 2;++ Cursor =3D Dhcp6AppendI= aOptionTest::Packet->Dhcp6.Option;++ Packet->Length =3D sizeof (EFI_DHCP6_= HEADER);+ OriginalLength =3D Packet->Length;++ Ia->Descriptor.Type =3D Dh= cp6OptIana;+ Ia->Descriptor.IaId =3D 0x12345678;++ Status =3D Dhcp6Append= IaOption (+ Dhcp6AppendIaOptionTest::Packet,+ &Curs= or,+ Ia,+ 0x12345678,+ 0x12345678,+ = Dhcp6OptIana+ );++ // verify that the pointer to curs= or moved by the expected amount+ ASSERT_EQ (Cursor, (UINT8 *)Dhcp6AppendIa= OptionTest::Packet->Dhcp6.Option + ExpectedSize);++ // verify that the len= gth of the packet is now the expected amount+ ASSERT_EQ (Dhcp6AppendIaOpti= onTest::Packet->Length, OriginalLength + ExpectedSize);++ // verify that t= he status is EFI_SUCCESS+ ASSERT_EQ (Status, EFI_SUCCESS);+}++TEST_F (Dhcp= 6AppendIaOptionTest, IaTaValidDataExpectSuccess) {+ UINT8 *Cursor;+ = EFI_STATUS Status;+ UINTN ExpectedSize;+ UINTN OriginalLeng= th;++ //+ // 2 bytes for the option header type+ //+ ExpectedSize =3D 2= ;+ //+ // 2 bytes for the option header length+ //+ ExpectedSize +=3D 2= ;+ //+ // 4 bytes for the IAID+ //+ ExpectedSize +=3D 4;+ //+ // + (4= + sizeof (EFI_DHCP6_IA_ADDRESS)) * 2;+ // + 2 bytes for the option head= er type+ // + 2 bytes for the option header length+ // + sizeof (EFI_= DHCP6_IA_ADDRESS) for the IA Address+ //+ ExpectedSize +=3D (4 + sizeof (= EFI_DHCP6_IA_ADDRESS)) * 2;++ Cursor =3D Dhcp6AppendIaOptionTest::Packet->= Dhcp6.Option;++ Packet->Length =3D sizeof (EFI_DHCP6_HEADER);+ OriginalLe= ngth =3D Packet->Length;++ Ia->Descriptor.Type =3D Dhcp6OptIata;+ Ia->Des= criptor.IaId =3D 0x12345678;++ Status =3D Dhcp6AppendIaOption (+ = Dhcp6AppendIaOptionTest::Packet,+ &Cursor,+ Ia,+= 0,+ 0,+ Dhcp6OptIata+ );++= // verify that the pointer to cursor moved by the expected amount+ ASSER= T_EQ (Cursor, (UINT8 *)Dhcp6AppendIaOptionTest::Packet->Dhcp6.Option + Expe= ctedSize);++ // verify that the length of the packet is now the expected a= mount+ ASSERT_EQ (Dhcp6AppendIaOptionTest::Packet->Length, OriginalLength = + ExpectedSize);++ // verify that the status is EFI_SUCCESS+ ASSERT_EQ (S= tatus, 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 (#114957): https://edk2.groups.io/g/devel/message/114957 Mute This Topic: https://groups.io/mt/103964978/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-