public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Sami Mujawar" <sami.mujawar@arm.com>
To: <devel@edk2.groups.io>
Cc: Sami Mujawar <sami.mujawar@arm.com>, <ardb+tianocore@kernel.org>,
	<leif@nuviainc.com>, <rebecca@bsdio.com>, <kraxel@redhat.com>,
	<michael.d.kinney@intel.com>, <gaoliming@byosoft.com.cn>,
	<zhiguang.liu@intel.com>, <jiewen.yao@intel.com>,
	<jian.j.wang@intel.com>, <Matteo.Carlini@arm.com>,
	<Akanksha.Jain2@arm.com>, <Ben.Adderson@arm.com>, <nd@arm.com>
Subject: [PATCH v1 7/9] SecurityPkg: Restructure checks in RngGetInfo
Date: Thu, 30 Sep 2021 16:40:42 +0100	[thread overview]
Message-ID: <20210930154044.37336-8-sami.mujawar@arm.com> (raw)
In-Reply-To: <20210930154044.37336-1-sami.mujawar@arm.com>

Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)

Move the check to see if the RNGAlgorithmList pointer is NULL to
ArchGetSupportedRngAlgorithms(). This allows the caller to obtain
the buffer size required to store the Algorithm List by passing
RNGAlgorithmListSize as zero and RNGAlgorithmList as NULL.

Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
---
 SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c     |  6 ++++++
 SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c          | 11 ++---------
 SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h |  2 +-
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
index 2009f95b4cadb07fc9073c3c0660cf549965422a..f1122a48102595506cc423c3ab501d9a72f50543 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c
@@ -16,6 +16,7 @@
 
   Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
   (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
   SPDX-License-Identifier: BSD-2-Clause-Patent
 
 **/
@@ -116,6 +117,7 @@ RngGetRNG (
 
   @retval EFI_SUCCESS                 The RNG algorithm list was returned successfully.
   @retval EFI_BUFFER_TOO_SMALL        The buffer RNGAlgorithmList is too small to hold the result.
+  @retval EFI_INVALID_PARAMETER       The pointer to the buffer RNGAlgorithmList is invalid.
 
 **/
 UINTN
@@ -135,6 +137,10 @@ ArchGetSupportedRngAlgorithms (
     return EFI_BUFFER_TOO_SMALL;
   }
 
+  if (RNGAlgorithmList == NULL) {
+    return EFI_INVALID_PARAMETER;
+  }
+
   CpuRngSupportedAlgorithm = PcdGetPtr (PcdCpuRngSupportedAlgorithm);
 
   CopyMem(&RNGAlgorithmList[0], CpuRngSupportedAlgorithm, sizeof (EFI_RNG_ALGORITHM));
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c
index b959c70536ea3b9049905bbfd3d973fc9b2f6dcf..2e3b714bc691e4e517866369c034b721fbccfa24 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c
@@ -14,6 +14,7 @@
 
 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
 (C) Copyright 2015 Hewlett Packard Enterprise Development LP<BR>
+  Copyright (c) 2021, Arm Limited. All rights reserved.<BR>
 
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -59,8 +60,6 @@ RngGetInfo (
   OUT EFI_RNG_ALGORITHM           *RNGAlgorithmList
   )
 {
-  EFI_STATUS    Status;
-
   if ((This == NULL) || (RNGAlgorithmListSize == NULL)) {
     return EFI_INVALID_PARAMETER;
   }
@@ -68,13 +67,7 @@ RngGetInfo (
   //
   // Return algorithm list supported by driver.
   //
-  if (RNGAlgorithmList != NULL) {
-    Status = ArchGetSupportedRngAlgorithms (RNGAlgorithmListSize, RNGAlgorithmList);
-  } else {
-    Status = EFI_INVALID_PARAMETER;
-  }
-
-  return Status;
+  return ArchGetSupportedRngAlgorithms (RNGAlgorithmListSize, RNGAlgorithmList);
 }
 
 //
diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
index 34886adcf549efdedc1a7b8f16b81a5148531de2..37c27c4094e5302dfe2e7d9bbeef33a24b0c73ea 100644
--- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
+++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h
@@ -90,7 +90,7 @@ RngGetRNG (
 
   @retval EFI_SUCCESS                 The RNG algorithm list was returned successfully.
   @retval EFI_BUFFER_TOO_SMALL        The buffer RNGAlgorithmList is too small to hold the result.
-
+  @retval EFI_INVALID_PARAMETER       The pointer to the buffer RNGAlgorithmList is invalid.
 **/
 UINTN
 EFIAPI
-- 
'Guid(CE165669-3EF3-493F-B85D-6190EE5B9759)'


  parent reply	other threads:[~2021-09-30 15:41 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-30 15:40 [PATCH v1 0/9] Add Raw algorithm support using Arm FW-TRNG interface Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 1/9] MdePkg: Definition for TRNG library class interface Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 2/9] ArmPkg: PCD to select conduit for monitor calls Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 3/9] ArmPkg: Add Arm Firmware TRNG library Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 4/9] MdePkg: Add definition for NULL GUID Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 5/9] MdePkg: Add NULL instance of TRNG Library Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 6/9] SecurityPkg: Rename RdRandGenerateEntropy to common name Sami Mujawar
2021-09-30 15:40 ` Sami Mujawar [this message]
2021-09-30 15:40 ` [PATCH v1 8/9] SecurityPkg: Add RawAlgorithm support using TRNG library Sami Mujawar
2021-09-30 15:40 ` [PATCH v1 9/9] ArmVirtPkg: Kvmtool: Add RNG support using FW-TRNG interface Sami Mujawar
2021-10-01 17:47   ` [edk2-devel] " Joey Gouly
2021-10-08  5:35 ` 回复: [PATCH v1 0/9] Add Raw algorithm support using Arm " gaoliming

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210930154044.37336-8-sami.mujawar@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox