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.10935.1631105210829056545 for ; Wed, 08 Sep 2021 05:46:50 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=l7Q6j/hQ; 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 (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 188CjmoN147544; Wed, 8 Sep 2021 08:46:50 -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=l7Q6j/hQBAdwIpG5wjpqnosFqvyJ6a6ZFcmQv/ZIs8Wx37ll0p5BQwmWeCODIsLTmGSP yoYkxCGlpq5UuxkVVLxW8edZ1tBFSD0g9scNxxYZfwpcuM8+drVuKZ0pXgk2q9IAId0o hP4jRyz1dMteLSZ1jJQrJ4UTsgFOM268R/QXyOI/YXpCWVhQJt2JJtu9DAGwq6+tjpWo aG+MG/Gs19TtdOsJKrxNBL2yQIe1L309EKcmA5Ds9crEqODKlpfYFKxFzGZu1szeLfVA Xg4qiAfDmCXBMIaqd62DVWiA+NpyKfXnBtq2gqo5jKkf44JJvaZqVus4VTc4m2XUAdec UA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3axwf4g0n5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Sep 2021 08:46:50 -0400 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 188CkSp5153546; Wed, 8 Sep 2021 08:46:49 -0400 Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com with ESMTP id 3axwf4g0mc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Sep 2021 08:46:49 -0400 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 188CgGY1014201; Wed, 8 Sep 2021 12:46:48 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma02wdc.us.ibm.com with ESMTP id 3axcnnhtst-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Sep 2021 12:46:48 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 188Ckl4Q43647344 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 8 Sep 2021 12:46:47 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 94905112075; Wed, 8 Sep 2021 12:46:47 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8CD76112076; Wed, 8 Sep 2021 12:46:47 +0000 (GMT) Received: from sbct-2.pok.ibm.com (unknown [9.47.158.152]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 8 Sep 2021 12:46:47 +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 v6 2/9] SecurityPkg/TPM: Fix bugs in imported PeiDxeTpmPlatformHierarchyLib Date: Wed, 8 Sep 2021 08:46:37 -0400 Message-Id: <20210908124644.816856-3-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210908124644.816856-1-stefanb@linux.vnet.ibm.com> References: <20210908124644.816856-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: PUmtCHqLYxuzrEfhH-CDCD7np29T-YJ3 X-Proofpoint-ORIG-GUID: bv-9enDIi6laiHxwxP5EUhEIkS-GLryl X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-09-08_05:2021-09-07,2021-09-08 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxscore=0 bulkscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 clxscore=1015 impostorscore=0 phishscore=0 spamscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109080080 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