Blame SOURCES/0001-tpm2-When-writing-state-initialize-s_ContextSlotMask.patch

a6f07b
From b662e6fd7169f31ef664ecd0b0b45547462e1e31 Mon Sep 17 00:00:00 2001
a6f07b
From: Stefan Berger <stefanb@linux.ibm.com>
a6f07b
Date: Tue, 4 Jan 2022 14:45:31 -0500
a6f07b
Subject: [PATCH] tpm2: When writing state initialize s_ContextSlotMask if not
a6f07b
 set
a6f07b
a6f07b
If s_ContextSlotMask was not set since the TPM 2 was not initialized
a6f07b
by a call to TPM_Manufacture() or the state was not resumed, then
a6f07b
initialize the s_ContextSlotMask to 0xffff.
a6f07b
a6f07b
This situation can occur if a VM with an attached swtpm was started
a6f07b
and the VM's firmware either doesn't support TPM or didn't get to
a6f07b
initialize the vTPM.
a6f07b
a6f07b
The following commands recreated the issue with a SeaBIOS-only VM that
a6f07b
had no attached hard disk but an attached TPM 2:
a6f07b
a6f07b
virsh start BIOS-only-VM ; virsh save BIOS-only-VM save.bin ; \
a6f07b
 virsh restore save.bin
a6f07b
a6f07b
Error: Failed to restore domain from save.bin
a6f07b
error: internal error: qemu unexpectedly closed the monitor: \
a6f07b
2022-01-04T19:26:18.835851Z qemu-system-x86_64: tpm-emulator: Setting the stateblob (type 2) failed with a TPM error 0x3 a parameter is bad
a6f07b
2022-01-04T19:26:18.835899Z qemu-system-x86_64: error while loading state for instance 0x0 of device 'tpm-emulator'
a6f07b
2022-01-04T19:26:18.835929Z qemu-system-x86_64: load of migration failed: Input/output error
a6f07b
a6f07b
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2035731
a6f07b
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
a6f07b
---
a6f07b
 src/tpm2/NVMarshal.c | 5 +++++
a6f07b
 1 file changed, 5 insertions(+)
a6f07b
a6f07b
diff --git a/src/tpm2/NVMarshal.c b/src/tpm2/NVMarshal.c
a6f07b
index 996c73c..c7cd1e0 100644
a6f07b
--- a/src/tpm2/NVMarshal.c
a6f07b
+++ b/src/tpm2/NVMarshal.c
a6f07b
@@ -1422,6 +1422,11 @@ STATE_RESET_DATA_Marshal(STATE_RESET_DATA *data, BYTE **buffer, INT32 *size)
a6f07b
     written += UINT16_Marshal(&array_size, buffer, size);
a6f07b
     for (i = 0; i < array_size; i++)
a6f07b
         written += UINT16_Marshal(&data->contextArray[i], buffer, size);
a6f07b
+
a6f07b
+    if (s_ContextSlotMask != 0x00ff && s_ContextSlotMask != 0xffff) {
a6f07b
+        /* TPM wasn't initialized, so s_ContextSlotMask wasn't set */
a6f07b
+        s_ContextSlotMask = 0xffff;
a6f07b
+    }
a6f07b
     written += UINT16_Marshal(&s_ContextSlotMask, buffer, size);
a6f07b
 
a6f07b
     written += UINT64_Marshal(&data->contextCounter, buffer, size);
a6f07b
-- 
a6f07b
2.36.1
a6f07b