Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko@kernel.org>
To: Thorsten Blum <thorsten.blum@linux.dev>
Cc: Peter Huewe <peterhuewe@gmx.de>, Jason Gunthorpe <jgg@ziepe.ca>,
	Colin Ian King <colin.i.king@gmail.com>,
	Harald Hoyer <harald@redhat.com>,
	stable@vger.kernel.org, linux-integrity@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tpm: fix event_size output in tpm1_binary_bios_measurements_show
Date: Fri, 22 May 2026 03:30:20 +0300	[thread overview]
Message-ID: <ag-jnBZl2rtx1Pjn@kernel.org> (raw)
In-Reply-To: <20260521093639.162095-3-thorsten.blum@linux.dev>

On Thu, May 21, 2026 at 11:36:39AM +0200, Thorsten Blum wrote:
> Commit 186d124f07da ("tpm_eventlog.c: fix binary_bios_measurements")
> split the output to write the endian-converted event header first and
> then the variable-length event data.
> 
> However, the split was at sizeof(struct tcpa_event) - 1, even though
> event_data was a zero-length array, and later a flexible array member,
> both of which already excluded the event data.
> 
> Therefore, the current code writes the first three bytes of event_size
> from the endian-converted header and then the last byte from the raw
> header, which can emit a corrupted event_size on PPC64, where
> do_endian_conversion() maps to be32_to_cpu().
> 
> Use seq_write() to write the full endian-converted header, followed by
> the variable-length event->event_data.
> 
> Drop the obvious comment while at it.
> 
> Fixes: 186d124f07da ("tpm_eventlog.c: fix binary_bios_measurements")
> Cc: stable@vger.kernel.org
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
>  drivers/char/tpm/eventlog/tpm1.c | 16 ++--------------
>  1 file changed, 2 insertions(+), 14 deletions(-)

Got it, I think you're probably right.

> 
> diff --git a/drivers/char/tpm/eventlog/tpm1.c b/drivers/char/tpm/eventlog/tpm1.c
> index e7913b2853d5..291720e89d91 100644
> --- a/drivers/char/tpm/eventlog/tpm1.c
> +++ b/drivers/char/tpm/eventlog/tpm1.c
> @@ -224,29 +224,17 @@ static int tpm1_binary_bios_measurements_show(struct seq_file *m, void *v)
>  {
>  	struct tcpa_event *event = v;
>  	struct tcpa_event temp_event;
> -	char *temp_ptr;
> -	int i;
>  
>  	memcpy(&temp_event, event, sizeof(struct tcpa_event));
>  
> -	/* convert raw integers for endianness */

spurious change

>  	temp_event.pcr_index = do_endian_conversion(event->pcr_index);
>  	temp_event.event_type = do_endian_conversion(event->event_type);
>  	temp_event.event_size = do_endian_conversion(event->event_size);
>  
> -	temp_ptr = (char *) &temp_event;
> -
> -	for (i = 0; i < (sizeof(struct tcpa_event) - 1) ; i++)
> -		seq_putc(m, temp_ptr[i]);

Why changing condition does not fix the bug? This could be just +-1 line
change.

> -
> -	temp_ptr = (char *) v;
> -
> -	for (i = (sizeof(struct tcpa_event) - 1);
> -	     i < (sizeof(struct tcpa_event) + temp_event.event_size); i++)
> -		seq_putc(m, temp_ptr[i]);
> +	seq_write(m, &temp_event, sizeof(temp_event));
> +	seq_write(m, event->event_data, temp_event.event_size);
>  
>  	return 0;
> -
>  }
>  
>  static int tpm1_ascii_bios_measurements_show(struct seq_file *m, void *v)

BR, Jarkko

      reply	other threads:[~2026-05-22  0:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21  9:36 [PATCH] tpm: fix event_size output in tpm1_binary_bios_measurements_show Thorsten Blum
2026-05-22  0:30 ` Jarkko Sakkinen [this message]

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=ag-jnBZl2rtx1Pjn@kernel.org \
    --to=jarkko@kernel.org \
    --cc=colin.i.king@gmail.com \
    --cc=harald@redhat.com \
    --cc=jgg@ziepe.ca \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterhuewe@gmx.de \
    --cc=stable@vger.kernel.org \
    --cc=thorsten.blum@linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox