mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tpm: efi: reject a final events table with an oversized preboot log
@ 2026-11-06  1:49 Guo Zihao
  2026-11-06  9:12 ` Ard Biesheuvel
  2026-11-06 15:24 ` [PATCH] " Jarkko Sakkinen
  0 siblings, 2 replies; 4+ messages in thread
From: Guo Zihao @ 2026-11-06  1:49 UTC (permalink / raw)
  To: Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, Ard Biesheuvel, Matthew Garrett,
	linux-integrity, linux-kernel, stable

The preboot portion recorded in the main event log is subtracted from
the size of the final events table taken from the firmware:

	/*
	 * The 'final events log' size excludes the 'final events preboot log'
	 * at its beginning.
	 */
	final_events_log_size -= log_tbl->final_events_preboot_size;

Both sizes come from EFI configuration tables and are not validated
against each other. A final events table claiming a preboot portion
larger than the table itself makes final_events_log_size go negative:
the subsequent devm_krealloc() can then end up with a wrapped, too
small allocation, and the memcpy() that appends the final events log
uses the negative value as its length, running far past the buffer.

The boot path has no way to fix up such a table, so fail the final
events log instead of appending from it.

Fixes: 166a2809d65b ("tpm: Don't duplicate events from the final event log in the TCG2 log")
Cc: stable@vger.kernel.org
Signed-off-by: Guo Zihao <guozh23@xiaopeng.com>
---
 drivers/char/tpm/eventlog/efi.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/char/tpm/eventlog/efi.c b/drivers/char/tpm/eventlog/efi.c
index 4e9d7c2bf..0a8006f3e 100644
--- a/drivers/char/tpm/eventlog/efi.c
+++ b/drivers/char/tpm/eventlog/efi.c
@@ -82,6 +82,9 @@ int tpm_read_log_efi(struct tpm_chip *chip)
 		goto out;
 	}
 
+	if (log_tbl->final_events_preboot_size > final_events_log_size)
+		goto out;
+
 	/*
 	 * The 'final events log' size excludes the 'final events preboot log'
 	 * at its beginning.
-- 
2.50.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tpm: efi: reject a final events table with an oversized preboot log
  2026-11-06  1:49 [PATCH] tpm: efi: reject a final events table with an oversized preboot log Guo Zihao
@ 2026-11-06  9:12 ` Ard Biesheuvel
  2026-11-06  9:20   ` [PATCH v2] " Guo Zihao
  2026-11-06 15:24 ` [PATCH] " Jarkko Sakkinen
  1 sibling, 1 reply; 4+ messages in thread
From: Ard Biesheuvel @ 2026-11-06  9:12 UTC (permalink / raw)
  To: Guo Zihao, Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, Matthew Garrett, linux-integrity, linux-kernel, stable


On Fri, 6 Nov 2026, at 02:49, Guo Zihao wrote:
> The preboot portion recorded in the main event log is subtracted from
> the size of the final events table taken from the firmware:
>
> 	/*
> 	 * The 'final events log' size excludes the 'final events preboot log'
> 	 * at its beginning.
> 	 */
> 	final_events_log_size -= log_tbl->final_events_preboot_size;
>
> Both sizes come from EFI configuration tables and are not validated
> against each other. A final events table claiming a preboot portion
> larger than the table itself makes final_events_log_size go negative:
> the subsequent devm_krealloc() can then end up with a wrapped, too
> small allocation, and the memcpy() that appends the final events log
> uses the negative value as its length, running far past the buffer.
>
> The boot path has no way to fix up such a table, so fail the final
> events log instead of appending from it.
>
> Fixes: 166a2809d65b ("tpm: Don't duplicate events from the final event 
> log in the TCG2 log")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guo Zihao <guozh23@xiaopeng.com>
> ---
>  drivers/char/tpm/eventlog/efi.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/char/tpm/eventlog/efi.c b/drivers/char/tpm/eventlog/efi.c
> index 4e9d7c2bf..0a8006f3e 100644
> --- a/drivers/char/tpm/eventlog/efi.c
> +++ b/drivers/char/tpm/eventlog/efi.c
> @@ -82,6 +82,9 @@ int tpm_read_log_efi(struct tpm_chip *chip)
>  		goto out;
>  	}
> 
> +	if (log_tbl->final_events_preboot_size > final_events_log_size)
> +		goto out;
> +

Should we add a pr_warn() here?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2] tpm: efi: reject a final events table with an oversized preboot log
  2026-11-06  9:12 ` Ard Biesheuvel
@ 2026-11-06  9:20   ` Guo Zihao
  0 siblings, 0 replies; 4+ messages in thread
