Blame SOURCES/0001-ima-Fix-log-evaluation-on-quick-succession-execution.patch

c49324
From de8bbb63dca836bcf07586186218c3227749d2e7 Mon Sep 17 00:00:00 2001
c49324
From: Stefan Berger <stefanb@linux.ibm.com>
c49324
Date: Fri, 4 Nov 2022 11:20:15 -0400
c49324
Subject: [PATCH] ima: Fix log evaluation on quick-succession execution of
c49324
 scripts
c49324
c49324
In case the attested-to host quickly executes files measured by IMA we may
c49324
run into the case that the keylime agent retrieved the state of the PCR at
c49324
'state n' but then IMA appended the log with several entries leading to a
c49324
log representing 'state n + x' (with x>=1), which may not just be the
c49324
previously anticipated single additional entry (state n+1). Therefore,
c49324
remove the check for the number of entries in the log and always compare
c49324
the running_hash that iterative attestation was resumed with against the
c49324
provided PCR value from 'state n'.
c49324
c49324
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
c49324
---
c49324
 keylime/ima/ima.py | 8 +++++---
c49324
 1 file changed, 5 insertions(+), 3 deletions(-)
c49324
c49324
diff --git a/keylime/ima/ima.py b/keylime/ima/ima.py
c49324
index b88b1af..c4c2ae6 100644
c49324
--- a/keylime/ima/ima.py
c49324
+++ b/keylime/ima/ima.py
c49324
@@ -299,9 +299,11 @@ def _process_measurement_list(
c49324
 
c49324
     # Iterative attestation may send us no log [len(lines) == 1]; compare last know PCR 10 state
c49324
     # against current PCR state.
c49324
-    # Since IMA log append and PCR extend is not atomic, we may get a quote that does not yet take
c49324
-    # into account the next appended measurement's [len(lines) == 2] PCR extension.
c49324
-    if not found_pcr and len(lines) <= 2:
c49324
+    # Since IMA's append to the log and PCR extend as well as Keylime's retrieval of the quote, reading
c49324
+    # of PCR 10 and retrieval of the log are not atomic, we may get a quote that does not yet take into
c49324
+    # account the next-appended measurements' [len(lines) >= 2] PCR extension(s). In fact, the value of
c49324
+    # the PCR may lag the log by several entries.
c49324
+    if not found_pcr:
c49324
         found_pcr = running_hash == pcrval_bytes
c49324
 
c49324
     for linenum, line in enumerate(lines):
c49324
-- 
c49324
2.37.3
c49324