Enable TDX measurement to RTMR register
v4 cover Enable TDX measurement to RTMR register
Intel Trust Domain Extensions(Intel TDX) refers to an Intel technology that extends Virtual Machine Extensions(VMX) and Multi-Key Total Memory Encryption(MK-TME) with a new kind of virtual machine guest called a Trust Domain(TD)[1]. A TD runs in a CPU mode that protects the confidentiality of its memory contents and its CPU state from any other software, including the hosting Virtual Machine Monitor (VMM).
Trust Domain Virtual Firmware (TDVF) is required to provide TD services to
the TD guest OS.[2] Its reference code is available at https://github.com/tianocore/edk2-staging/tree/TDVF.
To support TD measurement/attestation, TDs provide 4 RTMR registers like TPM/TPM2 PCR as below:
- RTMR[0] is for TDVF configuration
- RTMR[1] is for the TD OS loader and kernel
- RTMR[2] is for the OS application
- RTMR[3] is reserved for special usage only
This patch adds TD Measurement protocol support along with TPM/TPM2 protocol.
References:
[1] https://software.intel.com/content/dam/develop/external/us/en/documents/tdx-whitepaper-v4.pdf
[2] https://software.intel.com/content/dam/develop/external/us/en/documents/tdx-virtual-firmware-design-guide-rev-1.pdf
Lu Ken (3):
efi/tpm.c: Refine the status of log event efi/tpm.c: Uses grub_strcpy() to replace grub_memcpy() efi/tpm.c: Enable EFI_CC_MEASUREMENT_PROTOCOL
grub-core/commands/efi/tpm.c | 64 ++++++++++++-- include/grub/efi/cc.h | 158 +++++++++++++++++++++++++++++++++++ 2 files changed, 215 insertions(+), 7 deletions(-) create mode 100644 include/grub/efi/cc.h
--
2.31.1
PATCH v4 1/3 efi/tpm.c: Refine the status of log event
1. Use macro GRUB_ERR_NONE instead of hard code 0.
2. Keep lowercase of the first char for the status string of log event.
--- grub-core/commands/efi/tpm.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
grub-core/commands/efi/tpm.c +5 -5
@@ -135,17 +135,17 @@ grub_efi_log_event_status (grub_efi_status_t status)switch (status) {case GRUB_EFI_SUCCESS : -return 0 ; +return GRUB_ERR_NONE ;case GRUB_EFI_DEVICE_ERROR : -return grub_error (GRUB_ERR_IO ,N_ ("Command failed" )); +return grub_error (GRUB_ERR_IO ,N_ ("command failed" ));case GRUB_EFI_INVALID_PARAMETER : -return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("Invalid parameter" )); +return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("invalid parameter" ));case GRUB_EFI_BUFFER_TOO_SMALL : -return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("Output buffer too small" )); +return grub_error (GRUB_ERR_BAD_ARGUMENT ,N_ ("output buffer too small" ));case GRUB_EFI_NOT_FOUND :return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,N_ ("TPM unavailable" ));default : -return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,N_ ("Unknown TPM error" )); +return grub_error (GRUB_ERR_UNKNOWN_DEVICE ,N_ ("unknown TPM error" )); } }
Signature · 1 line
2.31.1
PATCH v4 2/3 efi/tpm.c: Uses grub_strcpy() to replace grub_memcpy()
In reply to Lu KenThe event description is a string, so using grub_strcpy() is cleaner way than grub_memcpy().
--- grub-core/commands/efi/tpm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
grub-core/commands/efi/tpm.c +2 -2
@@ -175,7 +175,7 @@ grub_tpm1_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf, event->PCRIndex = pcr; event->EventType =EV_IPL ; event->EventSize =grub_strlen (description) +1 ; -grub_memcpy (event->Event, description, event->EventSize); +grub_strcpy (event->Event, description); algorithm =TCG_ALG_SHA ; status = efi_call_7 (tpm->log_extend_event, tpm, (grub_addr_t) buf, (grub_uint64_t) size,
@@ -212,7 +212,7 @@ grub_tpm2_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf, event->Header.EventType =EV_IPL ; event->Size =sizeof (*event) -sizeof (event->Event) +grub_strlen (description) +1 ; -grub_memcpy (event->Event, description,grub_strlen (description) +1 ); +grub_strcpy (event->Event, description); status =efi_call_5 (tpm->hash_log_extend_event, tpm,0 , (grub_addr_t ) buf, (grub_uint64_t ) size, event);
Signature · 1 line
2.31.1
PATCH v4 3/3 efi/tpm.c: Enable EFI_CC_MEASUREMENT_PROTOCOL
In reply to Lu KenEFI_CC_MEASUREMENT_PROTOCOL abstract the measurement for virtual firmware in confidential computing environment. It similiar to EFI_TCG2_PROTOCOL. It is proposed by Intel and ARM and approved by UEFI organization.
It is defined in Intel GHCI specification https://cdrdv2.intel.com/v1/dl/getContent/726790.
EDKII header file is at https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Protocol/CcMeasurement.h
--- grub-core/commands/efi/tpm.c | 50 +++++++++++ include/grub/efi/cc.h | 158 +++++++++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 include/grub/efi/cc.h
grub-core/commands/efi/tpm.c +50 -0
@@ -22,6 +22,7 @@#include <grub/i18n.h> #include <grub/efi/api.h> #include <grub/efi/efi.h> +#include <grub/efi/cc.h> #include <grub/efi/tpm.h> #include <grub/mm.h> #include <grub/tpm.h>
@@ -31,6 +32,7 @@ typedef TCG_PCR_EVENT grub_tpm_event_t;static grub_efi_guid_t tpm_guid =EFI_TPM_GUID ;static grub_efi_guid_t tpm2_guid =EFI_TPM2_GUID ; +static grub_efi_guid_t cc_measurement_guid =GRUB_EFI_CC_MEASUREMENT_PROTOCOL_GUID ;static grub_efi_handle_t *grub_tpm_handle;static grub_uint8_t grub_tpm_version;
@@ -221,6 +223,52 @@ grub_tpm2_log_event (grub_efi_handle_t tpm_handle, unsigned char *buf,return grub_efi_log_event_status (status); } +static +void +grub_cc_log_event (unsigned char *buf,grub_size_t size,grub_uint8_t pcr, +const char *description) +{ +grub_efi_cc_event_t *event; +grub_efi_status_t status; +grub_efi_cc_protocol_t *cc; +grub_efi_cc_mr_index_t mr; + + cc =grub_efi_locate_protocol (&cc_measurement_guid,NULL ); +if (cc ==NULL ) +return ; + + status =efi_call_3 (cc->map_pcr_to_mr_index, cc, pcr, &mr); +if (status !=GRUB_EFI_SUCCESS ) + { +grub_efi_log_event_status (status); +return ; + } + + event =grub_zalloc (sizeof (grub_efi_cc_event_t) + +grub_strlen (description) +1 ); +if (event ==NULL ) + { +grub_error (GRUB_ERR_OUT_OF_MEMORY , +N_ ("cannot allocate CC event buffer" )); +return ; + } + + event->Header.HeaderSize =sizeof (grub_efi_cc_event_header_t); + event->Header.HeaderVersion =GRUB_EFI_CC_EVENT_HEADER_VERSION ; + event->Header.MrIndex = mr; + event->Header.EventType =EV_IPL ; + event->Size =sizeof (*event) +grub_strlen (description) +1 ; +grub_strcpy (event->Event, description); + + status =efi_call_5 (cc->hash_log_extend_event, cc,0 , + (grub_efi_physical_address_t ) buf, + (grub_efi_uint64_t ) size, event); +grub_free (event); + +if (status !=GRUB_EFI_SUCCESS ) +grub_efi_log_event_status (status); +} +grub_err_t grub_tpm_measure (unsigned char *buf,grub_size_t size,grub_uint8_t pcr,const char *description)
@@ -228,6 +276,8 @@ grub_tpm_measure (unsigned char *buf, grub_size_t size, grub_uint8_t pcr,grub_efi_handle_t tpm_handle;grub_efi_uint8_t protocol_version; +grub_cc_log_event (buf, size, pcr, description); +if (!grub_tpm_handle_find (&tpm_handle, &protocol_version))return 0 ;
include/grub/efi/cc.h new file +158 -0
159 lines not on this page · raw message
Signature · 1 line
2.31.1
Quoted 19 lines · Lu Ken
Intel Trust Domain Extensions(Intel TDX) refers to an Intel technology that extends Virtual Machine Extensions(VMX) and Multi-Key Total Memory Encryption(MK-TME) with a new kind of virtual machine guest called a Trust Domain(TD)[1]. A TD runs in a CPU mode that protects the confidentiality of its memory contents and its CPU state from any other software, including the hosting Virtual Machine Monitor (VMM).
Trust Domain Virtual Firmware (TDVF) is required to provide TD services to
the TD guest OS.[2] Its reference code is available at https://github.com/tianocore/edk2-staging/tree/TDVF.To support TD measurement/attestation, TDs provide 4 RTMR registers like TPM/TPM2 PCR as below:
- RTMR[0] is for TDVF configuration
- RTMR[1] is for the TD OS loader and kernel
- RTMR[2] is for the OS application
- RTMR[3] is reserved for special usage onlyThis patch adds TD Measurement protocol support along with TPM/TPM2 protocol.
Quoted 8 lines
References:
[1] https://software.intel.com/content/dam/develop/external/us/en/documents/tdx-whitepaper-v4.pdf
[2] https://software.intel.com/content/dam/develop/external/us/en/documents/tdx-virtual-firmware-design-guide-rev-1.pdfLu Ken (3):
efi/tpm.c: Refine the status of log eventefi/tpm.c: Usesgrub_strcpy()to replacegrub_memcpy()efi/tpm.c: EnableEFI_CC_MEASUREMENT_PROTOCOL
There are still some nits but I will fix them for you.
Anyway, for all patches Reviewed-by: Daniel Kiper <[email protected]>...
Daniel
Quoted 38 lines
-----Original Message-----
From: Daniel Kiper <[email protected]>
Sent: Tuesday, July 19, 2022 9:52 PM
To: Lu, Ken <[email protected]>
Cc: [email protected]; Xu, Min M <[email protected]>
Subject: Re: [PATCH V4 0/3] Enable TDX measurement to RTMR registerQuoted 10 lines · Lu Ken
Intel Trust Domain Extensions(Intel TDX) refers to an Intel technology that extends Virtual Machine Extensions(VMX) and Multi-Key Total Memory
Encryption(MK-TME) with a new kind of virtual machine guest called a Trust Domain(TD)[1]. A TD runs in a CPU mode that protects the confidentiality of its memory contents and its CPU state from any other software, including the hosting Virtual Machine Monitor (VMM).Trust Domain Virtual Firmware (TDVF) is required to provide TD services to the TD guest OS.[2] Its reference code is available at
https://github.com/tianocore/edk2-staging/tree/TDVF.
Quoted 10 lines
To support TD measurement/attestation, TDs provide 4 RTMR registers like
TPM/TPM2 PCR as below:
- RTMR[0] is for TDVF configuration
- RTMR[1] is for the TD OS loader and kernel
- RTMR[2] is for the OS application
- RTMR[3] is reserved for special usage onlyThis patch adds TD Measurement protocol support along with TPM/TPM2
protocol.
Quoted 8 lines
References:
[1]
https://software.intel.com/content/dam/develop/external/us/en/document
s/tdx-whitepaper-v4.pdf [2]
https://software.intel.com/content/dam/develop/external/us/en/document
s/tdx-virtual-firmware-design-guide-rev-1.pdf
Quoted 8 lines
Quoted 4 lines
Lu Ken (3):
efi/tpm.c: Refine the status of log eventefi/tpm.c: Usesgrub_strcpy()to replacegrub_memcpy()efi/tpm.c: EnableEFI_CC_MEASUREMENT_PROTOCOLThere are still some nits but I will fix them for you.
Anyway, for all patches Reviewed-by: Daniel Kiper <[email protected]>...
[Lu, Ken] Thanks Daniel!
Quoted 2 lines
Daniel