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

Inteltxt support #13

Merged
merged 5 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 1 addition & 1 deletion 1100-i386-msr-Merge-rdmsr.h-and-wrmsr.h-into-msr.h.patch
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,5 @@ index c0a0c717a0e9..000000000000

base-commit: ae94b97be2b81b625d6af6654d3ed79078b50ff6
--
2.17.1
2.41.0

Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ index 7b52b5d61229..4fba1b8e0d04 100644
grub_uint32_t low = msr_value, high = msr_value >> 32;

--
2.17.1
2.41.0

Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ index 4fba1b8e0d04..1e838c022f41 100644
* TODO: Add a general protection exception handler.
* Accessing a reserved or unimplemented MSR address results in a GP#.
--
2.17.1
2.41.0

Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,5 @@ index 5cb607fb4667..7be57d6d7ecc 100644
/* The flag for protected mode. */
#define GRUB_MEMORY_CPU_CR0_PE_ON 0x1
--
2.17.1
2.41.0

Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,5 @@ index 7be57d6d7ecc..c64529630f19 100644
/* The flag for protected mode. */
#define GRUB_MEMORY_CPU_CR0_PE_ON 0x1
--
2.17.1
2.41.0

41 changes: 41 additions & 0 deletions 1105-i386-memory-Define-GRUB_PAGE_MASK-constant-and-GRUB_.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
From 868093de8910bd66abcde04ca928538e07366ad7 Mon Sep 17 00:00:00 2001
From: Krystian Hebel <[email protected]>
Date: Mon, 22 Jan 2024 13:14:39 +0100
Subject: [PATCH] i386/memory: Define GRUB_PAGE_MASK constant and
GRUB_PAGE_{UP,DOWN} macros

Subsequent patches will use those macros and constant.

Signed-off-by: Krystian Hebel <[email protected]>
---
include/grub/i386/memory.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/include/grub/i386/memory.h b/include/grub/i386/memory.h
index c64529630f19..56f64855be7e 100644
--- a/include/grub/i386/memory.h
+++ b/include/grub/i386/memory.h
@@ -22,6 +22,7 @@

#define GRUB_PAGE_SHIFT 12
#define GRUB_PAGE_SIZE (1UL << GRUB_PAGE_SHIFT)
+#define GRUB_PAGE_MASK (~(GRUB_PAGE_SIZE - 1))

/* The flag for protected mode. */
#define GRUB_MEMORY_CPU_CR0_PE_ON 0x1
@@ -43,8 +44,12 @@

#define GRUB_MMAP_MALLOC_LOW 1

+#include <grub/misc.h>
#include <grub/types.h>

+#define GRUB_PAGE_UP(p) ALIGN_UP (p, GRUB_PAGE_SIZE)
+#define GRUB_PAGE_DOWN(p) ALIGN_DOWN (p, GRUB_PAGE_SIZE)
+
struct grub_e820_mmap_entry
{
grub_uint64_t addr;
--
2.41.0

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 47c88e17987444c862dd83a5e5aeb2faa6b4afb1 Mon Sep 17 00:00:00 2001
From 0cfc0a5385a0847f79c9225d9dd9522ef25efaad Mon Sep 17 00:00:00 2001
From: Daniel Kiper <[email protected]>
Date: Mon, 4 May 2020 22:34:59 +0200
Subject: [PATCH] mmap: Add grub_mmap_get_lowest() and grub_mmap_get_highest()
Expand All @@ -11,15 +11,23 @@ Intel TXT secure launcher introduced by subsequent patches.

Signed-off-by: Daniel Kiper <[email protected]>
---
grub-core/mmap/mmap.c | 70 +++++++++++++++++++++++++++++++++++++++++++
grub-core/mmap/mmap.c | 79 +++++++++++++++++++++++++++++++++++++++++++
include/grub/memory.h | 3 ++
2 files changed, 73 insertions(+)
2 files changed, 82 insertions(+)

diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c
index c8c8312c56f2..1e93b7e3cabb 100644
index c8c8312c56f2..5b18b1a4c297 100644
--- a/grub-core/mmap/mmap.c
+++ b/grub-core/mmap/mmap.c
@@ -343,6 +343,76 @@ grub_mmap_unregister (int handle)
@@ -26,6 +26,7 @@
#include <grub/command.h>
#include <grub/dl.h>
#include <grub/i18n.h>
+#include <grub/safemath.h>

GRUB_MOD_LICENSE ("GPLv3+");

@@ -343,6 +344,84 @@ grub_mmap_unregister (int handle)

#endif /* ! GRUB_MMAP_REGISTER_BY_FIRMWARE */

Expand All @@ -35,14 +43,18 @@ index c8c8312c56f2..1e93b7e3cabb 100644
+ void *data)
+{
+ addr_limit_t *al = data;
+ grub_uint64_t end;
+
+ if (type != GRUB_MEMORY_AVAILABLE)
+ return 0;
+
+ if (grub_add (addr, size, &end))
+ return 0;
+
+ if (addr >= al->limit)
+ al->addr = grub_min (al->addr, addr);
+
+ if ((addr < al->limit) && ((addr + size) > al->limit))
+ if ((addr < al->limit) && (end > al->limit))
+ al->addr = al->limit;
+
+ return 0;
Expand All @@ -66,14 +78,18 @@ index c8c8312c56f2..1e93b7e3cabb 100644
+ void *data)
+{
+ addr_limit_t *al = data;
+ grub_uint64_t end;
+
+ if (type != GRUB_MEMORY_AVAILABLE)
+ return 0;
+
+ if ((addr + size) < al->limit)
+ al->addr = grub_max (al->addr, addr + size);
+ if (grub_add (addr, size, &end))
+ return 0;
+
+ if (end < al->limit)
+ al->addr = grub_max (al->addr, end);
+
+ if ((addr < al->limit) && ((addr + size) >= al->limit))
+ if ((addr < al->limit) && (end >= al->limit))
+ al->addr = al->limit;
+
+ return 0;
Expand Down Expand Up @@ -111,5 +127,5 @@ index 6da114a1bdc1..8f22f752502b 100644

struct grub_mmap_region
--
2.17.1
2.41.0

4 changes: 2 additions & 2 deletions 1107-i386-tpm-Rename-tpm-module-to-tpm_verifier.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 979cabb7a0e1bb6119b32a7465a569d6ddd8ee84 Mon Sep 17 00:00:00 2001
From a14dcf40c6eddc23c90a2486eb2665433824a4e2 Mon Sep 17 00:00:00 2001
From: Daniel Kiper <[email protected]>
Date: Wed, 22 Apr 2020 21:41:24 +0200
Subject: [PATCH] i386/tpm: Rename tpm module to tpm_verifier
Expand Down Expand Up @@ -92,5 +92,5 @@ index 2052c36eaba5..1d820a774b3b 100644
grub_verifier_unregister (&grub_tpm_verifier);
}
--
2.17.1
2.41.0

