From nobody Tue Oct 7 19:50:22 2025 Received: from m16.mail.126.com (m16.mail.126.com [220.197.31.8]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60B8B12B94; Mon, 7 Jul 2025 03:30:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.8 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751859047; cv=none; b=df5aZIkn52NIvwG1bJ3eu1eGsNFEpJZInhA/yaQt6kqO4mXOh450BNBXlb30wmlCraBqevZ4X+lh0zD+9LVwqzcMEvZhmuhl/q/XTfVjbp+WcgZAyiFVl5337y0Yg1SoZXkTPHTdQDHsIWFU5i8BFaSZ5IJG7TldsflBAG0vUDo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751859047; c=relaxed/simple; bh=kxBDgCOSz0tq1MaLRMuxn7XrqsVVSATXO/ynrjrJbd0=; h=From:To:Cc:Subject:Date:Message-Id; b=dbN/bd3RaaebwIbS8un1mtquzB9sI7mz2OHSvEJetWC9kAa9oWfA+ioKt0j/RD6W/mgWLcTzM5FyA22rZ+mHJK7hCer2BpS1BUTMBuZma2FNjV2t1+edssbQlyvQePHNIHlKo6EPfMrB9K6MnVap8e1G7FnNKeV1isPVJu9cFaE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com; spf=pass smtp.mailfrom=126.com; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b=iO2AS+Bt; arc=none smtp.client-ip=220.197.31.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b="iO2AS+Bt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:To:Subject:Date:Message-Id; bh=HP8tZujBjcSHGre MG32sL06BiLfrv9CiKF8NSKgD8CQ=; b=iO2AS+Bt7g1bJfHsadCJ/avBYWhlivM hGDlFCw4gJZjPqnyyWWxzbnXbPeR1Fb4HaeMAUw8+XRjaWGvzvIzb7whz7S7AQnA i/ePZUoox4I+ZaUytryt2THzbQRet/GLEjglDFLc7B6UnGqQwBw6i9u5ZTU6956x 1DjdcyXLrzeQ= Received: from hg-OptiPlex-7040.hygon.cn (unknown []) by gzga-smtp-mtada-g0-0 (Coremail) with SMTP id _____wDnr9uoO2tor4cpBA--.25530S2; Mon, 07 Jul 2025 11:14:49 +0800 (CST) From: yangge1116@126.com To: ardb@kernel.org Cc: jarkko@kernel.org, sathyanarayanan.kuppuswamy@linux.intel.com, ilias.apalodimas@linaro.org, jgg@ziepe.ca, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, liuzixing@hygon.cn, Ge Yang Subject: [PATCH V3] efi/tpm: Fix the issue where the CC platforms event log header can't be correctly identified Date: Mon, 7 Jul 2025 11:14:47 +0800 Message-Id: <1751858087-10366-1-git-send-email-yangge1116@126.com> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: _____wDnr9uoO2tor4cpBA--.25530S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxtryxtrW3CF4DXrW3Xr13Jwb_yoW3JF4DpF 48Jr9Yyr45ta1Igw1fAw1UCwsxXw4ktrZrGFyDK34jyrnxWFyIgFWUGFy5GF93trs7J3Z0 qa4Utr17Ca4UuaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRoKZXUUUUU= X-CM-SenderInfo: 51dqwwjhrrila6rslhhfrp/1tbiOhGDG2hrOMlJZwAAsv Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ge Yang Since commit d228814b1913 ("efi/libstub: Add get_event_log() support for CC platforms") reuses TPM2 support code for the CC platforms, when launching a TDX virtual machine with coco measurement enabled, the following error log is generated: [Firmware Bug]: Failed to parse event in TPM Final Events Log Call Trace: efi_config_parse_tables() efi_tpm_eventlog_init() tpm2_calc_event_log_size() __calc_tpm2_event_size() The pcr_idx value in the Intel TDX log header is 1, causing the function __calc_tpm2_event_size() to fail to recognize the log header, ultimately leading to the "Failed to parse event in TPM Final Events Log" error. According to UEFI Specification 2.10, Section 38.4.1: For TDX, TPM PCR 0 maps to MRTD, so the log header uses TPM PCR 1 instead. To successfully parse the TDX event log header, the check for a pcr_idx value of 0 must be skipped. According to Table 6 in Section 10.2.1 of the TCG PC Client Specification, the index field does not require the PCR index to be fixed at zero. Therefore, skipping the check for a pcr_idx value of 0 for CC platforms is safe. Link: https://uefi.org/specs/UEFI/2.10/38_Confidential_Computing.html#intel= -trust-domain-extension Link: https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClient_PFP= _r1p05_v23_pub.pdf Fixes: d228814b1913 ("efi/libstub: Add get_event_log() support for CC platf= orms") Signed-off-by: Ge Yang Cc: stable@vger.kernel.org --- V3: - fix build error V2: - limit the fix for CC only suggested by Jarkko and Sathyanarayanan drivers/char/tpm/eventlog/tpm2.c | 4 +++- drivers/firmware/efi/libstub/tpm.c | 13 +++++++++---- drivers/firmware/efi/tpm.c | 4 +++- include/linux/tpm_eventlog.h | 14 +++++++++++--- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/char/tpm/eventlog/tpm2.c b/drivers/char/tpm/eventlog/t= pm2.c index 37a0580..30ef47c 100644 --- a/drivers/char/tpm/eventlog/tpm2.c +++ b/drivers/char/tpm/eventlog/tpm2.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 #include "../tpm.h" #include "common.h" @@ -36,7 +37,8 @@ static size_t calc_tpm2_event_size(struct tcg_pcr_event2_head *event, struct tcg_pcr_event *event_header) { - return __calc_tpm2_event_size(event, event_header, false); + return __calc_tpm2_event_size(event, event_header, false, + cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)); } =20 static void *tpm2_bios_measurements_start(struct seq_file *m, loff_t *pos) diff --git a/drivers/firmware/efi/libstub/tpm.c b/drivers/firmware/efi/libs= tub/tpm.c index a5c6c4f..9728060 100644 --- a/drivers/firmware/efi/libstub/tpm.c +++ b/drivers/firmware/efi/libstub/tpm.c @@ -50,7 +50,8 @@ void efi_enable_reset_attack_mitigation(void) static void efi_retrieve_tcg2_eventlog(int version, efi_physical_addr_t lo= g_location, efi_physical_addr_t log_last_entry, efi_bool_t truncated, - struct efi_tcg2_final_events_table *final_events_table) + struct efi_tcg2_final_events_table *final_events_table, + bool is_cc_event) { efi_guid_t linux_eventlog_guid =3D LINUX_EFI_TPM_EVENT_LOG_GUID; efi_status_t status; @@ -87,7 +88,8 @@ static void efi_retrieve_tcg2_eventlog(int version, efi_p= hysical_addr_t log_loca last_entry_size =3D __calc_tpm2_event_size((void *)last_entry_addr, (void *)(long)log_location, - false); + false, + is_cc_event); } else { last_entry_size =3D sizeof(struct tcpa_event) + ((struct tcpa_event *) last_entry_addr)->event_size; @@ -123,7 +125,8 @@ static void efi_retrieve_tcg2_eventlog(int version, efi= _physical_addr_t log_loca header =3D data + offset + final_events_size; event_size =3D __calc_tpm2_event_size(header, (void *)(long)log_location, - false); + false, + is_cc_event); /* If calc fails this is a malformed log */ if (!event_size) break; @@ -157,6 +160,7 @@ void efi_retrieve_eventlog(void) efi_tcg2_protocol_t *tpm2 =3D NULL; efi_bool_t truncated; efi_status_t status; + bool is_cc_event =3D false; =20 status =3D efi_bs_call(locate_protocol, &tpm2_guid, NULL, (void **)&tpm2); if (status =3D=3D EFI_SUCCESS) { @@ -186,11 +190,12 @@ void efi_retrieve_eventlog(void) =20 final_events_table =3D get_efi_config_table(EFI_CC_FINAL_EVENTS_TABLE_GUID); + is_cc_event =3D true; } =20 if (status !=3D EFI_SUCCESS || !log_location) return; =20 efi_retrieve_tcg2_eventlog(version, log_location, log_last_entry, - truncated, final_events_table); + truncated, final_events_table, is_cc_event); } diff --git a/drivers/firmware/efi/tpm.c b/drivers/firmware/efi/tpm.c index cdd4310..ca8535d 100644 --- a/drivers/firmware/efi/tpm.c +++ b/drivers/firmware/efi/tpm.c @@ -12,6 +12,7 @@ #include #include #include +#include =20 int efi_tpm_final_log_size; EXPORT_SYMBOL(efi_tpm_final_log_size); @@ -23,7 +24,8 @@ static int __init tpm2_calc_event_log_size(void *data, in= t count, void *size_inf =20 while (count > 0) { header =3D data + size; - event_size =3D __calc_tpm2_event_size(header, size_info, true); + event_size =3D __calc_tpm2_event_size(header, size_info, true, + cc_platform_has(CC_ATTR_GUEST_STATE_ENCRYPT)); if (event_size =3D=3D 0) return -1; size +=3D event_size; diff --git a/include/linux/tpm_eventlog.h b/include/linux/tpm_eventlog.h index 891368e..b3380c9 100644 --- a/include/linux/tpm_eventlog.h +++ b/include/linux/tpm_eventlog.h @@ -143,6 +143,7 @@ struct tcg_algorithm_info { * @event: Pointer to the event whose size should be calculated * @event_header: Pointer to the initial event containing the digest lengt= hs * @do_mapping: Whether or not the event needs to be mapped + * @is_cc_event: Whether or not the event is from a CC platform * * The TPM2 event log format can contain multiple digests corresponding to * separate PCR banks, and also contains a variable length of the data that @@ -159,7 +160,8 @@ struct tcg_algorithm_info { =20 static __always_inline u32 __calc_tpm2_event_size(struct tcg_pcr_event2_he= ad *event, struct tcg_pcr_event *event_header, - bool do_mapping) + bool do_mapping, + bool is_cc_event) { struct tcg_efi_specid_event_head *efispecid; struct tcg_event_field *event_field; @@ -201,8 +203,14 @@ static __always_inline u32 __calc_tpm2_event_size(stru= ct tcg_pcr_event2_head *ev count =3D event->count; event_type =3D event->event_type; =20 - /* Verify that it's the log header */ - if (event_header->pcr_idx !=3D 0 || + /* + * Verify that it's the log header. According to the TCG PC Client + * Specification, when identifying a log header, the check for a + * pcr_idx value of 0 is not required. For CC platforms, skipping + * this check during log header is necessary; otherwise, the CC + * platform's log header may fail to be recognized. + */ + if ((!is_cc_event && event_header->pcr_idx !=3D 0) || event_header->event_type !=3D NO_ACTION || memcmp(event_header->digest, zero_digest, sizeof(zero_digest))) { size =3D 0; --=20 2.7.4