mirror of
https://src.fedoraproject.org/rpms/grub2.git
synced 2024-11-24 14:32:58 +00:00
TDX measurements to RTMR
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
This commit is contained in:
parent
fdd5c6f423
commit
bc32a76bab
5 changed files with 344 additions and 1 deletions
42
0285-commands-efi-tpm-Refine-the-status-of-log-event.patch
Normal file
42
0285-commands-efi-tpm-Refine-the-status-of-log-event.patch
Normal file
|
@ -0,0 +1,42 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Lu Ken <ken.lu@intel.com>
|
||||
Date: Wed, 13 Jul 2022 10:06:10 +0800
|
||||
Subject: [PATCH] commands/efi/tpm: 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.
|
||||
|
||||
Signed-off-by: Lu Ken <ken.lu@intel.com>
|
||||
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
||||
(cherry picked from commit 922898573e37135f5dedc16f3e15a1d1d4c53f8a)
|
||||
---
|
||||
grub-core/commands/efi/tpm.c | 10 +++++-----
|
||||
1 file changed, 5 insertions(+), 5 deletions(-)
|
||||
|
||||
diff --git a/grub-core/commands/efi/tpm.c b/grub-core/commands/efi/tpm.c
|
||||
index a97d85368a..7acf510499 100644
|
||||
--- a/grub-core/commands/efi/tpm.c
|
||||
+++ b/grub-core/commands/efi/tpm.c
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Lu Ken <ken.lu@intel.com>
|
||||
Date: Wed, 13 Jul 2022 10:06:11 +0800
|
||||
Subject: [PATCH] commands/efi/tpm: Use grub_strcpy() instead of grub_memcpy()
|
||||
|
||||
The event description is a string, so using grub_strcpy() is cleaner than
|
||||
using grub_memcpy().
|
||||
|
||||
Signed-off-by: Lu Ken <ken.lu@intel.com>
|
||||
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
||||
(cherry picked from commit ef8679b645a63eb9eb191bb9539d7d25a9d6ff3b)
|
||||
---
|
||||
grub-core/commands/efi/tpm.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/grub-core/commands/efi/tpm.c b/grub-core/commands/efi/tpm.c
|
||||
index 7acf510499..bb59599721 100644
|
||||
--- a/grub-core/commands/efi/tpm.c
|
||||
+++ b/grub-core/commands/efi/tpm.c
|
||||
@@ -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 ((char *) 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 ((char *) event->Event, description);
|
||||
|
||||
status = efi_call_5 (tpm->hash_log_extend_event, tpm, 0, (grub_addr_t) buf,
|
||||
(grub_uint64_t) size, event);
|
258
0287-efi-tpm-Add-EFI_CC_MEASUREMENT_PROTOCOL-support.patch
Normal file
258
0287-efi-tpm-Add-EFI_CC_MEASUREMENT_PROTOCOL-support.patch
Normal file
|
@ -0,0 +1,258 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Lu Ken <ken.lu@intel.com>
|
||||
Date: Wed, 13 Jul 2022 10:06:12 +0800
|
||||
Subject: [PATCH] efi/tpm: Add EFI_CC_MEASUREMENT_PROTOCOL support
|
||||
|
||||
The EFI_CC_MEASUREMENT_PROTOCOL abstracts the measurement for virtual firmware
|
||||
in confidential computing environment. It is similar to the EFI_TCG2_PROTOCOL.
|
||||
It was 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 .
|
||||
The EDKII header file is available at https://github.com/tianocore/edk2/blob/master/MdePkg/Include/Protocol/CcMeasurement.h .
|
||||
|
||||
Signed-off-by: Lu Ken <ken.lu@intel.com>
|
||||
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
||||
(cherry picked from commit 4c76565b6cb885b7e144dc27f3612066844e2d19)
|
||||
---
|
||||
grub-core/commands/efi/tpm.c | 48 ++++++++++++++
|
||||
include/grub/efi/cc.h | 151 +++++++++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 199 insertions(+)
|
||||
create mode 100644 include/grub/efi/cc.h
|
||||
|
||||
diff --git a/grub-core/commands/efi/tpm.c b/grub-core/commands/efi/tpm.c
|
||||
index bb59599721..ae09c1bf8b 100644
|
||||
--- a/grub-core/commands/efi/tpm.c
|
||||
+++ b/grub-core/commands/efi/tpm.c
|
||||
@@ -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,50 @@ 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 ((char *) event->Event, description);
|
||||
+
|
||||
+ status = efi_call_5 (cc->hash_log_extend_event, cc, 0,
|
||||
+ (grub_efi_physical_address_t)(grub_addr_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 +274,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;
|
||||
|
||||
diff --git a/include/grub/efi/cc.h b/include/grub/efi/cc.h
|
||||
new file mode 100644
|
||||
index 0000000000..8960306890
|
||||
--- /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 <http://www.gnu.org/licenses/>.
|
||||
+ */
|
||||
+
|
||||
+#ifndef GRUB_EFI_CC_H
|
||||
+#define GRUB_EFI_CC_H 1
|
||||
+
|
||||
+#include <grub/efi/api.h>
|
||||
+#include <grub/efi/efi.h>
|
||||
+#include <grub/err.h>
|
||||
+
|
||||
+#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
|
|
@ -282,3 +282,6 @@ Patch0281: 0281-loader-arm64-linux-Remove-magic-number-header-field-.patch
|
|||
Patch0282: 0282-Correct-BSS-zeroing-on-aarch64.patch
|
||||
Patch0283: 0283-linuxefi-Invalidate-i-cache-before-starting-the-kern.patch
|
||||
Patch0284: 0284-x86-efi-Fix-an-incorrect-array-size-in-kernel-alloca.patch
|
||||
Patch0285: 0285-commands-efi-tpm-Refine-the-status-of-log-event.patch
|
||||
Patch0286: 0286-commands-efi-tpm-Use-grub_strcpy-instead-of-grub_mem.patch
|
||||
Patch0287: 0287-efi-tpm-Add-EFI_CC_MEASUREMENT_PROTOCOL-support.patch
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
Name: grub2
|
||||
Epoch: 1
|
||||
Version: 2.06
|
||||
Release: 60%{?dist}
|
||||
Release: 61%{?dist}
|
||||
Summary: Bootloader with support for Linux, Multiboot and more
|
||||
License: GPLv3+
|
||||
URL: http://www.gnu.org/software/grub/
|
||||
|
@ -530,6 +530,9 @@ mv ${EFI_HOME}/grub.cfg.stb ${EFI_HOME}/grub.cfg
|
|||
%endif
|
||||
|
||||
%changelog
|
||||
* Fri Oct 28 2022 Robbie Harwood <rharwood@redhat.com> - 2.06-61
|
||||
- TDX measurements to RTMR
|
||||
|
||||
* Wed Oct 12 2022 Robbie Harwood <rharwood@redhat.com> - 2.06-60
|
||||
- x86-efi: Fix an incorrect array size in kernel allocation
|
||||
|
||||
|
|
Loading…
Reference in a new issue