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.web10.2510.1631208942583406277 for ; Thu, 09 Sep 2021 10:35:42 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=kOWR4hh1; 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 189HXlUW190262; Thu, 9 Sep 2021 13:35:42 -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=kOWR4hh1lmUJHj78B3PFjFtDmQWi81mfTvfJINqlcO4jfqUpsWcAQqpxr7aAzQe4G63r d16yk5WnufN8X/qBORPSW0CRUguXcPKOiAsrtnkbl8lNLL22q5499lTi/UqPmu4Dfu2z GeAdP3KNK5lax8oJo1hfXPoPrpicgUYpQqScvK1vWoOafUlBK4Ysw0YxTveD6QLZCUkc PWgJ6hjzgEdBn5m9UyVUfaH5qRjwMQxPKwmEmlrSO7+7d8w5DrfdN6C83I6zDoh6mmfl wZVPvJwfE+JIBCU4JcaZclotcG+4qOJVjfkgqDWNu/ixN0tIoTqGQno6Y03w39FZtlzB Cg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ayn4xakt3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Sep 2021 13:35:42 -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 189HYnv7195873; Thu, 9 Sep 2021 13:35:41 -0400 Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ayn4xaksr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Sep 2021 13:35:41 -0400 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 189HM6q9025593; Thu, 9 Sep 2021 17:35:40 GMT Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by ppma01wdc.us.ibm.com with ESMTP id 3axcnp2vqk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 09 Sep 2021 17:35:40 +0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 189HZdLn38273292 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 9 Sep 2021 17:35:39 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AE558AC064; Thu, 9 Sep 2021 17:35:39 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 911F4AC069; Thu, 9 Sep 2021 17:35:39 +0000 (GMT) Received: from sbct-2.pok.ibm.com (unknown [9.47.158.152]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 9 Sep 2021 17:35:39 +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 v7 2/9] SecurityPkg/TPM: Fix bugs in imported PeiDxeTpmPlatformHierarchyLib Date: Thu, 9 Sep 2021 13:35:31 -0400 Message-Id: <20210909173538.2380673-3-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909173538.2380673-1-stefanb@linux.vnet.ibm.com> References: <20210909173538.2380673-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: j5d4XVxmYY2MnbTDM4u53uNIrMG9egz7 X-Proofpoint-GUID: uaCvfvToNZbNYA2lHYV2W6Ooy29CqSl_ X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-09-09_06:2021-09-09,2021-09-09 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 impostorscore=0 clxscore=1015 adultscore=0 priorityscore=1501 bulkscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109090107 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