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

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