keylime/SOURCES/0002-tpm_bootlog_enrich-Get...

71 lines
2.5 KiB
Diff

From 2fee03637d3a1d0c9c004b958af69f4b0e4b57f3 Mon Sep 17 00:00:00 2001
From: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Date: Fri, 4 Nov 2022 17:41:31 +0100
Subject: [PATCH 2/2] tpm_bootlog_enrich: Get DevicePath length from
LengthOfDevicePath
In enrich_device_path(), get the length of DevicePath from the field
LengthOfDevicePath instead of calculating the length from the bytes
array.
This avoids a segmentation fault when processing the measured boot event
log in create_mb_refstate script.
This is called for the events "EV_EFI_BOOT_SERVICES_APPLICATION",
"EV_EFI_BOOT_SERVICES_DRIVER", and "EV_EFI_RUNTIME_SERVICES_DRIVER".
Fixes: #1153
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
---
keylime/tpm_bootlog_enrich.py | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/keylime/tpm_bootlog_enrich.py b/keylime/tpm_bootlog_enrich.py
index ef8e9f7..621bc67 100644
--- a/keylime/tpm_bootlog_enrich.py
+++ b/keylime/tpm_bootlog_enrich.py
@@ -46,14 +46,14 @@ yaml.add_representer(hexint, representer)
efivarlib_functions = CDLL(config.LIBEFIVAR)
-def getDevicePath(b):
- ret = efivarlib_functions.efidp_format_device_path(0, 0, b, len(b))
+def getDevicePath(b, l):
+ ret = efivarlib_functions.efidp_format_device_path(0, 0, b, l)
if ret < 0:
raise Exception(f"getDevicePath: efidp_format_device_path({b}) returned {ret}")
s = create_string_buffer(ret + 1)
- ret = efivarlib_functions.efidp_format_device_path(s, ret + 1, b, len(b))
+ ret = efivarlib_functions.efidp_format_device_path(s, ret + 1, b, l)
if ret < 0:
raise Exception(f"getDevicePath: efidp_format_device_path({b}) returned {ret}")
@@ -174,7 +174,7 @@ def getVar(event, b):
c = w.decode("utf-16", errors="ignore")
description += c
r["Description"] = description
- devicePath = getDevicePath(b[i:])
+ devicePath = getDevicePath(b[i:], len(b[i:]))
r["DevicePath"] = devicePath
return r
return None
@@ -184,10 +184,11 @@ def enrich_device_path(d: dict) -> None:
if isinstance(d.get("DevicePath"), str):
try:
b = bytes.fromhex(d["DevicePath"])
+ l = int(d["LengthOfDevicePath"])
except Exception:
return
try:
- p = getDevicePath(b)
+ p = getDevicePath(b, l)
# Deal with garbage devicePath
except Exception:
return
--
2.38.1