Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AEM fedora41 rebase #24

Draft
wants to merge 24 commits into
base: aem-fedora41
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6d90da4
i386/msr: Merge rdmsr.h and wrmsr.h into msr.h
Dec 17, 2019
f73757d
i386/msr: Rename grub_msr_read() and grub_msr_write()
Dec 17, 2019
0ce8664
i386/msr: Extract and improve MSR support detection code
Apr 25, 2020
a79a24e
i386/memory: Rename PAGE_SHIFT to GRUB_PAGE_SHIFT
Nov 20, 2019
81b40ff
i386/memory: Rename PAGE_SIZE to GRUB_PAGE_SIZE and make it global
Nov 20, 2019
7f1e107
i386/memory: Define GRUB_PAGE_MASK constant and GRUB_PAGE_{UP,DOWN} m…
krystian-hebel Jan 22, 2024
e0bc92a
mmap: Add grub_mmap_get_lowest() and grub_mmap_get_highest()
May 4, 2020
7266492
i386/tpm: Rename tpm module to tpm_verifier
Apr 22, 2020
e0f005e
i386/tpm: Add TPM TIS and CRB driver
May 4, 2020
ee6d318
include/grub: Introduce Secure Launch Resource Table (SLRT)
rossphilipson Jan 9, 2023
0b1682c
i386/slaunch: Add basic platform support for secure launch
rossphilipson Aug 7, 2019
f47656a
i386/txt: Add Intel TXT definitions header file
rossphilipson Aug 7, 2019
d684f47
i386/txt: Add Intel TXT core implementation
rossphilipson Aug 7, 2019
498f5f4
i386/txt: Add Intel TXT ACM module support
rossphilipson Aug 7, 2019
4ce728a
i386/txt: Add Intel TXT verification routines
rossphilipson Aug 7, 2019
442d234
i386/txt: Initialize TPM 1.2 event log in TXT heap
miczyg1 Aug 31, 2022
ff72719
i386/slaunch: Add secure launch framework and commands
rossphilipson Aug 7, 2019
73804b0
loader/i386/linux.c: fix cleanup if kernel doesn't support 64-bit add…
SergiiDmytruk Aug 4, 2024
a32a034
multiboot: Make GRUB_MULTIBOOT(make_mbi) return MBI's size
SergiiDmytruk Nov 22, 2023
17f8534
multiboot2: Implement TXT slaunch support
miczyg1 Sep 1, 2022
c300206
i386/skinit: Add AMD SKINIT implementation
krystian-hebel Nov 10, 2020
dd76fda
i386/slaunch: Add support for AMD SKINIT
krystian-hebel Nov 10, 2020
48e32e8
multiboot2: Support AMD SKINIT
krystian-hebel Dec 30, 2020
1bfb72e
i386/linux: Add support for AMD SKINIT
rossphilipson Aug 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions docs/grub.texi
Original file line number Diff line number Diff line change
Expand Up @@ -6775,10 +6775,10 @@ grub-mkimage -O x86_64-efi -o grubx64.efi -p '(tftp)/grub' --sbat sbat.csv efine
@node Measured Boot
@section Measuring boot components

If the tpm module is loaded and the platform has a Trusted Platform Module
installed, GRUB will log each command executed and each file loaded into the
TPM event log and extend the PCR values in the TPM correspondingly. All events
will be logged into the PCR described below with a type of EV_IPL and an
If the tpm_verifier module is loaded and the platform has a Trusted Platform
Module installed, GRUB will log each command executed and each file loaded into
the TPM event log and extend the PCR values in the TPM correspondingly. All
events will be logged into the PCR described below with a type of EV_IPL and an
event description as described below.

@multitable @columnfractions 0.3 0.1 0.6
Expand All @@ -6803,9 +6803,10 @@ corresponding to the filename.

GRUB will not measure its own @file{core.img} - it is expected that firmware
will carry this out. GRUB will also not perform any measurements until the
tpm module is loaded. As such it is recommended that the tpm module be built
into @file{core.img} in order to avoid a potential gap in measurement between
@file{core.img} being loaded and the tpm module being loaded.
tpm_verifier module is loaded. As such it is recommended that the tpm_verifier
module be built into @file{core.img} in order to avoid a potential gap in
measurement between @file{core.img} being loaded and the tpm_verifier module
being loaded.

