lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240830212852.2794145-1-usamaarif642@gmail.com>
Date: Fri, 30 Aug 2024 22:28:52 +0100
From: Usama Arif <usamaarif642@...il.com>
To: ardb@...nel.org,
	linux-efi@...r.kernel.org
Cc: linux-kernel@...r.kernel.org,
	leitao@...ian.org,
	gourry@...rry.net,
	Usama Arif <usamaarif642@...il.com>
Subject: [PATCH] efi: reserve memory for tpm_log only if TPM final events table is valid

If efi.tpm_log is corrupted, log_tbl->size can be garbage (and
negative). This can result in a large memblock reservation, resulting
in the kernel booting without sufficient memory. Move the memblock
reservation after log_tbl->version check, and check the value of
both tbl_size and memblock_reserve.

Signed-off-by: Usama Arif <usamaarif642@...il.com>
---
 drivers/firmware/efi/tpm.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c
index e8d69bd548f3..cfc6a065f441 100644
--- a/drivers/firmware/efi/tpm.c
+++ b/drivers/firmware/efi/tpm.c
@@ -59,9 +59,6 @@ int __init efi_tpm_eventlog_init(void)
 		return -ENOMEM;
 	}
 
-	tbl_size = sizeof(*log_tbl) + log_tbl->size;
-	memblock_reserve(efi.tpm_log, tbl_size);
-
 	if (efi.tpm_final_log == EFI_INVALID_TABLE_ADDR) {
 		pr_info("TPM Final Events table not present\n");
 		goto out;
@@ -70,6 +67,19 @@ int __init efi_tpm_eventlog_init(void)
 		goto out;
 	}
 
+	tbl_size = sizeof(*log_tbl) + log_tbl->size;
+	if (tbl_size < 0) {
+		pr_err(FW_BUG "Failed to parse event in TPM Final Events Log\n");
+		ret = -EINVAL;
+		goto out;
+	}
+	if (memblock_reserve(efi.tpm_log, tbl_size)) {
+		pr_err("TPM Event Log memblock reserve fails 0x%lx - %x\n",
+		       efi.tpm_log, tbl_size);
+		ret = -ENOMEM;
+		goto out;
+	}
+
 	final_tbl = early_memremap(efi.tpm_final_log, sizeof(*final_tbl));
 
 	if (!final_tbl) {
-- 
2.43.5


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