From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.158.5]) by mx.groups.io with SMTP id smtpd.web09.2342.1630531143238075420 for ; Wed, 01 Sep 2021 14:19:03 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=H22FzBax; spf=none, err=permanent DNS error (domain: linux.vnet.ibm.com, ip: 148.163.158.5, mailfrom: stefanb@linux.vnet.ibm.com) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 181L311B165604; Wed, 1 Sep 2021 17:19:02 -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=H22FzBaxvtscMEZYHH8Nna1XOl8/yRVV2qfQFpQBKIYxHanPxeHU8bD7lERtjnLTPc0D KT/20V8oIBinWilSdmBoG4qGWgDl05WLkaAALhpwvUS9A+diqx/mNWTQIDLh5dgbgnZM udAT8BZO5YYjOd2bLrEpDjAFBZrVh9Jy+tdzNVOz3wTEk4v+rhGG2D92Q6C/c7m5tgVR uxbUR9UFE7yoIHb12agMPrI178xsnYTZpiWOj0RJRwNvfwLiG3IdqiNfLnevpLzyyjJw 0VmdvY16/x6MMXP7ilonMcOzUnyLl51+WzympqqrSFjnXUu8VHE4A3oFMVsabylP+m6t +g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3atg5m9fmh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 17:19:02 -0400 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 181L3gUV181003; Wed, 1 Sep 2021 17:19:01 -0400 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0b-001b2d01.pphosted.com with ESMTP id 3atg5m9fm2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 17:19:01 -0400 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 181LCq53003681; Wed, 1 Sep 2021 21:19:01 GMT Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by ppma04wdc.us.ibm.com with ESMTP id 3atdxdv948-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 21:19:01 +0000 Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 181LJ0OU45154688 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Sep 2021 21:19:00 GMT Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0CB806A05F; Wed, 1 Sep 2021 21:19:00 +0000 (GMT) Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2AB926A058; Wed, 1 Sep 2021 21:18:59 +0000 (GMT) Received: from sbct-2.. (unknown [9.47.158.152]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 1 Sep 2021 21:18:59 +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 17:18:48 -0400 Message-Id: <20210901211854.3795207-3-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210901211854.3795207-1-stefanb@linux.vnet.ibm.com> References: <20210901211854.3795207-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: _-d3JiL8ZGAHZhejz-g4A-fP-wb2yJf- X-Proofpoint-GUID: hrFuxjC2EE68UfgorliVxYo831lPAV8- 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 phishscore=0 bulkscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 spamscore=0 clxscore=1015 adultscore=0 mlxscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2108310000 definitions=main-2109010123 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