public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tpm/eventlog: Limit memory allocations for event logs with excessive size
@ 2024-12-10 22:26 Stefan Berger
  2024-12-14  3:51 ` Jarkko Sakkinen
  2024-12-20  1:47 ` Liang, Andy (Linux Ecosystem Engineering)
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Berger @ 2024-12-10 22:26 UTC (permalink / raw)
  To: linux-integrity, jarkko
  Cc: linux-kernel, Stefan Berger, Andy Liang, Takashi Iwai

The TPM2 ACPI BIOS eventlog of a particular machine indicates that the
length of the log is 4MB, even though the actual length of its useful data,
when dumped, are only 69kb. To avoid allocating excessive amounts of memory
for the event log, limit the size of any eventlog to 128kb. This should be
sufficient memory and also not unnecessarily truncate event logs on any
other machine.

Reported-by: Andy Liang <andy.liang@hpe.com>
Closes: https://bugzilla.kernel.org/show_bug.cgi?id=219495
Cc: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
 drivers/char/tpm/eventlog/acpi.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/char/tpm/eventlog/acpi.c b/drivers/char/tpm/eventlog/acpi.c
index 69533d0bfb51..701fd7d4cc28 100644
--- a/drivers/char/tpm/eventlog/acpi.c
+++ b/drivers/char/tpm/eventlog/acpi.c
@@ -26,6 +26,8 @@
 #include "../tpm.h"
 #include "common.h"
 
+#define MAX_TPM_LOG_LEN		(128 * 1024)
+
 struct acpi_tcpa {
 	struct acpi_table_header hdr;
 	u16 platform_class;
@@ -135,6 +137,12 @@ int tpm_read_log_acpi(struct tpm_chip *chip)
 		return -EIO;
 	}
 
+	if (len > MAX_TPM_LOG_LEN) {
+		dev_warn(&chip->dev, "Excessive TCPA log len %llu truncated to %u bytes\n",
+			 len, MAX_TPM_LOG_LEN);
+		len = MAX_TPM_LOG_LEN;
+	}
+
 	/* malloc EventLog space */
 	log->bios_event_log = devm_kmalloc(&chip->dev, len, GFP_KERNEL);
 	if (!log->bios_event_log)
-- 
2.43.0


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

end of thread, other threads:[~2024-12-20 10:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-10 22:26 [PATCH] tpm/eventlog: Limit memory allocations for event logs with excessive size Stefan Berger
2024-12-14  3:51 ` Jarkko Sakkinen
2024-12-16 19:29   ` Stefan Berger
2024-12-19 15:29     ` Jarkko Sakkinen
2024-12-19 15:38       ` Jarkko Sakkinen
2024-12-20 10:15         ` Takashi Iwai
2024-12-20  1:47 ` Liang, Andy (Linux Ecosystem Engineering)

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