From nobody Fri May 10 08:13:50 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+106686+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+106686+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1688633554; cv=none; d=zohomail.com; s=zohoarc; b=bK8aXsgRyoHfCqarFGGcAGlyWGVov+fuLss2qKRkz2KtvYbAGPVhUinZA/xx8EkqQBKESmVqCIsYoCXrYNQ6sLBPtcYchBi13lG1CpRyLXQYCvueUM4iOgaGjcW2YPi/AyIk944+m8aNTNPQqEjeHKeNFN98CYo1J3Pm6V6uxzQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688633554; 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=YMCGuIzVkTdbP2X3Q6tZ8tC6OyOBSvtpFcWteTDfWWY=; b=KXKA4v/E06Aoq7q/SH4SdrdHwq1Pmf0D5x2B6CkTgqJFaO9Ipsr6SxqNQTI4EYMVtrmw/kiQH/c9HBpRF6MtWazAaGndbvlNDeIfDuk15DDJidkdr1kX63mg1gsWadS16/98SBEmy/N8Pju5xbtKVydcJUGYBsZFBPvpq82ZkDo= 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+106686+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 1688633554117677.959905266091; Thu, 6 Jul 2023 01:52:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ASlmYY1788612x8rhOZ3duPU; Thu, 06 Jul 2023 01:52:33 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.17194.1688633552998185212 for ; Thu, 06 Jul 2023 01:52:33 -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 9AE5EC14; Thu, 6 Jul 2023 01:53:14 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.86.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1DE9B3F73F; Thu, 6 Jul 2023 01:52:29 -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 , Jose Marinho , Kun Qin Subject: [edk2-devel] [PATCH v3 1/6] SecurityPkg/SecurityPkg.dec: Move PcdCpuRngSupportedAlgorithm to MdePkg Date: Thu, 6 Jul 2023 10:51:54 +0200 Message-Id: <20230706085159.626374-2-pierre.gondois@arm.com> In-Reply-To: <20230706085159.626374-1-pierre.gondois@arm.com> References: <20230706085159.626374-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: gqkctr0ZUo4oJb1Gp2RpWSOjx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688633553; bh=UrXE1PGbY6IfzKGt3izIz0A8pfZBm+R3GPJ+zhgzJ5Y=; h=Cc:Date:From:Reply-To:Subject:To; b=TcX0SukUDTkJT01f4tuUAZ/MswLKMvb80z5CxLttSa9cmfbwbwd+mCXxNe/BUre7dTB qx2xzbDF6WgXUqY4Zg+aUCH2RQEQbYi+Di2B0+fvhnisFA2cLNw4U3cCDBWeFhshi4AFA K6TaFbZJ2vdpqSnkpCvTA7J/NJSqSBIH3Qk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688633554417100006 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: Sami Mujawar Tested-by: Kun Qin tested-by tag, but the changes should be quite small, --- Notes: v2: - Change gEfiMdePkgTokenSpaceGuid.PcdCpuRngSupportedAlgorithm token number - Rename to 'SecurityPkg/SecurityPkg.dec: Move PcdCpuRngSupportedAlgorithm to MdePkg' MdePkg/MdePkg.dec | 5 +++++ SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf | 4 ++-- SecurityPkg/SecurityPkg.dec | 2 -- 3 files changed, 7 insertions(+), 4 deletions(-) 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 (#106686): https://edk2.groups.io/g/devel/message/106686 Mute This Topic: https://groups.io/mt/99981852/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 08:13:50 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+106687+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+106687+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1688633556; cv=none; d=zohomail.com; s=zohoarc; b=SV7AkGvMj+S2RjA4+ltdqDTlinB++l/7DZ7Iqn987rC9eikcf5aIiIWl5UD4VLe44pp63LewrJJdgwLXnVJrkNk+/fTEPI3KUtCB8mHJDJFQK0yiiNZiwOt9DWwXvuhAlQdXGQfHmkMiHfNtvTKPJzNyHWp94znzzJKoKuK9iHU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688633556; 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=oL3gB+iJBczVMPr9W5FZ0IqeHSJ/g4mVyjKBRSCb6Lo=; b=aI1ZMDsZUsV2Sfk67Av9VM6CkvTWHtEOMaPVOfV5MmNgL9WDUyu18D/eCl5T2OGH1TRibvBaXbwcH53Z5NhwuRE2jm4TtqQ10nSd7V3yrrYa99YEdDt0aw+y5xPOT03b8JCaMM7SXoYX+aAYxMnMong6W75L/CVUqvnGhz2YjYQ= 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+106687+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 1688633556543807.4905659807764; Thu, 6 Jul 2023 01:52:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YmN3YY1788612x33JpWd6Faq; Thu, 06 Jul 2023 01:52:36 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.17196.1688633555621121298 for ; Thu, 06 Jul 2023 01:52:35 -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 48C79DE0; Thu, 6 Jul 2023 01:53:17 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.86.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D3AE53F73F; Thu, 6 Jul 2023 01:52:32 -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 , Jose Marinho , Kun Qin Subject: [edk2-devel] [PATCH v3 2/6] MdePkg/DxeRngLib: Request raw algorithm instead of default Date: Thu, 6 Jul 2023 10:51:55 +0200 Message-Id: <20230706085159.626374-3-pierre.gondois@arm.com> In-Reply-To: <20230706085159.626374-1-pierre.gondois@arm.com> References: <20230706085159.626374-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: MIuI8yxEi73CghOeozSyP00jx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688633556; bh=5F/rSKBh4JMheymDnbk7xaQWxayhxoYtpYrTrWlM94k=; h=Cc:Date:From:Reply-To:Subject:To; b=SU289jmqqNJbPO3KRu8rkybIcycxXxaot1CAfNqAtlaZn6ktMjWcz/rmDGUnpBC5CCX Hfe6uqcivJKdgT4rcMveaL/Hg3OHphgO5hClRyHZLVprQbfz9fIMHXDxerjoXSgOmfjQZ bgT50S2ufv/NKbv9hPtL4ZUaC8jandcgVoY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688633558128100001 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 Tested-by: Kun Qin tested-by tag, but the changes should be quite small, --- 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 (#106687): https://edk2.groups.io/g/devel/message/106687 Mute This Topic: https://groups.io/mt/99981853/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 08:13:50 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+106688+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+106688+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1688633559; cv=none; d=zohomail.com; s=zohoarc; b=XWAN8qYAYozjSd/jP+k3yedh2yR02UK8LOCXrh2a73Jwv7u5hUXbaMjjm7gTrvxobHHqJ/sIPbFKrm8SUErLVQPZUhI3TGYGQ3OlpCd17qIGZGvNLcInMCDhI+gDHN2bse3JlxARrWsl6wlU1wiGYnlYSZxBgA22tcT4A+qBU+Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688633559; 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=9WczzBsno4kZJUDxpMLIu52TCS6cryEeKcjeLR9Qzvw=; b=NWZbB8g82htHwBna61vNtzU6atAAZ0KumlQ1nj8WgvZMS19LzvPgZaegKPTdJvFgQ8UTalJvW0JvTa1/0agdxA+qAUP91N27sm4OhTN3B6Bs6JLFlTVlfNPVo5IdWr02B9ZTEoZgNE5M3psWrMLIlEpDVmMOvqijKuo1mSmjGxE= 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+106688+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 1688633559191597.6637496387258; Thu, 6 Jul 2023 01:52:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id SLQRYY1788612xvmblIOFC7V; Thu, 06 Jul 2023 01:52:38 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.17197.1688633558141717638 for ; Thu, 06 Jul 2023 01:52:38 -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 D14E41474; Thu, 6 Jul 2023 01:53:19 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.86.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9F4ED3F73F; Thu, 6 Jul 2023 01:52:35 -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 , Jose Marinho , Kun Qin Subject: [edk2-devel] [PATCH v3 3/6] MdePkg/Rng: Add GUIDs to describe Rng algorithms Date: Thu, 6 Jul 2023 10:51:56 +0200 Message-Id: <20230706085159.626374-4-pierre.gondois@arm.com> In-Reply-To: <20230706085159.626374-1-pierre.gondois@arm.com> References: <20230706085159.626374-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: CJYJOPJkuIxUXclJDG4wr8aEx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688633558; bh=i+JGpftxnbQECEKQ17uuTK3dIdnFJx/JRab71njSuWw=; h=Cc:Date:From:Reply-To:Subject:To; b=Yys2H+IIFNFU69Y/RK0FYsIyroJ+BaVcQyPCDi1SpJhMlCo2aL9fOu6hxnAOUCK6mn1 GHwrvhkkfzTBqeH5CvxlT33OQLvYh8u0RF9yuUOSexP47nOCmqY/vlnbUVhNsvTZsZl07 H8POlkXX//zB06jjKvNQk0wfw52/weA9ewo= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688633560425100005 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 GUIDs describing Rng algorithms: - 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. - gEdkiiRngAlgorithmUnSafe to describe an unsafe implementation, cf. the BaseRngLibTimerLib. [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 Tested-by: Kun Qin tested-by tag, but the changes should be quite small, --- MdePkg/Include/Protocol/Rng.h | 20 ++++++++++++++++++++ MdePkg/MdePkg.dec | 2 ++ 2 files changed, 22 insertions(+) diff --git a/MdePkg/Include/Protocol/Rng.h b/MdePkg/Include/Protocol/Rng.h index baf425587b3c..ceae77ba9c73 100644 --- a/MdePkg/Include/Protocol/Rng.h +++ b/MdePkg/Include/Protocol/Rng.h @@ -67,6 +67,24 @@ 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} \ + } +/// +/// 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 } \ + } =20 /** Returns information about the random number generation implementation. @@ -146,5 +164,7 @@ extern EFI_GUID gEfiRngAlgorithmSp80090Ctr256Guid; extern EFI_GUID gEfiRngAlgorithmX9313DesGuid; extern EFI_GUID gEfiRngAlgorithmX931AesGuid; extern EFI_GUID gEfiRngAlgorithmRaw; +extern EFI_GUID gEfiRngAlgorithmArmRndr; +extern EFI_GUID gEdkiiRngAlgorithmUnSafe; =20 #endif diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 5b8477f4cb8f..2c8f985f253e 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -643,6 +643,8 @@ [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 }} + gEdkiiRngAlgorithmUnSafe =3D { 0x869f728c, 0x409d, 0x4ab4, {0x= ac, 0x03, 0x71, 0xd3, 0x09, 0xc1, 0xb3, 0xf4 }} =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 (#106688): https://edk2.groups.io/g/devel/message/106688 Mute This Topic: https://groups.io/mt/99981855/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 08:13:50 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+106689+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+106689+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1688633561; cv=none; d=zohomail.com; s=zohoarc; b=WG8mm924kSRnbf9wSj2VsIhZFYZY+HUohL+A1BT3mIrO2s0hHcA77RM370TCou8D/KZ4fXkWcXO+vs1nEbcgFCa1Lm8sbv4yb3uWGXKW7CfgDUgQD5eHQPabAuOjIxSwfK+Dgs+g76f+S2VUFMiRy+7biWd7QgJPnXikxEdfHEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688633561; 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=i2EvdR4hD+l8iSqTtnQP1W5pWMzvg847sSTWaZHmgZc=; b=OpSiZ/5zRkzXmEqqpgS2Fl331gQ5KuAVlTS/IMTQj91q8m8stWdvafk+RsIvhRsbqEiROyIAQRMioeNhPcGAFNJ4teEAbx+delUiOqqXrm19kpDidTfq8Yju6ZRXuTayRQNxWkcW8HL1scRlAJPjSUYKSkUowYUJGhr41njGu5w= 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+106689+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 16886335616771011.9916176670455; Thu, 6 Jul 2023 01:52:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 0TLFYY1788612xC7Ynf3djmp; Thu, 06 Jul 2023 01:52:41 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.17200.1688633560847642815 for ; Thu, 06 Jul 2023 01:52:41 -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 895FC1477; Thu, 6 Jul 2023 01:53:22 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.86.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 348573F73F; Thu, 6 Jul 2023 01:52:38 -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 , Jose Marinho , Kun Qin Subject: [edk2-devel] [PATCH v3 4/6] MdePkg/Rng: Add GetRngGuid() to RngLib Date: Thu, 6 Jul 2023 10:51:57 +0200 Message-Id: <20230706085159.626374-5-pierre.gondois@arm.com> In-Reply-To: <20230706085159.626374-1-pierre.gondois@arm.com> References: <20230706085159.626374-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: DeuGg30VpnksBpQ6IP67Ypyxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688633561; bh=xotYlifxSp5p9ICdxhKeVFBd0zDSWqC1pbiFMAEBwgk=; h=Cc:Date:From:Reply-To:Subject:To; b=qADWbx2GaxB46JiCqReWtepa3HxfyYSDk5mrnow1no56aZvnoUt3B2MGkD344SpXG1R BPHExZB2qtOLJg3gP/O/NzB9QpR1UNZLjlia8mbOPQQcCN/VoLLapmC72pu3WpEbpla/t 9WIs5fePn6tU0vukX+IgkLokVuIz+HYzuYs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688633562582100011 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: Sami Mujawar Tested-by: Kun Qin tested-by tag, but the changes should be quite small, --- 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 ++++++++++ .../BaseRngLibTimerLib/BaseRngLibTimerLib.inf | 3 ++ .../Library/BaseRngLibTimerLib/RngLibTimer.c | 28 +++++++++++++ MdePkg/Library/DxeRngLib/DxeRngLib.c | 28 +++++++++++++ 8 files changed, 176 insertions(+) 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/BaseRngLibTimerLib.inf b/Mde= Pkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf index f857290e823b..76279b844962 100644 --- a/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf +++ b/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf @@ -30,6 +30,9 @@ [Sources] [Packages] MdePkg/MdePkg.dec =20 +[Guids] + gEdkiiRngAlgorithmUnSafe + [LibraryClasses] BaseLib DebugLib diff --git a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c b/MdePkg/Libra= ry/BaseRngLibTimerLib/RngLibTimer.c index 980854d67b72..110fad7cc116 100644 --- a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c +++ b/MdePkg/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/Library/DxeRngLib/DxeRngLib.c b/MdePkg/Library/DxeRngLi= b/DxeRngLib.c index a01b66ad7d20..cd23859e3112 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 (#106689): https://edk2.groups.io/g/devel/message/106689 Mute This Topic: https://groups.io/mt/99981857/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 08:13:50 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+106690+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+106690+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1688633564; cv=none; d=zohomail.com; s=zohoarc; b=nFTiTU2eI7leiSI1PE7B8UrejxMEVP3e2Zvm8U27sP2naGu8ebSftvMeehkfIMm7+mQ5fHzCF3jah9fw1t5WeY09PuZLEKCvhgYkq74SZLyUdyMooNGP+xwGjbzem6LWg9XSIkuUqWJyvDIoVlLZlkOiEozU6P4VbKToUDuIR4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688633564; 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=Qno6MdIW5S1/qU1UtVf3PPf+vwhi0e2YEuTvaV5Xj88=; b=EHMzRTI6JxhH/wRkkM97fP0S4fFh2htwTUXqzZ6v4a56FHDI1hAreggOAW3hHOpyGnfTqdbO0+nu8xjjJXltBRIlLM+TqUDSpsp04pJUfYg9t7HK9Od/yH+LR8FFiqv1syCf8WDyjdjh9nuKktawayH+dxxAHaI7rM+KVSrmF+A= 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+106690+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 1688633564363615.8686436381182; Thu, 6 Jul 2023 01:52:44 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 71oCYY1788612xJGnIXpTKdL; Thu, 06 Jul 2023 01:52:44 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.17202.1688633563458043535 for ; Thu, 06 Jul 2023 01:52:43 -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 2AF472F4; Thu, 6 Jul 2023 01:53:25 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.86.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C2D9F3F73F; Thu, 6 Jul 2023 01:52:40 -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 , Jose Marinho , Kun Qin Subject: [edk2-devel] [PATCH v3 5/6] SecurityPkg/RngDxe: Use GetRngGuid() when probing RngLib Date: Thu, 6 Jul 2023 10:51:58 +0200 Message-Id: <20230706085159.626374-6-pierre.gondois@arm.com> In-Reply-To: <20230706085159.626374-1-pierre.gondois@arm.com> References: <20230706085159.626374-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: HqsnSWMkTYuOB5OhbNt2T8Nqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688633564; bh=f6g6yF28IO3ZKVhLz9JqqVCPz9A1JLGgbzjNFwnxBy8=; h=Cc:Date:From:Reply-To:Subject:To; b=wSrPTFtzkDIpyg1DlRs1ZlR9Q1hlgX/ZNRts3U/W0w6m/+2IXJj2qcWapJHTb3khq4x J1+vUiEXxJTBRGjR/CooBj2aABDK37GWe9eIIsPrGP9CXvlGo+qwatvh7bnd/duV3AM+6 Q629D+LUHGcXtRbWzRQD854wsMQvcqPRhzg= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688633566216100001 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 tested-by tag, but the changes should be quite small, --- .../RngDxe/AArch64/AArch64Algo.c | 54 +++++++++++++------ .../RandomNumberGenerator/RngDxe/ArmRngDxe.c | 6 ++- .../RandomNumberGenerator/RngDxe/RngDxe.inf | 5 +- 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..d355f575d5c8 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c @@ -10,6 +10,7 @@ #include #include #include +#include =20 #include "RngDxeInternals.h" =20 @@ -28,9 +29,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 +43,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 +78,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..27d3e39a675b 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -75,13 +75,12 @@ [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 + gEfiRngAlgorithmArmRndr ## 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 (#106690): https://edk2.groups.io/g/devel/message/106690 Mute This Topic: https://groups.io/mt/99981859/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 08:13:50 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+106691+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+106691+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1688633567; cv=none; d=zohomail.com; s=zohoarc; b=YUHgSDnV0yHDCNrDaiRA6VO73lNdaTqZDwewOqK/1t6NRpCk1WuORz0uqgVY8tyOPFjgb83/SBrwwqjX2DOCoaD4Z35tz/wqU0S1Gf60SVSRyrZbreoI/9QmDKK4uHS+F0KrvDLVX4kyWszUEmXYAnX0kubNN9wayO86T/t6e+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688633567; 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=tbUqbnGJYbUcfSwu/Tb+1zyaTUkr7hAwL396URIL9nM=; b=CZ7jT9x/GsvNFB1/kejN/X7mKdY5wV1vesKpVAjjXoOTk+11l5BLNmGit5fktZpsc9IRorOU6popdruAcugelXx9khlVnULydj8tTUpJzmE09paQe5B6pzVkcKRbOBAml5KUAWR/353AzpHhNUNnKoiDFhfWP8rMN5GoTOiXzF8= 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+106691+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 16886335670947.560917854931745; Thu, 6 Jul 2023 01:52:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9pISYY1788612xCXCDzcuW3H; Thu, 06 Jul 2023 01:52:46 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.17204.1688633566238704533 for ; Thu, 06 Jul 2023 01:52:46 -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 E745EC14; Thu, 6 Jul 2023 01:53:27 -0700 (PDT) X-Received: from e126645.arm.com (unknown [10.57.86.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 831E13F73F; Thu, 6 Jul 2023 01:52:43 -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 , Jose Marinho , Kun Qin Subject: [edk2-devel] [PATCH v3 6/6] SecurityPkg/RngDxe: Simplify Rng algorithm selection for Arm Date: Thu, 6 Jul 2023 10:51:59 +0200 Message-Id: <20230706085159.626374-7-pierre.gondois@arm.com> In-Reply-To: <20230706085159.626374-1-pierre.gondois@arm.com> References: <20230706085159.626374-1-pierre.gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: fuNQqSZNh76yu3oUhrdXUgr0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1688633566; bh=Pp1FS0cZiHk+NvQEuMy0SakDEDYdQQsK36DxmbY72jE=; h=Cc:Date:From:Reply-To:Subject:To; b=odxQAgAEbT5F75QQ1esP6OJPIuNtcfOL+yLh8vNIuy3AZFawDkvJbZ+hiwdyo624HyS 8w0fYGx+Kc09C9j/niLjXif1sRk61bMrZptPo3ItSNYnXN09bhS94sXntFqT9k1+dOrIp Qe44ws3NdE/mB7OysQ8d4ESTxohrKdUgt1k= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1688633568227100006 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 tested-by tag, but the changes should be quite small, --- .../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 (#106691): https://edk2.groups.io/g/devel/message/106691 Mute This Topic: https://groups.io/mt/99981860/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-