From nobody Mon Apr 29 22:15:23 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+100807+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+100807+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1678209463; cv=none; d=zohomail.com; s=zohoarc; b=QX8jG9ePDNNgYJLTaAfhK2nQ9tXqoQk93Rp5MOKUNeUyoRj4msCeYQ4khYWfQ140AZpONLS1eb8Ge78dqRPwVMBQannB1fu6NJa516dRdYCRKHOiLx8Sv6kCbZpCqVEVnqX0dr+1OdwbpnutQ/lZAj7jO4tfKFfbg0apJJDbldQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678209463; 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=bcGPc25sX4tFDaZ/KvWts0gHhZJ0PICgUnKDMF/lHz4=; b=KoGAZ+QNTSj++W99e7CIH9NKhjIyYCJUQjxHRffMqmEHf/ZmeP4qI3YTEwVrRgrgMA0OIrPzC6lvfCcb2sXBdAEQK66P2tke2h2u9zBVNDnlZGgoDuKJvarqLFgUVwNl590ewkbIfAyGcZzCZ2GG1q4KyfYhAs6CEchQeB8DyrA= 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+100807+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 1678209463549405.27072609926097; Tue, 7 Mar 2023 09:17:43 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id p3ZdYY1788612xbQgRixzTMt; Tue, 07 Mar 2023 09:17:43 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.52.1678209396703085264 for ; Tue, 07 Mar 2023 09:16:36 -0800 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 0013A1C2B; Tue, 7 Mar 2023 09:17:19 -0800 (PST) X-Received: from cam-smtp0.cambridge.arm.com (pierre123.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 88B043F67D; Tue, 7 Mar 2023 09:16:34 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: ardb+tianocore@kernel.org, leif@nuviainc.com, sami.mujawar@arm.com, Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v4 1/2] SecurityPkg/RngDxe: Simplify Rng algorithm selection for Arm Date: Tue, 7 Mar 2023 18:15:49 +0100 Message-Id: <20230307171550.555541-2-pierre.gondois@arm.com> In-Reply-To: <20230307171550.555541-1-pierre.gondois@arm.com> References: <20230307171550.555541-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: nazqSv7rdCu9lREMYns7BiBUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1678209463; bh=klPgGgfEwHND/U1NlgeqjeVcOWzvb3nMtbD8m5D6Dgk=; h=Cc:Date:From:Reply-To:Subject:To; b=mVZAC1RVkkfo/PWmmh8EEw6ucONUZ6K+bogv0ysd7qG1pGZ+610n7oCzYdctTnkT+S4 M3dNEsqlxbv6cFrEBJpGnAKMmtwptom1rDl5jkfSOC0QACy8MuRXSHzEC8fPmJ+y4ijy5 TN2BHh/Gefjjwi7PB4SHXcgKZWoHQXx6y4w= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1678209465696100001 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The default algorithm to use is the first element of mAvailableAlgoArray. There is no need to iterate through the array to find a valid algorithm. Simplify the Rng algorithm selection by returning the first element of mAvailableAlgoArray. Signed-off-by: Pierre Gondois --- .../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 ce49ff7ae661..b8a343e3d397 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -77,7 +77,6 @@ RngGetRNG ( ) { EFI_STATUS Status; - UINTN Index; =20 if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; @@ -87,21 +86,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: if (CompareGuid (RNGAlgorithm, PcdGetPtr (PcdCpuRngSupportedAlgorithm)))= { Status =3D RngGetBytes (RNGValueLength, RNGValue); 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 (#100807): https://edk2.groups.io/g/devel/message/100807 Mute This Topic: https://groups.io/mt/97454017/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 Mon Apr 29 22:15:23 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+100808+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+100808+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1678209465; cv=none; d=zohomail.com; s=zohoarc; b=Gx0iNCo6b8dBCqNCSsRMRYIO0ZEhTLlUriFSgmo7JgDpsLW/VlsIQ/Gn2zxe/Dw0Bl+u7MbM7zISFsdU2DkM6PO88xone+1jKxaAkTJ5qvCEXA+qHpG7fJWSbi0tEUWn/Uj3ZIDtOWbMB+En6rOfL6OSR2MdCgrYESv1tGJgWOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678209465; 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=ihQowcb9m4xNdcMAZNajT1gEUf0B9dv4iIyLTb8kg90=; b=B6wIjngIUf0fzXGFo2NGmPNngLFbSUbalze1JRFOajEKm7lUO2+SHrEvGS0a2q5vEsB+I7cEES0fymL5d9WCfPF2MZKSF5WLJX6qks6QX1+4iM/IEltY7BG2wt5FsHyqmigvzLOH+2AqijmPc3RDvUhG6rAbxD1Yb/caN2j+9s4= 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+100808+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 16782094651585.582581179296994; Tue, 7 Mar 2023 09:17:45 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id uEUCYY1788612xLmgdajvjrD; Tue, 07 Mar 2023 09:17:44 -0800 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.53.1678209397175697012 for ; Tue, 07 Mar 2023 09:16:37 -0800 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 405A71CDD; Tue, 7 Mar 2023 09:17:20 -0800 (PST) X-Received: from cam-smtp0.cambridge.arm.com (pierre123.nice.arm.com [10.34.100.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C8E333F67D; Tue, 7 Mar 2023 09:16:35 -0800 (PST) From: "PierreGondois" To: devel@edk2.groups.io Cc: ardb+tianocore@kernel.org, leif@nuviainc.com, sami.mujawar@arm.com, Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v4 2/2] SecurityPkg/RngDxe: Check for NULL PcdCpuRngSupportedAlgorithm Date: Tue, 7 Mar 2023 18:15:50 +0100 Message-Id: <20230307171550.555541-3-pierre.gondois@arm.com> In-Reply-To: <20230307171550.555541-1-pierre.gondois@arm.com> References: <20230307171550.555541-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: L2O1epfCJ3lFqEBPLA5WzHGFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1678209464; bh=EpQJC6QH6v1t30fKCc6rE6/zlCvZ4NHMF2FtiCQz9To=; h=Cc:Date:From:Reply-To:Subject:To; b=wU3yHmeUA6hf9fg8O8LXA4fyN/A84ChHuYdGBFEBfAJDdgNNZmtOj15RFp38hflr0DG jTtl5QqTR9XiPzL28gZCRWkQ7q8wKQIHv8qJwqlkGfLT6E2Irr1NtKLBbM326TgD6205F ejTNlZ8itH0sjyys6Br1VdN1jhCu9biga8Y= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1678209465703100005 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 advertise multiple algorithms through Guids. The PcdCpuRngSupportedAlgorithm contains a Guid that can be configured. It represents the algorithm used in RngLib and using CPU instructions. When adding support for the Firmware Trng interface, it was made available through in the RngDxe module. In RngDxe, the algorithm associated with PcdCpuRngSupportedAlgorithm (implemented by the RngLib) was always advertised by default. It was assumed that support for RngLib and RNDR instructions should be kept in ArmVirtPkg. However this support did not exist as all ArmVirtPkg use the BaseRngLibTimerLib.inf implementation of the RngLib. Do not advertise the RngLib and PcdCpuRngSupportedAlgorithm if PcdCpuRngSupportedAlgorithm is NULL. Reported-by: Sami Mujawar Signed-off-by: Pierre Gondois --- .../RngDxe/AArch64/AArch64Algo.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c= b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c index e8be217f8a8c..c98e09363e25 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c @@ -39,23 +39,15 @@ GetAvailableAlgorithms ( } =20 // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. - if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) { + if (!IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm)) && + !EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) + { CopyMem ( &mAvailableAlgoArray[mAvailableAlgoArrayCount], PcdGetPtr (PcdCpuRngSupportedAlgorithm), sizeof (EFI_RNG_ALGORITHM) ); mAvailableAlgoArrayCount++; - - DEBUG_CODE_BEGIN (); - if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) { - DEBUG (( - DEBUG_WARN, - "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n" - )); - } - - DEBUG_CODE_END (); } =20 // Raw algorithm (Trng) --=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 (#100808): https://edk2.groups.io/g/devel/message/100808 Mute This Topic: https://groups.io/mt/97454018/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-