Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 07FC0C83F1B for ; Thu, 17 Jul 2025 07:14:55 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ucIpA-0003lx-Re; Thu, 17 Jul 2025 03:14:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucIp7-0003hx-4F for grub-devel@gnu.org; Thu, 17 Jul 2025 03:14:34 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ucIp4-0006va-Gh for grub-devel@gnu.org; Thu, 17 Jul 2025 03:14:32 -0400 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 56GJvU7h027865; Thu, 17 Jul 2025 07:14:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=pp1; bh=3uG59Fu3R4HeoDqCfehYGldSs22fHb WPHs6phg6E/AY=; b=XBuTI0GCxLrTFX7hsBHiPi9KXrONO/QBQ8Yg5pZsHCEkec pqErAefKB78I3cqdN9I0IaXPeiGbz/a4HubN+jngLkLRJksAi4joFst6ZGZL+Mu3 jKsL0GlFIn7TeaA7VZT+4CW7YXDIySNkrpsBdiz9tldDElDe6iQbs2GpxszjkFca nVJCruUPus/ffhtHh9g+lgi9q/xhfwUmdwQRU2zXsySLO6nfwUKgi2s+A3JIg9ij qItU1UWblw8j98mdDfBPzHvxW+AG9ZKVf/DwTVJzybtiDfNdzIdoXG6O3yOOKvo0 twmzEHH7H5oFVJKOOm0c9x2dBoi9t+aQw76n77mg== Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 47vamu4qva-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 17 Jul 2025 07:14:28 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 56H3KHQT031922; Thu, 17 Jul 2025 07:14:27 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 47v21uban4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 17 Jul 2025 07:14:27 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 56H7EPse53739804 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Jul 2025 07:14:25 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8BD2D20040; Thu, 17 Jul 2025 07:14:25 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 543FA2004B; Thu, 17 Jul 2025 07:14:24 +0000 (GMT) Received: from smtpclient.apple (unknown [9.124.219.74]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTPS; Thu, 17 Jul 2025 07:14:24 +0000 (GMT) From: Sudhakar Kuppusamy Message-Id: <70CDBEC0-6062-4373-BF9F-E4DB6C3B240B@linux.ibm.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.600.51.1.1\)) Subject: Re: [PATCH v2 3/7] tss2: Implement grub_tcg2_cap_pcr() for EFI Date: Thu, 17 Jul 2025 12:44:12 +0530 In-Reply-To: <20250715053634.20799-4-glin@suse.com> Cc: The development of GNU GRUB , Daniel Kiper , mchang@suse.com, patrick.colp@oracle.com, Stefan Berger To: Gary Lin References: <20250715053634.20799-1-glin@suse.com> <20250715053634.20799-4-glin@suse.com> X-Mailer: Apple Mail (2.3826.600.51.1.1) X-TM-AS-GCONF: 00 X-Proofpoint-GUID: m6rXVfb8Z7TZJKiqEZgdzpSDn7gqKBh5 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzE3MDA1NyBTYWx0ZWRfXzVXsE5h5OSOk u1ifzq+RT1xZ707fMnUZoTowoFhXpQ9IVikXj7KVafsojoG/eyxJ7DrKaCfr3vz+gu5VrxGrXy6 suhS0SEiYZ6UD1KzWo3d91G1oZf/QAFNJurLURmWSF4d1Y/tkJ79A6TYW+mv/CFL/LauiuMrnvR Bbr2prRnmzWvRgxQDAO3KwzkR3CXPYQIcbYlWJ+Erz7h+jMWAJ3cYaeI7Z3UbPaqjr2QWNsg0Q3 992Bk0GbG9ba2ffMo0H3eFwIXVxDZFrg7dNTv9QF2TWrhlaJUNpgQYobl6317UbHS5vx5Gl2PjB t9D6Q6IImH3HX9e70aQYJEGNnkFt0/Wrxme/JAem1EI7X1zBUboUpCHkKd97hRMt+d8fMyLyqHA 5UwxhM50QaJEgnTNhJUAfXKL3ICt9SE5TEMZ2+MrYuK9YlCoR2Z/5C2D6AV0ZSzMd2zPWsxW X-Proofpoint-ORIG-GUID: m6rXVfb8Z7TZJKiqEZgdzpSDn7gqKBh5 X-Authority-Analysis: v=2.4 cv=dNSmmPZb c=1 sm=1 tr=0 ts=6878a2d4 cx=c_pps a=bLidbwmWQ0KltjZqbj+ezA==:117 a=bLidbwmWQ0KltjZqbj+ezA==:17 a=Wb1JkmetP80A:10 a=iox4zFpeAAAA:8 a=VnNF1IyMAAAA:8 a=PX8j7HDqYPPKqnk5UUEA:9 a=QEXdDO2ut3YA:10 a=ryL0_POAN_TRqCNyXnwA:9 a=F5gNCjAcTG_xyd_a:21 a=_W_S_7VecoQA:10 a=lqcHg5cX4UMA:10 a=WzC6qhA0u3u7Ye7llzcV:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.9,FMLib:17.12.80.40 definitions=2025-07-17_01,2025-07-16_02,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 bulkscore=0 lowpriorityscore=0 suspectscore=0 spamscore=0 clxscore=1015 phishscore=0 malwarescore=0 mlxscore=0 adultscore=0 impostorscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2507170057 Received-SPF: pass client-ip=148.163.158.5; envelope-from=sudhakar@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The development of GNU GRUB Content-Type: multipart/mixed; boundary="===============6442789554213960803==" Errors-To: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org Sender: grub-devel-bounces+grub-devel=archiver.kernel.org@gnu.org --===============6442789554213960803== Content-Type: multipart/alternative; boundary="Apple-Mail=_47CF9E67-C17D-44F9-803B-EA2C872C029F" --Apple-Mail=_47CF9E67-C17D-44F9-803B-EA2C872C029F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On 15 Jul 2025, at 11:06=E2=80=AFAM, Gary Lin wrote: >=20 > This commit implements grub_tcg2_cap_pcr() for EFI by using the UEFI > TCG2 protocol, HashLogExtendEvent, to extend the specified PCR with an > EV_SEPARATOR event and ensure the event will be recorded properly in = the > TPM event log. >=20 > Signed-off-by: Gary Lin > Reviewed-by: Stefan Berger > --- > grub-core/lib/efi/tcg2.c | 40 ++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 40 insertions(+) >=20 > diff --git a/grub-core/lib/efi/tcg2.c b/grub-core/lib/efi/tcg2.c > index 841bf50bb..ba2834544 100644 > --- a/grub-core/lib/efi/tcg2.c > +++ b/grub-core/lib/efi/tcg2.c > @@ -22,6 +22,7 @@ > #include > #include >=20 > +#include > #include >=20 > static grub_err_t > @@ -141,3 +142,42 @@ grub_tcg2_submit_command (grub_size_t input_size, >=20 > return GRUB_ERR_NONE; > } > + > +grub_err_t > +grub_tcg2_cap_pcr (grub_uint8_t pcr) > +{ > + grub_err_t err; > + grub_efi_status_t status; > + grub_efi_tpm2_protocol_t *protocol; > + EFI_TCG2_EVENT *event; > + grub_uint8_t separator[4] =3D {0}; > + > + if (pcr >=3D TPM_MAX_PCRS) > + return GRUB_ERR_BAD_ARGUMENT; > + > + err =3D tcg2_get_protocol (&protocol); > + if (err !=3D GRUB_ERR_NONE) > + return err; > + > + event =3D grub_zalloc (sizeof (EFI_TCG2_EVENT) + sizeof = (separator)); > + if (!event) Use event =3D=3D NULL for pointers > + return grub_error (GRUB_ERR_OUT_OF_MEMORY, > + N_("cannot allocate TPM event buffer")); > + > + event->Header.HeaderSize =3D sizeof (EFI_TCG2_EVENT_HEADER); > + event->Header.HeaderVersion =3D 1; > + event->Header.PCRIndex =3D pcr; > + event->Header.EventType =3D EV_SEPARATOR; > + event->Size =3D sizeof (*event) - sizeof (event->Event) + sizeof = (separator); > + grub_memcpy (event->Event, separator, sizeof (separator)); > + > + status =3D protocol->hash_log_extend_event (protocol, 0, > + (grub_addr_t) separator, > + sizeof (separator), event); > + grub_free (event); > + > + if (status !=3D GRUB_EFI_SUCCESS) > + return grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot cap PCR %u"), = pcr); > + > + return GRUB_ERR_NONE; > +} With nit fix: Reviewed-by: Sudhakar Kuppusamy > > --=20 > 2.43.0 >=20 --Apple-Mail=_47CF9E67-C17D-44F9-803B-EA2C872C029F Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

On 15 Jul 2025, at 11:06=E2=80=AFAM, Gary Lin = <glin@suse.com> wrote:

This commit implements = grub_tcg2_cap_pcr() for EFI by using the UEFI
TCG2 protocol, = HashLogExtendEvent, to extend the specified PCR with an
EV_SEPARATOR = event and ensure the event will be recorded properly in the
TPM event = log.

Signed-off-by: Gary Lin = <glin@suse.com>
Reviewed-by: Stefan Berger = <stefanb@linux.ibm.com>
---
grub-core/lib/efi/tcg2.c | 40 = ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 = insertions(+)

diff --git a/grub-core/lib/efi/tcg2.c = b/grub-core/lib/efi/tcg2.c
index 841bf50bb..ba2834544 100644
--- = a/grub-core/lib/efi/tcg2.c
+++ b/grub-core/lib/efi/tcg2.c
@@ -22,6 = +22,7 @@
#include <grub/efi/tpm.h>
#include = <grub/mm.h>

+#include <tss2_types.h>
#include = <tcg2.h>

static grub_err_t
@@ -141,3 +142,42 @@ = grub_tcg2_submit_command (grub_size_t input_size,

=   return GRUB_ERR_NONE;
= }
+
+grub_err_t
+grub_tcg2_cap_pcr (grub_uint8_t = pcr)
+{
+  grub_err_t err;
+  grub_efi_status_t = status;
+  grub_efi_tpm2_protocol_t *protocol;
+ =  EFI_TCG2_EVENT *event;
+  grub_uint8_t separator[4] =3D = {0};
+
+  if (pcr >=3D TPM_MAX_PCRS)
+ =    return GRUB_ERR_BAD_ARGUMENT;
+
+  err =3D = tcg2_get_protocol (&protocol);
+  if (err !=3D = GRUB_ERR_NONE)
+    return err;
+
+  event = =3D grub_zalloc (sizeof (EFI_TCG2_EVENT) + sizeof (separator));
+ =  if (!event)

Use = event =3D=3D NULL for pointers

+    return grub_error = (GRUB_ERR_OUT_OF_MEMORY,
+ =       N_("cannot allocate TPM event = buffer"));
+
+  event->Header.HeaderSize =3D sizeof = (EFI_TCG2_EVENT_HEADER);
+  event->Header.HeaderVersion =3D = 1;
+  event->Header.PCRIndex =3D pcr;
+ =  event->Header.EventType =3D EV_SEPARATOR;
+ =  event->Size =3D sizeof (*event) - sizeof (event->Event) + = sizeof (separator);
+  grub_memcpy (event->Event, separator, = sizeof (separator));
+
+  status =3D = protocol->hash_log_extend_event (protocol, 0,
+ =    (grub_addr_t) separator,
+ =    sizeof (separator), event);
+  grub_free = (event);
+
+  if (status !=3D GRUB_EFI_SUCCESS)
+ =    return grub_error (GRUB_ERR_BAD_DEVICE, N_("cannot cap = PCR %u"), pcr);
+
+  return = GRUB_ERR_NONE;
+}

With = nit fix:

Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
-- =
2.43.0


= --Apple-Mail=_47CF9E67-C17D-44F9-803B-EA2C872C029F-- --===============6442789554213960803== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KR3J1Yi1kZXZl bCBtYWlsaW5nIGxpc3QKR3J1Yi1kZXZlbEBnbnUub3JnCmh0dHBzOi8vbGlzdHMuZ251Lm9yZy9t YWlsbWFuL2xpc3RpbmZvL2dydWItZGV2ZWwK --===============6442789554213960803==--