From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web12.8551.1573545470664115931 for ; Mon, 11 Nov 2019 23:57:50 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: jian.j.wang@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Nov 2019 23:57:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,295,1569308400"; d="scan'208";a="287468151" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga001.jf.intel.com with ESMTP; 11 Nov 2019 23:57:45 -0800 Received: from shsmsx105.ccr.corp.intel.com (10.239.4.158) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 11 Nov 2019 23:57:04 -0800 Received: from shsmsx107.ccr.corp.intel.com ([169.254.9.63]) by SHSMSX105.ccr.corp.intel.com ([169.254.11.225]) with mapi id 14.03.0439.000; Tue, 12 Nov 2019 15:56:41 +0800 From: "Wang, Jian J" To: "devel@edk2.groups.io" , "lersek@redhat.com" CC: "Yao, Jiewen" , "Zhang, Chao B" , "Kinney, Michael D" , "Gao, Liming" , Ard Biesheuvel , "Ni, Ray" Subject: Re: [edk2-devel] [PATCH] SecurityPkg/RngLibNull: add null version of RngLib Thread-Topic: [edk2-devel] [PATCH] SecurityPkg/RngLibNull: add null version of RngLib Thread-Index: AQHVmS3QthZ2MDZoDkW6mjLQqgQ8LqeHKk2A Date: Tue, 12 Nov 2019 07:56:40 +0000 Message-ID: References: <20191112055545.3948-1-jian.j.wang@intel.com> <77a7c143-8547-2bc6-4a87-d0afbf2529e5@redhat.com> In-Reply-To: <77a7c143-8547-2bc6-4a87-d0afbf2529e5@redhat.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNmZmYTEwODEtZGZjMy00MWNjLWIzNWEtNWM4MTY5MDIyOTI2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiUDJaVWdmTm9JbmdKalZhcjFqc1d4MHBPcFFEK3RGQk5UdXQ3aitVM0RyWGtDeVAzaG12RDVKcktDM2ZYTktUSyJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: jian.j.wang@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Laszlo, > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Laszlo Er= sek > Sent: Tuesday, November 12, 2019 3:50 PM > To: Wang, Jian J ; devel@edk2.groups.io > Cc: Yao, Jiewen ; Zhang, Chao B > ; Kinney, Michael D = ; > Gao, Liming ; Ard Biesheuvel > ; Ni, Ray > Subject: Re: [edk2-devel] [PATCH] SecurityPkg/RngLibNull: add null versi= on of > RngLib >=20 > On 11/12/19 06:55, Jian J Wang wrote: > > This is null version of RngLib which is used for those platforms or > > components which don't need random number. > > > > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1871 > > Cc: Jiewen Yao > > Cc: Chao Zhang > > Cc: Michael D Kinney > > Cc: Liming Gao > > Cc: Laszlo Ersek > > Cc: Ard Biesheuvel > > Cc: Ray Ni > > Signed-off-by: Jian J Wang > > --- > > .../RngLibNull/RngLibNull.c | 95 ++++++++++++++++++= + > > .../RngLibNull/RngLibNull.inf | 31 ++++++ > > .../RngLibNull/RngLibNull.uni | 14 +++ > > 3 files changed, 140 insertions(+) > > create mode 100644 > SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.c > > create mode 100644 > SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.inf > > create mode 100644 > SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.uni >=20 > (1) I don't see any reason why this library instance should not be added > under MdePkg/Library. The other library instance is already there (and > the lib class header too is from MdePkg): >=20 > MdePkg/Library/BaseRngLib >=20 > (2) I think this library instance should be called "BaseRngLibNull", not > just "RngLibNull". >=20 I have no strong opinion on this. Liming, do you have any comments? > More below: >=20 > > diff --git a/SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.c > b/SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.c > > new file mode 100644 > > index 0000000000..13677abc84 > > --- /dev/null > > +++ b/SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.c > > @@ -0,0 +1,95 @@ > > +/** @file > > + Null version of Random number generator services. > > + > > +Copyright (c) 2019, Intel Corporation. All rights reserved.
> > +SPDX-License-Identifier: BSD-2-Clause-Patent > > + > > +**/ > > + > > +#include > > +#include > > +#include > > + > > +/** > > + Generates a 16-bit random number. > > + > > + if Rand is NULL, then ASSERT(). > > + > > + @param[out] Rand Buffer pointer to store the 16-bit random valu= e. > > + > > + @retval TRUE Random number generated successfully. > > + @retval FALSE Failed to generate the random number. > > + > > +**/ > > +BOOLEAN > > +EFIAPI > > +GetRandomNumber16 ( > > + OUT UINT16 *Rand > > + ) > > +{ > > + ASSERT (FALSE); > > + return FALSE; > > +} > > + > > +/** > > + Generates a 32-bit random number. > > + > > + if Rand is NULL, then ASSERT(). > > + > > + @param[out] Rand Buffer pointer to store the 32-bit random valu= e. > > + > > + @retval TRUE Random number generated successfully. > > + @retval FALSE Failed to generate the random number. > > + > > +**/ > > +BOOLEAN > > +EFIAPI > > +GetRandomNumber32 ( > > + OUT UINT32 *Rand > > + ) > > +{ > > + ASSERT (FALSE); > > + return FALSE; > > +} > > + > > +/** > > + Generates a 64-bit random number. > > + > > + if Rand is NULL, then ASSERT(). > > + > > + @param[out] Rand Buffer pointer to store the 64-bit random valu= e. > > + > > + @retval TRUE Random number generated successfully. > > + @retval FALSE Failed to generate the random number. > > + > > +**/ > > +BOOLEAN > > +EFIAPI > > +GetRandomNumber64 ( > > + OUT UINT64 *Rand > > + ) > > +{ > > + ASSERT (FALSE); > > + return FALSE; > > +} > > + > > +/** > > + Generates a 128-bit random number. > > + > > + if Rand is NULL, then ASSERT(). > > + > > + @param[out] Rand Buffer pointer to store the 128-bit random val= ue. > > + > > + @retval TRUE Random number generated successfully. > > + @retval FALSE Failed to generate the random number. > > + > > +**/ > > +BOOLEAN > > +EFIAPI > > +GetRandomNumber128 ( > > + OUT UINT64 *Rand > > + ) > > +{ > > + ASSERT (FALSE); > > + return FALSE; > > +} > > diff --git a/SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.i= nf > b/SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.inf > > new file mode 100644 > > index 0000000000..f6494cdb82 > > --- /dev/null > > +++ b/SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.inf > > @@ -0,0 +1,31 @@ > > +## @file > > +# Null instance of RNG (Random Number Generator) Library. > > +# > > +# Copyright (c) 2019, Intel Corporation. All rights reserved.
> > +# > > +# SPDX-License-Identifier: BSD-2-Clause-Patent > > +# > > +## > > + > > +[Defines] > > + INF_VERSION =3D 0x00010005 > > + BASE_NAME =3D RngLibNull > > + MODULE_UNI_FILE =3D RngLibNull.uni > > + FILE_GUID =3D CD8991F8-2061-4084-8C9E-9C6F352D= C58D > > + MODULE_TYPE =3D BASE > > + VERSION_STRING =3D 1.0 > > + LIBRARY_CLASS =3D RngLib > > + > > +# > > +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 > > +# > > + > > +[Sources] > > + RngLibNull.c > > + > > +[Packages] > > + MdePkg/MdePkg.dec > > + > > +[LibraryClasses] > > + BaseLib > > + DebugLib > > diff --git a/SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.u= ni > b/SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.uni > > new file mode 100644 > > index 0000000000..40b2ec3fe1 > > --- /dev/null > > +++ b/SecurityPkg/RandomNumberGenerator/RngLibNull/RngLibNull.uni > > @@ -0,0 +1,14 @@ > > +// /** @file > > +// Null Instance of RNG (Random Number Generator) Library. > > +// > > +// Copyright (c) 2019, Intel Corporation. All rights reserved.
> > +// > > +// SPDX-License-Identifier: BSD-2-Clause-Patent > > +// > > +// **/ > > + > > + > > +#string STR_MODULE_ABSTRACT #language en-US "Null Instanc= e of > RNG Library" > > + > > +#string STR_MODULE_DESCRIPTION #language en-US "Caution: Thi= s is a > null version of RNG library and SHOULD NOT be used on any product ever." > > + > > >=20 > (3) I disagree with STR_MODULE_DESCRIPTION. >=20 > This library instance is appropriate even in production, namely for such > modules that *inherit* a dependency on RngLib -- for example, through > another library instance --, but, in practice, they never consume > randomness, and/or they never *must* consume randomness. >=20 > In other words, this library instance should be used with modules that > should, in practice, never *reach* any calls to GetRandomNumberXX() > APIs, but it is difficult to remove the call sites themselves -- for > example, because they are inherited (i.e., indirectly) through another > library class. >=20 > With that in mind, the ASSERT()s seem justified -- these functions > should never be reached. >=20 > Note: I'm not saying that the ASSERT()s are *required*. Luckily, all > these APIs are able to report failure, and so if all client code checks > the return values, no actual functionality will be misled. (The > functions in this lib instance all return FALSE, correctly.) But, the > ASSERT()s are good for pointing out the larger issue: if a module > actually calls these functions (because it needs actual randomness), > then the module / platform configuration (=3D DSC file) is broken. >=20 > In summary, STR_MODULE_DESCRIPTION should state, "this library instance > should be used with modules that inherit an (indirect) dependency on the > RngLib class, but never actually call RngLib APIs for consuming randomne= ss". >=20 Good explanation. Thanks. And I agree with your version of STR_MODULE_DESC= RIPTION. I'll update it in v2. Regards, Jian > Thanks, > Laszlo >=20 >=20 >=20