From nobody Fri May 10 07:36:47 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+107710+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+107710+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1691764405; cv=none; d=zohomail.com; s=zohoarc; b=RVRgu5l+8T3nb94jI1x3OYhhdz9g3VMEUFpfi7KE+0ZVzua9cwaeys0PVGr/cP2mDLAgYGGVlTSSGAtgVRxkrQdFaaf8EJCWyVT12cMe0su+GdzXpZlHgeFhqP/GqzwuLVFoTXPVpWRQNXFnxzZgGYE9gxxztV9ZKagt49orNT0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691764405; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=v32yON22KeKGt96s3UedEuNVUle3Ye7vma/zFvbFcV8=; b=lTXpxvwKk72LyWiDRBO/WIS+fjLL02ENnP8nCxv8YcRGO/8uhy7OMXTaTnPuV/uGdSD52He9tH3b2YyEnB0o8mQYmS+0MGOHxsXTz4e3ilWVVO+6fi05gbuEUdKQMRRu6d8gMpuxMwp84fiqWqfGObjIERjVc3knUT6e3/zP5LA= 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+107710+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 169176440532348.38979622526119; Fri, 11 Aug 2023 07:33:25 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=L3wsteh/PwqoLTeZ+9zFnrjZsn9JnkI0ftEK97765Cc=; 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=1691764404; v=1; b=skoAI0U6qpT6Q+DLHjFj8SB2WCc/QWHfAO7FQWgc3vDVTzN3x29EddZyTtBn99QRf+CkuaLz c/3KltVO8XuGUvwUtIY7Uub4ZBn1a/C2xlVMHsLg5MEW4oDskjumJ9BoRrpQ9nUDICqEH5vu4UH k42lM7CuyqZs2+LPDegMd428= X-Received: by 127.0.0.2 with SMTP id wVGpYY1788612x4dV9pXGjJ5; Fri, 11 Aug 2023 07:33:24 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.44217.1691764404105622392 for ; Fri, 11 Aug 2023 07:33:24 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1F076139F; Fri, 11 Aug 2023 07:34:06 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.35.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 628D53F64C; Fri, 11 Aug 2023 07:33:21 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Kun Qin Subject: [edk2-devel] [PATCH v6 1/9] MdeModulePkg: Duplicate BaseRngLibTimerLib to MdeModulePkg Date: Fri, 11 Aug 2023 16:33:02 +0200 Message-Id: <20230811143310.55101-2-pierre.gondois@arm.com> In-Reply-To: <20230811143310.55101-1-pierre.gondois@arm.com> References: <20230811143310.55101-1-pierre.gondois@arm.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 Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Woue4ryL7wKt2HQ83dgqhZBYx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1691764407091100008 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4504 The BaseRngLibTimerLib allows to generate number based on a timer. This mechanism allows to have a basic non-secure implementation for non-production platforms. To bind and identify Random Number Generators implementations with a GUID, an unsafe GUID should be added. This GUID cannot be added to the MdePkg unless it is also added to a specification. To keep the MdePkg self-contained, copy the BaseRngLibTimerLib to the MdeModulePkg. This will allow to define an unsafe Rng GUID in a later patch in the MdeModulePkg. The MdePkg implementation will be removed later. This allows to give some time to platform owners to switch to the MdeModulePkg implementation. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar Tested-by: Kun Qin --- ArmVirtPkg/ArmVirt.dsc.inc | 2 +- EmulatorPkg/EmulatorPkg.dsc | 2 +- .../BaseRngLibTimerLib/BaseRngLibTimerLib.inf | 36 ++++ .../BaseRngLibTimerLib/BaseRngLibTimerLib.uni | 15 ++ .../Library/BaseRngLibTimerLib/RngLibTimer.c | 192 ++++++++++++++++++ MdeModulePkg/MdeModulePkg.dsc | 1 + NetworkPkg/NetworkPkg.dsc | 4 +- OvmfPkg/AmdSev/AmdSevX64.dsc | 2 +- OvmfPkg/Bhyve/BhyveX64.dsc | 2 +- OvmfPkg/CloudHv/CloudHvX64.dsc | 2 +- OvmfPkg/IntelTdx/IntelTdxX64.dsc | 2 +- OvmfPkg/Microvm/MicrovmX64.dsc | 2 +- OvmfPkg/OvmfPkgIa32.dsc | 2 +- OvmfPkg/OvmfPkgIa32X64.dsc | 2 +- OvmfPkg/OvmfPkgX64.dsc | 2 +- OvmfPkg/OvmfXen.dsc | 2 +- OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc | 2 +- SecurityPkg/SecurityPkg.dsc | 4 +- SignedCapsulePkg/SignedCapsulePkg.dsc | 4 +- 19 files changed, 262 insertions(+), 18 deletions(-) create mode 100644 MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimer= Lib.inf create mode 100644 MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimer= Lib.uni create mode 100644 MdeModulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 2443e8351c99..3f7bac6bf33a 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -154,7 +154,7 @@ [LibraryClasses.common] OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 # # Secure Boot dependencies diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc index b44435d7e6ee..b14654739b54 100644 --- a/EmulatorPkg/EmulatorPkg.dsc +++ b/EmulatorPkg/EmulatorPkg.dsc @@ -128,7 +128,7 @@ [LibraryClasses] FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecu= reLibNull.inf diff --git a/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf= b/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf new file mode 100644 index 000000000000..f857290e823b --- /dev/null +++ b/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf @@ -0,0 +1,36 @@ +## @file +# Instance of RNG (Random Number Generator) Library. +# +# BaseRng Library that uses the TimerLib to provide reasonably random num= bers. +# Do NOT use this on a production system as this uses the system performa= nce +# counter rather than a true source of random in addition to having a weak +# random algorithm. This is provided primarily as a source of entropy for +# OpenSSL for platforms that do not have a good built in RngLib as this +# emulates what was done before (though it isn't perfect). +# +# Copyright (c) Microsoft Corporation. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D BaseRngLibTimerLib + MODULE_UNI_FILE =3D BaseRngLibTimerLib.uni + FILE_GUID =3D 74950C45-10FC-4AB5-B114-49C87C17409B + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D RngLib + +[Sources] + RngLibTimer.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + BaseLib + DebugLib + TimerLib diff --git a/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni= b/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni new file mode 100644 index 000000000000..fde24b9f0107 --- /dev/null +++ b/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni @@ -0,0 +1,15 @@ +// @file +// Instance of RNG (Random Number Generator) Library. +// +// RngLib that uses TimerLib's performance counter to provide random numbe= rs. +// +// Copyright (c) Microsoft Corporation. +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// + + +#string STR_MODULE_ABSTRACT #language en-US "Instance of RNG Library" + +#string STR_MODULE_DESCRIPTION #language en-US "BaseRng Library that uses= the TimerLib to provide low-entropy random numbers" + diff --git a/MdeModulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c b/MdeMod= ulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c new file mode 100644 index 000000000000..980854d67b72 --- /dev/null +++ b/MdeModulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c @@ -0,0 +1,192 @@ +/** @file + BaseRng Library that uses the TimerLib to provide reasonably random numb= ers. + Do not use this on a production system. + + Copyright (c) Microsoft Corporation. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include + +#define DEFAULT_DELAY_TIME_IN_MICROSECONDS 10 + +/** + Using the TimerLib GetPerformanceCounterProperties() we delay + for enough time for the PerformanceCounter to increment. + + If the return value from GetPerformanceCounterProperties (TimerLib) + is zero, this function will return 10 and attempt to assert. + **/ +STATIC +UINT32 +CalculateMinimumDecentDelayInMicroseconds ( + VOID + ) +{ + UINT64 CounterHz; + + // Get the counter properties + CounterHz =3D GetPerformanceCounterProperties (NULL, NULL); + // Make sure we won't divide by zero + if (CounterHz =3D=3D 0) { + ASSERT (CounterHz !=3D 0); // Assert so the developer knows something = is wrong + return DEFAULT_DELAY_TIME_IN_MICROSECONDS; + } + + // Calculate the minimum delay based on 1.5 microseconds divided by the = hertz. + // We calculate the length of a cycle (1/CounterHz) and multiply it by 1= .5 microseconds + // This ensures that the performance counter has increased by at least o= ne + return (UINT32)(MAX (DivU64x64Remainder (1500000, CounterHz, NULL), 1)); +} + +/** + Generates a 16-bit random number. + + if Rand is NULL, then ASSERT(). + + @param[out] Rand Buffer pointer to store the 16-bit random value. + + @retval TRUE Random number generated successfully. + @retval FALSE Failed to generate the random number. + +**/ +BOOLEAN +EFIAPI +GetRandomNumber16 ( + OUT UINT16 *Rand + ) +{ + UINT32 Index; + UINT8 *RandPtr; + UINT32 DelayInMicroSeconds; + + ASSERT (Rand !=3D NULL); + + if (Rand =3D=3D NULL) { + return FALSE; + } + + DelayInMicroSeconds =3D CalculateMinimumDecentDelayInMicroseconds (); + RandPtr =3D (UINT8 *)Rand; + // Get 2 bytes of random ish data + for (Index =3D 0; Index < sizeof (UINT16); Index++) { + *RandPtr =3D (UINT8)(GetPerformanceCounter () & 0xFF); + // Delay to give the performance counter a chance to change + MicroSecondDelay (DelayInMicroSeconds); + RandPtr++; + } + + return TRUE; +} + +/** + Generates a 32-bit random number. + + if Rand is NULL, then ASSERT(). + + @param[out] Rand Buffer pointer to store the 32-bit random value. + + @retval TRUE Random number generated successfully. + @retval FALSE Failed to generate the random number. + +**/ +BOOLEAN +EFIAPI +GetRandomNumber32 ( + OUT UINT32 *Rand + ) +{ + UINT32 Index; + UINT8 *RandPtr; + UINT32 DelayInMicroSeconds; + + ASSERT (Rand !=3D NULL); + + if (NULL =3D=3D Rand) { + return FALSE; + } + + RandPtr =3D (UINT8 *)Rand; + DelayInMicroSeconds =3D CalculateMinimumDecentDelayInMicroseconds (); + // Get 4 bytes of random ish data + for (Index =3D 0; Index < sizeof (UINT32); Index++) { + *RandPtr =3D (UINT8)(GetPerformanceCounter () & 0xFF); + // Delay to give the performance counter a chance to change + MicroSecondDelay (DelayInMicroSeconds); + RandPtr++; + } + + return TRUE; +} + +/** + Generates a 64-bit random number. + + if Rand is NULL, then ASSERT(). + + @param[out] Rand Buffer pointer to store the 64-bit random value. + + @retval TRUE Random number generated successfully. + @retval FALSE Failed to generate the random number. + +**/ +BOOLEAN +EFIAPI +GetRandomNumber64 ( + OUT UINT64 *Rand + ) +{ + UINT32 Index; + UINT8 *RandPtr; + UINT32 DelayInMicroSeconds; + + ASSERT (Rand !=3D NULL); + + if (NULL =3D=3D Rand) { + return FALSE; + } + + RandPtr =3D (UINT8 *)Rand; + DelayInMicroSeconds =3D CalculateMinimumDecentDelayInMicroseconds (); + // Get 8 bytes of random ish data + for (Index =3D 0; Index < sizeof (UINT64); Index++) { + *RandPtr =3D (UINT8)(GetPerformanceCounter () & 0xFF); + // Delay to give the performance counter a chance to change + MicroSecondDelay (DelayInMicroSeconds); + RandPtr++; + } + + return TRUE; +} + +/** + Generates a 128-bit random number. + + if Rand is NULL, then ASSERT(). + + @param[out] Rand Buffer pointer to store the 128-bit random value. + + @retval TRUE Random number generated successfully. + @retval FALSE Failed to generate the random number. + +**/ +BOOLEAN +EFIAPI +GetRandomNumber128 ( + OUT UINT64 *Rand + ) +{ + ASSERT (Rand !=3D NULL); + // This should take around 80ms + + // Read first 64 bits + if (!GetRandomNumber64 (Rand)) { + return FALSE; + } + + // Read second 64 bits + return GetRandomNumber64 (++Rand); +} diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index db3b5af53795..c7af921782ee 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -345,6 +345,7 @@ [Components] MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdateProgr= essLibGraphics.inf MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdateProgressL= ibText.inf + MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 MdeModulePkg/Universal/BdsDxe/BdsDxe.inf MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf diff --git a/NetworkPkg/NetworkPkg.dsc b/NetworkPkg/NetworkPkg.dsc index 6c231c97b544..808c6bffce2c 100644 --- a/NetworkPkg/NetworkPkg.dsc +++ b/NetworkPkg/NetworkPkg.dsc @@ -82,10 +82,10 @@ [LibraryClasses.ARM, LibraryClasses.AARCH64] ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf =20 [LibraryClasses.ARM] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [LibraryClasses.RISCV64] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [PcdsFeatureFlag] gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index 2c6ed7c9745f..022104dfdce6 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -185,7 +185,7 @@ [LibraryClasses] =20 IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc index 82c60ace1bbd..6693342c5f6e 100644 --- a/OvmfPkg/Bhyve/BhyveX64.dsc +++ b/OvmfPkg/Bhyve/BhyveX64.dsc @@ -196,7 +196,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.dsc index e000deed9e4d..35942e02df93 100644 --- a/OvmfPkg/CloudHv/CloudHvX64.dsc +++ b/OvmfPkg/CloudHv/CloudHvX64.dsc @@ -206,7 +206,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdxX6= 4.dsc index 193657ff2d61..bbf218488127 100644 --- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc +++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc @@ -184,7 +184,7 @@ [LibraryClasses] =20 IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.dsc index 2f7585639374..d5c1a2fe3a91 100644 --- a/OvmfPkg/Microvm/MicrovmX64.dsc +++ b/OvmfPkg/Microvm/MicrovmX64.dsc @@ -203,7 +203,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index ed36935770f3..c1f1733a483d 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -210,7 +210,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 919315e4cb33..bdd6c3bc96ae 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -215,7 +215,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 823de0d0f9e0..a54e17dd087d 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -231,7 +231,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 !if $(SECURE_BOOT_ENABLE) =3D=3D TRUE PlatformSecureLib|OvmfPkg/Library/PlatformSecureLib/PlatformSecureLib.inf diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 210578c1d74d..26d2a6963de5 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -194,7 +194,7 @@ [LibraryClasses] !else OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf diff --git a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc b/OvmfPkg/RiscVVirt/RiscVV= irt.dsc.inc index bc204ba5fe52..fe320525153f 100644 --- a/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc +++ b/OvmfPkg/RiscVVirt/RiscVVirt.dsc.inc @@ -118,7 +118,7 @@ [LibraryClasses.common] OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf !endif BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 # # Secure Boot dependencies diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 3c62205162ce..7682066cd9fe 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -92,10 +92,10 @@ [LibraryClasses.ARM, LibraryClasses.AARCH64] ArmTrngLib|MdePkg/Library/BaseArmTrngLibNull/BaseArmTrngLibNull.inf =20 [LibraryClasses.ARM] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [LibraryClasses.RISCV64] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [LibraryClasses.X64.SEC] HashLib|SecurityPkg/Library/HashLibTdx/HashLibTdx.inf diff --git a/SignedCapsulePkg/SignedCapsulePkg.dsc b/SignedCapsulePkg/Signe= dCapsulePkg.dsc index 8a27207a6f20..4c656666e981 100644 --- a/SignedCapsulePkg/SignedCapsulePkg.dsc +++ b/SignedCapsulePkg/SignedCapsulePkg.dsc @@ -110,10 +110,10 @@ [LibraryClasses.AARCH64, LibraryClasses.ARM] NULL|MdePkg/Library/BaseStackCheckLib/BaseStackCheckLib.inf =20 [LibraryClasses.ARM] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [LibraryClasses.RISCV64] - RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + RngLib|MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 [LibraryClasses.common.PEI_CORE] HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf --=20 2.25.1 -=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 (#107710): https://edk2.groups.io/g/devel/message/107710 Mute This Topic: https://groups.io/mt/100684681/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- From nobody Fri May 10 07:36:47 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+107711+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+107711+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1691764408; cv=none; d=zohomail.com; s=zohoarc; b=JQ36ix+DTaGTbZ7uHzjupsCjOJmY1exFakkdfNonRnK1buLT/cQEW0UqzQ51/HHpMeDqzqBXY9xKXcRBoIIZiaj9gYYqmxj3bC5cmDblv3YocqKtTTmuqiMXW2Tw2TaGj7GxKLZDypRZ3TUMngYT6wlfRbhhjawD1uv3CxfT9aU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691764408; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ZAGkwJBYj2LvMpIjDz/aTNH6g0BMiqM/LEwlPtnxXI4=; b=ajovCQpE66X5ktWmwvtO/qPOo2TvOyRvOAv7ZtASdnPZI1AYOYj2ukyTPcur82xWCksfgGvLXDQvZDdLlNbjaPbeeJUarHz+2Ys7HkfeZ6DNNK3NuMGwv6NAYU42HFkCNQOJ7vpo2NRr4RcA58UHoZwFa8NvGDLVp0C9L4n3KEA= 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+107711+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 169176440792351.767643018915805; Fri, 11 Aug 2023 07:33:27 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=5nv5Xs9qMRzE98paVgLVr29+DuCeeAX4PD3Fh42lM8E=; 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=1691764407; v=1; b=ULgE0RX74FERWt+ZWIYX1w6iqKyejCDbPFfLqqy/IgUIFqihw/gGXRCKh3Nf7Z6zB9kGc6mY Qb/FbyoIswJeZy48OTMNxXEyDhrnV0GM6woWWCjm3ku3c7FyHtIHO7ff+6DDunA336Kw7FXuxcz 1JaigzajMvz7+/qiS9aTUeBc= X-Received: by 127.0.0.2 with SMTP id 6t9KYY1788612xFW6nQpvxyU; Fri, 11 Aug 2023 07:33:27 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.44270.1691764406522302610 for ; Fri, 11 Aug 2023 07:33:26 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B62B1424; Fri, 11 Aug 2023 07:34:08 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.35.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0D7F33F64C; Fri, 11 Aug 2023 07:33:23 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Kun Qin Subject: [edk2-devel] [PATCH v6 2/9] MdePkg: Add deprecated warning to BaseRngLibTimer Date: Fri, 11 Aug 2023 16:33:03 +0200 Message-Id: <20230811143310.55101-3-pierre.gondois@arm.com> In-Reply-To: <20230811143310.55101-1-pierre.gondois@arm.com> References: <20230811143310.55101-1-pierre.gondois@arm.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 Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: V10lYAWpwcKWHbRxpTgzZF1Lx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1691764409558100015 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4504 To keep the MdePkg self-contained and avoid dependencies on GUIDs defined in other packages, the BaseRngLibTimer was moved to the MdePkg. Add a constructor to warn and request to use the MdeModulePkg implementation. Signed-off-by: Pierre Gondois Reviewed-by: Liming Gao Reviewed-by: Sami Mujawar Tested-by: Kun Qin --- .../BaseRngLibTimerLib/BaseRngLibTimerLib.inf | 1 + .../Library/BaseRngLibTimerLib/RngLibTimer.c | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf b/Mde= Pkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf index f857290e823b..96c90db63f6f 100644 --- a/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf +++ b/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf @@ -23,6 +23,7 @@ [Defines] MODULE_TYPE =3D BASE VERSION_STRING =3D 1.0 LIBRARY_CLASS =3D RngLib + CONSTRUCTOR =3D BaseRngLibTimerConstructor =20 [Sources] RngLibTimer.c diff --git a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c b/MdePkg/Libra= ry/BaseRngLibTimerLib/RngLibTimer.c index 980854d67b72..c4fdd1df68d3 100644 --- a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c +++ b/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c @@ -13,6 +13,28 @@ =20 #define DEFAULT_DELAY_TIME_IN_MICROSECONDS 10 =20 +/** + This implementation is to be replaced by its MdeModulePkg copy. + The cause being that some GUIDs (gEdkiiRngAlgorithmUnSafe) cannot + be defined in the MdePkg. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. +**/ +RETURN_STATUS +EFIAPI +BaseRngLibTimerConstructor ( + VOID + ) +{ + DEBUG (( + DEBUG_WARN, + "Warning: This BaseRngTimerLib implementation will be deprecated. " + "Please use the MdeModulePkg implementation equivalent.\n" + )); + + return RETURN_SUCCESS; +} + /** Using the TimerLib GetPerformanceCounterProperties() we delay for enough time for the PerformanceCounter to increment. --=20 2.25.1 -=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 (#107711): https://edk2.groups.io/g/devel/message/107711 Mute This Topic: https://groups.io/mt/100684683/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- From nobody Fri May 10 07:36:47 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+107712+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+107712+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1691764410; cv=none; d=zohomail.com; s=zohoarc; b=NBIiZvr/mqQodbtdbmFpTOFWY/lrkMdowvxFAGd97C/noXzmGU/zHvGZ2RMppn25UaUUOcrCJkJ2AEkpFKGCy3Q7mc/dq5cPC8FZH1/xMJuS1Shm8DcNTnANrc9Qkejygg0X8zqPzv8VU8Ljg1ZdllTPGLwH9lg2W5RoWSo2+0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691764410; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=tQaZx9Juq2FntcMf6QmX+G98rjCtpQ8+ng2UsxXq7Bo=; b=GPe6oQmSKw4GUwkLZ3slgEZJ+nXgSVEGdoxemd1zJhj0kmx5Rx/ZyYy2wee8+ipHEzj6gJL2bxXe0SDinkqJ6t13TLljzHVmgmTBnHQAiB0ovadbvTuE/8lsyObNX1sjh6xYq8vU9GeG9YCzaYtXCOGOBit9Hw1RzaDOWiwpjH0= 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+107712+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1691764410153977.0636552653041; Fri, 11 Aug 2023 07:33:30 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=xZXa/vY5rU/WUWedYN2YNdSnAUftiw/sE2zDDtbN2I4=; 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=1691764409; v=1; b=Kie95U0xVJLMgsDILVSFzlom6as++UIwdbCtmB0NACsluePtn8iyKeCUVm9mBV/j0CHKYPJK NIeBn3dOcqwhgQiCNuR+P78rBlQkEfX5sv7K4UISgzHvD4wzb2hmpN+qkG3lXGErf4obf5IdRtZ 3rzHUZpYpDqrFbmfpjA9axS0= X-Received: by 127.0.0.2 with SMTP id lPwMYY1788612x732WuPmn3F; Fri, 11 Aug 2023 07:33:29 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.44221.1691764408943700373 for ; Fri, 11 Aug 2023 07:33:29 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 071EC14BF; Fri, 11 Aug 2023 07:34:11 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.35.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8CFC73F64C; Fri, 11 Aug 2023 07:33:26 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Kun Qin Subject: [edk2-devel] [PATCH v6 3/9] SecurityPkg/SecurityPkg.dec: Move PcdCpuRngSupportedAlgorithm to MdePkg Date: Fri, 11 Aug 2023 16:33:04 +0200 Message-Id: <20230811143310.55101-4-pierre.gondois@arm.com> In-Reply-To: <20230811143310.55101-1-pierre.gondois@arm.com> References: <20230811143310.55101-1-pierre.gondois@arm.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 Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: VuV3QXUU4ugaXXrIf7HUkQ3fx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1691764411560100019 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois In order to use PcdCpuRngSupportedAlgorithm in the MdePkg in a following patch and to avoid making the MdePkg dependent on another package, move PcdCpuRngSupportedAlgorithm to the MdePkg. As the Pcd is only used for AARCH64, place it in an AARCH64 specific sections. Signed-off-by: Pierre Gondois Reviewed-by: Liming Gao Reviewed-by: Sami Mujawar Tested-by: Kun Qin --- .../Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf | 2 +- MdePkg/MdePkg.dec | 5 +++++ SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf | 4 ++-- SecurityPkg/SecurityPkg.dec | 2 -- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf= b/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf index f857290e823b..f7290010604f 100644 --- a/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf +++ b/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf @@ -19,7 +19,7 @@ [Defines] INF_VERSION =3D 1.27 BASE_NAME =3D BaseRngLibTimerLib MODULE_UNI_FILE =3D BaseRngLibTimerLib.uni - FILE_GUID =3D 74950C45-10FC-4AB5-B114-49C87C17409B + FILE_GUID =3D B3E66B05-D218-4B9A-AC33-EF0F83D6A513 MODULE_TYPE =3D BASE VERSION_STRING =3D 1.0 LIBRARY_CLASS =3D RngLib diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index b85614992b94..5b8477f4cb8f 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -2393,6 +2393,11 @@ [PcdsFixedAtBuild,PcdsPatchableInModule] # @Prompt Time-out for a response, internal gEfiMdePkgTokenSpaceGuid.PcdIpmiSsifResponseRetryIntervalMicrosecond|600= 00|UINT32|0x00000036 =20 +[PcdsFixedAtBuild.AARCH64, PcdsPatchableInModule.AARCH64] + ## GUID identifying the Rng algorithm implemented by CPU instruction. + # @Prompt CPU Rng algorithm's GUID. + gEfiMdePkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm|{0x00,0x00,0x00,0x0= 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}|VOID*|0x0000= 0037 + [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] ## This value is used to set the base address of PCI express hierarchy. # @Prompt PCI Express Base Address. diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index c8e0ee4ae5d9..d6c2d30195bf 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -79,8 +79,8 @@ [Guids] [Protocols] gEfiRngProtocolGuid ## PRODUCES =20 -[Pcd] - gEfiSecurityPkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm ## CONSUM= ES +[Pcd.AARCH64] + gEfiMdePkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm ## CONSUMES =20 [Depex] TRUE diff --git a/SecurityPkg/SecurityPkg.dec b/SecurityPkg/SecurityPkg.dec index 53aa7ec43557..00c4ebdbed59 100644 --- a/SecurityPkg/SecurityPkg.dec +++ b/SecurityPkg/SecurityPkg.dec @@ -325,8 +325,6 @@ [PcdsFixedAtBuild, PcdsPatchableInModule] gEfiSecurityPkgTokenSpaceGuid.PcdStatusCodeFvVerificationPass|0x0303100A= |UINT32|0x00010030 gEfiSecurityPkgTokenSpaceGuid.PcdStatusCodeFvVerificationFail|0x0303100B= |UINT32|0x00010031 =20 - gEfiSecurityPkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm|{0x00,0x00,0x0= 0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}|VOID*|0= x00010032 - [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] ## Image verification policy for OptionRom. Only following values are va= lid:

# NOTE: Do NOT use 0x5 and 0x2 since it violates the UEFI specification= and has been removed.
--=20 2.25.1 -=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 (#107712): https://edk2.groups.io/g/devel/message/107712 Mute This Topic: https://groups.io/mt/100684685/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- From nobody Fri May 10 07:36:47 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+107713+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+107713+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1691764412; cv=none; d=zohomail.com; s=zohoarc; b=Cvreno5lJgypUX/MMQOa4OZUwNJr9b1MveejbJtpHSNxv2LsHWdfyrMWIX7kFVa3tpEUrFGkEYl1dJKCz+ZffNy00T3TqA7VTvvGsU7CgMB7SLdcQFOXG+1xQVEgcN/pXEcJPI1df6rR2knrFGm0yJ5aHqwvZKxMw5zBkMO5bMY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691764412; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=jLshmL87NBpi5vR+k0oCSj8W3RqwaSUp8dpyBya0mw8=; b=ZRA/YjYTWtGGrhWnBxmcJi8Htyz4aZOLBHbBuejtfTIyIh+0dJpflHn3KX4vsgObAstKgaNnc/lqLMJYY/0e18eO5A+KsgHyicR4NPBQHu2IMQekAbB3kDSYKcHSpGZI917Sc7xH1nRQEgRhiSamIYujUbmhYznVBP1YzubanMs= 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+107713+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1691764412822898.7103490613483; Fri, 11 Aug 2023 07:33:32 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=cqx20reUOC8kag/S7tWs6Ihy28C5BG4Q+5/cBThK0WA=; 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=1691764412; v=1; b=J5vFLTFv2o8afRP7HoL5Wy6rh5gvlpktA85HpHNnplMgJmhNN4IK7moMTYj0nM+qmzqdrG+k K76h/heX/kxwHPJe9OPI8r4nEbZt0WdGBTQmEV84yrIZskz9Iwi9FiDRj+rL3U95uDReNfZt9Fh 0HgVOJXKicN+92jm5zb2unHI= X-Received: by 127.0.0.2 with SMTP id Ry4aYY1788612xRUJhaQAOi9; Fri, 11 Aug 2023 07:33:32 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.44223.1691764411540563483 for ; Fri, 11 Aug 2023 07:33:31 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8F4BA150C; Fri, 11 Aug 2023 07:34:13 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.35.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 088293F64C; Fri, 11 Aug 2023 07:33:28 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Kun Qin Subject: [edk2-devel] [PATCH v6 4/9] MdePkg/DxeRngLib: Request raw algorithm instead of default Date: Fri, 11 Aug 2023 16:33:05 +0200 Message-Id: <20230811143310.55101-5-pierre.gondois@arm.com> In-Reply-To: <20230811143310.55101-1-pierre.gondois@arm.com> References: <20230811143310.55101-1-pierre.gondois@arm.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 Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: dVcUD2iexrsx7i82LIPtsjnex1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1691764413118100024 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The DxeRngLib tries to generate a random number using the 3 NIST SP 800-90 compliant DRBG algorithms, i.e. 256-bits CTR, HASH and HMAC. If none of the call is successful, the fallback option is the default RNG algorithm of the EFI_RNG_PROTOCOL. This default algorithm might be an unsafe implementation. Try requesting the Raw algorithm before requesting the default one. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar Reviewed-by: Liming Gao Tested-by: Kun Qin --- MdePkg/Library/DxeRngLib/DxeRngLib.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/MdePkg/Library/DxeRngLib/DxeRngLib.c b/MdePkg/Library/DxeRngLi= b/DxeRngLib.c index 46aea515924f..a01b66ad7d20 100644 --- a/MdePkg/Library/DxeRngLib/DxeRngLib.c +++ b/MdePkg/Library/DxeRngLib/DxeRngLib.c @@ -65,9 +65,15 @@ GenerateRandomNumberViaNist800Algorithm ( return Status; } =20 + Status =3D RngProtocol->GetRNG (RngProtocol, &gEfiRngAlgorithmRaw, Buffe= rSize, Buffer); + DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Raw - Status =3D %r\n", __func= __, Status)); + if (!EFI_ERROR (Status)) { + return Status; + } + // If all the other methods have failed, use the default method from the= RngProtocol Status =3D RngProtocol->GetRNG (RngProtocol, NULL, BufferSize, Buffer); - DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm Hash-256 - Status =3D %r\n", _= _func__, Status)); + DEBUG ((DEBUG_INFO, "%a: GetRNG algorithm default - Status =3D %r\n", __= func__, Status)); if (!EFI_ERROR (Status)) { return Status; } --=20 2.25.1 -=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 (#107713): https://edk2.groups.io/g/devel/message/107713 Mute This Topic: https://groups.io/mt/100684687/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- From nobody Fri May 10 07:36:47 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+107714+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+107714+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1691764415; cv=none; d=zohomail.com; s=zohoarc; b=AMPTcyW4SBTIUHGZGXsUel4kEmnhDtx7PdM3BNAiC1eC+SjrZQINjjGcRHnD2m2wNycTDJWErcsAqCvW6Jhh2dGcXkkF1qBMLEfb3zvH3eMdvDh+hUQTCfHdXwR03CHOoHsWK1VTqFC0ak8eOKL30fKyi8I86pla8TpKKvOKD2c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691764415; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=h/unWgkTBVC11VZB0UMTz+Ou9NPm1EWZsKqk9WP+W/c=; b=Z823x4w1cf+qPXOrhcjWfoQgBGluzAu35ylJYyzfS99ra3xkPn3obDBCNS6qoq7sFxW5abhiRJ3MWzpHRqSmprQmPLXxfgvFab+p1KGwA0Up7K+pbnqJDUNVbT/sksJaBBIRuxfKhEdUEMP+MeGSJ+0u5PKXUaJuU/WjBIrS0uQ= 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+107714+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1691764415404418.32166354499304; Fri, 11 Aug 2023 07:33:35 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=vA6mZgKLoy8cnw6xQSFBxsjTuz2X1/cV/R7Z3qHspgg=; 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=1691764414; v=1; b=XxQImNqqcBX0JliLXNAGrZt1TyfAdYSGCmFAoOCgmgUv3R+JIDeviasC/TL9IsVm7+N6as9H NyrcBVd4g8l6Z2T87Xvyi/49t897rS2asRvSD5u49K983MCLQU7wi2fosSXWx/KY//K0nFaNV2K Fsj4ARXBjgokMd1bBUnf9L0U= X-Received: by 127.0.0.2 with SMTP id UbdeYY1788612xjaVjHE1OyK; Fri, 11 Aug 2023 07:33:34 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.44226.1691764414034155092 for ; Fri, 11 Aug 2023 07:33:34 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0AAAD113E; Fri, 11 Aug 2023 07:34:16 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.35.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 915F03F64C; Fri, 11 Aug 2023 07:33:31 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Kun Qin Subject: [edk2-devel] [PATCH v6 5/9] MdePkg/Rng: Add GUID to describe Arm Rndr Rng algorithms Date: Fri, 11 Aug 2023 16:33:06 +0200 Message-Id: <20230811143310.55101-6-pierre.gondois@arm.com> In-Reply-To: <20230811143310.55101-1-pierre.gondois@arm.com> References: <20230811143310.55101-1-pierre.gondois@arm.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 Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: d1MoRJqB6yVPMiMzO8sGA05sx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1691764417629100033 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4441 The EFI_RNG_PROTOCOL can rely on the RngLib. The RngLib has multiple implementations, some of them are unsafe (e.g. BaseRngLibTimerLib). To allow the RngDxe to detect when such implementation is used, a GetRngGuid() function is added in a following patch. Prepare GetRngGuid() return values and add a gEfiRngAlgorithmArmRndr to describe a Rng algorithm accessed through Arm's RNDR instruction. [1] states that the implementation of this algorithm should be compliant to NIST SP900-80. The compliance is not guaranteed. [1] Arm Architecture Reference Manual Armv8, for A-profile architecture sK12.1 'Properties of the generated random number' Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar Reviewed-by: Liming Gao Tested-by: Kun Qin --- MdePkg/Include/Protocol/Rng.h | 10 ++++++++++ MdePkg/MdePkg.dec | 1 + 2 files changed, 11 insertions(+) diff --git a/MdePkg/Include/Protocol/Rng.h b/MdePkg/Include/Protocol/Rng.h index baf425587b3c..38bde53240d1 100644 --- a/MdePkg/Include/Protocol/Rng.h +++ b/MdePkg/Include/Protocol/Rng.h @@ -67,6 +67,15 @@ typedef EFI_GUID EFI_RNG_ALGORITHM; { \ 0xe43176d7, 0xb6e8, 0x4827, {0xb7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85,= 0x61 } \ } +/// +/// The Arm Architecture states the RNDR that the DRBG algorithm should be= compliant +/// with NIST SP800-90A, while not mandating a particular algorithm, so as= to be +/// inclusive of different geographies. +/// +#define EFI_RNG_ALGORITHM_ARM_RNDR \ + { \ + 0x43d2fde3, 0x9d4e, 0x4d79, {0x02, 0x96, 0xa8, 0x9b, 0xca, 0x78, 0x08= , 0x41} \ + } =20 /** Returns information about the random number generation implementation. @@ -146,5 +155,6 @@ extern EFI_GUID gEfiRngAlgorithmSp80090Ctr256Guid; extern EFI_GUID gEfiRngAlgorithmX9313DesGuid; extern EFI_GUID gEfiRngAlgorithmX931AesGuid; extern EFI_GUID gEfiRngAlgorithmRaw; +extern EFI_GUID gEfiRngAlgorithmArmRndr; =20 #endif diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 5b8477f4cb8f..ac54338089e8 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -643,6 +643,7 @@ [Guids] gEfiRngAlgorithmX9313DesGuid =3D { 0x63c4785a, 0xca34, 0x4012, {0x= a3, 0xc8, 0x0b, 0x6a, 0x32, 0x4f, 0x55, 0x46 }} gEfiRngAlgorithmX931AesGuid =3D { 0xacd03321, 0x777e, 0x4d3d, {0x= b1, 0xc8, 0x20, 0xcf, 0xd8, 0x88, 0x20, 0xc9 }} gEfiRngAlgorithmRaw =3D { 0xe43176d7, 0xb6e8, 0x4827, {0x= b7, 0x84, 0x7f, 0xfd, 0xc4, 0xb6, 0x85, 0x61 }} + gEfiRngAlgorithmArmRndr =3D { 0x43d2fde3, 0x9d4e, 0x4d79, {0x= 02, 0x96, 0xa8, 0x9b, 0xca, 0x78, 0x08, 0x41 }} =20 ## Include/Protocol/AdapterInformation.h gEfiAdapterInfoMediaStateGuid =3D { 0xD7C74207, 0xA831, 0x4A26, {0= xB1, 0xF5, 0xD1, 0x93, 0x06, 0x5C, 0xE8, 0xB6 }} --=20 2.25.1 -=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 (#107714): https://edk2.groups.io/g/devel/message/107714 Mute This Topic: https://groups.io/mt/100684690/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- From nobody Fri May 10 07:36:47 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+107715+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+107715+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1691764417; cv=none; d=zohomail.com; s=zohoarc; b=KQ0D0x8H5ZKzDm+Zgr2xccwjLJ+34lvPAqcu9DNuNadncUemIvKPd7aBAuHrgNPBq/LiMER75zERlNrqyZPeIQsJDdmktAFLVojLlk3aYY6AoNjFKT/aNLm6wzblAi7odbkMhkUdX5fLa2rwkYale8fP8CksvmkZZF/lIPSYvwg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691764417; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=EpxGthB6f63ZS3eb5uCoWunihoHCZ/KDOALaL8shdqQ=; b=ODeMEm3gypoLaVwmEAfC/Ls4EroCorKRllp382yA85FxqZkVaIIYj4vCaiQLlxya4HLqKESgxhtF5mUlGhi4N5ARzg1YSTcffgMcBH00TlUyogaVrOoHb6BKyGPK8GZFhGcd7gRBcT/lzinV3iCdCjTXp0yPJfa8OKsc71P3in0= 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+107715+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1691764417859260.4736946615627; Fri, 11 Aug 2023 07:33:37 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=smyRZRN6ISZ4xhFMnRV5mkrUIuB1GIVy1g8iFYPkQjI=; 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=1691764417; v=1; b=OYoQmJktx3k9xYNOOMSekLOmPtXfYujlF/4gaG3APY0s8S6NJCR/jn2ohwqvROT+VqkkNiId yCH0Tf0upUTyLHAv6fOV2Pwy9Z3qT2voDVC4y/ASa30EZjHviK6LNw6FP65lNJv0wXnKDd0FVY/ XVmJTCWlDpvpkeztB6jPT1D4= X-Received: by 127.0.0.2 with SMTP id GFgXYY1788612x4SsJDetkgc; Fri, 11 Aug 2023 07:33:37 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.44279.1691764416657710016 for ; Fri, 11 Aug 2023 07:33:36 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AD06C1424; Fri, 11 Aug 2023 07:34:18 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.35.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0CEAB3F64C; Fri, 11 Aug 2023 07:33:33 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Kun Qin Subject: [edk2-devel] [PATCH v6 6/9] MdeModulePkg/Rng: Add GUID to describe unsafe Rng algorithms Date: Fri, 11 Aug 2023 16:33:07 +0200 Message-Id: <20230811143310.55101-7-pierre.gondois@arm.com> In-Reply-To: <20230811143310.55101-1-pierre.gondois@arm.com> References: <20230811143310.55101-1-pierre.gondois@arm.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 Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: yRV22YVoq8zO5haVLqLhwHTdx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1691764419695100036 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4441 The EFI_RNG_PROTOCOL can rely on the RngLib. The RngLib has multiple implementations, some of them are unsafe (e.g. BaseRngLibTimerLib). To allow the RngDxe to detect when such implementation is used, a GetRngGuid() function is added in a following patch. Prepare GetRngGuid() return values and add a gEdkiiRngAlgorithmUnSafe to describe an unsafe implementation, cf. the BaseRngLibTimerLib. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar Tested-by: Kun Qin --- MdeModulePkg/Include/Guid/RngAlgorithm.h | 23 +++++++++++++++++++++++ MdeModulePkg/MdeModulePkg.dec | 3 +++ 2 files changed, 26 insertions(+) create mode 100644 MdeModulePkg/Include/Guid/RngAlgorithm.h diff --git a/MdeModulePkg/Include/Guid/RngAlgorithm.h b/MdeModulePkg/Includ= e/Guid/RngAlgorithm.h new file mode 100644 index 000000000000..e2ac2ba3e5c6 --- /dev/null +++ b/MdeModulePkg/Include/Guid/RngAlgorithm.h @@ -0,0 +1,23 @@ +/** @file + Rng Algorithm + + Copyright (c) 2023, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef RNG_ALGORITHM_GUID_H_ +#define RNG_ALGORITHM_GUID_H_ + +/// +/// The implementation of a Random Number Generator might be unsafe, when = using +/// a dummy implementation for instance. Allow identifying such implementa= tion +/// with this GUID. +/// +#define EDKII_RNG_ALGORITHM_UNSAFE \ + { \ + 0x869f728c, 0x409d, 0x4ab4, {0xac, 0x03, 0x71, 0xd3, 0x09, 0xc1, 0xb3,= 0xf4 } \ + } + +extern EFI_GUID gEdkiiRngAlgorithmUnSafe; + +#endif // #ifndef RNG_ALGORITHM_GUID_H_ diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 0ff058b0a9da..dd182c02fdf6 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -418,6 +418,9 @@ [Guids] ## Include/Guid/MigratedFvInfo.h gEdkiiMigratedFvInfoGuid =3D { 0xc1ab12f7, 0x74aa, 0x408d, { 0xa2, 0xf4,= 0xc6, 0xce, 0xfd, 0x17, 0x98, 0x71 } } =20 + ## Include/Guid/RngAlgorithm.h + gEdkiiRngAlgorithmUnSafe =3D { 0x869f728c, 0x409d, 0x4ab4, {0xac, 0x03, = 0x71, 0xd3, 0x09, 0xc1, 0xb3, 0xf4 }} + # # GUID defined in UniversalPayload # --=20 2.25.1 -=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 (#107715): https://edk2.groups.io/g/devel/message/107715 Mute This Topic: https://groups.io/mt/100684692/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- From nobody Fri May 10 07:36:47 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+107716+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+107716+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1691764421; cv=none; d=zohomail.com; s=zohoarc; b=S/fvmuxgqM2H+Qp/AEoK2szlJmpxMVfEt5/kKTpCTVKidOG/PQi2XhBwyPscyZSEf2e7vr1lypD1RdbEhJ11Ldxndp0yH5uJ057k+LpZHnv73c80obTm8UfjKuhVM3keS+DNI2WXDp4YYvWJ6UNh3R/3QQ1Y/o4Jf+w/ko03ikE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691764421; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=uLl2p4uYiuZrHio5+uC0VGatlzvSb0b5kHLeeuW4Yhg=; b=C/Tfapgs4EPh/aBpw5ElVLRgJnXceIrpSyRs8zqfwsH8RbSXuixmq7njIAXuF/W2Hhmm3UKNT7PFEGqugLQlwzKPpgCIE3ltQi9WZg9ytaMP03uwYm3weYqsOyJusQOL1ThZ+XApFIO96kTfxxMMZ0+caleN3iOBu+9QuGqqy90= 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+107716+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1691764420828684.6224031120923; Fri, 11 Aug 2023 07:33:40 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Lf9wuPZxl1PmJXsS4NAzNULNg1RBEEsNVQ7TvH6vEHg=; 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=1691764419; v=1; b=uDuBhy1ECDbZ8GBN5C9ps0LYCknhNSqbXGohQiWYitfb3LmS3YpyxIQk9KDfoIwhuLDITAbJ QfwRRhhQh0jDcVREc1fsWxertk0gr1dX6ezFz7b8ap0vHiyAXoMM/TmSfRIiVdaBHFiFNEuBLC4 Ox8COgof76VItlD06cI1mv/o= X-Received: by 127.0.0.2 with SMTP id Yr7YYY1788612xAalxbijg9L; Fri, 11 Aug 2023 07:33:39 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.44227.1691764419246488869 for ; Fri, 11 Aug 2023 07:33:39 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5A98D1515; Fri, 11 Aug 2023 07:34:21 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.35.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id AEA773F64C; Fri, 11 Aug 2023 07:33:36 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Kun Qin Subject: [edk2-devel] [PATCH v6 7/9] MdePkg/Rng: Add GetRngGuid() to RngLib Date: Fri, 11 Aug 2023 16:33:08 +0200 Message-Id: <20230811143310.55101-8-pierre.gondois@arm.com> In-Reply-To: <20230811143310.55101-1-pierre.gondois@arm.com> References: <20230811143310.55101-1-pierre.gondois@arm.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 Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Htz7sFzWR64ba8zdL35Q6kITx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1691764423358100041 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The EFI_RNG_PROTOCOL can use the RngLib. The RngLib has multiple implementations, some of them are unsafe (e.g. BaseRngLibTimerLib). To allow the RngDxe to detect when such implementation is used, add a GetRngGuid() function to the RngLib. Signed-off-by: Pierre Gondois Reviewed-by: Liming Gao Reviewed-by: Sami Mujawar Tested-by: Kun Qin --- .../BaseRngLibTimerLib/BaseRngLibTimerLib.inf | 4 ++ .../Library/BaseRngLibTimerLib/RngLibTimer.c | 28 +++++++++++++ MdePkg/Include/Library/RngLib.h | 17 ++++++++ MdePkg/Library/BaseRngLib/AArch64/Rndr.c | 42 +++++++++++++++++++ MdePkg/Library/BaseRngLib/BaseRngLib.inf | 10 +++++ MdePkg/Library/BaseRngLib/Rand/RdRand.c | 26 ++++++++++++ .../Library/BaseRngLibNull/BaseRngLibNull.c | 22 ++++++++++ .../Library/BaseRngLibTimerLib/RngLibTimer.c | 23 ++++++++++ MdePkg/Library/DxeRngLib/DxeRngLib.c | 28 +++++++++++++ 9 files changed, 200 insertions(+) diff --git a/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf= b/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf index f7290010604f..8461260cc812 100644 --- a/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf +++ b/MdeModulePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf @@ -29,6 +29,10 @@ [Sources] =20 [Packages] MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[Guids] + gEdkiiRngAlgorithmUnSafe =20 [LibraryClasses] BaseLib diff --git a/MdeModulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c b/MdeMod= ulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c index 980854d67b72..28ff46c71fa2 100644 --- a/MdeModulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c +++ b/MdeModulePkg/Library/BaseRngLibTimerLib/RngLibTimer.c @@ -2,14 +2,18 @@ BaseRng Library that uses the TimerLib to provide reasonably random numb= ers. Do not use this on a production system. =20 + Copyright (c) 2023, Arm Limited. All rights reserved. Copyright (c) Microsoft Corporation. SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include +#include #include +#include #include #include +#include =20 #define DEFAULT_DELAY_TIME_IN_MICROSECONDS 10 =20 @@ -190,3 +194,27 @@ GetRandomNumber128 ( // Read second 64 bits return GetRandomNumber64 (++Rand); } + +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ) +{ + if (RngGuid =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + CopyMem (RngGuid, &gEdkiiRngAlgorithmUnSafe, sizeof (*RngGuid)); + return EFI_SUCCESS; +} diff --git a/MdePkg/Include/Library/RngLib.h b/MdePkg/Include/Library/RngLi= b.h index 429ed19e287e..945482cd5e56 100644 --- a/MdePkg/Include/Library/RngLib.h +++ b/MdePkg/Include/Library/RngLib.h @@ -1,6 +1,7 @@ /** @file Provides random number generator services. =20 +Copyright (c) 2023, Arm Limited. All rights reserved.
Copyright (c) 2015, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -77,4 +78,20 @@ GetRandomNumber128 ( OUT UINT64 *Rand ); =20 +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ); + #endif // __RNG_LIB_H__ diff --git a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c b/MdePkg/Library/Base= RngLib/AArch64/Rndr.c index 20811bf3ebf3..d39db62153ee 100644 --- a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c +++ b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c @@ -2,6 +2,7 @@ Random number generator service that uses the RNDR instruction to provide pseudorandom numbers. =20 + Copyright (c) 2023, Arm Limited. All rights reserved.
Copyright (c) 2021, NUVIA Inc. All rights reserved.
Copyright (c) 2015, Intel Corporation. All rights reserved.
=20 @@ -11,6 +12,7 @@ =20 #include #include +#include #include #include =20 @@ -138,3 +140,43 @@ ArchIsRngSupported ( { return mRndrSupported; } + +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ) +{ + GUID *RngLibGuid; + + if (RngGuid =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (!mRndrSupported) { + return EFI_UNSUPPORTED; + } + + // + // If the platform advertises the algorithm behind RNDR instruction, + // use it. Otherwise use gEfiRngAlgorithmArmRndr. + // + RngLibGuid =3D PcdGetPtr (PcdCpuRngSupportedAlgorithm); + if (!IsZeroGuid (RngLibGuid)) { + CopyMem (RngGuid, RngLibGuid, sizeof (*RngGuid)); + } else { + CopyMem (RngGuid, &gEfiRngAlgorithmArmRndr, sizeof (*RngGuid)); + } + + return EFI_SUCCESS; +} diff --git a/MdePkg/Library/BaseRngLib/BaseRngLib.inf b/MdePkg/Library/Base= RngLib/BaseRngLib.inf index 1fcceb941495..49503b139be9 100644 --- a/MdePkg/Library/BaseRngLib/BaseRngLib.inf +++ b/MdePkg/Library/BaseRngLib/BaseRngLib.inf @@ -4,6 +4,7 @@ # BaseRng Library that uses CPU RNG instructions (e.g. RdRand) to # provide random numbers. # +# Copyright (c) 2023, Arm Limited. All rights reserved.
# Copyright (c) 2021, NUVIA Inc. All rights reserved.
# Copyright (c) 2015, Intel Corporation. All rights reserved.
# @@ -43,9 +44,18 @@ [Sources.AARCH64] AArch64/ArmReadIdIsar0.asm | MSFT AArch64/ArmRng.asm | MSFT =20 +[Guids.AARCH64] + gEfiRngAlgorithmArmRndr + +[Guids.Ia32, Guids.X64] + gEfiRngAlgorithmSp80090Ctr256Guid + [Packages] MdePkg/MdePkg.dec =20 +[Pcd.AARCH64] + gEfiMdePkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm + [LibraryClasses] BaseLib DebugLib diff --git a/MdePkg/Library/BaseRngLib/Rand/RdRand.c b/MdePkg/Library/BaseR= ngLib/Rand/RdRand.c index 070d41e2555f..9bd68352f9f7 100644 --- a/MdePkg/Library/BaseRngLib/Rand/RdRand.c +++ b/MdePkg/Library/BaseRngLib/Rand/RdRand.c @@ -2,6 +2,7 @@ Random number generator services that uses RdRand instruction access to provide high-quality random numbers. =20 +Copyright (c) 2023, Arm Limited. All rights reserved.
Copyright (c) 2021, NUVIA Inc. All rights reserved.
Copyright (c) 2015, Intel Corporation. All rights reserved.
=20 @@ -11,6 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include #include +#include #include =20 #include "BaseRngLibInternals.h" @@ -128,3 +130,27 @@ ArchIsRngSupported ( */ return TRUE; } + +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ) +{ + if (RngGuid =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + CopyMem (RngGuid, &gEfiRngAlgorithmSp80090Ctr256Guid, sizeof (*RngGuid)); + return EFI_SUCCESS; +} diff --git a/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c b/MdePkg/Librar= y/BaseRngLibNull/BaseRngLibNull.c index efba5c851ead..af5e8eb8f72a 100644 --- a/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c +++ b/MdePkg/Library/BaseRngLibNull/BaseRngLibNull.c @@ -1,13 +1,16 @@ /** @file Null version of Random number generator services. =20 +Copyright (c) 2023, Arm Limited. All rights reserved.
Copyright (c) 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 +#include #include #include +#include =20 /** Generates a 16-bit random number. @@ -92,3 +95,22 @@ GetRandomNumber128 ( ASSERT (FALSE); return FALSE; } + +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ) +{ + return EFI_UNSUPPORTED; +} diff --git a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c b/MdePkg/Libra= ry/BaseRngLibTimerLib/RngLibTimer.c index c4fdd1df68d3..4a7cae78f85c 100644 --- a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c +++ b/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c @@ -212,3 +212,26 @@ GetRandomNumber128 ( // Read second 64 bits return GetRandomNumber64 (++Rand); } + +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +RETURN_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ) +{ + /* This implementation is to be replaced by its MdeModulePkg copy. + * The cause being that some GUIDs (gEdkiiRngAlgorithmUnSafe) cannot + * be defined in the MdePkg. + */ + return RETURN_UNSUPPORTED; +} diff --git a/MdePkg/Library/DxeRngLib/DxeRngLib.c b/MdePkg/Library/DxeRngLi= b/DxeRngLib.c index a01b66ad7d20..05c795759b9a 100644 --- a/MdePkg/Library/DxeRngLib/DxeRngLib.c +++ b/MdePkg/Library/DxeRngLib/DxeRngLib.c @@ -1,6 +1,7 @@ /** @file Provides an implementation of the library class RngLib that uses the Rng = protocol. =20 + Copyright (c) 2023, Arm Limited. All rights reserved. Copyright (c) Microsoft Corporation. All rights reserved. SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -207,3 +208,30 @@ GetRandomNumber128 ( =20 return TRUE; } + +/** + Get a GUID identifying the RNG algorithm implementation. + + @param [out] RngGuid If success, contains the GUID identifying + the RNG algorithm implementation. + + @retval EFI_SUCCESS Success. + @retval EFI_UNSUPPORTED Not supported. + @retval EFI_INVALID_PARAMETER Invalid parameter. +**/ +EFI_STATUS +EFIAPI +GetRngGuid ( + GUID *RngGuid + ) +{ + /* It is not possible to know beforehand which Rng algorithm will + * be used by this library. + * This API is mainly used by RngDxe. RngDxe relies on the RngLib. + * The RngLib|DxeRngLib.inf implementation locates and uses an installed + * EFI_RNG_PROTOCOL. + * It is thus not possible to have both RngDxe and RngLib|DxeRngLib.inf. + * and it is ok not to support this API. + */ + return EFI_UNSUPPORTED; +} --=20 2.25.1 -=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 (#107716): https://edk2.groups.io/g/devel/message/107716 Mute This Topic: https://groups.io/mt/100684695/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- From nobody Fri May 10 07:36:47 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+107717+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+107717+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1691764423; cv=none; d=zohomail.com; s=zohoarc; b=G79bMwf+W3scGHFoPBxBgo9rpohAZ8PPDde1GmG54pJOj4Q4v5K3U/dSh6jo2lJzmeoqZx3yfrqXPjOC5fxUvupuYz/wTCCo7J9ElgAfTysslXHgKG26MjujbgD4MqMV+JqZtv8n764+SX672O20EkRhS3GH+TTEMxNT4mksH5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691764423; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=AZPPxzz2cfT/uCPV8aBxwXeCAw2FEe27IyUBDrSyiJ8=; b=lrWj/Ch41hENpmANQ1pYO141aCbtJvkUWjjN/McU9bE+NXaNDSqP9QPP/amVKvHN9ccldhJh9FO3CFXZmW24aWJ9qYRH+GrJKmor9pJqyckotuweNELZzPnNw7FpR0MRllcWM4pt6gJtLzZ6rYkFY6uySnCNgfbZPJeu8p04qF0= 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+107717+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 169176442314225.218794146699224; Fri, 11 Aug 2023 07:33:43 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=njyDwmfYJqrYdR13Azd/3tzvCh9ElJV0bm1g/Ie2rQ0=; 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=1691764422; v=1; b=Uwra5IFdobEta9Kk4l6OspK5GQUvL6DvScZdFjiY9k5gklWERVA+/MAdazk4vZ25ttBGPNy/ IK2uEupJ0T+gkY2N7PGRFSYsbEC1qCA7g+cPdTs4+ERE54t4w4uJI53r56aCzizwpU7YUgPTyqx GCU/81z2/FUwsLIg6i7/HFNs= X-Received: by 127.0.0.2 with SMTP id 7rQlYY1788612xjcce9yFuti; Fri, 11 Aug 2023 07:33:42 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.44229.1691764421943122173 for ; Fri, 11 Aug 2023 07:33:42 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 07FAF150C; Fri, 11 Aug 2023 07:34:24 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.35.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5C2623F64C; Fri, 11 Aug 2023 07:33:39 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Kun Qin Subject: [edk2-devel] [PATCH v6 8/9] SecurityPkg/RngDxe: Use GetRngGuid() when probing RngLib Date: Fri, 11 Aug 2023 16:33:09 +0200 Message-Id: <20230811143310.55101-9-pierre.gondois@arm.com> In-Reply-To: <20230811143310.55101-1-pierre.gondois@arm.com> References: <20230811143310.55101-1-pierre.gondois@arm.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 Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: q9Ke90UJVt8HwckTvQIhIMyTx1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1691764423548100043 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4151 The EFI_RNG_PROTOCOL can rely on the RngLib. The RngLib has multiple implementations, some of them are unsafe (e.g. BaseRngLibTimerLib). To allow the RngDxe to detect when such implementation is used, a GetRngGuid() function was added in a previous patch. The EFI_RNG_PROTOCOL can advertise multiple algorithms through Guids. The PcdCpuRngSupportedAlgorithm is currently used to advertise the RngLib in the Arm implementation. The issues of doing that are: - the RngLib implementation might not use CPU instructions, cf. the BaseRngLibTimerLib - most platforms don't set PcdCpuRngSupportedAlgorithm A GetRngGuid() was added to the RngLib in a previous patch, allowing to identify the algorithm implemented by the RngLib. Make use of this function and place the unsage algorithm at the last position in the mAvailableAlgoArray. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar Tested-by: Kun Qin --- .../RngDxe/AArch64/AArch64Algo.c | 55 +++++++++++++------ .../RandomNumberGenerator/RngDxe/ArmRngDxe.c | 6 +- .../RandomNumberGenerator/RngDxe/RngDxe.inf | 4 +- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c= b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c index e8be217f8a8c..a270441ebba0 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include =20 #include "RngDxeInternals.h" =20 @@ -28,9 +30,13 @@ GetAvailableAlgorithms ( VOID ) { - UINT64 DummyRand; - UINT16 MajorRevision; - UINT16 MinorRevision; + EFI_STATUS Status; + UINT16 MajorRevision; + UINT16 MinorRevision; + GUID RngGuid; + BOOLEAN UnSafeAlgo; + + UnSafeAlgo =3D FALSE; =20 // Rng algorithms 2 times, one for the allocation, one to populate. mAvailableAlgoArray =3D AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX); @@ -38,24 +44,29 @@ GetAvailableAlgorithms ( return EFI_OUT_OF_RESOURCES; } =20 - // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. - if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) { - CopyMem ( - &mAvailableAlgoArray[mAvailableAlgoArrayCount], - PcdGetPtr (PcdCpuRngSupportedAlgorithm), - sizeof (EFI_RNG_ALGORITHM) - ); - mAvailableAlgoArrayCount++; - - DEBUG_CODE_BEGIN (); - if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) { + // Identify RngLib algorithm. + Status =3D GetRngGuid (&RngGuid); + if (!EFI_ERROR (Status)) { + if (IsZeroGuid (&RngGuid) || + CompareGuid (&RngGuid, &gEdkiiRngAlgorithmUnSafe)) + { + // Treat zero GUID as an unsafe algorithm DEBUG (( DEBUG_WARN, - "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n" + "RngLib uses an Unsafe algorithm and " + "must not be used for production builds.\n" )); + // Set the UnSafeAlgo flag to indicate an unsafe algorithm was found + // so that it can be added at the end of the algorithm list. + UnSafeAlgo =3D TRUE; + } else { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + &RngGuid, + sizeof (RngGuid) + ); + mAvailableAlgoArrayCount++; } - - DEBUG_CODE_END (); } =20 // Raw algorithm (Trng) @@ -68,5 +79,15 @@ GetAvailableAlgorithms ( mAvailableAlgoArrayCount++; } =20 + // Add unsafe algorithm at the end of the list. + if (UnSafeAlgo) { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + &gEdkiiRngAlgorithmUnSafe, + sizeof (EFI_RNG_ALGORITHM) + ); + mAvailableAlgoArrayCount++; + } + return EFI_SUCCESS; } diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Securit= yPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index ce49ff7ae661..78a18c5e1177 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -78,6 +78,7 @@ RngGetRNG ( { EFI_STATUS Status; UINTN Index; + GUID RngGuid; =20 if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; @@ -102,7 +103,10 @@ RngGetRNG ( } =20 FoundAlgo: - if (CompareGuid (RNGAlgorithm, PcdGetPtr (PcdCpuRngSupportedAlgorithm)))= { + Status =3D GetRngGuid (&RngGuid); + if (!EFI_ERROR (Status) && + CompareGuid (RNGAlgorithm, &RngGuid)) + { Status =3D RngGetBytes (RNGValueLength, RNGValue); return Status; } diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index d6c2d30195bf..8704a644414f 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -75,13 +75,11 @@ [Guids] gEfiRngAlgorithmX9313DesGuid ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG gEfiRngAlgorithmX931AesGuid ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG gEfiRngAlgorithmRaw ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG + gEdkiiRngAlgorithmUnSafe ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG =20 [Protocols] gEfiRngProtocolGuid ## PRODUCES =20 -[Pcd.AARCH64] - gEfiMdePkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm ## CONSUMES - [Depex] TRUE =20 --=20 2.25.1 -=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 (#107717): https://edk2.groups.io/g/devel/message/107717 Mute This Topic: https://groups.io/mt/100684696/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- From nobody Fri May 10 07:36:47 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+107718+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+107718+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1691764425; cv=none; d=zohomail.com; s=zohoarc; b=W1JWbHiJbqnTapRpQvDLhWZxSqrv+2DSu/eLxnxcJweWCrYWrs1n0i9mD2MZOpDXdutl8Ad+KNU9VgXJmf6KzrLOkMRJ0SgNrhQDRHKx0gELuKE56bkjJim2DZ0vUFPbmASt+qnOOzMlrj008rh5zmqLessC7I17oZpxT6IQjwg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691764425; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=lpxp1zCMMOdPCgXBoVkNIJ6mxZ/enT91Nm72Cnnue+k=; b=g7spU1FrQXo9ok+K1T9ykXyetOaxF/VPYJ27kkq3HJHJQwhZa4s24+DwiU5D9e9NmHy8CtuA+wc79r6XZxjDneRXYgBaUg0cRriMBwVmHEBqV3UmqlzLKxTN4YKvyHplLTBnYH70MYfR8vokB4Nk6Yvvdex/6+o82QSAJI9fZf4= 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+107718+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1691764425727610.8868762895653; Fri, 11 Aug 2023 07:33:45 -0700 (PDT) Return-Path: DKIM-Signature: a=rsa-sha256; bh=Ul588p29LITGMdBJRN8u7LmLyVpUjFL76Dn7kXB1XsU=; 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=1691764425; v=1; b=vTGsFufqllIBCLs8UZBDgX0mzpUzINxC4Wmit7irt2UuulItux2XlZR7suaqUvg3/n5V9C2k LmB6Io4FRJHD7B56k9mF9LEP1swkxQ3BsCaMzVn9uxwNdiNsQEp7sNd0WPtohzdh27KMkmHuzsb SOBlc6a+04WYES9vwxtUeb7c= X-Received: by 127.0.0.2 with SMTP id f4XSYY1788612xwGqcmEM9hq; Fri, 11 Aug 2023 07:33:45 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.44283.1691764424562362588 for ; Fri, 11 Aug 2023 07:33:44 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A91A31516; Fri, 11 Aug 2023 07:34:26 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.35.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 09C013F64C; Fri, 11 Aug 2023 07:33:41 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu , Jiewen Yao , Jian J Wang , Ard Biesheuvel , Sami Mujawar , Kun Qin Subject: [edk2-devel] [PATCH v6 9/9] SecurityPkg/RngDxe: Simplify Rng algorithm selection for Arm Date: Fri, 11 Aug 2023 16:33:10 +0200 Message-Id: <20230811143310.55101-10-pierre.gondois@arm.com> In-Reply-To: <20230811143310.55101-1-pierre.gondois@arm.com> References: <20230811143310.55101-1-pierre.gondois@arm.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 Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: ALWpVLF70Tn8aKIaih0HoOEux1787277AA= Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1691764427352100001 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The first element of mAvailableAlgoArray is defined as the default Rng algorithm to use. Don't go through the array at each RngGetRNG() call and just return the first element of the array. Signed-off-by: Pierre Gondois Reviewed-by: Sami Mujawar Tested-by: Kun Qin --- .../RandomNumberGenerator/RngDxe/ArmRngDxe.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Securit= yPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index 78a18c5e1177..7a42e3cbe3d2 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -77,7 +77,6 @@ RngGetRNG ( ) { EFI_STATUS Status; - UINTN Index; GUID RngGuid; =20 if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { @@ -88,21 +87,13 @@ RngGetRNG ( // // Use the default RNG algorithm if RNGAlgorithm is NULL. // - for (Index =3D 0; Index < mAvailableAlgoArrayCount; Index++) { - if (!IsZeroGuid (&mAvailableAlgoArray[Index])) { - RNGAlgorithm =3D &mAvailableAlgoArray[Index]; - goto FoundAlgo; - } - } - - if (Index =3D=3D mAvailableAlgoArrayCount) { - // No algorithm available. - ASSERT (Index !=3D mAvailableAlgoArrayCount); - return EFI_DEVICE_ERROR; + if (mAvailableAlgoArrayCount !=3D 0) { + RNGAlgorithm =3D &mAvailableAlgoArray[0]; + } else { + return EFI_UNSUPPORTED; } } =20 -FoundAlgo: Status =3D GetRngGuid (&RngGuid); if (!EFI_ERROR (Status) && CompareGuid (RNGAlgorithm, &RngGuid)) --=20 2.25.1 -=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 (#107718): https://edk2.groups.io/g/devel/message/107718 Mute This Topic: https://groups.io/mt/100684698/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-