43 changes: 20 additions & 23 deletions 1108-i386-tpm-Add-TPM-TIS-and-CRB-driver.patch
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
From 5eca1b0802b90b5c0c928809f8bb76f41fd0e589 Mon Sep 17 00:00:00 2001
From 8527ee439916f427443d0eb68b7eb9be031611ee Mon Sep 17 00:00:00 2001
From: Daniel Kiper <[email protected]>
Date: Mon, 4 May 2020 22:30:58 +0200
Subject: [PATCH] i386/tpm: Add TPM TIS and CRB driver
Expand All @@ -9,18 +9,18 @@ by subsequent patches.
Signed-off-by: Daniel Kiper <[email protected]>
Signed-off-by: Krystian Hebel <[email protected]>
---
grub-core/commands/i386/tpm.c | 152 ++++++++++++++++++++++++++++++++++
grub-core/commands/i386/tpm.c | 149 ++++++++++++++++++++++++++++++++++
include/grub/i386/tpm.h | 36 ++++++++
2 files changed, 188 insertions(+)
2 files changed, 185 insertions(+)
create mode 100644 grub-core/commands/i386/tpm.c
create mode 100644 include/grub/i386/tpm.h

diff --git a/grub-core/commands/i386/tpm.c b/grub-core/commands/i386/tpm.c
new file mode 100644
index 000000000000..1c57e5e826f9
index 000000000000..f3b6f51ecd05
--- /dev/null
+++ b/grub-core/commands/i386/tpm.c
@@ -0,0 +1,152 @@
@@ -0,0 +1,149 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2020 Free Software Foundation, Inc.
Expand Down Expand Up @@ -108,9 +108,9 @@ index 000000000000..1c57e5e826f9
+ grub_addr_t addr = TPM_MMIO_BASE + lcl * GRUB_PAGE_SIZE;
+
+ if (tpm_intf == TPM_INTF_TIS)
+ grub_writeb (TIS_RELINQUISH_LCL, addr + TPM_ACCESS);
+ grub_write8 (TIS_RELINQUISH_LCL, addr + TPM_ACCESS);
+ else if (tpm_intf == TPM_INTF_CRB)
+ grub_writel (CRB_RELINQUISH_LCL, addr + TPM_LOC_CTRL);
+ grub_write32 (CRB_RELINQUISH_LCL, addr + TPM_LOC_CTRL);
+}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if neither of those are correct, as would be the case on e.g. a system with no TPM at all?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACM will fail, but I think there are enough tests in this code that should catch it before this function is called. In any case, the function does the sane thing of not writing to non-existing register if there is no TPM detected.

+
+static grub_err_t
Expand Down Expand Up @@ -146,27 +146,24 @@ index 000000000000..1c57e5e826f9
+ cmd_tpm_type = grub_register_command ("tpm_type", grub_cmd_tpm_type,
+ NULL, N_("Show TPM version and interface type."));
+
+ intf_cap = grub_readl (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;
+ tpm_intf = TPM_INTF_TIS;
+ return;
+ }
+
+ if (intf_cap != TPM_20_TIS_INTF_13)
+ return;
+
+ tpm_ver = GRUB_TPM_20;
+
+ intf_id = grub_readl (TPM_MMIO_BASE + TPM_INTERFACE_ID);
+ 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)
Expand Down Expand Up @@ -216,5 +213,5 @@ index 000000000000..d22a2507efa1
+
+#endif /* GRUB_I386_TPM_H */
--
2.17.1
2.41.0

Loading