All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
To: Gary Lin <glin@suse.com>
Cc: The development of GNU GRUB <grub-devel@gnu.org>,
	Daniel Kiper <daniel.kiper@oracle.com>,
	mchang@suse.com, patrick.colp@oracle.com,
	Stefan Berger <stefanb@linux.ibm.com>
Subject: Re: [PATCH v2 3/7] tss2: Implement grub_tcg2_cap_pcr() for EFI
Date: Thu, 17 Jul 2025 12:44:12 +0530	[thread overview]
Message-ID: <70CDBEC0-6062-4373-BF9F-E4DB6C3B240B@linux.ibm.com> (raw)
In-Reply-To: <20250715053634.20799-4-glin@suse.com>


[-- Attachment #1.1: Type: text/plain, Size: 2415 bytes --]



> On 15 Jul 2025, at 11:06 AM, 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] = {0};
> +
> +  if (pcr >= TPM_MAX_PCRS)
> +    return GRUB_ERR_BAD_ARGUMENT;
> +
> +  err = tcg2_get_protocol (&protocol);
> +  if (err != GRUB_ERR_NONE)
> +    return err;
> +
> +  event = grub_zalloc (sizeof (EFI_TCG2_EVENT) + sizeof (separator));
> +  if (!event)

Use event == NULL for pointers

> +    return grub_error (GRUB_ERR_OUT_OF_MEMORY,
> +		       N_("cannot allocate TPM event buffer"));
> +
> +  event->Header.HeaderSize = sizeof (EFI_TCG2_EVENT_HEADER);
> +  event->Header.HeaderVersion = 1;
> +  event->Header.PCRIndex = pcr;
> +  event->Header.EventType = EV_SEPARATOR;
> +  event->Size = sizeof (*event) - sizeof (event->Event) + sizeof (separator);
> +  grub_memcpy (event->Event, separator, sizeof (separator));
> +
> +  status = protocol->hash_log_extend_event (protocol, 0,
> +					    (grub_addr_t) separator,
> +					    sizeof (separator), event);
> +  grub_free (event);
> +
> +  if (status != 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 <mailto:sudhakar@linux.ibm.com>>
> -- 
> 2.43.0
> 


[-- Attachment #1.2: Type: text/html, Size: 4189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 141 bytes --]

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  reply	other threads:[~2025-07-17  7:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-15  5:36 [PATCH v2 0/7] TPM2 PCR Capping Gary Lin via Grub-devel
2025-07-15  5:36 ` [PATCH v2 1/7] tss2: Add TPM2_PCR_Event command Gary Lin via Grub-devel
2025-07-17  6:54   ` Sudhakar Kuppusamy
2025-07-15  5:36 ` [PATCH v2 2/7] tss2: Introduce grub_tcg2_cap_pcr() Gary Lin via Grub-devel
2025-07-17  6:55   ` Sudhakar Kuppusamy
2025-07-15  5:36 ` [PATCH v2 3/7] tss2: Implement grub_tcg2_cap_pcr() for EFI Gary Lin via Grub-devel
2025-07-17  7:14   ` Sudhakar Kuppusamy [this message]
2025-07-15  5:36 ` [PATCH v2 4/7] tss2: Implement grub_tcg2_cap_pcr() for ieee1275 Gary Lin via Grub-devel
2025-07-15  5:36 ` [PATCH v2 5/7] tss2: Implement grub_tcg2_cap_pcr() for EMU Gary Lin via Grub-devel
2025-07-17  7:30   ` Sudhakar Kuppusamy
2025-07-15  5:36 ` [PATCH v2 6/7] tpm2_key_protector: Support PCR capping Gary Lin via Grub-devel
2025-07-15  5:36 ` [PATCH v2 7/7] tests/tpm2_key_protector_test: Add a test for PCR Capping Gary Lin via Grub-devel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=70CDBEC0-6062-4373-BF9F-E4DB6C3B240B@linux.ibm.com \
    --to=sudhakar@linux.ibm.com \
    --cc=daniel.kiper@oracle.com \
    --cc=glin@suse.com \
    --cc=grub-devel@gnu.org \
    --cc=mchang@suse.com \
    --cc=patrick.colp@oracle.com \
    --cc=stefanb@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.