From mboxrd@z Thu Jan 1 00:00:00 1970 Subject: [PATCH] SecurityPkg/Tcg/Tcg2Config: Fix REVERSE_INULL Coverity issue To: devel@edk2.groups.io From: "Ranbir Singh" X-Originating-Location: Bengaluru, Karnataka, IN (122.172.85.38) X-Originating-Platform: Windows Chrome 108 User-Agent: GROUPS.IO Web Poster MIME-Version: 1.0 Date: Wed, 04 Jan 2023 02:50:11 -0800 Message-ID: Content-Type: multipart/alternative; boundary="0h9tUeihhw572Cz0XfsO" --0h9tUeihhw572Cz0XfsO Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The function Tcg2ConfigDriverEntryPoint at the point of creating a private data structure makes a call to AllocateCopyPool and stores the return value in PrivateData. Thereafter it does a check ASSERT (PrivateData !=3D NULL); but this is applicable only in DEBUG mode. In Release mode, the code continues further and will dereference "PrivateData" which will lead to CRASH if PrivateData is NULL. Hence, for safety add PrivateData NULL pointer check and return from there saying EFI_OUT_OF_RESOURCES when PrivateData is NULL. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4229 Signed-off-by: Ranbir Singh --- SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c b/SecurityPkg/Tc= g/Tcg2Config/Tcg2ConfigDriver.c index edf5f0fc77..f023b3ccb8 100644 --- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c +++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c @@ -283,6 +283,10 @@ Tcg2ConfigDriverEntryPoint ( // PrivateData =3D AllocateCopyPool (sizeof (TCG2_CONFIG_PRIVATE_DATA), &mTcg2= ConfigPrivateDateTemplate); ASSERT (PrivateData !=3D NULL); +=C2=A0 if (PrivateData =3D=3D NULL) { +=C2=A0 =C2=A0 return EFI_OUT_OF_RESOURCES; +=C2=A0 } + mTcg2ConfigPrivateDate =3D PrivateData; // // Install private GUID. -- 2.36.1.windows.1 --0h9tUeihhw572Cz0XfsO Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
The function Tcg2ConfigDriverEntryPoint at the point of creating a
private data structure makes a call to AllocateCopyPool and stores
the return value in PrivateData. Thereafter it does a check
 
    ASSERT (PrivateData !=3D NULL);
 
but this is applicable only in DEBUG mode. In Release mode, the code
continues further and will dereference "PrivateData" which will lead
to CRASH if PrivateData is NULL.
 
Hence, for safety add PrivateData NULL pointer check and return from
there saying EFI_OUT_OF_RESOURCES when PrivateData is NULL.
 
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4229
Signed-off-by: Ranbir Singh <Ranbir.Singh3@Dell.com>
---
 SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c | 4 ++++
 1 file changed, 4 insertions(+)
 
diff --git a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c b/SecurityP= kg/Tcg/Tcg2Config/Tcg2ConfigDriver.c
index edf5f0fc77..f023b3ccb8 100644
--- a/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c
+++ b/SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDriver.c
@@ -283,6 +283,10 @@ Tcg2ConfigDriverEntryPoint (
   //
   PrivateData =3D AllocateCopyPool (sizeof (TCG2_CONFIG_PRI= VATE_DATA), &mTcg2ConfigPrivateDateTemplate);
   ASSERT (PrivateData !=3D NULL);
+  if (PrivateData =3D=3D NULL) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+
   mTcg2ConfigPrivateDate =3D PrivateData;
   //
   // Install private GUID.
--
2.36.1.windows.1
--0h9tUeihhw572Cz0XfsO--