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.2329.1630531318078220825 for ; Wed, 01 Sep 2021 14:21:58 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@ibm.com header.s=pp1 header.b=LWpkiQMk; 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 (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 181L2mmK107464; Wed, 1 Sep 2021 17:21:57 -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=LWpkiQMkoRF2bRzQqxKXzecdvNe5OM2gZcngvc3dq+5Vi6PtM1kYeHPrdav4az72CMaE rZiULmafYK7gEs2dS+up2inepDg6PG1Wlf5rRwFjM55smjHF+tV5+HiA7sM+xfjx8MYb d/OlEl47xwRcSglzDBnkCGHnPJZLkKY3nNHSnsp4PcYAudtASh8/jPfb2haEeJ9i0WHQ EpwJs0j4V/ftMzscbNfm0nJ2PmeQzQCLb4BrSe1QSdIjcWXMWItAmUgPnzbaXRvRzxOz VgYkJz/X3bvtMKslNBa0tCw7hzt4Hi9uuWLydnv5IWBhW0rnxUiO/DRSyDGBCWi32V8K 2A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ate1tcqxq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 17:21:57 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 181L3twG122532; Wed, 1 Sep 2021 17:21:57 -0400 Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ate1tcqx9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 17:21:57 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 181LBkmn018106; Wed, 1 Sep 2021 21:21:55 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma03wdc.us.ibm.com with ESMTP id 3atdxtv9yd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 21:21:55 +0000 Received: from b01ledav006.gho.pok.ibm.com (b01ledav006.gho.pok.ibm.com [9.57.199.111]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 181LLtm936635100 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Sep 2021 21:21:55 GMT Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1721FAC05E; Wed, 1 Sep 2021 21:21:55 +0000 (GMT) Received: from b01ledav006.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 08DB4AC059; Wed, 1 Sep 2021 21:21:55 +0000 (GMT) Received: from sbct-3.pok.ibm.com?044watson.ibm.com (unknown [9.47.158.153]) by b01ledav006.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 1 Sep 2021 21:21:54 +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:21:47 -0400 Message-Id: <20210901212153.1915585-3-stefanb@linux.vnet.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210901212153.1915585-1-stefanb@linux.vnet.ibm.com> References: <20210901212153.1915585-1-stefanb@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: fF409q3GArgWUf8mihfQeW5G2dE6LdPV X-Proofpoint-GUID: Pb_5aoW7h1uoJENnh2jEe4YlugpdQRJt 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 impostorscore=0 bulkscore=0 adultscore=0 phishscore=0 priorityscore=1501 mlxscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 malwarescore=0 suspectscore=0 lowpriorityscore=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