x86: Trenchboot Secure Launch DRTM for AMD SKINIT (Linux)
Subsystems (6)
v2 cover x86: Trenchboot Secure Launch DRTM for AMD SKINIT (Linux)
NOTE: this patch set follows up on Intel TXT DRTM patches that are currently under review in their 14th version [0]; therefore, it is not standalone!
The publication of the patches at this point pursues several goals:
- Make anyone tracking upstream aware of the maturity of the support for AMD SKINIT.
- Collect early feedback on the SKINIT implementation.
- Finally, demonstrate the extensibility of Secure Launch for incorporating additional platforms.
As the RFC suggest, this series is temporal and will be updated based on changes made to the initial Secure Launch series. Review comments are greatly welcomed and will be worked/addressed, but we would caution that changes to the Secure Launch series will take precedence over review comments. Once the Secure Launch series is merged, this series will transition from RFC to a formally submitted series.
-----
The patches extend Secure Launch for legacy and UEFI boot with support for AMD CPUs and their DRTM in two flavours: SKINIT on its own and SKINIT with DRTM service running in PSP/ASP.
The code is adjusted to detect CPU type and handle AMD differently. DRTM-specific differences relative to Intel TXT include:
- absence of DRTM-specific registers to pass data from bootloader to DLME, resulting in passing some information via boot parameters
- use of a different SLRT entry
- not sending #INIT to APs
- special handling for TPM event logs to make them "compatible" with TXT logs
-----
[0]: https://lore.kernel.org/lkml/[email protected]/
Changes in v2:
- rebase onto v14 of the main patch set
- cleaner handling of reset in sl_main.c leading to a smaller diff
- renamed slr_entry_amd_info::boot_params_{base,addr} for consistency with slr_entry_intel_info
- slightly safer slaunch_reset() macro in slmodule.c
-----
Jagannathan Raman (1):
psp: Perform kernel portion of DRTM procedures
Michał Żygowski (1):
x86: Implement AMD support for Secure Launch
Ross Philipson (6):
x86: AMD changes for Secure Launch Resource Table header file
x86: Secure Launch main header file AMD support
x86: Split up Secure Launch setup and finalize functions
x86: Prepare CPUs for post SKINIT launch x86/slmodule: Support AMD SKINIT
x86: AMD changes for EFI stub DRTM launch support
Sergii Dmytruk (1):
Documentation/x86: update Secure Launch for AMD SKINIT
.../secure_launch_details.rst | 83 +++++- .../secure_launch_overview.rst | 61 ++-- arch/x86/Kconfig | 9 +- arch/x86/boot/compressed/sl_main.c | 271 ++++++++++++++---- arch/x86/boot/compressed/sl_stub.S | 41 ++- arch/x86/include/asm/svm.h | 2 + arch/x86/include/uapi/asm/setup_data.h | 3 +- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/setup.c | 2 +- arch/x86/kernel/sl-psp.c | 239 +++++++++++++++ arch/x86/kernel/slaunch.c | 193 +++++++++++-- arch/x86/kernel/slmodule.c | 161 +++++++++-- arch/x86/kernel/smpboot.c | 15 +- arch/x86/kernel/traps.c | 4 + drivers/firmware/efi/libstub/x86-stub.c | 12 +- drivers/iommu/amd/init.c | 12 + include/linux/slaunch.h | 83 +++++- include/linux/slr_table.h | 15 + 18 files changed, 1044 insertions(+), 163 deletions(-) create mode 100644 arch/x86/kernel/sl-psp.c
base-commit: 616c6ae2fa0b736552873af08ad0e5532e04ad80
Signature · 1 line
2.49.0
RFC PATCH v2 1/9 Documentation/x86: update Secure Launch for AMD SKINIT
* Switch ACM to DCE where not talking exclusively about Intel TXT
* Switch MLE to DLME where not talking exclusively about Intel TXT
* Add information about Secure Loader
* Update information about Secure Launch to account for AMD SKINIT
--- .../secure_launch_details.rst | 83 ++++++++++++++++--- .../secure_launch_overview.rst | 61 +++++++++----- 2 files changed, 113 insertions(+), 31 deletions(-)
Documentation/security/launch-integrity/secure_launch_details.rst +73 -10
@@ -18,13 +18,13 @@ The settings to enable Secure Launch using Kconfig are under:: A kernel with this option enabled can still be booted using other supported methods. -To reduce the Trusted Computing Base (TCB) of the MLE [1]_, the build +To reduce the Trusted Computing Base (TCB) of the DLME [1]_, the build configuration should be pared down as narrowly as one's use case allows. Fewer drivers (less active hardware) and features reduce the attack surface. -As an example in the extreme, the MLE could only have local disk access with no +As an example in the extreme, the DLME could only have local disk access with no other hardware supports except optional network access for remote attestation. -It is also desirable, if possible, to embed the initrd used with the MLE kernel +It is also desirable, if possible, to embed the initrd used with the DLME kernel image to reduce complexity. The following are important configuration necessities to always consider:
@@ -39,7 +39,8 @@ other instabilities at boot. Even in cases where Secure Launch and KASLR work together, it is still recommended that KASLR be disabled to avoid introducing security concerns with unprotected kernel memory. -If possible, a kernel being used as an MLE should be built with KASLR disabled:: +If possible, a kernel being used as an DLME should be built with KASLR +disabled:: "Processor type and features" --> "Build a relocatable kernel" -->
@@ -64,7 +65,7 @@ IOMMU Configuration When doing a Secure Launch, the IOMMU should always be enabled and the drivers loaded. However, IOMMU passthrough mode should never be used. This leaves the -MLE completely exposed to DMA after the PMRs [2]_ are disabled. The current +DLME completely exposed to DMA after the PMRs [2]_ are disabled. The current default mode is to use IOMMU in lazy translated mode, but strict translated mode, is the preferred IOMMU mode and this should be selected in the build configuration::
@@ -109,9 +110,9 @@ Intel TXT Interface The primary interfaces between the various components in TXT are the TXT MMIO registers and the TXT heap. The MMIO register banks are described in Appendix B -of the TXT MLE [1]_ Development Guide. +of the TXT MLE Development Guide. -The TXT heap is described in Appendix C of the TXT MLE [1]_ Development +The TXT heap is described in Appendix C of the TXT MLE Development Guide. Most of the TXT heap is predefined in the specification. The heap is initialized by firmware and the pre-launch environment and is subsequently used by the SINIT ACM. One section, called the OS to MLE Data Table, is reserved for
@@ -571,10 +572,68 @@ An error occurred in the Secure Launch module while mapping the Secure Launch Resource table. The underlying issue is memremap() failure, most likely due to a resource shortage. +AMD SKINIT Interface +==================== + +This DRTM comes in two flavours: with DRTM service running in PSP/ASP and +without one. The DRTM service effectively extends basic functionality of the +SKINIT instruction providing stronger security guarantees at the cost of more +complicated programming interface. + +As of the end of 2024 the DRTM service is available on Milan/Genoa platforms +running suitable firmware releases. When firmware doesn't provide the service, +simpler DRTM process is used. + +Basic SKINIT DRTM workflow is straightforward in its design. It defines only +the bare minimum necessary to perform the DRTM and to pass some data from pre- +to post-launch code. DRTM service extends the workflow by adding more metadata +and performing some of the operations itself instead of leaving their +implementation to a user-provided code (Secure Loader or SL). + +Secure Loader image is a binary to which SKINIT instruction passes control. The +binary must start with a short header defined in the second volume of AMD64 +Architecture Programmer's Manual to have only two required fields. DRTM +integration guide [4]_ adds an extended header which is mostly opaque and can be +treated as reserved area in the kernel. Together these fields can be presented +as the following structure:: + + struct sl_header { + u16 entry_point; + u16 image_size; + grub_uint8_t reserved[62]; + /* + * Any other fields, if present, are implementation-specific. + */ + } __packed; + +Secure Loader is loaded into Secure Loader Block (SLB) which is a 64 KiB area of +RAM below 4 GiB that starts on a 64 KiB boundary. The smaller a particular SL +image is, the more space is available for passing additional data which is to +be placed after the image so it doesn't get measured by SKINIT. + +Passing of the information from bootloader to the kernel is carried out by the +SLRT which is placed after the end of Secure Loader. A platform-specific entry +of the SLRT is additionally linked as `setup_data` structure allowing the +kernel to discover location of the SLRT by traversing boot parameters looking +for the entry. + +Description of the header: + +===================== ======================================================================== +Field Use +===================== ======================================================================== +entry_point Offset from the start of the image +image_size How much of the SLB area is actually occupied by the image +reserved Data for DRTM service +===================== ======================================================================== + .. [1] - MLE: Measured Launch Environment is the binary runtime that is measured and - then run by the TXT SINIT ACM. The TXT MLE Development Guide describes the - requirements for the MLE in detail. + DLME: Dynamic Launch Measured Environment (which Intel calls MLE for + Measured Launch Environment) is the binary runtime that is measured and + then run by the DCE. The TXT MLE Development Guide describes the + requirements for the MLE in detail. Because AMD SKINIT doesn't impose any + specific requirements of that sort, TXT's format of MLE is used on AMD + devices as well for simplicity. .. [2] PMR: Intel VTd has a feature in the IOMMU called Protected Memory Registers.
@@ -585,3 +644,7 @@ a resource shortage. .. [3] Secure Launch Specification: https://trenchboot.org/specifications/Secure_Launch/ + +.. [4] + Dynamic Root of Trust Measurement (DRTM) Service Integration Guide: + https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/user-guides/58453.pdf
Documentation/security/launch-integrity/secure_launch_overview.rst +40 -21
104 lines not on this page · raw message
Signature · 1 line
2.49.0
RFC PATCH v2 2/9 x86: AMD changes for Secure Launch Resource Table header file
In reply to Sergii DmytrukFrom: Ross Philipson <[email protected]>
Introduce the AMD info table that allows the SLRT to be linked in as a setup_data entry. This allows the SLRT to be found and in addition all the DLMR information needed by the SKL (Secure Kernel Loader).
--- include/linux/slr_table.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
include/linux/slr_table.h +15 -0
@@ -180,6 +180,21 @@ struct slr_entry_intel_info {struct slr_txt_mtrr_state saved_bsp_mtrrs; } __packed; +/* +* AMD SKINIT Info table +*/ +struct slr_entry_amd_info { +struct slr_entry_hdr hdr; +u64 next; +u32 type; +u32 len; +u64 slrt_size; +u64 slrt_base; +u64 boot_params_addr; +u16 psp_version; +u16 reserved[3 ]; +} __packed; +/* * UEFI config measurement entry */
Signature · 1 line
2.49.0
RFC PATCH v2 3/9 x86: Secure Launch main header file AMD support
In reply to Sergii DmytrukFrom: Ross Philipson <[email protected]>
Add additional Secure Launch definitions and declarations for AMD/SKINIT support.
Use a single implementation of slaunch_is_txt_launch(), slaunch_get_flags() returns to 0 if Secure Launch support isn't enabled.
--- include/linux/slaunch.h | 81 +++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 11 deletions(-)
include/linux/slaunch.h +70 -11
@@ -14,11 +14,14 @@*/ #define SL_FLAG_ACTIVE 0x00000001#define SL_FLAG_ARCH_TXT 0x00000002 +#define SL_FLAG_ARCH_SKINIT 0x00000004 +#define SL_FLAG_SKINIT_PSP 0x00000008/* * Secure Launch CPU Type */ #define SL_CPU_INTEL 1 +#define SL_CPU_AMD 2#define __SL32_CS 0x0008#define __SL32_DS 0x0010
@@ -146,6 +149,8 @@#define SL_ERROR_INVALID_SLRT 0xc0008022#define SL_ERROR_SLRT_MISSING_ENTRY 0xc0008023#define SL_ERROR_SLRT_MAP 0xc0008024 +#define SL_ERROR_MISSING_EVENT_LOG 0xc0008025 +#define SL_ERROR_MAP_SETUP_DATA 0xc0008026/* * Secure Launch Defined Limits
@@ -325,9 +330,25 @@ struct smx_rlp_mle_join {u32 rlp_entry_point;/* phys addr */ } __packed; +/* The TCG original Spec ID structure defined for TPM 1.2 */ +#define TCG_SPECID_SIG00 "Spec ID Event00" + +struct tpm_tcg_specid_event_head { +char signature[16 ]; +u32 platform_class; +u8 spec_ver_minor; +u8 spec_ver_major; +u8 errata; +u8 uintn_size;/* reserved (must be 0) for 1.21 */ +u8 vendor_info_size; +/* vendor_info[]; */ +} __packed; +/* -* TPM event log structures defined in both the TXT specification and -* the TCG documentation. +* TPM event log structures defined by the TXT specification derived +* from the TCG documentation. For TXT this is setup as the conainter +* header. On AMD this header is embedded in to vendor information +* after the TCG spec ID header. */ #define TPM_EVTLOG_SIGNATURE "TXT Event Container"
@@ -344,6 +365,25 @@ struct tpm_event_log_header {/* PCREvents[] */ } __packed; +/* TPM Event Log Size Macros */ +#define TCG_PCClientSpecIDEventStruct_SIZE \ + (sizeof(struct tpm_tcg_specid_event_head)) +#define TCG_EfiSpecIdEvent_SIZE(n) \ + ((n) * sizeof(struct tcg_efi_specid_event_algs) \ + + sizeof(struct tcg_efi_specid_event_head) \ + + sizeof(u8) /* vendorInfoSize */) +#define TPM2_HASH_COUNT (base) (*((u32 *)(base) \ + + (offsetof(struct tcg_efi_specid_event_head, num_algs) >> 2))) + +/* AMD Specific Structures and Definitions */ +struct sl_header { +u16 skl_entry_point; +u16 length; +u8 reserved[62 ]; +u16 skl_info_offset; +u16 bootloader_data_offset; +} __packed; +/* * Functions to extract data from the Intel TXT Heap Memory. The layout * of the heap is as follows:
@@ -512,16 +552,14 @@ void slaunch_fixup_jump_vector(void);u32 slaunch_get_flags (void );struct sl_ap_wake_info *slaunch_get_ap_wake_info (void );struct acpi_table_header *slaunch_get_dmar_table (struct acpi_table_header *dmar); +void slaunch_cpu_setup_skinit (void ); +void __noreturn slaunch_skinit_reset (const char *msg,u64 error);void __noreturn slaunch_txt_reset (void __iomem *txt,const char *msg,u64 error);void slaunch_finalize (int do_sexit); - -static inline bool slaunch_is_txt_launch (void ) -{ -u32 mask =SL_FLAG_ACTIVE |SL_FLAG_ARCH_TXT ; - -return (slaunch_get_flags () & mask) == mask; -} +bool slaunch_psp_tmr_release (void ); +void slaunch_psp_setup (void ); +void slaunch_psp_finalize (void );#else
@@ -529,6 +567,10 @@ static inline void slaunch_setup_txt(void) { } +static inline void slaunch_cpu_setup_skinit (void ) +{ +} +static inline void slaunch_fixup_jump_vector (void ) { }
@@ -545,14 +587,31 @@ static inline struct acpi_table_header *slaunch_get_dmar_table(struct acpi_tablestatic inline void slaunch_finalize (int do_sexit) { + (void )do_sexit; } +#endif /* !IS_ENABLED(CONFIG_SECURE_LAUNCH) */ +static inline bool slaunch_is_txt_launch (void ) { -return false; +u32 mask =SL_FLAG_ACTIVE |SL_FLAG_ARCH_TXT ; + +return (slaunch_get_flags () & mask) == mask; } -#endif /* !IS_ENABLED(CONFIG_SECURE_LAUNCH) */ +static inline bool slaunch_is_skinit_launch (void ) +{ +u32 mask =SL_FLAG_ACTIVE |SL_FLAG_ARCH_SKINIT ; + +return (slaunch_get_flags () & mask) == mask; +} + +static inline bool slaunch_is_skinit_psp (void ) +{ +u32 mask =SL_FLAG_ACTIVE |SL_FLAG_ARCH_SKINIT |SL_FLAG_SKINIT_PSP ; + +return (slaunch_get_flags () & mask) == mask; +}#endif /* !__ASSEMBLY */
Signature · 1 line
2.49.0
RFC PATCH v2 4/9 x86: Split up Secure Launch setup and finalize functions
In reply to Sergii DmytrukFrom: Ross Philipson <[email protected]>
Split up the setup and findalize functions internally to determine the type of launch and call the appropriate function (TXT or SKINIT version).
--- arch/x86/include/asm/svm.h | 2 ++ arch/x86/kernel/setup.c | 2 +- arch/x86/kernel/slaunch.c | 69 +++++++++++++++++++++++++++++++------- include/linux/slaunch.h | 4 +-- 4 files changed, 62 insertions(+), 15 deletions(-)
arch/x86/include/asm/svm.h +2 -0
@@ -584,6 +584,8 @@ static inline void __unused_size_checks(void)#define SVM_CPUID_FUNC 0x8000000a +#define SVM_VM_CR_INIT_REDIRECTION 1 +#define SVM_SELECTOR_S_SHIFT 4#define SVM_SELECTOR_DPL_SHIFT 5#define SVM_SELECTOR_P_SHIFT 7
arch/x86/kernel/setup.c +1 -1
@@ -999,7 +999,7 @@ void __init setup_arch(char **cmdline_p)early_gart_iommu_check ();#endif -slaunch_setup_txt (); +slaunch_setup ();/* * partially used pages are not usable - thus
arch/x86/kernel/slaunch.c +57 -12
100 lines not on this page · raw message
include/linux/slaunch.h +2 -2
@@ -547,7 +547,7 @@ static inline int tpm2_log_event(struct txt_heap_event_log_pointer2_1_element *e/* * External functions available in mainline kernel. */ -void slaunch_setup_txt (void ); +void slaunch_setup (void );void slaunch_fixup_jump_vector (void );u32 slaunch_get_flags (void );struct sl_ap_wake_info *slaunch_get_ap_wake_info (void );
@@ -563,7 +563,7 @@ void slaunch_psp_finalize(void);#else -static inline void slaunch_setup_txt (void ) +static inline void slaunch_setup (void ) { }
Signature · 1 line
2.49.0
RFC PATCH v2 5/9 x86: Implement AMD support for Secure Launch
In reply to Sergii DmytrukFrom: Michał Żygowski <[email protected]>
AMD SKINIT uses the same entry point as Intel TXT (sl_stub_entry). It follows similar, but simpler path than TXT; there is no TXT heap and APs are started by a standard INIT/SIPI/SIPI sequence.
Contrary to the TXT, SKINIT does not use code provided by a CPU vendor. Instead it requires an intermediate loader (SKL), whose task is to set up memory protection and set a proper CPU context before handling control over to the kernel.
In order to simplify adding new entries and to minimize the number of differences between AMD and Intel, the event logs have actually two headers, both for TPM 1.2 and 2.0.
For TPM 1.2 this is TCG_PCClientSpecIDEventStruct [1] with Intel's own TXT-specific header embedded inside its 'vendorInfo' field. The offset to this field is added to the base address on AMD path, making the code for adding new events the same for both vendors.
TPM 2.0 in TXT uses HEAP_EVENT_LOG_POINTER_ELEMENT2_1 structure, which is normally constructed on the TXT stack [2]. For AMD, this structure is put inside TCG_EfiSpecIdEvent [3], also in 'vendorInfo' field. The actual offset to this field depends on the number of hash algorithms supported by the event log.
Other changes:
- update common code to handle reset on AMD as well
- reserve memory region occupied by SKL (called SLB) and event log
[1] https://www.trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientImplementation_1-21_1_00.pdf
[2] http://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-txt-software-development-guide.pdf
[3] https://trustedcomputinggroup.org/wp-content/uploads/TCG_PCClientSpecPlat_TPM_2p0_1p04_pub.pdf
--- arch/x86/Kconfig | 9 +- arch/x86/boot/compressed/sl_main.c | 271 ++++++++++++++++++++----- arch/x86/boot/compressed/sl_stub.S | 41 +++- arch/x86/include/uapi/asm/setup_data.h | 3 +- arch/x86/kernel/slaunch.c | 99 ++++++++- 5 files changed, 347 insertions(+), 76 deletions(-)
arch/x86/Kconfig +5 -4
@@ -2006,11 +2006,12 @@ config SECURE_LAUNCH depends on X86_64 && X86_X2APIC && TCG_TIS && TCG_CRB && CRYPTO_LIB_SHA1 && CRYPTO_LIB_SHA256 help The Secure Launch feature allows a kernel to be loaded - directly through an Intel TXT measured launch. Intel TXT + directly through a dynamic launch. Intel TXT or AMD SKINIT establishes a Dynamic Root of Trust for Measurement (DRTM) - where the CPU measures the kernel image. This feature then - continues the measurement chain over kernel configuration - information and init images. + where the CPU or a Dynamic Configuration Environment (DCE) + measures the kernel image. This feature then continues the + measurement chain over kernel configuration information and + init images. source "kernel/Kconfig.hz"
arch/x86/boot/compressed/sl_main.c +216 -55
407 lines not on this page · raw message
arch/x86/boot/compressed/sl_stub.S +36 -5
83 lines not on this page · raw message
arch/x86/include/uapi/asm/setup_data.h +2 -1
@@ -13,7 +13,8 @@#define SETUP_CC_BLOB 7#define SETUP_IMA 8#define SETUP_RNG_SEED 9 -#define SETUP_ENUM_MAX SETUP_RNG_SEED +#define SETUP_SECURE_LAUNCH 10 +#define SETUP_ENUM_MAX SETUP_SECURE_LAUNCH#define SETUP_INDIRECT (1<<31)#define SETUP_TYPE_MAX (SETUP_ENUM_MAX | SETUP_INDIRECT)
arch/x86/kernel/slaunch.c +88 -11
158 lines not on this page · raw message
Signature · 1 line
2.49.0
RFC PATCH v2 6/9 x86: Prepare CPUs for post SKINIT launch
In reply to Sergii DmytrukFrom: Ross Philipson <[email protected]>
The SKINIT instruction disables the GIF and it must be re-enabled on the BSP and APs as they are started. Since enabling GIF also re-enables NMIs, it should be done after a valid IDT is loaded for each CPU.
SKINIT also already performed #INIT on the APs and it should be bypassed before issuing the startup IPIs.
--- arch/x86/kernel/slaunch.c | 23 +++++++++++++++++++++++ arch/x86/kernel/smpboot.c | 15 ++++++++++++++- arch/x86/kernel/traps.c | 4 ++++ 3 files changed, 41 insertions(+), 1 deletion(-)
arch/x86/kernel/slaunch.c +23 -0
@@ -17,6 +17,7 @@#include <asm/sections.h> #include <asm/tlbflush.h> #include <asm/e820/api.h> +#include <asm/svm.h> #include <asm/setup.h> #include <asm/svm.h> #include <asm/realmode.h>
@@ -716,3 +717,25 @@ void slaunch_finalize(int do_sexit)else if (boot_cpu_has (X86_FEATURE_SKINIT ))slaunch_finalize_skinit (); } + +/* +* AMD specific SKINIT CPU setup and initialization. +*/ +void slaunch_cpu_setup_skinit (void ) +{ +u64 val; + +if (!slaunch_is_skinit_launch ()) +return ; + +/* +* We don't yet handle #SX. Disable INIT_REDIRECTION first, before +* enabling GIF, so a pending INIT resets us, rather than causing a +* panic due to an unknown exception. +*/ +rdmsrl (MSR_VM_CR , val); +wrmsrl (MSR_VM_CR , val & ~(1 <<SVM_VM_CR_INIT_REDIRECTION )); + +/* Enable Global Interrupts flag */ + asmvolatile ("stgi" :::"memory" ); +}
arch/x86/kernel/smpboot.c +14 -1
@@ -251,6 +251,12 @@ static void notrace __noendbr start_secondary(void *unused)cpu_init_exception_handling (false); +/* +* If this is an AMD SKINIT secure launch, some extra work is done +* to prepare to start the secondary CPUs. +*/ +slaunch_cpu_setup_skinit (); +/* * Load the microcode before reaching the AP alive synchronization * point below so it is not part of the full per CPU serialized
@@ -703,7 +709,14 @@ static int wakeup_secondary_cpu_via_init(u32 phys_apicid, unsigned long start_eipreempt_disable (); maxlvt =lapic_get_maxlvt (); -send_init_sequence (phys_apicid); + +/* +* If this is an SKINIT secure launch, #INIT is already done on the APs +* by issuing the SKINIT instruction. For security reasons #INIT +* should not be done again. +*/ +if (!slaunch_is_skinit_launch ()) +send_init_sequence (phys_apicid);mb ();
arch/x86/kernel/traps.c +4 -0
@@ -43,6 +43,7 @@#include <linux/atomic.h> #include <linux/iommu.h> #include <linux/ubsan.h> +#include <linux/slaunch.h> #include <asm/stacktrace.h> #include <asm/processor.h>
@@ -1564,5 +1565,8 @@ void __init trap_init(void)if (!cpu_feature_enabled (X86_FEATURE_FRED ))idt_setup_traps (); +/* If SKINIT was done on the BSP, this is the spot to enable GIF */ +slaunch_cpu_setup_skinit (); +cpu_init (); }
Signature · 1 line
2.49.0
RFC PATCH v2 7/9 x86/slmodule: Support AMD SKINIT
In reply to Sergii DmytrukFrom: Ross Philipson <[email protected]>
Some of the changes are related to generalization: common macro for resetting the platform. The rest are:
- SKINIT-specific way of getting to SLRT
- handling of TPM log which has TXT-specific header embedded as vendor data of a TCG-compliant one
--- arch/x86/kernel/slmodule.c | 161 ++++++++++++++++++++++++++++++------- 1 file changed, 134 insertions(+), 27 deletions(-)
arch/x86/kernel/slmodule.c +134 -27
@@ -18,12 +18,21 @@#include <linux/security.h> #include <linux/memblock.h> #include <linux/tpm.h> +#include <asm/setup.h> #include <asm/segment.h> #include <asm/sections.h> #include <crypto/sha2.h> #include <linux/slr_table.h> #include <linux/slaunch.h> +#define slaunch_reset (t, m, e) \ + do { \ + if (t) \ + slaunch_txt_reset((t), (m), (e)); \ + else \ + slaunch_skinit_reset((m), (e)); \ + } while (0) +/* * The macro DECLARE_TXT_PUB_READ_U is used to read values from the TXT * public registers as unsigned values.
@@ -83,6 +92,7 @@ struct memfile {static struct memfile sl_evtlog = {"eventlog" ,NULL ,0 };static void *txt_heap; +static void *skinit_evtlog;static struct txt_heap_event_log_pointer2_1_element *evtlog21;static DEFINE_MUTEX (sl_evt_log_mutex);static struct tcg_efi_specid_event_head *efi_head;
@@ -239,12 +249,19 @@ static void slaunch_teardown_securityfs(void)memunmap (txt_heap); txt_heap =NULL ; } + }else if (slaunch_get_flags () &SL_FLAG_ARCH_SKINIT ) { +if (skinit_evtlog) { +memunmap (skinit_evtlog); + skinit_evtlog =NULL ; + } + sl_evtlog.addr =NULL ; + sl_evtlog.size =0 ; }securityfs_remove (slaunch_dir); } -static void slaunch_intel_evtlog (void __iomem *txt) +static void slaunch_txt_evtlog (void __iomem *txt) {struct slr_entry_log_info *log_info;struct txt_os_mle_data *params;
@@ -312,6 +329,88 @@ static void slaunch_intel_evtlog(void __iomem *txt) efi_head = (struct tcg_efi_specid_event_head *)(sl_evtlog.addr +sizeof (struct tcg_pcr_event )); } +static void slaunch_skinit_evtlog (void ) +{ +struct slr_entry_amd_info amd_info_temp; +struct slr_entry_amd_info *amd_info; +struct slr_entry_log_info *log_info; +struct setup_data *data; +struct slr_table *slrt; +u64 pa_data; + + pa_data = (u64 )boot_params.hdr.setup_data; + amd_info =NULL ; + +while (pa_data) { + data = (struct setup_data *)memremap (pa_data,sizeof (*data),MEMREMAP_WB ); +if (!data) +slaunch_skinit_reset ("Error failed to memremap setup data\n" , +SL_ERROR_MAP_SETUP_DATA ); + +if (data->type ==SETUP_SECURE_LAUNCH ) { +memunmap (data); + amd_info = (struct slr_entry_amd_info *) +memremap (pa_data -sizeof (struct slr_entry_hdr ), +sizeof (*amd_info),MEMREMAP_WB ); +if (!amd_info) +slaunch_skinit_reset ("Error failed to memremap AMD info\n" , +SL_ERROR_MAP_SETUP_DATA ); +break ; + } + + pa_data = data->next; +memunmap (data); + } + +if (!amd_info) +slaunch_skinit_reset ("Error failed to find AMD info\n" ,SL_ERROR_MISSING_EVENT_LOG ); + + amd_info_temp = *amd_info; +memunmap (amd_info); + +/* Get the SLRT and remap it */ + slrt =memremap (amd_info_temp.slrt_base, amd_info_temp.slrt_size,MEMREMAP_WB ); +if (!slrt) +slaunch_skinit_reset ("Error failed to memremap SLR Table\n" ,SL_ERROR_SLRT_MAP ); + + log_info =slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_LOG_INFO ); +if (!log_info) +slaunch_skinit_reset ("Error failed to find event log info SLR Table\n" , +SL_ERROR_SLRT_MISSING_ENTRY ); + +/* Finally map the actual event log and find the proper offsets */ + skinit_evtlog =memremap (log_info->addr, log_info->size,MEMREMAP_WB ); +if (!skinit_evtlog) +slaunch_skinit_reset ("Error failed to memremap TPM event log\n" , +SL_ERROR_EVENTLOG_MAP ); + + sl_evtlog.size = log_info->size; + sl_evtlog.addr = skinit_evtlog; + +memunmap (slrt); + +/* +* See the comment for the following function concerning the +* logic used here: +* arch/x86/boot/compressed/sl_main.c:sl_find_event_log() +*/ +if (!memcmp (skinit_evtlog +sizeof (struct tcg_pcr_event ), +TCG_SPECID_SIG ,sizeof (TCG_SPECID_SIG ))) { + evtlog21 = skinit_evtlog +sizeof (struct tcg_pcr_event ) + +TCG_EfiSpecIdEvent_SIZE ( +TPM2_HASH_COUNT (skinit_evtlog + +sizeof (struct tcg_pcr_event ))); + }else { + sl_evtlog.addr +=sizeof (struct tcg_pcr_event ) + + TCG_PCClientSpecIDEventStruct_SIZE; + sl_evtlog.size -=sizeof (struct tcg_pcr_event ) + + TCG_PCClientSpecIDEventStruct_SIZE; + } + +/* Save pointer to the EFI SpecID log header */ + efi_head = (struct tcg_efi_specid_event_head *)(skinit_evtlog +sizeof (struct tcg_pcr_event )); +} +static void slaunch_tpm2_extend_event (struct tpm_chip *tpm,void __iomem *txt,struct tcg_pcr_event2_head *event) {
@@ -331,8 +430,7 @@ static void slaunch_tpm2_extend_event(struct tpm_chip *tpm, void __iomem *txt, digests =kzalloc (efi_head->num_algs *sizeof (*digests),GFP_KERNEL );if (!digests) -slaunch_txt_reset (txt,"Failed to allocate array of digests\n" , -SL_ERROR_GENERIC ); +slaunch_reset (txt,"Failed to allocate array of digests\n" ,SL_ERROR_GENERIC );for (i =0 ; i < event->count; i++) { dptr = (u8 *)alg_id_field +sizeof (u16);
@@ -349,8 +447,7 @@ static void slaunch_tpm2_extend_event(struct tpm_chip *tpm, void __iomem *txt, ret =tpm_pcr_extend (tpm, event->pcr_idx, digests);if (ret) {pr_err ("Error extending TPM20 PCR, result: %d\n" , ret); -slaunch_txt_reset (txt,"Failed to extend TPM20 PCR\n" , -SL_ERROR_TPM_EXTEND ); +slaunch_reset (txt,"Failed to extend TPM20 PCR\n" ,SL_ERROR_TPM_EXTEND ); }kfree (digests);
@@ -372,8 +469,8 @@ static void slaunch_tpm2_extend(struct tpm_chip *tpm, void __iomem *txt)while ((void *)event < sl_evtlog.addr + evtlog21->next_record_offset) { size =__calc_tpm2_event_size (event, event_header, false);if (!size) -slaunch_txt_reset (txt,"TPM20 invalid event in event log\n" , -SL_ERROR_TPM_INVALID_EVENT ); +slaunch_reset (txt,"TPM20 invalid event in event log\n" , +SL_ERROR_TPM_INVALID_EVENT );/* * Marker events indicate where the Secure Launch early stub
@@ -400,8 +497,8 @@ static void slaunch_tpm2_extend(struct tpm_chip *tpm, void __iomem *txt) }if (!start || !end) -slaunch_txt_reset (txt,"Missing start or end events for extending TPM20 PCRs\n" , -SL_ERROR_TPM_EXTEND ); +slaunch_reset (txt,"Missing start or end events for extending TPM20 PCRs\n" , +SL_ERROR_TPM_EXTEND ); }static void slaunch_tpm_extend (struct tpm_chip *tpm,void __iomem *txt)
@@ -442,8 +539,8 @@ static void slaunch_tpm_extend(struct tpm_chip *tpm, void __iomem *txt) ret =tpm_pcr_extend (tpm, event->pcr_idx, &digest);if (ret) {pr_err ("Error extending TPM12 PCR, result: %d\n" , ret); -slaunch_txt_reset (txt,"Failed to extend TPM12 PCR\n" , -SL_ERROR_TPM_EXTEND ); +slaunch_reset (txt,"Failed to extend TPM12 PCR\n" , +SL_ERROR_TPM_EXTEND ); } }
@@ -452,8 +549,8 @@ static void slaunch_tpm_extend(struct tpm_chip *tpm, void __iomem *txt) }if (!start || !end) -slaunch_txt_reset (txt,"Missing start or end events for extending TPM12 PCRs\n" , -SL_ERROR_TPM_EXTEND ); +slaunch_reset (txt,"Missing start or end events for extending TPM12 PCRs\n" , +SL_ERROR_TPM_EXTEND ); }static void slaunch_pcr_extend (void __iomem *txt)
@@ -463,13 +560,11 @@ static void slaunch_pcr_extend(void __iomem *txt) tpm =tpm_default_chip ();if (!tpm) -slaunch_txt_reset (txt,"Could not get default TPM chip\n" , -SL_ERROR_TPM_INIT ); +slaunch_reset (txt,"Could not get default TPM chip\n" ,SL_ERROR_TPM_INIT ); rc =tpm_chip_set_locality (tpm,2 );if (rc) -slaunch_txt_reset (txt,"Could not set TPM chip locality 2\n" , -SL_ERROR_TPM_INIT ); +slaunch_reset (txt,"Could not set TPM chip locality 2\n" ,SL_ERROR_TPM_INIT );if (evtlog21)slaunch_tpm2_extend (tpm, txt);
@@ -482,19 +577,31 @@ static int __init slaunch_module_init(void)void __iomem *txt;/* Check to see if Secure Launch happened */ -if ((slaunch_get_flags () & (SL_FLAG_ACTIVE |SL_FLAG_ARCH_TXT )) != - (SL_FLAG_ACTIVE |SL_FLAG_ARCH_TXT )) +if (!(slaunch_get_flags () &SL_FLAG_ACTIVE ))return 0 ; - txt =ioremap (TXT_PRIV_CONFIG_REGS_BASE ,TXT_NR_CONFIG_PAGES * -PAGE_SIZE ); -if (!txt) -panic ("Error ioremap of TXT priv registers\n" ); +if (slaunch_get_flags () &SL_FLAG_ARCH_TXT ) { + txt =ioremap (TXT_PRIV_CONFIG_REGS_BASE ,TXT_NR_CONFIG_PAGES * +PAGE_SIZE ); +if (!txt) +panic ("Error ioremap of TXT priv registers\n" ); + +slaunch_txt_evtlog (txt); + +slaunch_pcr_extend (txt); + +iounmap (txt); + +pr_info ("TXT Secure Launch module setup\n" ); + }else if (slaunch_get_flags () &SL_FLAG_ARCH_SKINIT ) { +slaunch_skinit_evtlog (); + +slaunch_pcr_extend (NULL ); + +pr_info ("SKINIT Secure Launch module setup\n" ); + }else +panic ("Secure Launch unknown architecture\n" ); -/* Only Intel TXT is supported at this point */ -slaunch_intel_evtlog (txt); -slaunch_pcr_extend (txt); -iounmap (txt);return slaunch_expose_securityfs (); }
Signature · 1 line
2.49.0
RFC PATCH v2 8/9 x86: AMD changes for EFI stub DRTM launch support
In reply to Sergii DmytrukFrom: Ross Philipson <[email protected]>
* Only do the TXT setup steps if this is a TXT launch not an SKINIT one.
* Initialize boot params address for SKINIT.
--- drivers/firmware/efi/libstub/x86-stub.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/firmware/efi/libstub/x86-stub.c +9 -3
@@ -798,15 +798,21 @@ static bool efi_secure_launch_update_boot_params(struct slr_table *slrt, struct boot_params *boot_params) {struct slr_entry_intel_info *txt_info; +struct slr_entry_amd_info *skinit_info;struct slr_entry_policy *policy;bool updated = false;int i; txt_info =slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_INTEL_INFO ); -if (!txt_info) -return false; +if (txt_info) + txt_info->boot_params_addr = (u64 )boot_params; + + skinit_info =slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_AMD_INFO ); +if (skinit_info) + skinit_info->boot_params_addr = (u64 )boot_params; - txt_info->boot_params_addr = (u64 )boot_params; +if (!txt_info && !skinit_info) +return false; policy =slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_ENTRY_POLICY );if (!policy)
Signature · 1 line
2.49.0
Re: [RFC PATCH v2 8/9] x86: AMD changes for EFI stub DRTM launch support
Quoted 8 lines · Sergii Dmytruk
From: Ross Philipson <[email protected]>
* Only do the TXT setup steps if this is a TXT launch not an SKINIT one.
* Initialize boot params address for SKINIT.Signed-off-by Ross Philipson <[email protected]>Signed-off-by Sergii Dmytruk <[email protected]>
Quoted 36 lines
--- drivers/firmware/efi/libstub/x86-stub.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)drivers/firmware/efi/libstub/x86-stub.c +9
-4@@ -798,15 +798,21 @@ static bool efi_secure_launch_update_boot_params(struct slr_table *slrt, struct boot_params *boot_params) {struct slr_entry_intel_info *txt_info; +struct slr_entry_amd_info *skinit_info;struct slr_entry_policy *policy;bool updated = false;int i; txt_info =slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_INTEL_INFO ); -if (!txt_info) -return false; +if (txt_info) + txt_info->boot_params_addr = (u64 )boot_params; + + skinit_info =slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_AMD_INFO ); +if (skinit_info) + skinit_info->boot_params_addr = (u64 )boot_params; - txt_info->boot_params_addr = (u64 )boot_params; +if (!txt_info && !skinit_info) +return false; policy =slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_ENTRY_POLICY );if (!policy) --2.49.0
RFC PATCH v2 9/9 psp: Perform kernel portion of DRTM procedures
In reply to Sergii DmytrukFrom: Jagannathan Raman <[email protected]>
GRUB and AMD-SL would have executed the SKINIT instruction and performed DRTM setup procedures. As part of DRTM, GRUB sets up TMRs to cover the whole of the system's physical memory regions. The Kernel should release these TMRs to facilitate communication between devices and drivers. TMRs are released after the Kernel sets up IOMMU.
Releasing TMRs concludes DRTM. The Kernel should also execute DRTM_CMD_TPM_LOCALITY_ACCESS to lock TPM locality two before removing TMRs. But this prevents the Kernel's TPM driver (which loads subsequently) from extending PCRs. As such, we are skipping the TPM locality access command.
--- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/sl-psp.c | 239 ++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/slaunch.c | 4 +- drivers/iommu/amd/init.c | 12 ++ 4 files changed, 255 insertions(+), 1 deletion(-) create mode 100644 arch/x86/kernel/sl-psp.c
arch/x86/kernel/Makefile +1 -0
@@ -84,6 +84,7 @@ obj-y += step.o obj-$(CONFIG_INTEL_TXT) += tboot.o obj-$(CONFIG_SECURE_LAUNCH) += slaunch.o obj-$(CONFIG_SECURE_LAUNCH) += slmodule.o +obj-$(CONFIG_SECURE_LAUNCH) += sl-psp.o obj-$(CONFIG_ISA_DMA_API) += i8237.o obj-y += stacktrace.o obj-y += cpu/
arch/x86/kernel/sl-psp.c new file +239 -0
239 lines not on this page · raw message
arch/x86/kernel/slaunch.c +3 -1
@@ -701,13 +701,15 @@ static void slaunch_finalize_txt(int do_sexit) }/* -* Used during kexec and on reboot paths to finalize the SKINIT. +* Used during kexec and on reboot paths to finalize the SKINIT PSP state. */ static void slaunch_finalize_skinit (void ) {/* AMD CPUs with PSP-supported DRTM */ if (!slaunch_is_skinit_psp ())return ; + +slaunch_psp_finalize (); }void slaunch_finalize (int do_sexit)
drivers/iommu/amd/init.c +12 -0
@@ -21,6 +21,7 @@#include <linux/kmemleak.h> #include <linux/cc_platform.h> #include <linux/iopoll.h> +#include <linux/slaunch.h> #include <asm/pci-direct.h> #include <asm/iommu.h> #include <asm/apic.h>
@@ -3357,6 +3358,17 @@ int __init amd_iommu_enable(void)if (ret)return ret; +#if IS_ENABLED (CONFIG_SECURE_LAUNCH ) +if (slaunch_is_skinit_psp ()) { +/* Initialize PSP access to SKINIT DRTM functions */ +slaunch_psp_setup (); + +/* Release the Trusted Memory Region since IOMMU is configured */ +if (!slaunch_psp_tmr_release ()) +return -ENODEV ; + } +#endif + irq_remapping_enabled =1 ;return amd_iommu_xt_mode; }
Signature · 1 line
2.49.0