From e19e07937f73644abaad530387de09e74352b110 Mon Sep 17 00:00:00 2001 From: Sergii Dmytruk Date: Fri, 5 Apr 2024 20:54:17 +0300 Subject: [PATCH] arch/x86/tpm.c: fix appending to event log of TPM1 Just like TPM2 case this code path also needs extra handling on AMD because TXT-compatible data prepared by SKL is stored inside of vendor data field of TCG header. Signed-off-by: Sergii Dmytruk --- xen/arch/x86/tpm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/xen/arch/x86/tpm.c b/xen/arch/x86/tpm.c index b4b73b6eb2..a713be6cd4 100644 --- a/xen/arch/x86/tpm.c +++ b/xen/arch/x86/tpm.c @@ -276,6 +276,21 @@ struct TPM12_PCREvent { uint8_t Data[]; }; +struct tpm1_spec_id_event { + uint32_t pcrIndex; + uint32_t eventType; + uint8_t digest[20]; + uint32_t eventSize; + uint8_t signature[16]; + uint32_t platformClass; + uint8_t specVersionMinor; + uint8_t specVersionMajor; + uint8_t specErrata; + uint8_t uintnSize; + uint8_t vendorInfoSize; + uint8_t vendorInfo[0]; /* variable number of members */ +} __packed; + struct txt_ev_log_container_12 { char Signature[20]; /* "TXT Event Container", null-terminated */ uint8_t Reserved[12]; @@ -409,6 +424,15 @@ static void *create_log_event12(struct txt_ev_log_container_12 *evt_log, { struct TPM12_PCREvent *new_entry; + if ( is_amd_cpu() ) { + /* + * On AMD, TXT-compatible structure is stored as vendor data of + * TCG-defined event log header. + */ + struct tpm1_spec_id_event *spec_id = (void *)evt_log; + evt_log = (struct txt_ev_log_container_12 *)&spec_id->vendorInfo[0]; + } + new_entry = (void *)(((uint8_t *)evt_log) + evt_log->NextEventOffset); /*