Measured boot is currently only supported on EFI and IBM IEEE1275 PowerPC
platforms.
Expand Down
6 changes: 6 additions & 0 deletions grub-core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pxe.h
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/int.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/slaunch.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/slr_table.h
endif

if COND_i386_xen_pvh
Expand All @@ -124,6 +126,8 @@ KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/slaunch.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/slr_table.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h
Expand Down Expand Up @@ -186,6 +190,8 @@ KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/kernel.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/efi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/efi/disk.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/tsc.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/slaunch.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/slr_table.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/acpi.h
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/i386/pmtimer.h
Expand Down
18 changes: 17 additions & 1 deletion grub-core/Makefile.core.def
Original file line number Diff line number Diff line change
Expand Up @@ -1912,6 +1912,16 @@ module = {
common = lib/cmdline.c;
};

module = {
name = slaunch;
x86 = loader/i386/slaunch.c;
x86 = loader/i386/txt/txt.c;
x86 = loader/i386/txt/acmod.c;
x86 = loader/i386/txt/verify.c;
x86 = loader/i386/skinit.c;
enable = x86;
};

module = {
name = fdt;
efi = loader/efi/fdt.c;
Expand Down Expand Up @@ -2621,7 +2631,13 @@ module = {

module = {
name = tpm;
common = commands/tpm.c;
x86 = commands/i386/tpm.c;
enable = x86;
};

module = {
name = tpm_verifier;
common = commands/tpm_verifier.c;
efi = commands/efi/tpm.c;
enable = efi;
};
Expand Down
25 changes: 7 additions & 18 deletions grub-core/commands/i386/rdmsr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <grub/extcmd.h>
#include <grub/i18n.h>
#include <grub/i386/cpuid.h>
#include <grub/i386/rdmsr.h>
#include <grub/i386/msr.h>

GRUB_MOD_LICENSE("GPLv3+");

Expand All @@ -42,27 +42,16 @@ static const struct grub_arg_option options[] =
static grub_err_t
grub_cmd_msr_read (grub_extcmd_context_t ctxt, int argc, char **argv)
{
grub_uint32_t manufacturer[3], max_cpuid, a, b, c, features, addr;
grub_err_t err;
grub_uint32_t addr;
grub_uint64_t value;
const char *ptr;
char buf[sizeof("1122334455667788")];

/*
* The CPUID instruction should be used to determine whether MSRs
* are supported. (CPUID.01H:EDX[5] = 1)
*/
if (! grub_cpu_is_cpuid_supported ())
return grub_error (GRUB_ERR_BUG, N_("unsupported instruction"));
err = grub_cpu_is_msr_supported ();

grub_cpuid (0, max_cpuid, manufacturer[0], manufacturer[2], manufacturer[1]);

if (max_cpuid < 1)
return grub_error (GRUB_ERR_BUG, N_("unsupported instruction"));

grub_cpuid (1, a, b, c, features);

if (!(features & (1 << 5)))
return grub_error (GRUB_ERR_BUG, N_("unsupported instruction"));
if (err != GRUB_ERR_NONE)
return grub_error (err, N_("RDMSR is unsupported"));

if (argc != 1)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("one argument expected"));
Expand All @@ -76,7 +65,7 @@ grub_cmd_msr_read (grub_extcmd_context_t ctxt, int argc, char **argv)
if (*ptr != '\0')
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid argument"));

value = grub_msr_read (addr);
value = grub_rdmsr (addr);

if (ctxt->state[0].set)
{
Expand Down
151 changes: 151 additions & 0 deletions grub-core/commands/i386/tpm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2020 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/>.
*
* TPM TIS and CRB driver.
*
* Note: It is suggested to not use this driver together with UEFI TPM driver.
*/

#include <grub/command.h>
#include <grub/dl.h>
#include <grub/err.h>
#include <grub/i386/memory.h>
#include <grub/i386/mmio.h>
#include <grub/i386/tpm.h>
#include <grub/mm.h>
#include <grub/types.h>

GRUB_MOD_LICENSE ("GPLv3+");

/*
* Code based on TCG PC Client Platform TPM Profile Specification for TPM 2.0,
* Version 1.05 Revision 14 released September 4, 2020.
*/

#define TPM_MMIO_BASE 0xfed40000

/* 6.3.2 Register Space Addresses */
/* TIS registers. */
#define TPM_ACCESS 0x0000
#define TPM_INTF_CAPABILITY 0x0014
#define INTF_CAP_INTERFACE_VERSION_SHIFT 28
#define INTF_CAP_INTERFACE_VERSION_MASK 7
#define TPM_INTERFACE_ID 0x0030
#define INTERFACE_ID_INTERFACE_TYPE_SHIFT 0
#define INTERFACE_ID_INTERFACE_TYPE_MASK 0xF

/* CRB registers. */
#define TPM_LOC_CTRL 0x0008


#define TIS_RELINQUISH_LCL 0x20
#define CRB_RELINQUISH_LCL 0x0002

/* 6.4.2 Interface Identifier Register */
#define TPM_CRB_INTF_ACTIVE 0x1

/* 6.5.2.7 Interface Capability */
#define TPM_12_TIS_INTF_12 0x0
#define TPM_12_TIS_INTF_13 0x2
#define TPM_20_TIS_INTF_13 0x3

typedef enum
{
TPM_INTF_NONE = 0,
TPM_INTF_TIS,
TPM_INTF_CRB
}
tpm_intf_t;

static grub_tpm_ver_t tpm_ver = GRUB_TPM_NONE;
static tpm_intf_t tpm_intf = TPM_INTF_NONE;

grub_tpm_ver_t
grub_get_tpm_ver (void)
{
return tpm_ver;
}

/* Localities 0-4 are supported only. */
void
grub_tpm_relinquish_locality (grub_uint8_t lcl)
{
grub_addr_t addr = TPM_MMIO_BASE + lcl * GRUB_PAGE_SIZE;

if (tpm_intf == TPM_INTF_TIS)
grub_write8 (TIS_RELINQUISH_LCL, addr + TPM_ACCESS);
else if (tpm_intf == TPM_INTF_CRB)
grub_write32 (CRB_RELINQUISH_LCL, addr + TPM_LOC_CTRL);
}

static grub_err_t
grub_cmd_tpm_type (grub_command_t cmd __attribute__ ((unused)),
int argc __attribute__ ((unused)),
char *argv[] __attribute__ ((unused)))
{
const char *tpm_ver_s = "NONE";
const char *tpm_intf_s = "NONE";

if (tpm_ver == GRUB_TPM_12)
tpm_ver_s = "1.2";
else if (tpm_ver == GRUB_TPM_20)
tpm_ver_s = "2.0";

if (tpm_intf == TPM_INTF_TIS)
tpm_intf_s = "TIS";
else if (tpm_intf == TPM_INTF_CRB)
tpm_intf_s = "CRB";

grub_printf ("TPM family: %s\nTPM interface: %s\n", tpm_ver_s, tpm_intf_s);

return GRUB_ERR_NONE;
}

static grub_command_t cmd_tpm_type;

GRUB_MOD_INIT (tpm)
{
grub_uint32_t intf_id;
grub_uint32_t intf_cap;

cmd_tpm_type = grub_register_command ("tpm_type", grub_cmd_tpm_type,
NULL, N_("Show TPM version and interface type."));

tpm_ver = GRUB_TPM_20;

intf_id = grub_read32 (TPM_MMIO_BASE + TPM_INTERFACE_ID);
intf_id >>= INTERFACE_ID_INTERFACE_TYPE_SHIFT;
intf_id &= INTERFACE_ID_INTERFACE_TYPE_MASK;

tpm_intf = (intf_id == TPM_CRB_INTF_ACTIVE) ? TPM_INTF_CRB : TPM_INTF_TIS;

/* CRB exists only in TPM 2.0 */
if (tpm_intf == TPM_INTF_CRB)
return;

intf_cap = grub_read32 (TPM_MMIO_BASE + TPM_INTF_CAPABILITY);
intf_cap >>= INTF_CAP_INTERFACE_VERSION_SHIFT;
intf_cap &= INTF_CAP_INTERFACE_VERSION_MASK;

if (intf_cap == TPM_12_TIS_INTF_12 || intf_cap == TPM_12_TIS_INTF_13)
tpm_ver = GRUB_TPM_12;
}

GRUB_MOD_FINI (tpm)
{
grub_unregister_command (cmd_tpm_type);
}
25 changes: 7 additions & 18 deletions grub-core/commands/i386/wrmsr.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <grub/lockdown.h>
#include <grub/i18n.h>
#include <grub/i386/cpuid.h>
#include <grub/i386/wrmsr.h>
#include <grub/i386/msr.h>

GRUB_MOD_LICENSE("GPLv3+");

Expand All @@ -36,26 +36,15 @@ static grub_command_t cmd_write;
static grub_err_t
grub_cmd_msr_write (grub_command_t cmd __attribute__ ((unused)), int argc, char **argv)
{
grub_uint32_t manufacturer[3], max_cpuid, a, b, c, features, addr;
grub_err_t err;
grub_uint32_t addr;
grub_uint64_t value;
const char *ptr;

/*
* The CPUID instruction should be used to determine whether MSRs
* are supported. (CPUID.01H:EDX[5] = 1)
*/
if (!grub_cpu_is_cpuid_supported ())
return grub_error (GRUB_ERR_BUG, N_("unsupported instruction"));
err = grub_cpu_is_msr_supported ();

grub_cpuid (0, max_cpuid, manufacturer[0], manufacturer[2], manufacturer[1]);

if (max_cpuid < 1)
return grub_error (GRUB_ERR_BUG, N_("unsupported instruction"));

grub_cpuid (1, a, b, c, features);

if (!(features & (1 << 5)))
return grub_error (GRUB_ERR_BUG, N_("unsupported instruction"));
if (err != GRUB_ERR_NONE)
return grub_error (err, N_("WRMSR is unsupported"));

if (argc != 2)
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected"));
Expand All @@ -77,7 +66,7 @@ grub_cmd_msr_write (grub_command_t cmd __attribute__ ((unused)), int argc, char
if (*ptr != '\0')
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("invalid argument"));

grub_msr_write (addr, value);
grub_wrmsr (addr, value);

return GRUB_ERR_NONE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ grub_tpm_verify_string (char *str, enum grub_verify_string_type type)
}

struct grub_file_verifier grub_tpm_verifier = {
.name = "tpm",
.name = "tpm_verifier",
.init = grub_tpm_verify_init,
.write = grub_tpm_verify_write,
.verify_string = grub_tpm_verify_string,
};

GRUB_MOD_INIT (tpm)
GRUB_MOD_INIT (tpm_verifier)
{
/*
* Even though this now calls ibmvtpm's grub_tpm_present() from GRUB_MOD_INIT(),
Expand All @@ -107,7 +107,7 @@ GRUB_MOD_INIT (tpm)
grub_verifier_register (&grub_tpm_verifier);
}

GRUB_MOD_FINI (tpm)
GRUB_MOD_FINI (tpm_verifier)
{
if (!grub_tpm_present())
return;
Expand Down
14 changes: 14 additions & 0 deletions grub-core/lib/i386/relocator32.S
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include "relocator_common.S"

#include <grub/i386/slaunch.h>

.p2align 4 /* force 16-byte alignment */

VARIABLE(grub_relocator32_start)
Expand Down Expand Up @@ -110,11 +112,23 @@ VARIABLE(grub_relocator32_edx)
payload and makes this implementation easier. */
cld

cmpl $SLP_INTEL_TXT, %edi
je LOCAL(intel_txt)

cmpl $SLP_AMD_SKINIT, %edi
je LOCAL(amd_skinit)

.byte 0xea
VARIABLE(grub_relocator32_eip)
.long 0
.word CODE_SEGMENT

LOCAL(intel_txt):
getsec

LOCAL(amd_skinit):
skinit

/* GDT. Copied from loader/i386/linux.c. */
.p2align 4
LOCAL(gdt):
Expand Down
Loading