From: Guo Zihao @ 2026-11-06  9:20 UTC (permalink / raw)
  To: Peter Huewe, Jarkko Sakkinen
  Cc: Jason Gunthorpe, Ard Biesheuvel, Matthew Garrett,
	linux-integrity, linux-kernel, stable

The preboot portion recorded in the main event log is subtracted from
the size of the final events table taken from the firmware:

/*
 * The 'final events log' size excludes the 'final events preboot log'
 * at its beginning.
 */
final_events_log_size -= log_tbl->final_events_preboot_size;

Both sizes come from EFI configuration tables and are not validated
against each other. A final events table claiming a preboot portion
larger than the table itself makes final_events_log_size go negative:
the subsequent devm_krealloc() can then end up with a wrapped, too
small allocation, and the memcpy() that appends the final events log
uses the negative value as its length, running far past the buffer.

The boot path has no way to fix up such a table, so fail the final
events log instead of appending from it. Warn before dropping it, so
a malformed firmware table leaves a trace instead of a silently
missing final events log.

Fixes: 166a2809d65b ("tpm: Don't duplicate events from the final event log in the TCG2 log")
Cc: stable@vger.kernel.org
Signed-off-by: Guo Zihao <guozh23@xiaopeng.com>
---

v2: Add a pr_warn() before dropping the final events log, as suggested
by Ard Biesheuvel, so a malformed firmware table leaves a trace.

 drivers/char/tpm/eventlog/efi.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/char/tpm/eventlog/efi.c b/drivers/char/tpm/eventlog/efi.c
index 4e9d7c2bf32e..76860f9a25de 100644
--- a/drivers/char/tpm/eventlog/efi.c
+++ b/drivers/char/tpm/eventlog/efi.c
@@ -82,6 +82,13 @@ int tpm_read_log_efi(struct tpm_chip *chip)
 		goto out;
 	}
 
+	if (log_tbl->final_events_preboot_size > final_events_log_size) {
+		pr_warn("UEFI TPM final events table has an oversized preboot log: %u > %d\n",
+			log_tbl->final_events_preboot_size,
+			final_events_log_size);
+		goto out;
+	}
+
 	/*
 	 * The 'final events log' size excludes the 'final events preboot log'
 	 * at its beginning.
-- 
2.50.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] tpm: efi: reject a final events table with an oversized preboot log
  2026-11-06  1:49 [PATCH] tpm: efi: reject a final events table with an oversized preboot log Guo Zihao
  2026-11-06  9:12 ` Ard Biesheuvel
@ 2026-11-06 15:24 ` Jarkko Sakkinen
  1 sibling, 0 replies; 4+ messages in thread
From: Jarkko Sakkinen @ 2026-11-06 15:24 UTC (permalink / raw)
  To: Guo Zihao
  Cc: Peter Huewe, Jason Gunthorpe, Ard Biesheuvel, Matthew Garrett,
	linux-integrity, linux-kernel, stable

On Fri, Nov 06, 2026 at 09:49:56AM +0800, Guo Zihao wrote:
> The preboot portion recorded in the main event log is subtracted from
> the size of the final events table taken from the firmware:
> 
> 	/*
> 	 * The 'final events log' size excludes the 'final events preboot log'
> 	 * at its beginning.
> 	 */
> 	final_events_log_size -= log_tbl->final_events_preboot_size;
> 
> Both sizes come from EFI configuration tables and are not validated
> against each other. A final events table claiming a preboot portion
> larger than the table itself makes final_events_log_size go negative:
> the subsequent devm_krealloc() can then end up with a wrapped, too
> small allocation, and the memcpy() that appends the final events log
> uses the negative value as its length, running far past the buffer.
> 
> The boot path has no way to fix up such a table, so fail the final
> events log instead of appending from it.
> 
> Fixes: 166a2809d65b ("tpm: Don't duplicate events from the final event log in the TCG2 log")
> Cc: stable@vger.kernel.org
> Signed-off-by: Guo Zihao <guozh23@xiaopeng.com>

Ditto.

For all four address validation vs bug fix intersection. I did not
check throughly enough to be exactly sure of all four.

Br, Jarkko

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-06 15:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06  1:49 [PATCH] tpm: efi: reject a final events table with an oversized preboot log Guo Zihao
2026-11-06  9:12 ` Ard Biesheuvel
2026-11-06  9:20   ` [PATCH v2] " Guo Zihao
2026-11-06 15:24 ` [PATCH] " Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®