From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by mx.groups.io with SMTP id smtpd.web12.1390.1630527168840343627 for ; Wed, 01 Sep 2021 13:12:49 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Rkh6AeYU; spf=none, err=permanent DNS error (domain: linux.vnet.ibm.com, ip: 148.163.156.1, mailfrom: stefanb@linux.vnet.ibm.com) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 181K98Rg121198; Wed, 1 Sep 2021 16:12:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=NIDNm3MFktm+937Luua7hsWMmhfqcH0IpN2dLpWAyB8=; b=Rkh6AeYUy/VV2pU3cFrBI76S3nHglUGEJrNRteJtMLLxgO2dR+27Zca/s60bzOvjVe1c krobcxc9A0PYHApj/HefJRAQ5l0t2/po17n8rZg6hbyOfKfPMIYW/sjZv5Xf98PfquY1 Z8w3400b/oZEPgJKr2l98lJBm2E29uNTrRxdFA5i8rdm4sjh51Bey19yuUIxXyXvMNKh Fs9Y5tWv4TBzLA3MNualw1uITx5nfMu+7ToKlswKf4Wk/qPVHr4l9+1ib6NzTQPGNHRQ 4Y3Rl0ncG7B9XjdKGufQCU7va3yNdlOFASD9WNze2vYW3VkQX2b3MQyRka/dZSTVNqqj /w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3atg7s06wg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 16:12:48 -0400 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 181K9JnN128522; Wed, 1 Sep 2021 16:12:47 -0400 Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com with ESMTP id 3atg7s06w6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 16:12:47 -0400 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 181KCkF9017568; Wed, 1 Sep 2021 20:12:46 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma03dal.us.ibm.com with ESMTP id 3atdxbkxas-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 20:12:46 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 181KCjJ819792386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Sep 2021 20:12:45 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4ADBDBE056; Wed, 1 Sep 2021 20:12:45 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 57233BE05B; Wed, 1 Sep 2021 20:12:44 +0000 (GMT) Received: from sbct-2.. (unknown [9.47.158.152]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 1 Sep 2021 20:12:44 +0000 (GMT) From: Stefan Berger To: devel@edk2.groups.io Cc: mhaeuser@posteo.de, spbrogan@outlook.com, marcandre.lureau@redhat.com, kraxel@redhat.com, jiewen.yao@intel.com, Stefan Berger , Stefan Berger Subject: [PATCH v5 2/8] SecurityPkg/TPM: Fix bugs in imported PeiDxeTpmPlatformHierarchyLib Date: Wed, 1 Sep 2021 16:12:32 -0400 Message-Id: <20210901201238.3152761-3-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210901201238.3152761-1-stefanb@linux.vnet.ibm.com> References: <20210901201238.3152761-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 01DLiiJO-o0RtPVL4NVNCCsfzyQ-gXif X-Proofpoint-ORIG-GUID: Xqdg5CitmCRkK-qW8vfWw3hg8XEOQOme X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-09-01_05:2021-09-01,2021-09-01 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 phishscore=0 clxscore=1015 bulkscore=0 adultscore=0 malwarescore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2108310000 definitions=main-2109010116 Content-Transfer-Encoding: quoted-printable Fix some bugs in the original PeiDxeTpmPlatformHierarchyLib.c. Signed-off-by: Stefan Berger --- .../PeiDxeTpmPlatformHierarchyLib.c | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLib/PeiDxeTpmPla= tformHierarchyLib.c b/SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLib/Pei= DxeTpmPlatformHierarchyLib.c index 9812ab99ab..d82a0ae1bd 100644 --- a/SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLib/PeiDxeTpmPlatformHi= erarchyLib.c +++ b/SecurityPkg/Library/PeiDxeTpmPlatformHierarchyLib/PeiDxeTpmPlatformHi= erarchyLib.c @@ -18,7 +18,6 @@ #include =0D #include =0D #include =0D -#include =0D #include =0D #include =0D #include =0D @@ -27,7 +26,6 @@ // The authorization value may be no larger than the digest produced by th= e hash=0D // algorithm used for context integrity.=0D //=0D -#define MAX_NEW_AUTHORIZATION_SIZE SHA512_DIGEST_SIZE=0D =0D UINT16 mAuthSize;=0D =0D @@ -54,7 +52,7 @@ RdRandGenerateEntropy ( UINT8 *Ptr;=0D =0D Status =3D EFI_NOT_READY;=0D - BlockCount =3D Length / 64;=0D + BlockCount =3D Length / sizeof(Seed);=0D Ptr =3D (UINT8 *)Entropy;=0D =0D //=0D @@ -65,10 +63,10 @@ RdRandGenerateEntropy ( if (EFI_ERROR (Status)) {=0D return Status;=0D }=0D - CopyMem (Ptr, Seed, 64);=0D + CopyMem (Ptr, Seed, sizeof(Seed));=0D =0D BlockCount--;=0D - Ptr =3D Ptr + 64;=0D + Ptr =3D Ptr + sizeof(Seed);=0D }=0D =0D //=0D @@ -78,7 +76,7 @@ RdRandGenerateEntropy ( if (EFI_ERROR (Status)) {=0D return Status;=0D }=0D - CopyMem (Ptr, Seed, (Length % 64));=0D + CopyMem (Ptr, Seed, (Length % sizeof(Seed)));=0D =0D return Status;=0D }=0D @@ -164,8 +162,6 @@ RandomizePlatformAuth ( {=0D EFI_STATUS Status;=0D UINT16 AuthSize;=0D - UINT8 *Rand;=0D - UINTN RandSize;=0D TPM2B_AUTH NewPlatformAuth;=0D =0D //=0D @@ -174,19 +170,13 @@ RandomizePlatformAuth ( =0D GetAuthSize (&AuthSize);=0D =0D - ZeroMem (NewPlatformAuth.buffer, AuthSize);=0D NewPlatformAuth.size =3D AuthSize;=0D =0D //=0D - // Allocate one buffer to store random data.=0D + // Create the random bytes in the destination buffer=0D //=0D - RandSize =3D MAX_NEW_AUTHORIZATION_SIZE;=0D - Rand =3D AllocatePool (RandSize);=0D -=0D - RdRandGenerateEntropy (RandSize, Rand);=0D - CopyMem (NewPlatformAuth.buffer, Rand, AuthSize);=0D =0D - FreePool (Rand);=0D + RdRandGenerateEntropy (NewPlatformAuth.size, NewPlatformAuth.buffer);=0D =0D //=0D // Send Tpm2HierarchyChangeAuth command with the new Auth value=0D @@ -194,7 +184,6 @@ RandomizePlatformAuth ( Status =3D Tpm2HierarchyChangeAuth (TPM_RH_PLATFORM, NULL, &NewPlatformA= uth);=0D DEBUG ((DEBUG_INFO, "Tpm2HierarchyChangeAuth Result: - %r\n", Status));= =0D ZeroMem (NewPlatformAuth.buffer, AuthSize);=0D - ZeroMem (Rand, RandSize);=0D }=0D =0D /**=0D --=20 2.31.1