diff --git a/1007-fix-tdx-efi-call-error.patch b/1007-fix-tdx-efi-call-error.patch new file mode 100644 index 0000000000000000000000000000000000000000..88cc2992505d55a2aa74578a4f5a5a766a8d2ee1 --- /dev/null +++ b/1007-fix-tdx-efi-call-error.patch @@ -0,0 +1,230 @@ +From 74967085d15e5a759f1ec504c86a2665b41abbd4 Mon Sep 17 00:00:00 2001 +From: sunweidong.swd@alibaba-inc.com +From: Fedora Ninjas +Date: Fri, 16 May 2025 15:34:47 +0800 +Subject: [PATCH] fix tdx from https://github.com/rhboot/grub2/commit/fd559454a1e758954a0bc3ccc151cfe24e3e9ce5#diff-be02b63c26a90b6b1a309fc4e8fde327c52143f30a72fa0d2474006410fef000 + +--- + grub-core/kern/efi/tdx.c | 25 +++++-- + include/grub/efi/cc.h | 151 +++++++++++++++++++++++++++++++++++++++ + 2 files changed, 169 insertions(+), 7 deletions(-) + create mode 100644 include/grub/efi/cc.h + +diff --git a/grub-core/kern/efi/tdx.c b/grub-core/kern/efi/tdx.c +index 3a49f8d..d21c842 100644 +--- a/grub-core/kern/efi/tdx.c ++++ b/grub-core/kern/efi/tdx.c +@@ -4,6 +4,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -44,27 +45,37 @@ grub_tdx_log_event(unsigned char *buf, grub_size_t size, grub_uint8_t pcr, + { + EFI_TCG2_EVENT *event; + grub_efi_status_t status; +- grub_efi_tdx_protocol_t *tdx; ++ grub_efi_cc_protocol_t *tdx; ++ grub_efi_cc_mr_index_t mr; + + tdx = grub_efi_locate_protocol (&tdx_guid, NULL); + + if (!tdx) + return 0; + +- event = grub_zalloc(sizeof (EFI_TCG2_EVENT) + grub_strlen(description) + 1); ++ status = efi_call_3 (tdx->map_pcr_to_mr_index, tdx, pcr, &mr); ++ if (status != GRUB_EFI_SUCCESS) ++ { ++ grub_tdx_dprintf (status); ++ return; ++ } ++ ++ event = grub_zalloc(sizeof (grub_efi_cc_event_t) + grub_strlen(description) + 1); + if (!event) + return grub_error (GRUB_ERR_OUT_OF_MEMORY, +- N_("cannot allocate TCG2 event buffer")); ++ N_("cannot allocate cc event buffer")); + +- event->Header.HeaderSize = sizeof(EFI_TCG2_EVENT_HEADER); ++ event->Header.HeaderSize = sizeof(grub_efi_cc_event_header_t); + event->Header.HeaderVersion = 1; +- event->Header.PCRIndex = pcr; ++ event->Header.PCRIndex = mr; + 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); ++ event->Size = sizeof (*event) + grub_strlen (description) + 1; ++ grub_strcpy ((char *) event->Event, description); + + status = efi_call_5 (tdx->hash_log_extend_event, tdx, 0, (unsigned long) buf, + (grub_uint64_t) size, event); ++ ++ grub_free (event); + + return grub_tdx_dprintf(status); + } +\ No newline at end of file +diff --git a/include/grub/efi/cc.h b/include/grub/efi/cc.h +new file mode 100644 +index 0000000..dfd9057 +--- /dev/null ++++ b/include/grub/efi/cc.h +@@ -0,0 +1,151 @@ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2022 Free Software Foundation, Inc. ++ * ++ * GRUB is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, either version 3 of the License, or ++ * (at your option) any later version. ++ * ++ * GRUB is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with GRUB. If not, see . ++ */ ++ ++#ifndef GRUB_EFI_CC_H ++#define GRUB_EFI_CC_H 1 ++ ++#include ++#include ++#include ++ ++#define GRUB_EFI_CC_MEASUREMENT_PROTOCOL_GUID \ ++ { 0x96751a3d, 0x72f4, 0x41a6, \ ++ { 0xa7, 0x94, 0xed, 0x5d, 0x0e, 0x67, 0xae, 0x6b } \ ++ }; ++ ++struct grub_efi_cc_version ++{ ++ grub_efi_uint8_t Major; ++ grub_efi_uint8_t Minor; ++}; ++typedef struct grub_efi_cc_version grub_efi_cc_version_t; ++ ++/* EFI_CC Type/SubType definition. */ ++#define GRUB_EFI_CC_TYPE_NONE 0 ++#define GRUB_EFI_CC_TYPE_SEV 1 ++#define GRUB_EFI_CC_TYPE_TDX 2 ++ ++struct grub_efi_cc_type ++{ ++ grub_efi_uint8_t Type; ++ grub_efi_uint8_t SubType; ++}; ++typedef struct grub_efi_cc_type grub_efi_cc_type_t; ++ ++typedef grub_efi_uint32_t grub_efi_cc_event_log_bitmap_t; ++typedef grub_efi_uint32_t grub_efi_cc_event_log_format_t; ++typedef grub_efi_uint32_t grub_efi_cc_event_algorithm_bitmap_t; ++typedef grub_efi_uint32_t grub_efi_cc_mr_index_t; ++ ++/* Intel TDX measure register index. */ ++#define GRUB_TDX_MR_INDEX_MRTD 0 ++#define GRUB_TDX_MR_INDEX_RTMR0 1 ++#define GRUB_TDX_MR_INDEX_RTMR1 2 ++#define GRUB_TDX_MR_INDEX_RTMR2 3 ++#define GRUB_TDX_MR_INDEX_RTMR3 4 ++ ++#define GRUB_EFI_CC_EVENT_LOG_FORMAT_TCG_2 0x00000002 ++#define GRUB_EFI_CC_BOOT_HASH_ALG_SHA384 0x00000004 ++#define GRUB_EFI_CC_EVENT_HEADER_VERSION 1 ++ ++struct grub_efi_cc_event_header ++{ ++ /* Size of the event header itself (sizeof(EFI_TD_EVENT_HEADER)). */ ++ grub_efi_uint32_t HeaderSize; ++ ++ /* ++ * Header version. For this version of this specification, ++ * the value shall be 1. ++ */ ++ grub_efi_uint16_t HeaderVersion; ++ ++ /* Index of the MR that shall be extended. */ ++ grub_efi_cc_mr_index_t MrIndex; ++ ++ /* Type of the event that shall be extended (and optionally logged). */ ++ grub_efi_uint32_t EventType; ++} GRUB_PACKED; ++typedef struct grub_efi_cc_event_header grub_efi_cc_event_header_t; ++ ++struct grub_efi_cc_event ++{ ++ /* Total size of the event including the Size component, the header and the Event data. */ ++ grub_efi_uint32_t Size; ++ grub_efi_cc_event_header_t Header; ++ grub_efi_uint8_t Event[0]; ++} GRUB_PACKED; ++typedef struct grub_efi_cc_event grub_efi_cc_event_t; ++ ++struct grub_efi_cc_boot_service_capability ++{ ++ /* Allocated size of the structure. */ ++ grub_efi_uint8_t Size; ++ ++ /* ++ * Version of the grub_efi_cc_boot_service_capability_t structure itself. ++ * For this version of the protocol, the Major version shall be set to 1 ++ * and the Minor version shall be set to 1. ++ */ ++ grub_efi_cc_version_t StructureVersion; ++ ++ /* ++ * Version of the EFI TD protocol. ++ * For this version of the protocol, the Major version shall be set to 1 ++ * and the Minor version shall be set to 1. ++ */ ++ grub_efi_cc_version_t ProtocolVersion; ++ ++ /* Supported hash algorithms. */ ++ grub_efi_cc_event_algorithm_bitmap_t HashAlgorithmBitmap; ++ ++ /* Bitmap of supported event log formats. */ ++ grub_efi_cc_event_log_bitmap_t SupportedEventLogs; ++ ++ /* Indicates the CC type. */ ++ grub_efi_cc_type_t CcType; ++}; ++typedef struct grub_efi_cc_boot_service_capability grub_efi_cc_boot_service_capability_t; ++ ++struct grub_efi_cc_protocol ++{ ++ grub_efi_status_t ++ (*get_capability) (struct grub_efi_cc_protocol *this, ++ grub_efi_cc_boot_service_capability_t *ProtocolCapability); ++ ++ grub_efi_status_t ++ (*get_event_log) (struct grub_efi_cc_protocol *this, ++ grub_efi_cc_event_log_format_t EventLogFormat, ++ grub_efi_physical_address_t *EventLogLocation, ++ grub_efi_physical_address_t *EventLogLastEntry, ++ grub_efi_boolean_t *EventLogTruncated); ++ ++ grub_efi_status_t ++ (*hash_log_extend_event) (struct grub_efi_cc_protocol *this, ++ grub_efi_uint64_t Flags, ++ grub_efi_physical_address_t DataToHash, ++ grub_efi_uint64_t DataToHashLen, ++ grub_efi_cc_event_t *EfiCcEvent); ++ ++ grub_efi_status_t ++ (*map_pcr_to_mr_index) (struct grub_efi_cc_protocol *this, ++ grub_efi_uint32_t PcrIndex, ++ grub_efi_cc_mr_index_t *MrIndex); ++}; ++typedef struct grub_efi_cc_protocol grub_efi_cc_protocol_t; ++ ++#endif +\ No newline at end of file +-- +2.43.5 diff --git a/grub.patches b/grub.patches index db20facc93c35cf879f498936016285da4466eb0..9911382d66ae17a14c528cdf05dff93450d54fc9 100644 --- a/grub.patches +++ b/grub.patches @@ -682,3 +682,4 @@ Patch1003: 1003-cryptodisk-make-the-password-getter-and-additional-a.patch Patch1004: 1004-cryptodisk-add-OS-provided-secret-support.patch Patch1005: 1005-efi-Add-API-for-retrieving-the-EFI-secret-for-crypto.patch Patch1006: 1006-Update-patches-in-sync-with-loongarch64.patch +Patch1007: 1007-fix-tdx-efi-call-error.patch diff --git a/grub2.spec b/grub2.spec index e09510a1d86a48784f015fce0e99df90e8d75dd0..38301695793dbbb932a32da52bf7560e9690d211 100644 --- a/grub2.spec +++ b/grub2.spec @@ -1,4 +1,4 @@ -%define anolis_release .0.1 +%define anolis_release .0.2 %undefine _hardened_build %global tarversion 2.02 @@ -536,6 +536,9 @@ fi %endif %changelog +* Tue May 27 2025 happy_orange - 2.02-165.0.2 +- fix the tdx error in grub2 + * Wed Apr 30 2025 Bo Ren - 2.02-165.0.1 - Build pc-modules package on x86_64 (geliwei@openanolis.org) - Add loongarch64 base support (zhangwenlong@loongson.cn)(chenguoqi@loongson.cn)