x86: Trenchboot secure dynamic launch Linux kernel support
Subsystems (12)
v8 cover x86: Trenchboot secure dynamic launch Linux kernel support
The larger focus of the TrenchBoot project (https://github.com/TrenchBoot) is to enhance the boot security and integrity in a unified manner. The first area of focus has been on the Trusted Computing Group's Dynamic Launch for establishing a hardware Root of Trust for Measurement, also know as DRTM (Dynamic Root of Trust for Measurement). The project has been and continues to work on providing a unified means to Dynamic Launch that is a cross-platform (Intel and AMD) and cross-architecture (x86 and Arm), with our recent involvment in the upcoming Arm DRTM specification. The order of introducing DRTM to the Linux kernel follows the maturity of DRTM in the architectures. Intel's Trusted eXecution Technology (TXT) is present today and only requires a preamble loader, e.g. a boot loader, and an OS kernel that is TXT-aware. AMD DRTM implementation has been present since the introduction of AMD-V but requires an additional component that is AMD specific and referred to in the specification as the Secure Loader, which the TrenchBoot project has an active prototype in development. Finally Arm's implementation is in specification development stage and the project is looking to support it when it becomes available.
This patchset provides detailed documentation of DRTM, the approach used for adding the capbility, and relevant API/ABI documentation. In addition to the documentation the patch set introduces Intel TXT support as the first platform for Linux Secure Launch.
A quick note on terminology. The larger open source project itself is called TrenchBoot, which is hosted on Github (links below). The kernel feature enabling the use of Dynamic Launch technology is referred to as "Secure Launch" within the kernel code. As such the prefixes sl_/SL_ or slaunch/SLAUNCH will be seen in the code. The stub code discussed above is referred to as the SL stub.
The Secure Launch feature starts with patch #2. Patch #1 was authored by Arvind Sankar. There is no further status on this patch at this point but Secure Launch depends on it so it is included with the set.
Links:
The TrenchBoot project including documentation:
The TrenchBoot project on Github:
Intel TXT is documented in its own specification and in the SDM Instruction Set volume:
https://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-txt-software-development-guide.pdf
https://software.intel.com/en-us/articles/intel-sdm
AMD SKINIT is documented in the System Programming manual:
https://www.amd.com/system/files/TechDocs/24593.pdf
The TrenchBoot project provides a quick start guide to help get a system up and running with Secure Launch for Linux:
https://github.com/TrenchBoot/documentation/blob/master/QUICKSTART.md
Patch set based on commit:
torvolds/master/54be6c6c5ae8e0d93a6c4641cb7528eb0b6ba478
Thanks
Ross Philipson and Daniel P. Smith
Changes in v2:
- Modified 32b entry code to prevent causing relocations in the compressed kernel.
- Dropped patches for compressed kernel TPM PCR extender.
- Modified event log code to insert log delimiter events and not rely on TPM access.
- Stop extending PCRs in the early Secure Launch stub code.
- Removed Kconfig options for hash algorithms and use the algorithms the ACM used.
- Match Secure Launch measurement algorithm use to those reported in the TPM 2.0 event log.
- Read the TPM events out of the TPM and extend them into the PCRs using the mainline TPM driver. This is done in the late initcall module.
- Allow use of alternate PCR 19 and 20 for post ACM measurements.
- Add Kconfig constraints needed by Secure Launch (disable KASLR and add x2apic dependency).
- Fix testing of SL_FLAGS when determining if Secure Launch is active and the architecture is TXT.
- Use SYM_DATA_START_LOCAL macros in early entry point code.
- Security audit changes:
- Validate buffers passed to MLE do not overlap the MLE and are properly laid out.
- Validate buffers and memory regions used by the MLE are protected by IOMMU PMRs.
- Force IOMMU to not use passthrough mode during a Secure Launch.
- Prevent KASLR use during a Secure Launch.
Changes in v3:
- Introduce x86 documentation patch to provide background, overview and configuration/ABI information for the Secure Launch kernel feature.
- Remove the IOMMU patch with special cases for disabling IOMMU passthrough. Configuring the IOMMU is now a documentation matter in the previously mentioned new patch.
- Remove special case KASLR disabling code. Configuring KASLR is now a documentation matter in the previously mentioned new patch.
- Fix incorrect panic on TXT public register read.
- Properly handle and measure setup_indirect bootparams in the early launch code.
- Use correct compressed kernel image base address when testing buffers in the early launch stub code. This bug was introduced by the changes to avoid relocation in the compressed kernel.
- Use CPUID feature bits instead of CPUID vendor strings to determine if SMX mode is supported and the system is Intel.
- Remove early NMI re-enable on the BSP. This can be safely done later on the BSP after an IDT is setup.
Changes in v4:
- Expand the cover letter to provide more context to the order that DRTM support will be added.
- Removed debug tracing in TPM request locality funciton and fixed local variable declarations.
- Fixed missing break in default case in slmodule.c.
- Reworded commit messages in patches 1 and 2 per suggestions.
Changes in v5:
- Comprehensive documentation rewrite.
- Use boot param loadflags to communicate Secure Launch status to kernel proper.
- Fix incorrect check of X86_FEATURE_BIT_SMX bit.
- Rename the alternate details and authorities PCR support.
- Refactor the securityfs directory and file setup in slmodule.c.
- Misc. cleanup from internal code reviews.
- Use reverse fir tree format for variables.
Changes in v6:
- Support for the new Secure Launch Resourse Table that standardizes the information passed and forms the ABI between the pre and post launch code.
- Support for booting Linux through the EFI stub entry point and then being able to do a Secure Launch once EFI stub is done and EBS is called.
- Updates to the documentation to reflect the previous two items listed.
Changes in v7:
- Switch to using MONITOR/MWAIT instead of NMIs to park the APs for later bringup by the SMP code.
- Use static inline dummy functions instead of macros when the Secure Launch feature is disabled.
- Move early SHA1 code to lib/crypto and pull it in from there.
- Numerous formatting fixes from comments on LKML.
- Remove efi-stub/DL stub patch temporarily for redesign/rework.
Changes in v8:
- Reintroduce efi-stub Linux kernel booting through the dynamic launch stub (DL stub).
- Add new approach to setting localities > 0 through kernel and sysfs interfaces in the TPM mainline driver.
- General code cleanup from v7 post comments.
Arvind Sankar (1):
x86/boot: Place kernel_info at a fixed offset
Daniel P. Smith (2):
x86: Add early SHA support for Secure Launch early measurements
x86: Secure Launch late initcall platform module
Ross Philipson (12):
Documentation/x86: Secure Launch kernel documentation
x86: Secure Launch Kconfig
x86: Secure Launch Resource Table header file
x86: Secure Launch main header file
x86: Secure Launch kernel early boot stub
x86: Secure Launch kernel late boot stub
x86: Secure Launch SMP bringup support
kexec: Secure Launch kexec SEXIT support
reboot: Secure Launch SEXIT support on reboot paths
tpm: Add ability to set the preferred locality the TPM chip uses
tpm: Add sysfs interface to allow setting and querying the preferred
locality
x86: EFI stub DRTM launch support for Secure Launch
*** BLURB HERE ***
Arvind Sankar (1):
x86/boot: Place kernel_info at a fixed offset
Daniel P. Smith (2):
x86: Add early SHA support for Secure Launch early measurements
x86: Secure Launch late initcall platform module
Ross Philipson (12):
Documentation/x86: Secure Launch kernel documentation
x86: Secure Launch Kconfig
x86: Secure Launch Resource Table header file
x86: Secure Launch main header file
x86: Secure Launch kernel early boot stub
x86: Secure Launch kernel late boot stub
x86: Secure Launch SMP bringup support
kexec: Secure Launch kexec SEXIT support
reboot: Secure Launch SEXIT support on reboot paths
tpm: Add ability to set the preferred locality the TPM chip uses
tpm: Add sysfs interface to allow setting and querying the preferred
locality
x86: EFI stub DRTM launch support for Secure Launch
Documentation/arch/x86/boot.rst | 21 + Documentation/security/index.rst | 1 + .../security/launch-integrity/index.rst | 11 + .../security/launch-integrity/principles.rst | 320 ++++++++ .../secure_launch_details.rst | 584 +++++++++++++++ .../secure_launch_overview.rst | 226 ++++++ arch/x86/Kconfig | 12 + arch/x86/boot/compressed/Makefile | 3 + arch/x86/boot/compressed/early_sha1.c | 12 + arch/x86/boot/compressed/early_sha256.c | 6 + arch/x86/boot/compressed/head_64.S | 34 + arch/x86/boot/compressed/kernel_info.S | 53 +- arch/x86/boot/compressed/kernel_info.h | 12 + arch/x86/boot/compressed/sl_main.c | 582 +++++++++++++++ arch/x86/boot/compressed/sl_stub.S | 705 ++++++++++++++++++ arch/x86/boot/compressed/vmlinux.lds.S | 6 + arch/x86/include/asm/msr-index.h | 5 + arch/x86/include/asm/realmode.h | 3 + arch/x86/include/uapi/asm/bootparam.h | 1 + arch/x86/kernel/Makefile | 2 + arch/x86/kernel/asm-offsets.c | 20 + arch/x86/kernel/reboot.c | 10 + arch/x86/kernel/setup.c | 3 + arch/x86/kernel/slaunch.c | 598 +++++++++++++++ arch/x86/kernel/slmodule.c | 511 +++++++++++++ arch/x86/kernel/smpboot.c | 58 +- arch/x86/realmode/init.c | 3 + arch/x86/realmode/rm/header.S | 3 + arch/x86/realmode/rm/trampoline_64.S | 32 + drivers/char/tpm/tpm-chip.c | 24 +- drivers/char/tpm/tpm-interface.c | 15 + drivers/char/tpm/tpm-sysfs.c | 30 + drivers/char/tpm/tpm.h | 1 + drivers/firmware/efi/libstub/x86-stub.c | 55 ++ drivers/iommu/intel/dmar.c | 4 + include/crypto/sha1.h | 1 + include/linux/slaunch.h | 542 ++++++++++++++ include/linux/slr_table.h | 270 +++++++ include/linux/tpm.h | 10 + kernel/kexec_core.c | 4 + lib/crypto/sha1.c | 81 ++ 41 files changed, 4867 insertions(+), 7 deletions(-) create mode 100644 Documentation/security/launch-integrity/index.rst create mode 100644 Documentation/security/launch-integrity/principles.rst create mode 100644 Documentation/security/launch-integrity/secure_launch_details.rst create mode 100644 Documentation/security/launch-integrity/secure_launch_overview.rst create mode 100644 arch/x86/boot/compressed/early_sha1.c create mode 100644 arch/x86/boot/compressed/early_sha256.c create mode 100644 arch/x86/boot/compressed/kernel_info.h create mode 100644 arch/x86/boot/compressed/sl_main.c create mode 100644 arch/x86/boot/compressed/sl_stub.S create mode 100644 arch/x86/kernel/slaunch.c create mode 100644 arch/x86/kernel/slmodule.c create mode 100644 include/linux/slaunch.h create mode 100644 include/linux/slr_table.h
Signature · 7 lines
2.39.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v8 1/15 x86/boot: Place kernel_info at a fixed offset
From: Arvind Sankar <[email protected]>
There are use cases for storing the offset of a symbol in kernel_info. For example, the trenchboot series [0] needs to store the offset of the Measured Launch Environment header in kernel_info.
Since commit (note: commit ID from tip/master)
commit 527afc212231 ("x86/boot: Check that there are no run-time relocations")
run-time relocations are not allowed in the compressed kernel, so simply using the symbol in kernel_info, as
.long symbol
will cause a linker error because this is not position-independent.
With kernel_info being a separate object file and in a different section from startup_32, there is no way to calculate the offset of a symbol from the start of the image in a position-independent way.
To enable such use cases, put kernel_info into its own section which is placed at a predetermined offset (KERNEL_INFO_OFFSET) via the linker script. This will allow calculating the symbol offset in a position-independent way, by adding the offset from the start of kernel_info to KERNEL_INFO_OFFSET.
Ensure that kernel_info is aligned, and use the SYM_DATA.* macros instead of bare labels. This stores the size of the kernel_info structure in the ELF symbol table.
--- arch/x86/boot/compressed/kernel_info.S | 19 +++++++++++++++---- arch/x86/boot/compressed/kernel_info.h | 12 ++++++++++++ arch/x86/boot/compressed/vmlinux.lds.S | 6 ++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 arch/x86/boot/compressed/kernel_info.h
arch/x86/boot/compressed/kernel_info.S +15 -4
@@ -1,12 +1,23 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/linkage.h> #include <asm/bootparam.h> +#include "kernel_info.h" - .section ".rodata.kernel_info", "a" +/* + * If a field needs to hold the offset of a symbol from the start + * of the image, use the macro below, eg + * .long rva(symbol) + * This will avoid creating run-time relocations, which are not + * allowed in the compressed kernel. + */ + +#define rva(X) (((X) - kernel_info) + KERNEL_INFO_OFFSET) - .global kernel_info + .section ".rodata.kernel_info", "a" -kernel_info: + .balign 16 +SYM_DATA_START(kernel_info) /* Header, Linux top (structure). */ .ascii "LToP" /* Size. */
@@ -19,4 +30,4 @@ kernel_info: kernel_info_var_len_data: /* Empty for time being... */ -kernel_info_end: +SYM_DATA_END_LABEL(kernel_info, SYM_L_LOCAL, kernel_info_end)
arch/x86/boot/compressed/kernel_info.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef BOOT_COMPRESSED_KERNEL_INFO_H +#define BOOT_COMPRESSED_KERNEL_INFO_H + +#ifdef CONFIG_X86_64 +#define KERNEL_INFO_OFFSET 0x500 +#else /* 32-bit */ +#define KERNEL_INFO_OFFSET 0x100 +#endif + +#endif /* BOOT_COMPRESSED_KERNEL_INFO_H */
arch/x86/boot/compressed/vmlinux.lds.S +6 -0
@@ -7,6 +7,7 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT) #include <asm/cache.h> #include <asm/page_types.h> +#include "kernel_info.h" #ifdef CONFIG_X86_64 OUTPUT_ARCH(i386:x86-64)
@@ -27,6 +28,11 @@ SECTIONS HEAD_TEXT _ehead = . ; } + .rodata.kernel_info KERNEL_INFO_OFFSET : { + *(.rodata.kernel_info) + } + ASSERT(ABSOLUTE(kernel_info) == KERNEL_INFO_OFFSET, "kernel_info at bad address!") + .rodata..compressed : { *(.rodata..compressed) }
Signature · 7 lines
2.39.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Ard Biesheuvel
maintainerRe: [PATCH v8 01/15] x86/boot: Place kernel_info at a fixed offset
Quoted 7 lines · Ross Philipson
From: Arvind Sankar <[email protected]>
There are use cases for storing the offset of a symbol in
kernel_info. For example, the trenchboot series [0] needs to store the offset of the Measured Launch Environment header inkernel_info.
Why? Is this information consumed by the bootloader?
I'd like to get away from x86 specific hacks for boot code and boot images, so I would like to explore if we can avoid kernel_info, or at least expose it in a generic way. We might just add a 32-bit offset somewhere in the first 64 bytes of the bootable image: this could co-exist with EFI bootable images, and can be implemented on arm64, RISC-V and LoongArch as well.
Quoted 117 lines
Since commit (note: commit ID from tip/master)
commit
527afc212231("x86/boot: Check that there are no run-time relocations")run-time relocations are not allowed in the compressed kernel, so simply using the symbol in
kernel_info, as.long symbol
will cause a linker error because this is not position-independent.
With
kernel_infobeing a separate object file and in a different section fromstartup_32, there is no way to calculate the offset of a symbol from the start of the image in a position-independent way.To enable such use cases, put
kernel_infointo its own section which is placed at a predetermined offset (KERNEL_INFO_OFFSET) via the linker script. This will allow calculating the symbol offset in a position-independent way, by adding the offset from the start ofkernel_infotoKERNEL_INFO_OFFSET.Ensure that
kernel_infois aligned, and use the SYM_DATA.* macros instead of bare labels. This stores the size of thekernel_infostructure in the ELF symbol table.Signed-off-by Arvind Sankar <[email protected]>Cc Ross Philipson <[email protected]>Signed-off-by Ross Philipson <[email protected]>--- arch/x86/boot/compressed/kernel_info.S | 19 +++++++++++++++---- arch/x86/boot/compressed/kernel_info.h | 12 ++++++++++++ arch/x86/boot/compressed/vmlinux.lds.S | 6 ++++++ 3 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 arch/x86/boot/compressed/kernel_info.harch/x86/boot/compressed/kernel_info.S +15
-4@@ -1,12 +1,23 @@ /* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/linkage.h> #include <asm/bootparam.h> +#include "kernel_info.h" - .section ".rodata.kernel_info", "a" +/* + * If a field needs to hold the offset of a symbol from the start + * of the image, use the macro below, eg + * .long rva(symbol) + * This will avoid creating run-time relocations, which are not + * allowed in the compressed kernel. + */ + +#define rva(X) (((X) - kernel_info) + KERNEL_INFO_OFFSET) - .global kernel_info + .section ".rodata.kernel_info", "a" -kernel_info: + .balign 16 +SYM_DATA_START(kernel_info) /* Header, Linux top (structure). */ .ascii "LToP" /* Size. */@@ -19,4 +30,4 @@ kernel_info: kernel_info_var_len_data: /* Empty for time being... */ -kernel_info_end: +SYM_DATA_END_LABEL(kernel_info, SYM_L_LOCAL, kernel_info_end)arch/x86/boot/compressed/kernel_info.h new file +12
-0@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef BOOT_COMPRESSED_KERNEL_INFO_H +#define BOOT_COMPRESSED_KERNEL_INFO_H + +#ifdef CONFIG_X86_64 +#define KERNEL_INFO_OFFSET 0x500 +#else /* 32-bit */ +#define KERNEL_INFO_OFFSET 0x100 +#endif + +#endif /* BOOT_COMPRESSED_KERNEL_INFO_H */ arch/x86/boot/compressed/vmlinux.lds.S +6
-1@@ -7,6 +7,7 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT) #include <asm/cache.h> #include <asm/page_types.h> +#include "kernel_info.h" #ifdef CONFIG_X86_64 OUTPUT_ARCH(i386:x86-64)@@ -27,6 +28,11 @@ SECTIONS HEAD_TEXT _ehead = . ; } + .rodata.kernel_info KERNEL_INFO_OFFSET : { + *(.rodata.kernel_info) + } + ASSERT(ABSOLUTE(kernel_info) == KERNEL_INFO_OFFSET, "kernel_info at bad address!") + .rodata..compressed : { *(.rodata..compressed) } --2.39.3
Re: [PATCH v8 01/15] x86/boot: Place kernel_info at a fixed offset
Quoted 10 lines · Ard Biesheuvel
Quoted 7 lines · Ross Philipson
From: Arvind Sankar <[email protected]>
There are use cases for storing the offset of a symbol in
kernel_info. For example, the trenchboot series [0] needs to store the offset of the Measured Launch Environment header inkernel_info.Why? Is this information consumed by the bootloader?
The bootloader stuffs this info, plus some offset IIRC, into special structure and finally it is consumed by SINIT ACM after GETSEC[SENTER] call.
Sadly this data is Intel specific and it is even not compatible with AMD. So, if I am not mistaken, we will need additional member for the AMD in the kernel_info.
Quoted 6 lines
I'd like to get away from x86 specific hacks for boot code and boot images, so I would like to explore if we can avoid
kernel_info, or at least expose it in a generic way. We might just add a 32-bit offset somewhere in the first 64 bytes of the bootable image: this could co-exist with EFI bootable images, and can be implemented on arm64, RISC-V and LoongArch as well.
The other architectures may or may not have need for such data due to differences in DRTM implementation. Anyway, whatever we do I want to be sure the DRTM can be used on UEFI and non-UEFI platforms. So, I am not entirely convinced the address/pointer to additional DRTM data should be part of the MS-DOS and/or PE header. Though I am not against building something generic shared among various architectures either.
Daniel
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v8 01/15] x86/boot: Place kernel_info at a fixed offset
In reply to Ard BiesheuvelHi Ard!
Quoted 10 lines · Ard Biesheuvel
Quoted 7 lines · Ross Philipson
From: Arvind Sankar <[email protected]>
There are use cases for storing the offset of a symbol in
kernel_info. For example, the trenchboot series [0] needs to store the offset of the Measured Launch Environment header inkernel_info.Why? Is this information consumed by the bootloader?
Yes, the bootloader needs a standardized means to find the offset of the MLE header, which communicates a set of meta-data needed by the DCE in order to set up for and start the loaded kernel. Arm will also need to provide a similar metadata structure and alternative entry point (or a complete rewrite of the existing entry point), as the current Arm entry point is in direct conflict with Arm DRTM specification.
Quoted 6 lines
I'd like to get away from x86 specific hacks for boot code and boot images, so I would like to explore if we can avoid
kernel_info, or at least expose it in a generic way. We might just add a 32-bit offset somewhere in the first 64 bytes of the bootable image: this could co-exist with EFI bootable images, and can be implemented on arm64, RISC-V and LoongArch as well.
With all due respect, I would not refer to boot params and the kern_info extension designed by the x86 maintainers as a hack. It is the well-defined boot protocol for x86, just as Arm has its own boot protocol around Device Tree.
We would gladly adopt a cross arch/cross image type, zImage and bzImage, means to embedded meta-data about the kernel that can be discovered by a bootloader. Otherwise, we are relegated to doing a per arch/per image type discovery mechanism. If you have any suggestions that are cross arch/cross image type that we could explore, we would be grateful and willing to investigate how to adopt such a method.
V/r,
Daniel
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
H. Peter Anvin
reviewerRe: [PATCH v8 01/15] x86/boot: Place kernel_info at a fixed offset
Quoted 23 lines · Daniel P. Smith
Hi Ard!
Quoted 10 lines · Ard Biesheuvel
Quoted 7 lines · Ross Philipson
From: Arvind Sankar <[email protected]>
There are use cases for storing the offset of a symbol in
kernel_info. For example, the trenchboot series [0] needs to store the offset of the Measured Launch Environment header inkernel_info.Why? Is this information consumed by the bootloader?
Yes, the bootloader needs a standardized means to find the offset of the MLE header, which communicates a set of meta-data needed by the DCE in order to set up for and start the loaded kernel. Arm will also need to provide a similar metadata structure and alternative entry point (or a complete rewrite of the existing entry point), as the current Arm entry point is in direct conflict with Arm DRTM specification.
Quoted 6 lines
I'd like to get away from x86 specific hacks for boot code and boot images, so I would like to explore if we can avoid
kernel_info, or at least expose it in a generic way. We might just add a 32-bit offset somewhere in the first 64 bytes of the bootable image: this could co-exist with EFI bootable images, and can be implemented on arm64, RISC-V and LoongArch as well.
Quoted 6 lines
With all due respect, I would not refer to boot params and the
kern_infoextension designed by the x86 maintainers as a hack. It is the well-defined boot protocol for x86, just as Arm has its own boot protocol around Device Tree.We would gladly adopt a cross
arch/crossimage type, zImage and bzImage, means to embedded meta-data about the kernel that can be discovered by a bootloader. Otherwise, we are relegated to doing a perarch/perimage type discovery mechanism. If you have any suggestions that are crossarch/crossimage type that we could explore, we would be grateful and willing to investigate how to adopt such a method.V/r,
Daniel
To be fair, the way things are going UEFI, i.e. PE/COFF, is becoming the new standard format. Yes, ELF would have been better, but...
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v8 01/15] x86/boot: Place kernel_info at a fixed offset
Quoted 24 lines · H. Peter Anvin
Quoted 23 lines · Daniel P. Smith
Hi Ard!
Quoted 10 lines · Ard Biesheuvel
Quoted 7 lines · Ross Philipson
From: Arvind Sankar <[email protected]>
There are use cases for storing the offset of a symbol in
kernel_info. For example, the trenchboot series [0] needs to store the offset of the Measured Launch Environment header inkernel_info.Why? Is this information consumed by the bootloader?
Yes, the bootloader needs a standardized means to find the offset of the MLE header, which communicates a set of meta-data needed by the DCE in order to set up for and start the loaded kernel. Arm will also need to provide a similar metadata structure and alternative entry point (or a complete rewrite of the existing entry point), as the current Arm entry point is in direct conflict with Arm DRTM specification.
Quoted 6 lines
I'd like to get away from x86 specific hacks for boot code and boot images, so I would like to explore if we can avoid
kernel_info, or at least expose it in a generic way. We might just add a 32-bit offset somewhere in the first 64 bytes of the bootable image: this could co-exist with EFI bootable images, and can be implemented on arm64, RISC-V and LoongArch as well.
Quoted 8 lines
Quoted 6 lines
With all due respect, I would not refer to boot params and the
kern_infoextension designed by the x86 maintainers as a hack. It is the well-defined boot protocol for x86, just as Arm has its own boot protocol around Device Tree.We would gladly adopt a cross
arch/crossimage type, zImage and bzImage, means to embedded meta-data about the kernel that can be discovered by a bootloader. Otherwise, we are relegated to doing a perarch/perimage type discovery mechanism. If you have any suggestions that are crossarch/crossimage type that we could explore, we would be grateful and willing to investigate how to adopt such a method.V/r,
DanielTo be fair, the way things are going UEFI, i.e. PE/COFF, is becoming the new standard format. Yes, ELF would have been better, but...
Fully agree with the ELF sentiment. We started looking to see if PE/COFF has something similar to a ELF NOTE, but figured maybe this has been solved for other cases. If that is not the case or there are not any suggestions, then we can see what we can devise.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Ard Biesheuvel
maintainerRe: [PATCH v8 01/15] x86/boot: Place kernel_info at a fixed offset
In reply to Daniel P. Smith(cc Stuart)
Quoted 13 lines · Daniel P. Smith
Hi Ard!
Quoted 9 lines · Ard Biesheuvel
Quoted 7 lines · Ross Philipson
From: Arvind Sankar <[email protected]>
There are use cases for storing the offset of a symbol in
kernel_info. For example, the trenchboot series [0] needs to store the offset of the Measured Launch Environment header inkernel_info.
Quoted 9 lines
Quoted 1 line
Why? Is this information consumed by the bootloader?
Yes, the bootloader needs a standardized means to find the offset of the MLE header, which communicates a set of meta-data needed by the DCE in order to set up for and start the loaded kernel. Arm will also need to provide a similar metadata structure and alternative entry point (or a complete rewrite of the existing entry point), as the current Arm entry point is in direct conflict with Arm DRTM specification.
Digging up an old thread here: could you elaborate on this? What do you mean by 'Arm entry point' and how does it conflict directly with the Arm DRTM specification? The Linux/arm64 port predates that spec by about 10 years, so I would expect the latter to take the former into account. If that failed to happen, we should fix the spec while we still can.
Thanks,
Ard.
Re: [PATCH v8 01/15] x86/boot: Place kernel_info at a fixed offset
Quoted 27 lines · Ard Biesheuvel
(cc Stuart)
Quoted 13 lines · Daniel P. Smith
Hi Ard!
Quoted 9 lines · Ard Biesheuvel
Quoted 7 lines · Ross Philipson
From: Arvind Sankar <[email protected]>
There are use cases for storing the offset of a symbol in
kernel_info. For example, the trenchboot series [0] needs to store the offset of the Measured Launch Environment header inkernel_info.Quoted 9 lines
Quoted 1 line
Why? Is this information consumed by the bootloader?
Yes, the bootloader needs a standardized means to find the offset of the MLE header, which communicates a set of meta-data needed by the DCE in order to set up for and start the loaded kernel. Arm will also need to provide a similar metadata structure and alternative entry point (or a complete rewrite of the existing entry point), as the current Arm entry point is in direct conflict with Arm DRTM specification.
Quoted 6 lines
Digging up an old thread here: could you elaborate on this? What do you mean by 'Arm entry point' and how does it conflict directly with the Arm DRTM specification? The Linux/arm64 port predates that spec by about 10 years, so I would expect the latter to take the former into account. If that failed to happen, we should fix the spec while we still can.
Yes, we have been working with Stuart regarding the specification and crafting a compliant implementation approach. It is still very early days, we are attempting to draft a plan around the specification with no physical implementation to validate against. After some discussion, the concern that a separate entry point may be needed has faded and in fact it likely will not be needed. As always, the devil is in the details, and until we have a hardware that has implemented the specification, and we attempt to light it up, we won't know what will be needed for the implementation.
In short, at this point it was determined no update to the DRTM spec is needed. As hardware becomes available, and we do battle with it, Stuart will be kept up to date. We will work with him to ensure any changes are captured that will help reduce chances that vendors and developers do not misinterpret the spec.
V/r,
Daniel P. Smith
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v8 2/15 Documentation/x86: Secure Launch kernel documentation
In reply to Ross PhilipsonIntroduce background, overview and configuration/ABI information for the Secure Launch kernel feature.
--- Documentation/security/index.rst | 1 + .../security/launch-integrity/index.rst | 11 + .../security/launch-integrity/principles.rst | 320 ++++++++++ .../secure_launch_details.rst | 584 ++++++++++++++++++ .../secure_launch_overview.rst | 226 +++++++ 5 files changed, 1142 insertions(+) create mode 100644 Documentation/security/launch-integrity/index.rst create mode 100644 Documentation/security/launch-integrity/principles.rst create mode 100644 Documentation/security/launch-integrity/secure_launch_details.rst create mode 100644 Documentation/security/launch-integrity/secure_launch_overview.rst
Documentation/security/index.rst +1 -0
@@ -19,3 +19,4 @@ Security Documentation digsig landlock secrets/index + launch-integrity/index
Documentation/security/launch-integrity/index.rst new file +11 -0
@@ -0,0 +1,11 @@ +===================================== +System Launch Integrity documentation +===================================== + +.. toctree:: + :maxdepth: 1 + + principles + secure_launch_overview + secure_launch_details +
Documentation/security/launch-integrity/principles.rst new file +320 -0
320 lines not on this page · raw message
Documentation/security/launch-integrity/secure_launch_details.rst new file +584 -0
584 lines not on this page · raw message
Documentation/security/launch-integrity/secure_launch_overview.rst new file +226 -0
226 lines not on this page · raw message
Signature · 1 line
2.39.3
PATCH v8 3/15 x86: Secure Launch Kconfig
In reply to Ross PhilipsonInitial bits to bring in Secure Launch functionality. Add Kconfig options for compiling in/out the Secure Launch code.
--- arch/x86/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/x86/Kconfig +12 -0
@@ -2071,6 +2071,18 @@ config EFI_RUNTIME_MAP See also Documentation/ABI/testing/sysfs-firmware-efi-runtime-map. +config SECURE_LAUNCH + bool "Secure Launch support" + default n + depends on X86_64 && X86_X2APIC + help + The Secure Launch feature allows a kernel to be loaded + directly through an Intel TXT measured launch. Intel TXT + 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. + source "kernel/Kconfig.hz" config ARCH_SUPPORTS_KEXEC
Signature · 1 line
2.39.3
Ard Biesheuvel
maintainerRe: [PATCH v8 03/15] x86: Secure Launch Kconfig
Quoted 14 lines · Ross Philipson
Initial bits to bring in Secure Launch functionality. Add
Kconfigoptions for compiling in/out the Secure Launch code.Signed-off-by Ross Philipson <[email protected]>--- arch/x86/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+)arch/x86/Kconfig +0
-0
arch/x86/Kconfig config EFI_RUNTIME_MAP · line 2076
Quoted 6 lines
arch/x86/Kconfig +3
-0@@ -2071,6 +2071,18 @@ config EFI_RUNTIME_MAP See also Documentation/ABI/testing/sysfs-firmware-efi-runtime-map. +config SECURE_LAUNCH + bool "Secure Launch support" + default n
'n' is already the default, so you can drop this line.
arch/x86/Kconfig config EFI_RUNTIME_MAP · line 2077
Quoted 1 line
arch/x86/Kconfig +1
-0+ depends on X86_64 && X86_X2APIC
This depends on CONFIG_TCG_TPM as well (I got build failures without it)
Quoted 14 lines
arch/x86/Kconfig +8
-1+ help + The Secure Launch feature allows a kernel to be loaded + directly through an Intel TXT measured launch. Intel TXT + 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. + source "kernel/Kconfig.hz" config ARCH_SUPPORTS_KEXEC --2.39.3
Re: [PATCH v8 03/15] x86: Secure Launch Kconfig
Quoted 16 lines · Ard Biesheuvel
Quoted 15 lines · Ross Philipson
Initial bits to bring in Secure Launch functionality. Add
Kconfigoptions for compiling in/out the Secure Launch code.Signed-off-by Ross Philipson <[email protected]>--- arch/x86/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+)arch/x86/Kconfig +0
-0@@ -2071,6 +2071,18 @@ config EFI_RUNTIME_MAP
Quoted 7 lines
arch/x86/Kconfig config EFI_RUNTIME_MAP · line 2076
Quoted 5 lines
arch/x86/Kconfig +3
-0See also Documentation/ABI/testing/sysfs-firmware-efi-runtime-map. +config SECURE_LAUNCH + bool "Secure Launch support" + default n'n' is already the default, so you can drop this line.
Ack
Quoted 4 lines
arch/x86/Kconfig config EFI_RUNTIME_MAP · line 2077
Quoted 2 lines
arch/x86/Kconfig +1
-0+ depends on X86_64 && X86_X2APICThis depends on
CONFIG_TCG_TPMas well (I got build failures without it)
Yes I will add that. I may have to add a couple of other things too.
Thanks
Ross
Quoted 11 lines
Quoted 11 lines
arch/x86/Kconfig +8
-0+ help + The Secure Launch feature allows a kernel to be loaded + directly through an Intel TXT measured launch. Intel TXT + 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. + source "kernel/Kconfig.hz"
Quoted 5 lines
Quoted 4 lines
arch/x86/Kconfig +0
-1config ARCH_SUPPORTS_KEXEC --2.39.3
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v8 4/15 x86: Secure Launch Resource Table header file
In reply to Ross PhilipsonIntroduce the Secure Launch Resource Table which forms the formal interface between the pre and post launch code.
--- include/linux/slr_table.h | 270 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 include/linux/slr_table.h
include/linux/slr_table.h new file +270 -0
@@ -0,0 +1,270 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Secure Launch Resource Table +* +* Copyright (c) 2023, Oracle and/or its affiliates. +*/ + +#ifndef _LINUX_SLR_TABLE_H +#define _LINUX_SLR_TABLE_H + +/* Put this in efi.h if it becomes a standard */ +#define SLR_TABLE_GUID EFI_GUID(0x877a9b2a, 0x0385, 0x45d1, 0xa0, 0x34, 0x9d, 0xac, 0x9c, 0x9e, 0x56, 0x5f) + +/* SLR table header values */ +#define SLR_TABLE_MAGIC 0x4452544d +#define SLR_TABLE_REVISION 1 + +/* Current revisions for the policy and UEFI config */ +#define SLR_POLICY_REVISION 1 +#define SLR_UEFI_CONFIG_REVISION 1 + +/* SLR defined architectures */ +#define SLR_INTEL_TXT 1 +#define SLR_AMD_SKINIT 2 + +/* SLR defined bootloaders */ +#define SLR_BOOTLOADER_INVALID 0 +#define SLR_BOOTLOADER_GRUB 1 + +/* Log formats */ +#define SLR_DRTM_TPM12_LOG 1 +#define SLR_DRTM_TPM20_LOG 2 + +/* DRTM Policy Entry Flags */ +#define SLR_POLICY_FLAG_MEASURED 0x1 +#define SLR_POLICY_IMPLICIT_SIZE 0x2 + +/* Array Lengths */ +#define TPM_EVENT_INFO_LENGTH 32 +#define TXT_VARIABLE_MTRRS_LENGTH 32 + +/* Tags */ +#define SLR_ENTRY_INVALID 0x0000 +#define SLR_ENTRY_DL_INFO 0x0001 +#define SLR_ENTRY_LOG_INFO 0x0002 +#define SLR_ENTRY_ENTRY_POLICY 0x0003 +#define SLR_ENTRY_INTEL_INFO 0x0004 +#define SLR_ENTRY_AMD_INFO 0x0005 +#define SLR_ENTRY_ARM_INFO 0x0006 +#define SLR_ENTRY_UEFI_INFO 0x0007 +#define SLR_ENTRY_UEFI_CONFIG 0x0008 +#define SLR_ENTRY_END 0xffff + +/* Entity Types */ +#define SLR_ET_UNSPECIFIED 0x0000 +#define SLR_ET_SLRT 0x0001 +#define SLR_ET_BOOT_PARAMS 0x0002 +#define SLR_ET_SETUP_DATA 0x0003 +#define SLR_ET_CMDLINE 0x0004 +#define SLR_ET_UEFI_MEMMAP 0x0005 +#define SLR_ET_RAMDISK 0x0006 +#define SLR_ET_TXT_OS2MLE 0x0010 +#define SLR_ET_UNUSED 0xffff + +#ifndef __ASSEMBLY__ + +/* +* Primary SLR Table Header +*/ +struct slr_table { +u32 magic; +u16 revision; +u16 architecture; +u32 size; +u32 max_size; +/* entries[] */ +} __packed; + +/* +* Common SLRT Table Header +*/ +struct slr_entry_hdr { +u16 tag; +u16 size; +} __packed; + +/* +* Boot loader context +*/ +struct slr_bl_context { +u16 bootloader; +u16 reserved; +u64 context; +} __packed; + +/* +* DRTM Dynamic Launch Configuration +*/ +struct slr_entry_dl_info { +struct slr_entry_hdr hdr; +struct slr_bl_context bl_context; +u64 dl_handler; +u64 dce_base; +u32 dce_size; +u64 dlme_entry; +} __packed; + +/* +* TPM Log Information +*/ +struct slr_entry_log_info { +struct slr_entry_hdr hdr; +u16 format; +u16 reserved; +u64 addr; +u32 size; +} __packed; + +/* +* DRTM Measurement Policy +*/ +struct slr_entry_policy { +struct slr_entry_hdr hdr; +u16 revision; +u16 nr_entries; +/* policy_entries[] */ +} __packed; + +/* +* DRTM Measurement Entry +*/ +struct slr_policy_entry { +u16 pcr; +u16 entity_type; +u16 flags; +u16 reserved; +u64 entity; +u64 size; +char evt_info[TPM_EVENT_INFO_LENGTH ]; +} __packed; + +/* +* Secure Launch defined MTRR saving structures +*/ +struct slr_txt_mtrr_pair { +u64 mtrr_physbase; +u64 mtrr_physmask; +} __packed; + +struct slr_txt_mtrr_state { +u64 default_mem_type; +u64 mtrr_vcnt; +struct slr_txt_mtrr_pair mtrr_pair[TXT_VARIABLE_MTRRS_LENGTH ]; +} __packed; + +/* +* Intel TXT Info table +*/ +struct slr_entry_intel_info { +struct slr_entry_hdr hdr; +u64 saved_misc_enable_msr; +struct slr_txt_mtrr_state saved_bsp_mtrrs; +} __packed; + +/* +* AMD SKINIT Info table +*/ +struct slr_entry_amd_info { +struct slr_entry_hdr hdr; +} __packed; + +/* +* ARM DRTM Info table +*/ +struct slr_entry_arm_info { +struct slr_entry_hdr hdr; +} __packed; + +struct slr_entry_uefi_config { +struct slr_entry_hdr hdr; +u16 revision; +u16 nr_entries; +/* uefi_cfg_entries[] */ +} __packed; + +struct slr_uefi_cfg_entry { +u16 pcr; +u16 reserved; +u64 cfg;/* address or value */ +u32 size; +char evt_info[TPM_EVENT_INFO_LENGTH ]; +} __packed; + +static inline void *slr_end_of_entrys (struct slr_table *table) +{ +return (((void *)table) + table->size); +} + +static inline struct slr_entry_hdr * +slr_next_entry (struct slr_table *table, +struct slr_entry_hdr *curr) +{ +struct slr_entry_hdr *next = (struct slr_entry_hdr *) + ((u8 *)curr + curr->size); + +if ((void *)next >=slr_end_of_entrys (table)) +return NULL ; +if (next->tag ==SLR_ENTRY_END ) +return NULL ; + +return next; +} + +static inline struct slr_entry_hdr * +slr_next_entry_by_tag (struct slr_table *table, +struct slr_entry_hdr *entry, +u16 tag) +{ +if (!entry)/* Start from the beginning */ + entry = (struct slr_entry_hdr *)(((u8 *)table) +sizeof (*table)); + +for ( ; ; ) { +if (entry->tag == tag) +return entry; + + entry =slr_next_entry (table, entry); +if (!entry) +return NULL ; + } + +return NULL ; +} + +static inline int +slr_add_entry (struct slr_table *table, +struct slr_entry_hdr *entry) +{ +struct slr_entry_hdr *end; + +if ((table->size + entry->size) > table->max_size) +return -1 ; + +memcpy ((u8 *)table + table->size -sizeof (*end), entry, entry->size); + table->size += entry->size; + + end = (struct slr_entry_hdr *)((u8 *)table + table->size -sizeof (*end)); + end->tag =SLR_ENTRY_END ; + end->size =sizeof (*end); + +return 0 ; +} + +static inline void +slr_init_table (struct slr_table *slrt,u16 architecture,u32 max_size) +{ +struct slr_entry_hdr *end; + + slrt->magic =SLR_TABLE_MAGIC ; + slrt->revision =SLR_TABLE_REVISION ; + slrt->architecture = architecture; + slrt->size =sizeof (*slrt) +sizeof (*end); + slrt->max_size = max_size; + end = (struct slr_entry_hdr *)((u8 *)slrt +sizeof (*slrt)); + end->tag =SLR_ENTRY_END ; + end->size =sizeof (*end); +} + +#endif /* !__ASSEMBLY */ + +#endif /* _LINUX_SLR_TABLE_H */
Signature · 7 lines
2.39.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Ard Biesheuvel
maintainerRe: [PATCH v8 04/15] x86: Secure Launch Resource Table header file
Quoted 83 lines · Ross Philipson
Introduce the Secure Launch Resource Table which forms the formal interface between the pre and post launch code.
Signed-off-by Ross Philipson <[email protected]>--- include/linux/slr_table.h | 270 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+) create mode 100644 include/linux/slr_table.hinclude/linux/slr_table.h new file +67
-0@@ -0,0 +1,270 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Secure Launch Resource Table +* +* Copyright (c) 2023, Oracle and/or its affiliates. +*/ + +#ifndef _LINUX_SLR_TABLE_H +#define _LINUX_SLR_TABLE_H + +/* Put this in efi.h if it becomes a standard */ +#define SLR_TABLE_GUID EFI_GUID(0x877a9b2a, 0x0385, 0x45d1, 0xa0, 0x34, 0x9d, 0xac, 0x9c, 0x9e, 0x56, 0x5f) + +/* SLR table header values */ +#define SLR_TABLE_MAGIC 0x4452544d +#define SLR_TABLE_REVISION 1 + +/* Current revisions for the policy and UEFI config */ +#define SLR_POLICY_REVISION 1 +#define SLR_UEFI_CONFIG_REVISION 1 + +/* SLR defined architectures */ +#define SLR_INTEL_TXT 1 +#define SLR_AMD_SKINIT 2 + +/* SLR defined bootloaders */ +#define SLR_BOOTLOADER_INVALID 0 +#define SLR_BOOTLOADER_GRUB 1 + +/* Log formats */ +#define SLR_DRTM_TPM12_LOG 1 +#define SLR_DRTM_TPM20_LOG 2 + +/* DRTM Policy Entry Flags */ +#define SLR_POLICY_FLAG_MEASURED 0x1 +#define SLR_POLICY_IMPLICIT_SIZE 0x2 + +/* Array Lengths */ +#define TPM_EVENT_INFO_LENGTH 32 +#define TXT_VARIABLE_MTRRS_LENGTH 32 + +/* Tags */ +#define SLR_ENTRY_INVALID 0x0000 +#define SLR_ENTRY_DL_INFO 0x0001 +#define SLR_ENTRY_LOG_INFO 0x0002 +#define SLR_ENTRY_ENTRY_POLICY 0x0003 +#define SLR_ENTRY_INTEL_INFO 0x0004 +#define SLR_ENTRY_AMD_INFO 0x0005 +#define SLR_ENTRY_ARM_INFO 0x0006 +#define SLR_ENTRY_UEFI_INFO 0x0007 +#define SLR_ENTRY_UEFI_CONFIG 0x0008 +#define SLR_ENTRY_END 0xffff + +/* Entity Types */ +#define SLR_ET_UNSPECIFIED 0x0000 +#define SLR_ET_SLRT 0x0001 +#define SLR_ET_BOOT_PARAMS 0x0002 +#define SLR_ET_SETUP_DATA 0x0003 +#define SLR_ET_CMDLINE 0x0004 +#define SLR_ET_UEFI_MEMMAP 0x0005 +#define SLR_ET_RAMDISK 0x0006 +#define SLR_ET_TXT_OS2MLE 0x0010 +#define SLR_ET_UNUSED 0xffff + +#ifndef __ASSEMBLY__ + +/*
include/linux/slr_table.h line 77
Quoted 10 lines
include/linux/slr_table.h new file +10
-0+* Primary SLR Table Header +*/ +struct slr_table { +u32 magic; +u16 revision; +u16 architecture; +u32 size; +u32 max_size; +/* entries[] */ +} __packed;
Packing this struct has no effect on the layout so better drop the __packed here. If this table is part of a structure that can appear misaligned in memory, better to pack the outer struct or deal with it there in another way.
include/linux/slr_table.h line 85
Quoted 8 lines
include/linux/slr_table.h new file +8
-0+ +/* +* Common SLRT Table Header +*/ +struct slr_entry_hdr { +u16 tag; +u16 size; +} __packed;
Same here
Quoted 7 lines
include/linux/slr_table.h new file +7
-0+ +/* +* Boot loader context +*/ +struct slr_bl_context { +u16 bootloader; +u16 reserved;
include/linux/slr_table.h line 102
Quoted 10 lines
include/linux/slr_table.h new file +10
-0+u64 context; +} __packed; + +/* +* DRTM Dynamic Launch Configuration +*/ +struct slr_entry_dl_info { +struct slr_entry_hdr hdr; +struct slr_bl_context bl_context; +u64 dl_handler;
I noticed in the EFI patch that this is actually
void (*dl_handler)(struct slr_bl_context *bl_context);
so better declare it as such.
Quoted 14 lines
include/linux/slr_table.h new file +14
-0+u64 dce_base; +u32 dce_size; +u64 dlme_entry; +} __packed; + +/* +* TPM Log Information +*/ +struct slr_entry_log_info { +struct slr_entry_hdr hdr; +u16 format; +u16 reserved; +u64 addr; +u32 size;
include/linux/slr_table.h line 126
Quoted 10 lines
include/linux/slr_table.h new file +10
-0+} __packed; + +/* +* DRTM Measurement Policy +*/ +struct slr_entry_policy { +struct slr_entry_hdr hdr; +u16 revision; +u16 nr_entries; +/* policy_entries[] */
Please use a flex array here:
struct slr_policy_entry policy_entries[];
Quoted 42 lines
include/linux/slr_table.h new file +42
-0+} __packed; + +/* +* DRTM Measurement Entry +*/ +struct slr_policy_entry { +u16 pcr; +u16 entity_type; +u16 flags; +u16 reserved; +u64 entity; +u64 size; +char evt_info[TPM_EVENT_INFO_LENGTH ]; +} __packed; + +/* +* Secure Launch defined MTRR saving structures +*/ +struct slr_txt_mtrr_pair { +u64 mtrr_physbase; +u64 mtrr_physmask; +} __packed; + +struct slr_txt_mtrr_state { +u64 default_mem_type; +u64 mtrr_vcnt; +struct slr_txt_mtrr_pair mtrr_pair[TXT_VARIABLE_MTRRS_LENGTH ]; +} __packed; + +/* +* Intel TXT Info table +*/ +struct slr_entry_intel_info { +struct slr_entry_hdr hdr; +u64 saved_misc_enable_msr; +struct slr_txt_mtrr_state saved_bsp_mtrrs; +} __packed; + +/* +* AMD SKINIT Info table +*/ +struct slr_entry_amd_info {
include/linux/slr_table.h line 178
Quoted 10 lines
include/linux/slr_table.h new file +10
-0+struct slr_entry_hdr hdr; +} __packed; + +/* +* ARM DRTM Info table +*/ +struct slr_entry_arm_info { +struct slr_entry_hdr hdr; +} __packed; +
These two look preliminary, so better to drop them now and introduce only once you know what they will look like.
include/linux/slr_table.h line 183
Quoted 5 lines
include/linux/slr_table.h new file +5
-0+struct slr_entry_uefi_config { +struct slr_entry_hdr hdr; +u16 revision; +u16 nr_entries; +/* uefi_cfg_entries[] */
Use a flex array
include/linux/slr_table.h line 194
Quoted 11 lines
include/linux/slr_table.h new file +11
-0+} __packed; + +struct slr_uefi_cfg_entry { +u16 pcr; +u16 reserved; +u64 cfg;/* address or value */ +u32 size; +char evt_info[TPM_EVENT_INFO_LENGTH ]; +} __packed; + +static inline void *slr_end_of_entrys (struct slr_table *table)
typo 'entrys' ?
include/linux/slr_table.h line 196
Quoted 2 lines
include/linux/slr_table.h new file +2
-0+{ +return (((void *)table) + table->size);
You can drop two sets of parens here
Quoted 77 lines
include/linux/slr_table.h new file +74
-1+} + +static inline struct slr_entry_hdr * +slr_next_entry (struct slr_table *table, +struct slr_entry_hdr *curr) +{ +struct slr_entry_hdr *next = (struct slr_entry_hdr *) + ((u8 *)curr + curr->size); + +if ((void *)next >=slr_end_of_entrys (table)) +return NULL ; +if (next->tag ==SLR_ENTRY_END ) +return NULL ; + +return next; +} + +static inline struct slr_entry_hdr * +slr_next_entry_by_tag (struct slr_table *table, +struct slr_entry_hdr *entry, +u16 tag) +{ +if (!entry)/* Start from the beginning */ + entry = (struct slr_entry_hdr *)(((u8 *)table) +sizeof (*table)); + +for ( ; ; ) { +if (entry->tag == tag) +return entry; + + entry =slr_next_entry (table, entry); +if (!entry) +return NULL ; + } + +return NULL ; +} + +static inline int +slr_add_entry (struct slr_table *table, +struct slr_entry_hdr *entry) +{ +struct slr_entry_hdr *end; + +if ((table->size + entry->size) > table->max_size) +return -1 ; + +memcpy ((u8 *)table + table->size -sizeof (*end), entry, entry->size); + table->size += entry->size; + + end = (struct slr_entry_hdr *)((u8 *)table + table->size -sizeof (*end)); + end->tag =SLR_ENTRY_END ; + end->size =sizeof (*end); + +return 0 ; +} + +static inline void +slr_init_table (struct slr_table *slrt,u16 architecture,u32 max_size) +{ +struct slr_entry_hdr *end; + + slrt->magic =SLR_TABLE_MAGIC ; + slrt->revision =SLR_TABLE_REVISION ; + slrt->architecture = architecture; + slrt->size =sizeof (*slrt) +sizeof (*end); + slrt->max_size = max_size; + end = (struct slr_entry_hdr *)((u8 *)slrt +sizeof (*slrt)); + end->tag =SLR_ENTRY_END ; + end->size =sizeof (*end); +} + +#endif /* !__ASSEMBLY */ + +#endif /* _LINUX_SLR_TABLE_H */ --2.39.3
Re: [PATCH v8 04/15] x86: Secure Launch Resource Table header file
Quoted 3 lines · Ard Biesheuvel
Quoted 2 lines · Ross Philipson
+/*
+ * Primary SLR Table Header
I know it's just a comment, but SLR ought to be written in longhand here.
Quoted 5 lines
Quoted 5 lines
+ */
include/linux/slr_table.h new file +4
-0+struct slr_table { +u32 magic; +u16 revision; +u16 architecture;
Quoted 8 lines
include/linux/slr_table.h line 77
Quoted 4 lines
include/linux/slr_table.h new file +4
-0+u32 size; +u32 max_size; +/* entries[] */ +} __packed;Packing this struct has no effect on the layout so better drop the
__packedhere. If this table is part of a structure that can appear misaligned in memory, better to pack the outer struct or deal with it there in another way.
As you note, __packed does two things not one.
The consumer of the random integer that is expected to be a pointer to a struct lsr_table doesn't know whether it was invoked by a 16bit bootloader or a 32bit bootloader, and this really does make a difference for an ABI described only in C.
Then again, we're holding off on setting the spec in stone until there's an agreement in principle, so we could retrofit a statement about the expected alignment of this structure in memory.
The sane choices are either 8b alignment (there are uint64_t's in entires[], but I also see there are some misaligned uint64_t's too, which is dull), or using the good old x86 fallback or paragraph alignment just in case we really want to extend it with a uint128_t in future.
Thoughts?
~Andrew
Re: [PATCH v8 04/15] x86: Secure Launch Resource Table header file
Quoted 6 lines · Andrew Cooper' via trenchboot-devel
Quoted 3 lines · Ard Biesheuvel
Quoted 2 lines · Ross Philipson
+/*
+ * Primary SLR Table HeaderI know it's just a comment, but SLR ought to be written in longhand here.
Will do, thanks. Ross.
Quoted 32 lines
Quoted 14 lines
include/linux/slr_table.h line 77
Quoted 10 lines
+ */
include/linux/slr_table.h new file +8
-0+struct slr_table { +u32 magic; +u16 revision; +u16 architecture; +u32 size; +u32 max_size; +/* entries[] */ +} __packed;Packing this struct has no effect on the layout so better drop the
__packedhere. If this table is part of a structure that can appear misaligned in memory, better to pack the outer struct or deal with it there in another way.As you note,
__packeddoes two things not one.The consumer of the random integer that is expected to be a pointer to a struct
lsr_tabledoesn't know whether it was invoked by a 16bit bootloader or a 32bit bootloader, and this really does make a difference for an ABI described only in C.Then again, we're holding off on setting the spec in stone until there's an agreement in principle, so we could retrofit a statement about the expected alignment of this structure in memory.
The sane choices are either 8b alignment (there are uint64_t's in entires[], but I also see there are some misaligned uint64_t's too, which is dull), or using the good old x86 fallback or paragraph alignment just in case we really want to extend it with a
uint128_tin future.
Quoted 4 lines
Thoughts?
~Andrew
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Re: [PATCH v8 04/15] x86: Secure Launch Resource Table header file
In reply to Ard BiesheuvelQuoted 162 lines · Ard Biesheuvel
Quoted 83 lines · Ross Philipson
Introduce the Secure Launch Resource Table which forms the formal interface between the pre and post launch code.
Signed-off-by Ross Philipson <[email protected]>--- include/linux/slr_table.h | 270 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+)create mode 100644
include/linux/slr_table.hinclude/linux/slr_table.h new file +67
-0@@ -0,0 +1,270 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Secure Launch Resource Table +* +* Copyright (c) 2023, Oracle and/or its affiliates. +*/ + +#ifndef _LINUX_SLR_TABLE_H +#define _LINUX_SLR_TABLE_H + +/* Put this in efi.h if it becomes a standard */ +#define SLR_TABLE_GUID EFI_GUID(0x877a9b2a, 0x0385, 0x45d1, 0xa0, 0x34, 0x9d, 0xac, 0x9c, 0x9e, 0x56, 0x5f) + +/* SLR table header values */ +#define SLR_TABLE_MAGIC 0x4452544d +#define SLR_TABLE_REVISION 1 + +/* Current revisions for the policy and UEFI config */ +#define SLR_POLICY_REVISION 1 +#define SLR_UEFI_CONFIG_REVISION 1 + +/* SLR defined architectures */ +#define SLR_INTEL_TXT 1 +#define SLR_AMD_SKINIT 2 + +/* SLR defined bootloaders */ +#define SLR_BOOTLOADER_INVALID 0 +#define SLR_BOOTLOADER_GRUB 1 + +/* Log formats */ +#define SLR_DRTM_TPM12_LOG 1 +#define SLR_DRTM_TPM20_LOG 2 + +/* DRTM Policy Entry Flags */ +#define SLR_POLICY_FLAG_MEASURED 0x1 +#define SLR_POLICY_IMPLICIT_SIZE 0x2 + +/* Array Lengths */ +#define TPM_EVENT_INFO_LENGTH 32 +#define TXT_VARIABLE_MTRRS_LENGTH 32 + +/* Tags */ +#define SLR_ENTRY_INVALID 0x0000 +#define SLR_ENTRY_DL_INFO 0x0001 +#define SLR_ENTRY_LOG_INFO 0x0002 +#define SLR_ENTRY_ENTRY_POLICY 0x0003 +#define SLR_ENTRY_INTEL_INFO 0x0004 +#define SLR_ENTRY_AMD_INFO 0x0005 +#define SLR_ENTRY_ARM_INFO 0x0006 +#define SLR_ENTRY_UEFI_INFO 0x0007 +#define SLR_ENTRY_UEFI_CONFIG 0x0008 +#define SLR_ENTRY_END 0xffff + +/* Entity Types */ +#define SLR_ET_UNSPECIFIED 0x0000 +#define SLR_ET_SLRT 0x0001 +#define SLR_ET_BOOT_PARAMS 0x0002 +#define SLR_ET_SETUP_DATA 0x0003 +#define SLR_ET_CMDLINE 0x0004 +#define SLR_ET_UEFI_MEMMAP 0x0005 +#define SLR_ET_RAMDISK 0x0006 +#define SLR_ET_TXT_OS2MLE 0x0010 +#define SLR_ET_UNUSED 0xffff + +#ifndef __ASSEMBLY__ + +/* include/linux/slr_table.h line 77
Quoted 10 lines
include/linux/slr_table.h new file +10
-0+* Primary SLR Table Header +*/ +struct slr_table { +u32 magic; +u16 revision; +u16 architecture; +u32 size; +u32 max_size; +/* entries[] */ +} __packed;Packing this struct has no effect on the layout so better drop the
__packedhere. If this table is part of a structure that can appear misaligned in memory, better to pack the outer struct or deal with it there in another way.include/linux/slr_table.h line 85
Quoted 8 lines
include/linux/slr_table.h new file +8
-0+ +/* +* Common SLRT Table Header +*/ +struct slr_entry_hdr { +u16 tag; +u16 size; +} __packed;Same here
Quoted 7 lines
include/linux/slr_table.h new file +7
-0+ +/* +* Boot loader context +*/ +struct slr_bl_context { +u16 bootloader; +u16 reserved;include/linux/slr_table.h line 102
Quoted 10 lines
include/linux/slr_table.h new file +10
-0+u64 context; +} __packed; + +/* +* DRTM Dynamic Launch Configuration +*/ +struct slr_entry_dl_info { +struct slr_entry_hdr hdr; +struct slr_bl_context bl_context; +u64 dl_handler;I noticed in the EFI patch that this is actually
void (*dl_handler)(struct
slr_bl_context*bl_context);so better declare it as such.
Quoted 14 lines
include/linux/slr_table.h new file +14
-0+u64 dce_base; +u32 dce_size; +u64 dlme_entry; +} __packed; + +/* +* TPM Log Information +*/ +struct slr_entry_log_info { +struct slr_entry_hdr hdr; +u16 format; +u16 reserved; +u64 addr; +u32 size;include/linux/slr_table.h line 126
Quoted 10 lines
include/linux/slr_table.h new file +10
-0+} __packed; + +/* +* DRTM Measurement Policy +*/ +struct slr_entry_policy { +struct slr_entry_hdr hdr; +u16 revision; +u16 nr_entries; +/* policy_entries[] */ Please use a flex array here:
Quoted 1 line
struct slr_policy_entry policy_entries[];
Yes we will use flex arrays everywhere it is relevant in here going forward.
Thanks
Ross
Quoted 161 lines
Quoted 43 lines
include/linux/slr_table.h new file +42
-0+} __packed; + +/* +* DRTM Measurement Entry +*/ +struct slr_policy_entry { +u16 pcr; +u16 entity_type; +u16 flags; +u16 reserved; +u64 entity; +u64 size; +char evt_info[TPM_EVENT_INFO_LENGTH ]; +} __packed; + +/* +* Secure Launch defined MTRR saving structures +*/ +struct slr_txt_mtrr_pair { +u64 mtrr_physbase; +u64 mtrr_physmask; +} __packed; + +struct slr_txt_mtrr_state { +u64 default_mem_type; +u64 mtrr_vcnt; +struct slr_txt_mtrr_pair mtrr_pair[TXT_VARIABLE_MTRRS_LENGTH ]; +} __packed; + +/* +* Intel TXT Info table +*/ +struct slr_entry_intel_info { +struct slr_entry_hdr hdr; +u64 saved_misc_enable_msr; +struct slr_txt_mtrr_state saved_bsp_mtrrs; +} __packed; + +/* +* AMD SKINIT Info table +*/ +struct slr_entry_amd_info {include/linux/slr_table.h line 178
Quoted 10 lines
include/linux/slr_table.h new file +10
-0+struct slr_entry_hdr hdr; +} __packed; + +/* +* ARM DRTM Info table +*/ +struct slr_entry_arm_info { +struct slr_entry_hdr hdr; +} __packed; +These two look preliminary, so better to drop them now and introduce only once you know what they will look like.
include/linux/slr_table.h line 183
Quoted 5 lines
include/linux/slr_table.h new file +5
-0+struct slr_entry_uefi_config { +struct slr_entry_hdr hdr; +u16 revision; +u16 nr_entries; +/* uefi_cfg_entries[] */ Use a flex array
include/linux/slr_table.h line 194
Quoted 11 lines
include/linux/slr_table.h new file +11
-0+} __packed; + +struct slr_uefi_cfg_entry { +u16 pcr; +u16 reserved; +u64 cfg;/* address or value */ +u32 size; +char evt_info[TPM_EVENT_INFO_LENGTH ]; +} __packed; + +static inline void *slr_end_of_entrys (struct slr_table *table)typo 'entrys' ?
include/linux/slr_table.h line 196
Quoted 2 lines
include/linux/slr_table.h new file +2
-0+{ +return (((void *)table) + table->size);You can drop two sets of parens here
Quoted 77 lines
include/linux/slr_table.h new file +74
-1+} + +static inline struct slr_entry_hdr * +slr_next_entry (struct slr_table *table, +struct slr_entry_hdr *curr) +{ +struct slr_entry_hdr *next = (struct slr_entry_hdr *) + ((u8 *)curr + curr->size); + +if ((void *)next >=slr_end_of_entrys (table)) +return NULL ; +if (next->tag ==SLR_ENTRY_END ) +return NULL ; + +return next; +} + +static inline struct slr_entry_hdr * +slr_next_entry_by_tag (struct slr_table *table, +struct slr_entry_hdr *entry, +u16 tag) +{ +if (!entry)/* Start from the beginning */ + entry = (struct slr_entry_hdr *)(((u8 *)table) +sizeof (*table)); + +for ( ; ; ) { +if (entry->tag == tag) +return entry; + + entry =slr_next_entry (table, entry); +if (!entry) +return NULL ; + } + +return NULL ; +} + +static inline int +slr_add_entry (struct slr_table *table, +struct slr_entry_hdr *entry) +{ +struct slr_entry_hdr *end; + +if ((table->size + entry->size) > table->max_size) +return -1 ; + +memcpy ((u8 *)table + table->size -sizeof (*end), entry, entry->size); + table->size += entry->size; + + end = (struct slr_entry_hdr *)((u8 *)table + table->size -sizeof (*end)); + end->tag =SLR_ENTRY_END ; + end->size =sizeof (*end); + +return 0 ; +} + +static inline void +slr_init_table (struct slr_table *slrt,u16 architecture,u32 max_size) +{ +struct slr_entry_hdr *end; + + slrt->magic =SLR_TABLE_MAGIC ; + slrt->revision =SLR_TABLE_REVISION ; + slrt->architecture = architecture; + slrt->size =sizeof (*slrt) +sizeof (*end); + slrt->max_size = max_size; + end = (struct slr_entry_hdr *)((u8 *)slrt +sizeof (*slrt)); + end->tag =SLR_ENTRY_END ; + end->size =sizeof (*end); +} + +#endif /* !__ASSEMBLY */ + +#endif /* _LINUX_SLR_TABLE_H */ --2.39.3
Re: [PATCH v8 04/15] x86: Secure Launch Resource Table header file
In reply to Ross PhilipsonHi Ross,
Quoted 80 lines · Ross Philipson
Introduce the Secure Launch Resource Table which forms the formal interface between the pre and post launch code.
Signed-off-by Ross Philipson <[email protected]>--- include/linux/slr_table.h | 270 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 270 insertions(+)create mode 100644
include/linux/slr_table.hinclude/linux/slr_table.h new file +65
-0@@ -0,0 +1,270 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Secure Launch Resource Table +* +* Copyright (c) 2023, Oracle and/or its affiliates. +*/ + +#ifndef _LINUX_SLR_TABLE_H +#define _LINUX_SLR_TABLE_H + +/* Put this in efi.h if it becomes a standard */ +#define SLR_TABLE_GUID EFI_GUID(0x877a9b2a, 0x0385, 0x45d1, 0xa0, 0x34, 0x9d, 0xac, 0x9c, 0x9e, 0x56, 0x5f) + +/* SLR table header values */ +#define SLR_TABLE_MAGIC 0x4452544d +#define SLR_TABLE_REVISION 1 + +/* Current revisions for the policy and UEFI config */ +#define SLR_POLICY_REVISION 1 +#define SLR_UEFI_CONFIG_REVISION 1 + +/* SLR defined architectures */ +#define SLR_INTEL_TXT 1 +#define SLR_AMD_SKINIT 2 + +/* SLR defined bootloaders */ +#define SLR_BOOTLOADER_INVALID 0 +#define SLR_BOOTLOADER_GRUB 1 + +/* Log formats */ +#define SLR_DRTM_TPM12_LOG 1 +#define SLR_DRTM_TPM20_LOG 2 + +/* DRTM Policy Entry Flags */ +#define SLR_POLICY_FLAG_MEASURED 0x1 +#define SLR_POLICY_IMPLICIT_SIZE 0x2 + +/* Array Lengths */ +#define TPM_EVENT_INFO_LENGTH 32 +#define TXT_VARIABLE_MTRRS_LENGTH 32 + +/* Tags */ +#define SLR_ENTRY_INVALID 0x0000 +#define SLR_ENTRY_DL_INFO 0x0001 +#define SLR_ENTRY_LOG_INFO 0x0002 +#define SLR_ENTRY_ENTRY_POLICY 0x0003 +#define SLR_ENTRY_INTEL_INFO 0x0004 +#define SLR_ENTRY_AMD_INFO 0x0005 +#define SLR_ENTRY_ARM_INFO 0x0006 +#define SLR_ENTRY_UEFI_INFO 0x0007 +#define SLR_ENTRY_UEFI_CONFIG 0x0008 +#define SLR_ENTRY_END 0xffff + +/* Entity Types */ +#define SLR_ET_UNSPECIFIED 0x0000 +#define SLR_ET_SLRT 0x0001 +#define SLR_ET_BOOT_PARAMS 0x0002 +#define SLR_ET_SETUP_DATA 0x0003 +#define SLR_ET_CMDLINE 0x0004 +#define SLR_ET_UEFI_MEMMAP 0x0005 +#define SLR_ET_RAMDISK 0x0006 +#define SLR_ET_TXT_OS2MLE 0x0010 +#define SLR_ET_UNUSED 0xffff + +#ifndef __ASSEMBLY__
include/linux/slr_table.h line 75
Quoted 10 lines
include/linux/slr_table.h new file +10
-0+ +/* +* Primary SLR Table Header +*/ +struct slr_table { +u32 magic; +u16 revision; +u16 architecture; +u32 size; +u32 max_size;
Do these need to have their endianness specified with, e.g., __le32?
include/linux/slr_table.h line 76
Quoted 1 line
include/linux/slr_table.h new file +1
-0+/* entries[] */
Instead of the above line, a legit 'entries' can be enabled using:
DECLARE_FLEX_ARRAY(struct slr_entry_hdr, entries);
include/linux/slr_table.h line 77
Quoted 1 line
include/linux/slr_table.h new file +1
-0+} __packed;
You'd have to move this above struct slr_table which would need it:
Quoted 89 lines
include/linux/slr_table.h new file +89
-0+/* +* Common SLRT Table Header +*/ +struct slr_entry_hdr { +u16 tag; +u16 size; +} __packed; + +/* +* Boot loader context +*/ +struct slr_bl_context { +u16 bootloader; +u16 reserved; +u64 context; +} __packed; + +/* +* DRTM Dynamic Launch Configuration +*/ +struct slr_entry_dl_info { +struct slr_entry_hdr hdr; +struct slr_bl_context bl_context; +u64 dl_handler; +u64 dce_base; +u32 dce_size; +u64 dlme_entry; +} __packed; + +/* +* TPM Log Information +*/ +struct slr_entry_log_info { +struct slr_entry_hdr hdr; +u16 format; +u16 reserved; +u64 addr; +u32 size; +} __packed; + +/* +* DRTM Measurement Policy +*/ +struct slr_entry_policy { +struct slr_entry_hdr hdr; +u16 revision; +u16 nr_entries; +/* policy_entries[] */ +} __packed; + +/* +* DRTM Measurement Entry +*/ +struct slr_policy_entry { +u16 pcr; +u16 entity_type; +u16 flags; +u16 reserved; +u64 entity; +u64 size; +char evt_info[TPM_EVENT_INFO_LENGTH ]; +} __packed; + +/* +* Secure Launch defined MTRR saving structures +*/ +struct slr_txt_mtrr_pair { +u64 mtrr_physbase; +u64 mtrr_physmask; +} __packed; + +struct slr_txt_mtrr_state { +u64 default_mem_type; +u64 mtrr_vcnt; +struct slr_txt_mtrr_pair mtrr_pair[TXT_VARIABLE_MTRRS_LENGTH ]; +} __packed; + +/* +* Intel TXT Info table +*/ +struct slr_entry_intel_info { +struct slr_entry_hdr hdr; +u64 saved_misc_enable_msr; +struct slr_txt_mtrr_state saved_bsp_mtrrs; +} __packed; + +/* +* AMD SKINIT Info table +*/
include/linux/slr_table.h line 177
Quoted 10 lines
include/linux/slr_table.h new file +10
-0+struct slr_entry_amd_info { +struct slr_entry_hdr hdr; +} __packed; + +/* +* ARM DRTM Info table +*/ +struct slr_entry_arm_info { +struct slr_entry_hdr hdr; +} __packed;
Shouldn't these three structs be added as part of their separate per-vendor enablement patches?
Quoted 32 lines
include/linux/slr_table.h new file +32
-0+struct slr_entry_uefi_config { +struct slr_entry_hdr hdr; +u16 revision; +u16 nr_entries; +/* uefi_cfg_entries[] */ +} __packed; + +struct slr_uefi_cfg_entry { +u16 pcr; +u16 reserved; +u64 cfg;/* address or value */ +u32 size; +char evt_info[TPM_EVENT_INFO_LENGTH ]; +} __packed; + +static inline void *slr_end_of_entrys (struct slr_table *table) +{ +return (((void *)table) + table->size); +} + +static inline struct slr_entry_hdr * +slr_next_entry (struct slr_table *table, +struct slr_entry_hdr *curr) +{ +struct slr_entry_hdr *next = (struct slr_entry_hdr *) + ((u8 *)curr + curr->size); + +if ((void *)next >=slr_end_of_entrys (table)) +return NULL ; +if (next->tag ==SLR_ENTRY_END ) +return NULL ; +
include/linux/slr_table.h line 220
Quoted 10 lines
include/linux/slr_table.h new file +10
-0+return next; +} + +static inline struct slr_entry_hdr * +slr_next_entry_by_tag (struct slr_table *table, +struct slr_entry_hdr *entry, +u16 tag) +{ +if (!entry)/* Start from the beginning */ + entry = (struct slr_entry_hdr *)(((u8 *)table) +sizeof (*table));
Back to the 'entries', the above line can now be made more readable:
entry = table->entries;
That's just one example, this flex array simplification can be made in other structs in this series, too.
Cheers,
Kim
Quoted 50 lines
include/linux/slr_table.h new file +50
-0+ +for ( ; ; ) { +if (entry->tag == tag) +return entry; + + entry =slr_next_entry (table, entry); +if (!entry) +return NULL ; + } + +return NULL ; +} + +static inline int +slr_add_entry (struct slr_table *table, +struct slr_entry_hdr *entry) +{ +struct slr_entry_hdr *end; + +if ((table->size + entry->size) > table->max_size) +return -1 ; + +memcpy ((u8 *)table + table->size -sizeof (*end), entry, entry->size); + table->size += entry->size; + + end = (struct slr_entry_hdr *)((u8 *)table + table->size -sizeof (*end)); + end->tag =SLR_ENTRY_END ; + end->size =sizeof (*end); + +return 0 ; +} + +static inline void +slr_init_table (struct slr_table *slrt,u16 architecture,u32 max_size) +{ +struct slr_entry_hdr *end; + + slrt->magic =SLR_TABLE_MAGIC ; + slrt->revision =SLR_TABLE_REVISION ; + slrt->architecture = architecture; + slrt->size =sizeof (*slrt) +sizeof (*end); + slrt->max_size = max_size; + end = (struct slr_entry_hdr *)((u8 *)slrt +sizeof (*slrt)); + end->tag =SLR_ENTRY_END ; + end->size =sizeof (*end); +} + +#endif /* !__ASSEMBLY */ + +#endif /* _LINUX_SLR_TABLE_H */
Re: [PATCH v8 04/15] x86: Secure Launch Resource Table header file
Quoted 88 lines · Kim Phillips' via trenchboot-devel
Hi Ross,
Quoted 85 lines · Ross Philipson
Introduce the Secure Launch Resource Table which forms the formal interface between the pre and post launch code.
Signed-off-by Ross Philipson <[email protected]>---
include/linux/slr_table.h| 270 ++++++++++++++++++++++++++++++++++++++1 file changed, 270 insertions(+)create mode 100644
include/linux/slr_table.hinclude/linux/slr_table.h new file +12
-0@@ -0,0 +1,270 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Secure Launch Resource Table +* +* Copyright (c) 2023, Oracle and/or its affiliates. +*/ + +#ifndef _LINUX_SLR_TABLE_H +#define _LINUX_SLR_TABLE_H + +/* Put this in efi.h if it becomes a standard */ +#define SLR_TABLE_GUID EFI_GUID(0x877a9b2a, 0x0385,
0x45d1,0xa0,0x34,0x9d,0xac,0x9c,0x9e,0x56,0x5f)include/linux/slr_table.h new file +57
-0+ +/* SLR table header values */ +#define SLR_TABLE_MAGIC 0x4452544d +#define SLR_TABLE_REVISION 1 + +/* Current revisions for the policy and UEFI config */ +#define SLR_POLICY_REVISION 1 +#define SLR_UEFI_CONFIG_REVISION 1 + +/* SLR defined architectures */ +#define SLR_INTEL_TXT 1 +#define SLR_AMD_SKINIT 2 + +/* SLR defined bootloaders */ +#define SLR_BOOTLOADER_INVALID 0 +#define SLR_BOOTLOADER_GRUB 1 + +/* Log formats */ +#define SLR_DRTM_TPM12_LOG 1 +#define SLR_DRTM_TPM20_LOG 2 + +/* DRTM Policy Entry Flags */ +#define SLR_POLICY_FLAG_MEASURED 0x1 +#define SLR_POLICY_IMPLICIT_SIZE 0x2 + +/* Array Lengths */ +#define TPM_EVENT_INFO_LENGTH 32 +#define TXT_VARIABLE_MTRRS_LENGTH 32 + +/* Tags */ +#define SLR_ENTRY_INVALID 0x0000 +#define SLR_ENTRY_DL_INFO 0x0001 +#define SLR_ENTRY_LOG_INFO 0x0002 +#define SLR_ENTRY_ENTRY_POLICY 0x0003 +#define SLR_ENTRY_INTEL_INFO 0x0004 +#define SLR_ENTRY_AMD_INFO 0x0005 +#define SLR_ENTRY_ARM_INFO 0x0006 +#define SLR_ENTRY_UEFI_INFO 0x0007 +#define SLR_ENTRY_UEFI_CONFIG 0x0008 +#define SLR_ENTRY_END 0xffff + +/* Entity Types */ +#define SLR_ET_UNSPECIFIED 0x0000 +#define SLR_ET_SLRT 0x0001 +#define SLR_ET_BOOT_PARAMS 0x0002 +#define SLR_ET_SETUP_DATA 0x0003 +#define SLR_ET_CMDLINE 0x0004 +#define SLR_ET_UEFI_MEMMAP 0x0005 +#define SLR_ET_RAMDISK 0x0006 +#define SLR_ET_TXT_OS2MLE 0x0010 +#define SLR_ET_UNUSED 0xffff + +#ifndef __ASSEMBLY__ + +/* +* Primary SLR Table Header +*/
Quoted 8 lines
Quoted 6 lines
+struct
slr_table{
+ u32 magic;
+ u16 revision;
+ u16 architecture;
+ u32 size;
+ u32max_size;Do these need to have their endianness specified with, e.g.,
__le32?
The working assumption was this would be handled by the way the pre and post launch code was built for a given platform.
Quoted 6 lines
Quoted 2 lines
+ /* entries[] */
Instead of the above line, a legit 'entries' can be enabled using:
DECLARE_FLEX_ARRAY(struct slr_entry_hdr, entries);
I just declared these without the macro. See below...
Quoted 45 lines
Quoted 2 lines
+}
__packed;You'd have to move this above struct
slr_tablewhich would need it:Quoted 40 lines
include/linux/slr_table.h new file +40
-0+/* +* Common SLRT Table Header +*/ +struct slr_entry_hdr { + u16 tag; + u16 size; +} __packed; + +/* +* Boot loader context +*/ +struct slr_bl_context { + u16 bootloader; + u16 reserved; + u64 context; +} __packed; + +/* +* DRTM Dynamic Launch Configuration +*/ +struct slr_entry_dl_info { + struct slr_entry_hdr hdr; + struct slr_bl_context bl_context; + u64 dl_handler; + u64 dce_base; + u32 dce_size; + u64 dlme_entry; +} __packed; + +/* +* TPM Log Information +*/ +struct slr_entry_log_info { + struct slr_entry_hdr hdr; + u16 format; + u16 reserved; + u64 addr; + u32 size; +} __packed; +
Quoted 8 lines
include/linux/slr_table.h line 126
Quoted 8 lines
include/linux/slr_table.h new file +8
-0+/* +* DRTM Measurement Policy +*/ +struct slr_entry_policy { + struct slr_entry_hdr hdr; + u16 revision; + u16 nr_entries; + /* policy_entries[] */
... for example
struct slr_policy_entry entries[];
Quoted 46 lines
Quoted 46 lines
include/linux/slr_table.h new file +46
-0+} __packed; + +/* +* DRTM Measurement Entry +*/ +struct slr_policy_entry { + u16 pcr; + u16 entity_type; + u16 flags; + u16 reserved; + u64 entity; + u64 size; + char evt_info[TPM_EVENT_INFO_LENGTH]; +} __packed; + +/* +* Secure Launch defined MTRR saving structures +*/ +struct slr_txt_mtrr_pair { + u64 mtrr_physbase; + u64 mtrr_physmask; +} __packed; + +struct slr_txt_mtrr_state { + u64 default_mem_type; + u64 mtrr_vcnt; + struct slr_txt_mtrr_pair mtrr_pair[TXT_VARIABLE_MTRRS_LENGTH]; +} __packed; + +/* +* Intel TXT Info table +*/ +struct slr_entry_intel_info { + struct slr_entry_hdr hdr; + u64 saved_misc_enable_msr; + struct slr_txt_mtrr_state saved_bsp_mtrrs; +} __packed; + +/* +* AMD SKINIT Info table +*/ +struct slr_entry_amd_info { + struct slr_entry_hdr hdr; +} __packed; + +/*
Quoted 8 lines
include/linux/slr_table.h line 177
Quoted 5 lines
+ * ARM DRTM Info table
+ */include/linux/slr_table.h new file +3
-0+struct slr_entry_arm_info { + struct slr_entry_hdr hdr; +} __packed;Shouldn't these three structs be added as part of their separate per-vendor enablement patches?
They got dropped for now. They will be introduced as they are needed. For AMD a platform specific structure would probably hold the address of the SKL which in AMD terms is the Secure Loader Block.
Quoted 47 lines
Quoted 43 lines
include/linux/slr_table.h new file +42
-0+struct slr_entry_uefi_config { + struct slr_entry_hdr hdr; + u16 revision; + u16 nr_entries; + /* uefi_cfg_entries[] */ +} __packed; + +struct slr_uefi_cfg_entry { + u16 pcr; + u16 reserved; + u64 cfg; /* address or value */ + u32 size; + char evt_info[TPM_EVENT_INFO_LENGTH]; +} __packed; + +static inline void *slr_end_of_entrys (struct slr_table *table) +{ + return (((void *)table) + table->size); +} + +static inline struct slr_entry_hdr * +slr_next_entry (struct slr_table *table, + struct slr_entry_hdr *curr) +{ + struct slr_entry_hdr *next = (struct slr_entry_hdr *) + ((u8 *)curr + curr->size); + + if ((void *)next >= slr_end_of_entrys(table)) + return NULL; + if (next->tag == SLR_ENTRY_END) + return NULL; + + return next; +} + +static inline struct slr_entry_hdr * +slr_next_entry_by_tag (struct slr_table *table, + struct slr_entry_hdr *entry, + u16 tag) +{ + if (!entry) /* Start from the beginning */ + entry = (struct slr_entry_hdr *)(((u8 *)table) +Quoted 1 line
sizeof(*table));Back to the 'entries', the above line can now be made more readable:
Quoted 4 lines
entry =
table->entries;That's just one example, this flex array simplification can be made in other structs in this series, too.
This one may have escaped me. I can take a look or if you want to submit a PR, the working v9 branch is here:
https://github.com/TrenchBoot/linux/tree/linux-sl-6.7
We have a format that we use for commit messages to make rebases easier. It was documented somewhere but I can't find it right now. It should be obvious looking at the existing commit though.
Thank you,
Ross
Quoted 49 lines
Cheers,
Kim
Quoted 44 lines
include/linux/slr_table.h new file +23
-0+ + for ( ; ; ) { + if (entry->tag == tag) + return entry; + + entry = slr_next_entry(table, entry); + if (!entry) + return NULL; + } + + return NULL; +} + +static inline int +slr_add_entry (struct slr_table *table, + struct slr_entry_hdr *entry) +{ + struct slr_entry_hdr *end; + + if ((table->size + entry->size) > table->max_size) + return -1; + + memcpy((u8 *)table + table->size - sizeof(*end), entry,
entry->size);
+table->size+=entry->size;
+
+ end = (structslr_entry_hdr*)((u8 *)table +table->size-sizeof(*end));
+end->tag=SLR_ENTRY_END;
+end->size=sizeof(*end);include/linux/slr_table.h new file +14
-0+ + return 0; +} + +static inline void +slr_init_table (struct slr_table *slrt,u16 architecture,u32 max_size) +{ + struct slr_entry_hdr *end; + + slrt->magic = SLR_TABLE_MAGIC; + slrt->revision = SLR_TABLE_REVISION; + slrt->architecture = architecture; + slrt->size = sizeof(*slrt) + sizeof(*end); + slrt->max_size = max_size;
Quoted 9 lines
include/linux/slr_table.h line 270
Quoted 8 lines
+ end = (struct
slr_entry_hdr*)((u8 *)slrt +sizeof(*slrt)); +end->tag=SLR_ENTRY_END;
+end->size=sizeof(*end);include/linux/slr_table.h new file +5
-0+} + +#endif /* !__ASSEMBLY */ + +#endif /* _LINUX_SLR_TABLE_H */
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
PATCH v8 5/15 x86: Secure Launch main header file
In reply to Ross PhilipsonIntroduce the main Secure Launch header file used in the early SL stub and the early setup code.
--- include/linux/slaunch.h | 542 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 542 insertions(+) create mode 100644 include/linux/slaunch.h
include/linux/slaunch.h new file +542 -0
@@ -0,0 +1,542 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Main Secure Launch header file. +* +* Copyright (c) 2022, Oracle and/or its affiliates. +*/ + +#ifndef _LINUX_SLAUNCH_H +#define _LINUX_SLAUNCH_H + +/* +* Secure Launch Defined State Flags +*/ +#define SL_FLAG_ACTIVE 0x00000001 +#define SL_FLAG_ARCH_SKINIT 0x00000002 +#define SL_FLAG_ARCH_TXT 0x00000004 + +/* +* Secure Launch CPU Type +*/ +#define SL_CPU_AMD 1 +#define SL_CPU_INTEL 2 + +#if IS_ENABLED (CONFIG_SECURE_LAUNCH ) + +#define __SL32_CS 0x0008 +#define __SL32_DS 0x0010 + +/* +* Intel Safer Mode Extensions (SMX) +* +* Intel SMX provides a programming interface to establish a Measured Launched +* Environment (MLE). The measurement and protection mechanisms supported by the +* capabilities of an Intel Trusted Execution Technology (TXT) platform. SMX is +* the processor’s programming interface in an Intel TXT platform. +* +* See Intel SDM Volume 2 - 6.1 "Safer Mode Extensions Reference" +*/ + +/* +* SMX GETSEC Leaf Functions +*/ +#define SMX_X86_GETSEC_SEXIT 5 +#define SMX_X86_GETSEC_SMCTRL 7 +#define SMX_X86_GETSEC_WAKEUP 8 + +/* +* Intel Trusted Execution Technology MMIO Registers Banks +*/ +#define TXT_PUB_CONFIG_REGS_BASE 0xfed30000 +#define TXT_PRIV_CONFIG_REGS_BASE 0xfed20000 +#define TXT_NR_CONFIG_PAGES ((TXT_PUB_CONFIG_REGS_BASE - \ + TXT_PRIV_CONFIG_REGS_BASE) >> PAGE_SHIFT) + +/* +* Intel Trusted Execution Technology (TXT) Registers +*/ +#define TXT_CR_STS 0x0000 +#define TXT_CR_ESTS 0x0008 +#define TXT_CR_ERRORCODE 0x0030 +#define TXT_CR_CMD_RESET 0x0038 +#define TXT_CR_CMD_CLOSE_PRIVATE 0x0048 +#define TXT_CR_DIDVID 0x0110 +#define TXT_CR_VER_EMIF 0x0200 +#define TXT_CR_CMD_UNLOCK_MEM_CONFIG 0x0218 +#define TXT_CR_SINIT_BASE 0x0270 +#define TXT_CR_SINIT_SIZE 0x0278 +#define TXT_CR_MLE_JOIN 0x0290 +#define TXT_CR_HEAP_BASE 0x0300 +#define TXT_CR_HEAP_SIZE 0x0308 +#define TXT_CR_SCRATCHPAD 0x0378 +#define TXT_CR_CMD_OPEN_LOCALITY1 0x0380 +#define TXT_CR_CMD_CLOSE_LOCALITY1 0x0388 +#define TXT_CR_CMD_OPEN_LOCALITY2 0x0390 +#define TXT_CR_CMD_CLOSE_LOCALITY2 0x0398 +#define TXT_CR_CMD_SECRETS 0x08e0 +#define TXT_CR_CMD_NO_SECRETS 0x08e8 +#define TXT_CR_E2STS 0x08f0 + +/* TXT default register value */ +#define TXT_REGVALUE_ONE 0x1ULL + +/* TXTCR_STS status bits */ +#define TXT_SENTER_DONE_STS BIT(0) +#define TXT_SEXIT_DONE_STS BIT(1) + +/* +* SINIT/MLE Capabilities Field Bit Definitions +*/ +#define TXT_SINIT_MLE_CAP_WAKE_GETSEC 0 +#define TXT_SINIT_MLE_CAP_WAKE_MONITOR 1 + +/* +* OS/MLE Secure Launch Specific Definitions +*/ +#define TXT_OS_MLE_STRUCT_VERSION 1 +#define TXT_OS_MLE_MAX_VARIABLE_MTRRS 32 + +/* +* TXT Heap Table Enumeration +*/ +#define TXT_BIOS_DATA_TABLE 1 +#define TXT_OS_MLE_DATA_TABLE 2 +#define TXT_OS_SINIT_DATA_TABLE 3 +#define TXT_SINIT_MLE_DATA_TABLE 4 +#define TXT_SINIT_TABLE_MAX TXT_SINIT_MLE_DATA_TABLE + +/* +* Secure Launch Defined Error Codes used in MLE-initiated TXT resets. +* +* TXT Specification +* Appendix I ACM Error Codes +*/ +#define SL_ERROR_GENERIC 0xc0008001 +#define SL_ERROR_TPM_INIT 0xc0008002 +#define SL_ERROR_TPM_INVALID_LOG20 0xc0008003 +#define SL_ERROR_TPM_LOGGING_FAILED 0xc0008004 +#define SL_ERROR_REGION_STRADDLE_4GB 0xc0008005 +#define SL_ERROR_TPM_EXTEND 0xc0008006 +#define SL_ERROR_MTRR_INV_VCNT 0xc0008007 +#define SL_ERROR_MTRR_INV_DEF_TYPE 0xc0008008 +#define SL_ERROR_MTRR_INV_BASE 0xc0008009 +#define SL_ERROR_MTRR_INV_MASK 0xc000800a +#define SL_ERROR_MSR_INV_MISC_EN 0xc000800b +#define SL_ERROR_INV_AP_INTERRUPT 0xc000800c +#define SL_ERROR_INTEGER_OVERFLOW 0xc000800d +#define SL_ERROR_HEAP_WALK 0xc000800e +#define SL_ERROR_HEAP_MAP 0xc000800f +#define SL_ERROR_REGION_ABOVE_4GB 0xc0008010 +#define SL_ERROR_HEAP_INVALID_DMAR 0xc0008011 +#define SL_ERROR_HEAP_DMAR_SIZE 0xc0008012 +#define SL_ERROR_HEAP_DMAR_MAP 0xc0008013 +#define SL_ERROR_HI_PMR_BASE 0xc0008014 +#define SL_ERROR_HI_PMR_SIZE 0xc0008015 +#define SL_ERROR_LO_PMR_BASE 0xc0008016 +#define SL_ERROR_LO_PMR_MLE 0xc0008017 +#define SL_ERROR_INITRD_TOO_BIG 0xc0008018 +#define SL_ERROR_HEAP_ZERO_OFFSET 0xc0008019 +#define SL_ERROR_WAKE_BLOCK_TOO_SMALL 0xc000801a +#define SL_ERROR_MLE_BUFFER_OVERLAP 0xc000801b +#define SL_ERROR_BUFFER_BEYOND_PMR 0xc000801c +#define SL_ERROR_OS_SINIT_BAD_VERSION 0xc000801d +#define SL_ERROR_EVENTLOG_MAP 0xc000801e +#define SL_ERROR_TPM_NUMBER_ALGS 0xc000801f +#define SL_ERROR_TPM_UNKNOWN_DIGEST 0xc0008020 +#define SL_ERROR_TPM_INVALID_EVENT 0xc0008021 +#define SL_ERROR_INVALID_SLRT 0xc0008022 +#define SL_ERROR_SLRT_MISSING_ENTRY 0xc0008023 +#define SL_ERROR_SLRT_MAP 0xc0008024 + +/* +* Secure Launch Defined Limits +*/ +#define TXT_MAX_CPUS 512 +#define TXT_BOOT_STACK_SIZE 128 + +/* +* Secure Launch event log entry type. The TXT specification defines the +* base event value as 0x400 for DRTM values. +*/ +#define TXT_EVTYPE_BASE 0x400 +#define TXT_EVTYPE_SLAUNCH (TXT_EVTYPE_BASE + 0x102) +#define TXT_EVTYPE_SLAUNCH_START (TXT_EVTYPE_BASE + 0x103) +#define TXT_EVTYPE_SLAUNCH_END (TXT_EVTYPE_BASE + 0x104) + +/* +* Measured Launch PCRs +*/ +#define SL_DEF_DLME_DETAIL_PCR17 17 +#define SL_DEF_DLME_AUTHORITY_PCR18 18 +#define SL_ALT_DLME_AUTHORITY_PCR19 19 +#define SL_ALT_DLME_DETAIL_PCR20 20 + +/* +* MLE scratch area offsets +*/ +#define SL_SCRATCH_AP_EBX 0 +#define SL_SCRATCH_AP_JMP_OFFSET 4 +#define SL_SCRATCH_AP_STACKS_OFFSET 8 + +#ifndef __ASSEMBLY__ + +#include <linux/io.h> +#include <linux/tpm.h> +#include <linux/tpm_eventlog.h> + +/* +* Secure Launch AP stack and monitor block +*/ +struct sl_ap_stack_and_monitor { +u32 monitor; +u32 cache_pad[15 ]; +u32 stack_pad[15 ]; +u32 apicid; +} __packed; + +/* +* Secure Launch AP wakeup information fetched in SMP boot code. +*/ +struct sl_ap_wake_info { +u32 ap_wake_block; +u32 ap_wake_block_size; +u32 ap_jmp_offset; +u32 ap_stacks_offset; +}; + +/* +* TXT heap extended data elements. +*/ +struct txt_heap_ext_data_element { +u32 type; +u32 size; +/* Data */ +} __packed; + +#define TXT_HEAP_EXTDATA_TYPE_END 0 + +struct txt_heap_end_element { +u32 type; +u32 size; +} __packed; + +#define TXT_HEAP_EXTDATA_TYPE_TPM_EVENT_LOG_PTR 5 + +struct txt_heap_event_log_element { +u64 event_log_phys_addr; +} __packed; + +#define TXT_HEAP_EXTDATA_TYPE_EVENT_LOG_POINTER2_1 8 + +struct txt_heap_event_log_pointer2_1_element { +u64 phys_addr; +u32 allocated_event_container_size; +u32 first_record_offset; +u32 next_record_offset; +} __packed; + +/* +* Secure Launch defined OS/MLE TXT Heap table +*/ +struct txt_os_mle_data { +u32 version; +u32 boot_params_addr; +u64 slrt; +u64 txt_info; +u32 ap_wake_block; +u32 ap_wake_block_size; +u8 mle_scratch[64 ]; +} __packed; + +/* +* TXT specification defined BIOS data TXT Heap table +*/ +struct txt_bios_data { +u32 version;/* Currently 5 for TPM 1.2 and 6 for TPM 2.0 */ +u32 bios_sinit_size; +u64 reserved1; +u64 reserved2; +u32 num_logical_procs; +/* Versions >= 5 with updates in version 6 */ +u32 sinit_flags; +u32 mle_flags; +/* Versions >= 4 */ +/* Ext Data Elements */ +} __packed; + +/* +* TXT specification defined OS/SINIT TXT Heap table +*/ +struct txt_os_sinit_data { +u32 version;/* Currently 6 for TPM 1.2 and 7 for TPM 2.0 */ +u32 flags; +u64 mle_ptab; +u64 mle_size; +u64 mle_hdr_base; +u64 vtd_pmr_lo_base; +u64 vtd_pmr_lo_size; +u64 vtd_pmr_hi_base; +u64 vtd_pmr_hi_size; +u64 lcp_po_base; +u64 lcp_po_size; +u32 capabilities; +/* Version = 5 */ +u64 efi_rsdt_ptr; +/* Versions >= 6 */ +/* Ext Data Elements */ +} __packed; + +/* +* TXT specification defined SINIT/MLE TXT Heap table +*/ +struct txt_sinit_mle_data { +u32 version;/* Current values are 6 through 9 */ +/* Versions <= 8 */ +u8 bios_acm_id[20 ]; +u32 edx_senter_flags; +u64 mseg_valid; +u8 sinit_hash[20 ]; +u8 mle_hash[20 ]; +u8 stm_hash[20 ]; +u8 lcp_policy_hash[20 ]; +u32 lcp_policy_control; +/* Versions >= 7 */ +u32 rlp_wakeup_addr; +u32 reserved; +u32 num_of_sinit_mdrs; +u32 sinit_mdrs_table_offset; +u32 sinit_vtd_dmar_table_size; +u32 sinit_vtd_dmar_table_offset; +/* Versions >= 8 */ +u32 processor_scrtm_status; +/* Versions >= 9 */ +/* Ext Data Elements */ +} __packed; + +/* +* TXT data reporting structure for memory types +*/ +struct txt_sinit_memory_descriptor_record { +u64 address; +u64 length; +u8 type; +u8 reserved[7 ]; +} __packed; + +/* +* TXT data structure used by a responsive local processor (RLP) to start +* execution in response to a GETSEC[WAKEUP]. +*/ +struct smx_rlp_mle_join { +u32 rlp_gdt_limit; +u32 rlp_gdt_base; +u32 rlp_seg_sel;/* cs (ds, es, ss are seg_sel+8) */ +u32 rlp_entry_point;/* phys addr */ +} __packed; + +/* +* TPM event log structures defined in both the TXT specification and +* the TCG documentation. +*/ +#define TPM12_EVTLOG_SIGNATURE "TXT Event Container" + +struct tpm12_event_log_header { +char signature[20 ]; +char reserved[12 ]; +u8 container_ver_major; +u8 container_ver_minor; +u8 pcr_event_ver_major; +u8 pcr_event_ver_minor; +u32 container_size; +u32 pcr_events_offset; +u32 next_event_offset; +/* PCREvents[] */ +} __packed; + +/* +* Functions to extract data from the Intel TXT Heap Memory. The layout +* of the heap is as follows: +* +----------------------------+ +* | Size Bios Data table (u64) | +* +----------------------------+ +* | Bios Data table | +* +----------------------------+ +* | Size OS MLE table (u64) | +* +----------------------------+ +* | OS MLE table | +* +--------------------------- + +* | Size OS SINIT table (u64) | +* +----------------------------+ +* | OS SINIT table | +* +----------------------------+ +* | Size SINIT MLE table (u64) | +* +----------------------------+ +* | SINIT MLE table | +* +----------------------------+ +* +* NOTE: the table size fields include the 8 byte size field itself. +*/ +static inline u64 txt_bios_data_size (void *heap) +{ +return *((u64 *)heap); +} + +static inline void *txt_bios_data_start (void *heap) +{ +return heap +sizeof (u64); +} + +static inline u64 txt_os_mle_data_size (void *heap) +{ +return *((u64 *)(heap +txt_bios_data_size (heap))); +} + +static inline void *txt_os_mle_data_start (void *heap) +{ +return heap +txt_bios_data_size (heap) +sizeof (u64); +} + +static inline u64 txt_os_sinit_data_size (void *heap) +{ +return *((u64 *)(heap +txt_bios_data_size (heap) + +txt_os_mle_data_size (heap))); +} + +static inline void *txt_os_sinit_data_start (void *heap) +{ +return heap +txt_bios_data_size (heap) + +txt_os_mle_data_size (heap) +sizeof (u64); +} + +static inline u64 txt_sinit_mle_data_size (void *heap) +{ +return *((u64 *)(heap +txt_bios_data_size (heap) + +txt_os_mle_data_size (heap) + +txt_os_sinit_data_size (heap))); +} + +static inline void *txt_sinit_mle_data_start (void *heap) +{ +return heap +txt_bios_data_size (heap) + +txt_os_mle_data_size (heap) + +txt_os_sinit_data_size (heap) +sizeof (u64); +} + +/* +* TPM event logging functions. +*/ +static inline struct txt_heap_event_log_pointer2_1_element * +tpm20_find_log2_1_element (struct txt_os_sinit_data *os_sinit_data) +{ +struct txt_heap_ext_data_element *ext_elem; + +/* The extended element array as at the end of this table */ + ext_elem = (struct txt_heap_ext_data_element *) + ((u8 *)os_sinit_data +sizeof (struct txt_os_sinit_data )); + +while (ext_elem->type !=TXT_HEAP_EXTDATA_TYPE_END ) { +if (ext_elem->type == +TXT_HEAP_EXTDATA_TYPE_EVENT_LOG_POINTER2_1 ) { +return (struct txt_heap_event_log_pointer2_1_element *) + ((u8 *)ext_elem + +sizeof (struct txt_heap_ext_data_element )); + } + ext_elem = + (struct txt_heap_ext_data_element *) + ((u8 *)ext_elem + ext_elem->size); + } + +return NULL ; +} + +static inline int tpm12_log_event (void *evtlog_base,u32 evtlog_size, +u32 event_size,void *event) +{ +struct tpm12_event_log_header *evtlog = + (struct tpm12_event_log_header *)evtlog_base; + +if (memcmp (evtlog->signature,TPM12_EVTLOG_SIGNATURE , +sizeof (TPM12_EVTLOG_SIGNATURE ))) +return -EINVAL ; + +if (evtlog->container_size > evtlog_size) +return -EINVAL ; + +if (evtlog->next_event_offset + event_size > evtlog->container_size) +return -E2BIG ; + +memcpy (evtlog_base + evtlog->next_event_offset, event, event_size); + evtlog->next_event_offset += event_size; + +return 0 ; +} + +static inline int tpm20_log_event (struct txt_heap_event_log_pointer2_1_element *elem, +void *evtlog_base,u32 evtlog_size, +u32 event_size,void *event) +{ +struct tcg_pcr_event *header = + (struct tcg_pcr_event *)evtlog_base; + +/* Has to be at least big enough for the signature */ +if (header->event_size <sizeof (TCG_SPECID_SIG )) +return -EINVAL ; + +if (memcmp ((u8 *)header +sizeof (struct tcg_pcr_event ), +TCG_SPECID_SIG ,sizeof (TCG_SPECID_SIG ))) +return -EINVAL ; + +if (elem->allocated_event_container_size > evtlog_size) +return -EINVAL ; + +if (elem->next_record_offset + event_size > + elem->allocated_event_container_size) +return -E2BIG ; + +memcpy (evtlog_base + elem->next_record_offset, event, event_size); + elem->next_record_offset += event_size; + +return 0 ; +} + +/* +* External functions avalailable in mainline kernel. +*/ +void slaunch_setup_txt (void ); +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 __noreturn slaunch_txt_reset (void __iomem *txt, +const char *msg,u64 error); +extern void slaunch_finalize (int do_sexit); + +#endif /* !__ASSEMBLY */ + +#else + +static inline void slaunch_setup_txt (void ) +{ +} + +static inline void slaunch_fixup_jump_vector (void ) +{ +} + +static inline u32 slaunch_get_flags (void ) +{ +return 0 ; +} + +static inline struct acpi_table_header *slaunch_get_dmar_table (struct acpi_table_header *dmar) +{ +return dmar; +} + +static inline void slaunch_finalize (int do_sexit) +{ +} + +#endif /* !IS_ENABLED(CONFIG_SECURE_LAUNCH) */ + +#endif /* _LINUX_SLAUNCH_H */
Signature · 7 lines
2.39.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v8 6/15 x86: Add early SHA support for Secure Launch early measurements
In reply to Ross PhilipsonFrom: "Daniel P. Smith" <[email protected]>
The SHA algorithms are necessary to measure configuration information into the TPM as early as possible before using the values. This implementation uses the established approach of #including the SHA libraries directly in the code since the compressed kernel is not uncompressed at this point.
The SHA code here has its origins in the code from the main kernel:
commit c4d5b9ffa31f ("crypto: sha1 - implement base layer for SHA-1")
A modified version of this code was introduced to the lib/crypto/sha1.c to bring it in line with the sha256 code and allow it to be pulled into the setup kernel in the same manner as sha256 is.
--- arch/x86/boot/compressed/Makefile | 2 + arch/x86/boot/compressed/early_sha1.c | 12 ++++ arch/x86/boot/compressed/early_sha256.c | 6 ++ include/crypto/sha1.h | 1 + lib/crypto/sha1.c | 81 +++++++++++++++++++++++++ 5 files changed, 102 insertions(+) create mode 100644 arch/x86/boot/compressed/early_sha1.c create mode 100644 arch/x86/boot/compressed/early_sha256.c
arch/x86/boot/compressed/Makefile +2 -0
@@ -118,6 +118,8 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a +vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/early_sha1.o $(obj)/early_sha256.o + $(obj)/vmlinux: $(vmlinux-objs-y) FORCE $(call if_changed,ld)
arch/x86/boot/compressed/early_sha1.c new file +12 -0
@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2022 Apertus Solutions, LLC. +*/ + +#include <linux/init.h> +#include <linux/linkage.h> +#include <linux/string.h> +#include <asm/boot.h> +#include <asm/unaligned.h> + +#include "../../../../lib/crypto/sha1.c"
arch/x86/boot/compressed/early_sha256.c new file +6 -0
@@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2022 Apertus Solutions, LLC +*/ + +#include "../../../../lib/crypto/sha256.c"
include/crypto/sha1.h +1 -0
@@ -42,5 +42,6 @@ extern int crypto_sha1_finup(struct shash_desc *desc, const u8 *data,#define SHA1_WORKSPACE_WORDS 16void sha1_init (__u32 *buf);void sha1_transform (__u32 *digest,const char *data,__u32 *W ); +void sha1 (const u8 *data,unsigned int len,u8 *out);#endif /* _CRYPTO_SHA1_H */
lib/crypto/sha1.c +81 -0
85 lines not on this page · raw message
Signature · 7 lines
2.39.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
Ard Biesheuvel
maintainerRe: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 10 lines · Ross Philipson
From: "Daniel P. Smith" <[email protected]>
The SHA algorithms are necessary to measure configuration information into the TPM as early as possible before using the values. This implementation uses the established approach of #including the SHA libraries directly in the code since the compressed kernel is not uncompressed at this point.
The SHA code here has its origins in the code from the main kernel:
Quoted 8 lines
commit
c4d5b9ffa31f("crypto: sha1 - implement base layer for SHA-1")A modified version of this code was introduced to the
lib/crypto/sha1.cto bring it in line with the sha256 code and allow it to be pulled into the setup kernel in the same manner as sha256 is.Signed-off-by Daniel P. Smith <[email protected]>Signed-off-by Ross Philipson <[email protected]>
We have had some discussions about this, and you really need to capture the justification in the commit log for introducing new code that implements an obsolete and broken hashing algorithm.
SHA-1 is broken and should no longer be used for anything. Introducing new support for a highly complex boot security feature, and then relying on SHA-1 in the implementation makes this whole effort seem almost futile, *unless* you provide some rock solid reasons here why this is still safe.
If the upshot would be that some people are stuck with SHA-1 so they won't be able to use this feature, then I'm not convinced we should obsess over that.
Quoted 9 lines
--- arch/x86/boot/compressed/Makefile | 2 + arch/x86/boot/compressed/early_sha1.c | 12 ++++ arch/x86/boot/compressed/early_sha256.c | 6 ++include/crypto/sha1.h | 1 + lib/crypto/sha1.c | 81 +++++++++++++++++++++++++
This needs to be a separate patch in any case.
Quoted 151 lines
5 files changed, 102 insertions(+) create mode 100644 arch/x86/boot/compressed/early_sha1.c create mode 100644 arch/x86/boot/compressed/early_sha256.carch/x86/boot/compressed/Makefile +2
-0@@ -118,6 +118,8 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a +vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/early_sha1.o $(obj)/early_sha256.o + $(obj)/vmlinux: $(vmlinux-objs-y) FORCE $(call if_changed,ld)arch/x86/boot/compressed/early_sha1.c new file +12
-0@@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2022 Apertus Solutions, LLC. +*/ + +#include <linux/init.h> +#include <linux/linkage.h> +#include <linux/string.h> +#include <asm/boot.h> +#include <asm/unaligned.h> + +#include "../../../../lib/crypto/sha1.c" arch/x86/boot/compressed/early_sha256.c new file +6
-0@@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright (c) 2022 Apertus Solutions, LLC +*/ + +#include "../../../../lib/crypto/sha256.c" include/crypto/sha1.h +1
-0@@ -42,5 +42,6 @@ extern int crypto_sha1_finup(struct shash_desc *desc, const u8 *data,#define SHA1_WORKSPACE_WORDS 16void sha1_init (__u32 *buf);void sha1_transform (__u32 *digest,const char *data,__u32 *W ); +void sha1 (const u8 *data,unsigned int len,u8 *out);#endif /* _CRYPTO_SHA1_H */ lib/crypto/sha1.c +81
-1@@ -137,4 +137,85 @@ void sha1_init(__u32 *buf) }EXPORT_SYMBOL (sha1_init); +static void __sha1_transform (u32 *digest,const char *data) +{ +u32 ws[SHA1_WORKSPACE_WORDS ]; + +sha1_transform (digest, data, ws); + +memzero_explicit (ws,sizeof (ws)); +} + +static void sha1_update (struct sha1_state *sctx,const u8 *data,unsigned int len) +{ +unsigned int partial = sctx->count %SHA1_BLOCK_SIZE ; + + sctx->count += len; + +if (likely ((partial + len) >=SHA1_BLOCK_SIZE )) { +int blocks; + +if (partial) { +int p =SHA1_BLOCK_SIZE - partial; + +memcpy (sctx->buffer + partial, data, p); + data += p; + len -= p; + +__sha1_transform (sctx->state, sctx->buffer); + } + + blocks = len /SHA1_BLOCK_SIZE ; + len %=SHA1_BLOCK_SIZE ; + +if (blocks) { +while (blocks--) { +__sha1_transform (sctx->state, data); + data +=SHA1_BLOCK_SIZE ; + } + } + partial =0 ; + } + +if (len) +memcpy (sctx->buffer + partial, data, len); +} + +static void sha1_final (struct sha1_state *sctx,u8 *out) +{ +const int bit_offset =SHA1_BLOCK_SIZE -sizeof (__be64); +unsigned int partial = sctx->count %SHA1_BLOCK_SIZE ; +__be64 *bits = (__be64 *)(sctx->buffer + bit_offset); +__be32 *digest = (__be32 *)out; +int i; + + sctx->buffer[partial++] =0x80 ; +if (partial > bit_offset) { +memset (sctx->buffer + partial,0x0 ,SHA1_BLOCK_SIZE - partial); + partial =0 ; + +__sha1_transform (sctx->state, sctx->buffer); + } + +memset (sctx->buffer + partial,0x0 , bit_offset - partial); + *bits =cpu_to_be64 (sctx->count <<3 ); +__sha1_transform (sctx->state, sctx->buffer); + +for (i =0 ; i <SHA1_DIGEST_SIZE /sizeof (__be32); i++) +put_unaligned_be32 (sctx->state[i], digest++); + + *sctx = (struct sha1_state ){}; +} + +void sha1 (const u8 *data,unsigned int len,u8 *out) +{ +struct sha1_state sctx = {0 }; + +sha1_init (sctx.state); + sctx.count =0 ; +sha1_update (&sctx, data, len); +sha1_final (&sctx, out); +} +EXPORT_SYMBOL (sha1); +MODULE_LICENSE ("GPL" ); --2.39.3
Re: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 28 lines · Ard Biesheuvel
Quoted 9 lines · Ross Philipson
From: "Daniel P. Smith" <[email protected]>
The SHA algorithms are necessary to measure configuration information into the TPM as early as possible before using the values. This implementation uses the established approach of #including the SHA libraries directly in the code since the compressed kernel is not uncompressed at this point.
The SHA code here has its origins in the code from the main kernel:
Quoted 8 lines
commit
c4d5b9ffa31f("crypto: sha1 - implement base layer for SHA-1")A modified version of this code was introduced to the
lib/crypto/sha1.cto bring it in line with the sha256 code and allow it to be pulled into the setup kernel in the same manner as sha256 is.Signed-off-by Daniel P. Smith <[email protected]>Signed-off-by Ross Philipson <[email protected]>We have had some discussions about this, and you really need to capture the justification in the commit log for introducing new code that implements an obsolete and broken hashing algorithm.
SHA-1 is broken and should no longer be used for anything. Introducing new support for a highly complex boot security feature, and then relying on SHA-1 in the implementation makes this whole effort seem almost futile, *unless* you provide some rock solid reasons here why this is still safe.
Quoted 3 lines
If the upshot would be that some people are stuck with SHA-1 so they won't be able to use this feature, then I'm not convinced we should obsess over that.
To be absolutely crystal clear here.
The choice of hash algorithm(s) are determined by the OEM and the platform, not by Linux.
Failing to (at least) cap a PCR in a bank which the OEM/platform left active is a security vulnerability. It permits the unsealing of secrets if an attacker can replay a good set of measurements into an unused bank.
The only way to get rid of the requirement for SHA-1 here is to lobby the IHVs/OEMs, or perhaps the TCG, to produce/spec a platform where the SHA-1 banks can be disabled. There are no known such platforms in the market today, to the best of our knowledge.
~Andrew
Ard Biesheuvel
maintainerRe: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 39 lines · Andrew Cooper
Quoted 28 lines · Ard Biesheuvel
Quoted 9 lines · Ross Philipson
From: "Daniel P. Smith" <[email protected]>
The SHA algorithms are necessary to measure configuration information into the TPM as early as possible before using the values. This implementation uses the established approach of #including the SHA libraries directly in the code since the compressed kernel is not uncompressed at this point.
The SHA code here has its origins in the code from the main kernel:
Quoted 8 lines
commit
c4d5b9ffa31f("crypto: sha1 - implement base layer for SHA-1")A modified version of this code was introduced to the
lib/crypto/sha1.cto bring it in line with the sha256 code and allow it to be pulled into the setup kernel in the same manner as sha256 is.Signed-off-by Daniel P. Smith <[email protected]>Signed-off-by Ross Philipson <[email protected]>We have had some discussions about this, and you really need to capture the justification in the commit log for introducing new code that implements an obsolete and broken hashing algorithm.
SHA-1 is broken and should no longer be used for anything. Introducing new support for a highly complex boot security feature, and then relying on SHA-1 in the implementation makes this whole effort seem almost futile, *unless* you provide some rock solid reasons here why this is still safe.
Quoted 3 lines
If the upshot would be that some people are stuck with SHA-1 so they won't be able to use this feature, then I'm not convinced we should obsess over that.
To be absolutely crystal clear here.
The choice of hash algorithm(s) are determined by the OEM and the platform, not by Linux.
Quoted 9 lines
Failing to (at least) cap a PCR in a bank which the OEM/platform left active is a security vulnerability. It permits the unsealing of secrets if an attacker can replay a good set of measurements into an unused bank.
The only way to get rid of the requirement for SHA-1 here is to lobby the IHVs/OEMs, or perhaps the TCG, to produce/spec a platform where the SHA-1 banks can be disabled. There are no known such platforms in the market today, to the best of our knowledge.
OK, so mainline Linux does not support secure launch at all today. At this point, we need to decide whether or not tomorrow's mainline Linux will support secure launch with SHA1 or without, right?
And the point you are making here is that we need SHA-1 not only to a) support systems that are on TPM 1.2 and support nothing else, but also to b) ensure that crypto agile TPM 2.0 with both SHA-1 and SHA-256 enabled can be supported in a safe manner, which would involve measuring some terminating event into the SHA-1 PCRs to ensure they are not left in a dangling state that might allow an adversary to trick the TPM into unsealing a secret that it shouldn't.
So can we support b) without a), and if so, does measuring an arbitrary dummy event into a PCR that is only meant to keep sealed forever really require a SHA-1 implementation, or could we just use an arbitrary (not even random) sequence of 160 bits and use that instead?
Re: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 42 lines · Ard Biesheuvel
Quoted 41 lines · Andrew Cooper
Quoted 28 lines · Ard Biesheuvel
Quoted 9 lines · Ross Philipson
From: "Daniel P. Smith" <[email protected]>
The SHA algorithms are necessary to measure configuration information into the TPM as early as possible before using the values. This implementation uses the established approach of #including the SHA libraries directly in the code since the compressed kernel is not uncompressed at this point.
The SHA code here has its origins in the code from the main kernel:
Quoted 8 lines
commit
c4d5b9ffa31f("crypto: sha1 - implement base layer for SHA-1")A modified version of this code was introduced to the
lib/crypto/sha1.cto bring it in line with the sha256 code and allow it to be pulled into the setup kernel in the same manner as sha256 is.Signed-off-by Daniel P. Smith <[email protected]>Signed-off-by Ross Philipson <[email protected]>We have had some discussions about this, and you really need to capture the justification in the commit log for introducing new code that implements an obsolete and broken hashing algorithm.
SHA-1 is broken and should no longer be used for anything. Introducing new support for a highly complex boot security feature, and then relying on SHA-1 in the implementation makes this whole effort seem almost futile, *unless* you provide some rock solid reasons here why this is still safe.
Quoted 3 lines
If the upshot would be that some people are stuck with SHA-1 so they won't be able to use this feature, then I'm not convinced we should obsess over that.
To be absolutely crystal clear here.
The choice of hash algorithm(s) are determined by the OEM and the platform, not by Linux.
Failing to (at least) cap a PCR in a bank which the OEM/platform left active is a security vulnerability. It permits the unsealing of secrets if an attacker can replay a good set of measurements into an unused bank.
Quoted 8 lines
Quoted 5 lines
The only way to get rid of the requirement for SHA-1 here is to lobby the IHVs/OEMs, or perhaps the TCG, to produce/spec a platform where the SHA-1 banks can be disabled. There are no known such platforms in the market today, to the best of our knowledge.
OK, so mainline Linux does not support secure launch at all today. At this point, we need to decide whether or not tomorrow's mainline Linux will support secure launch with SHA1 or without, right?
I'd argue that's a slightly unfair characterisation.
We want tomorrow's mainline to support Secure Launch. What that entails under the hood is largely outside of the control of the end user.
Quoted 7 lines
And the point you are making here is that we need SHA-1 not only to a) support systems that are on TPM 1.2 and support nothing else, but also to b) ensure that crypto agile TPM 2.0 with both SHA-1 and SHA-256 enabled can be supported in a safe manner, which would involve measuring some terminating event into the SHA-1 PCRs to ensure they are not left in a dangling state that might allow an adversary to trick the TPM into unsealing a secret that it shouldn't.
Yes. Also c) because if the end user wants to use SHA-1, they should be able to.
Quoted 4 lines
So can we support b) without a), and if so, does measuring an arbitrary dummy event into a PCR that is only meant to keep sealed forever really require a SHA-1 implementation, or could we just use an arbitrary (not even random) sequence of 160 bits and use that instead?
a) and b) are in principle independent, but we cannot support b) without SHA-1.
To cap a PCR, the event log still needs to be kept accurate, and that's at least one SHA-1 calculation. If you were to simply extend a dummy value, the system hopefully fails safe, but the user gets "something went wrong, you're on your own", rather than "we intentionally blocked the use of SHA-1, everything is good".
And frankly, you need SHA-1 just to read the event log, if any component (including TXT itself) wrote a SHA-1 entry into it.
To be blunt. SHA-1 support is not viably optional today as far as Secure Launch is concerned. If there's a suitable Kconfig symbol to use for people who want a completely SHA-1-less kernel, then we can make Secure Launch depend on that until such time as the hardware ecosystem has caught up.
~Andrew
Ard Biesheuvel
maintainerRe: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 49 lines · Andrew Cooper
Quoted 47 lines · Ard Biesheuvel
Quoted 46 lines · Andrew Cooper
Quoted 28 lines · Ard Biesheuvel
Quoted 9 lines · Ross Philipson
From: "Daniel P. Smith" <[email protected]>
The SHA algorithms are necessary to measure configuration information into the TPM as early as possible before using the values. This implementation uses the established approach of #including the SHA libraries directly in the code since the compressed kernel is not uncompressed at this point.
The SHA code here has its origins in the code from the main kernel:
Quoted 8 lines
commit
c4d5b9ffa31f("crypto: sha1 - implement base layer for SHA-1")A modified version of this code was introduced to the
lib/crypto/sha1.cto bring it in line with the sha256 code and allow it to be pulled into the setup kernel in the same manner as sha256 is.Signed-off-by Daniel P. Smith <[email protected]>Signed-off-by Ross Philipson <[email protected]>We have had some discussions about this, and you really need to capture the justification in the commit log for introducing new code that implements an obsolete and broken hashing algorithm.
SHA-1 is broken and should no longer be used for anything. Introducing new support for a highly complex boot security feature, and then relying on SHA-1 in the implementation makes this whole effort seem almost futile, *unless* you provide some rock solid reasons here why this is still safe.
Quoted 3 lines
If the upshot would be that some people are stuck with SHA-1 so they won't be able to use this feature, then I'm not convinced we should obsess over that.
To be absolutely crystal clear here.
The choice of hash algorithm(s) are determined by the OEM and the platform, not by Linux.
Failing to (at least) cap a PCR in a bank which the OEM/platform left active is a security vulnerability. It permits the unsealing of secrets if an attacker can replay a good set of measurements into an unused bank.
The only way to get rid of the requirement for SHA-1 here is to lobby the IHVs/OEMs, or perhaps the TCG, to produce/spec a platform where the SHA-1 banks can be disabled. There are no known such platforms in the market today, to the best of our knowledge.
Quoted 6 lines
Quoted 3 lines
OK, so mainline Linux does not support secure launch at all today. At this point, we need to decide whether or not tomorrow's mainline Linux will support secure launch with SHA1 or without, right?
I'd argue that's a slightly unfair characterisation.
Fair enough. I'm genuinely trying to have a precise understanding of this, not trying to be dismissive.
Quoted 3 lines
We want tomorrow's mainline to support Secure Launch. What that entails under the hood is largely outside of the control of the end user.
So the debate is really whether it makes sense at all to support Secure Launch on systems that are stuck on an obsolete and broken hash algorithm. This is not hyperbole: SHA-1 is broken today and once these changes hit production 1-2 years down the line, the situation will only have deteriorated. And another 2-3 years later, we will be the ones chasing obscure bugs on systems that were already obsolete when this support was added.
So what is the value proposition here? An end user today, who is mindful enough of security to actively invest the effort to migrate their system from ordinary measured boot to secure launch, is really going to do so on a system that only implements SHA-1 support?
Quoted 11 lines
Quoted 7 lines
And the point you are making here is that we need SHA-1 not only to a) support systems that are on TPM 1.2 and support nothing else, but also to b) ensure that crypto agile TPM 2.0 with both SHA-1 and SHA-256 enabled can be supported in a safe manner, which would involve measuring some terminating event into the SHA-1 PCRs to ensure they are not left in a dangling state that might allow an adversary to trick the TPM into unsealing a secret that it shouldn't.
Yes. Also c) because if the end user wants to use SHA-1, they should be able to.
The end user can do whatever they want, of course. Whether it belongs in the upstream is an entirely different matter, though, especially because we will effectively be forced to support this forever.
Quoted 18 lines
Quoted 4 lines
So can we support b) without a), and if so, does measuring an arbitrary dummy event into a PCR that is only meant to keep sealed forever really require a SHA-1 implementation, or could we just use an arbitrary (not even random) sequence of 160 bits and use that instead?
a) and b) are in principle independent, but we cannot support b) without SHA-1.
To cap a PCR, the event log still needs to be kept accurate, and that's at least one SHA-1 calculation. If you were to simply extend a dummy value, the system hopefully fails safe, but the user gets "something went wrong, you're on your own", rather than "we intentionally blocked the use of SHA-1, everything is good".
And frankly, you need SHA-1 just to read the event log, if any component (including TXT itself) wrote a SHA-1 entry into it.
Quoted 6 lines
To be blunt. SHA-1 support is not viably optional today as far as Secure Launch is concerned. If there's a suitable
Kconfigsymbol to use for people who want a completely SHA-1-less kernel, then we can make Secure Launch depend on that until such time as the hardware ecosystem has caught up.
Yes, this crossed my mind as well. There is a Kconfig symbol CRYPTO_USER_API_ENABLE_OBSOLETE I added a while ago for a similar purpose.
I am still disappointed that we have to go down this path, but I understand the concerns now that you have explained them to me (again) in more detail.
These considerations need to be recorded in the documentation or commit logs as well, so that we can easily refer back to them without having to dig through the mail archives.
Re: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 49 lines · Ard Biesheuvel
Quoted 48 lines · Andrew Cooper
Quoted 47 lines · Ard Biesheuvel
Quoted 46 lines · Andrew Cooper
Quoted 28 lines · Ard Biesheuvel
Quoted 9 lines · Ross Philipson
From: "Daniel P. Smith" <[email protected]>
The SHA algorithms are necessary to measure configuration information into the TPM as early as possible before using the values. This implementation uses the established approach of #including the SHA libraries directly in the code since the compressed kernel is not uncompressed at this point.
The SHA code here has its origins in the code from the main kernel:
Quoted 8 lines
commit
c4d5b9ffa31f("crypto: sha1 - implement base layer for SHA-1")A modified version of this code was introduced to the
lib/crypto/sha1.cto bring it in line with the sha256 code and allow it to be pulled into the setup kernel in the same manner as sha256 is.Signed-off-by Daniel P. Smith <[email protected]>Signed-off-by Ross Philipson <[email protected]>We have had some discussions about this, and you really need to capture the justification in the commit log for introducing new code that implements an obsolete and broken hashing algorithm.
SHA-1 is broken and should no longer be used for anything. Introducing new support for a highly complex boot security feature, and then relying on SHA-1 in the implementation makes this whole effort seem almost futile, *unless* you provide some rock solid reasons here why this is still safe.
Quoted 3 lines
If the upshot would be that some people are stuck with SHA-1 so they won't be able to use this feature, then I'm not convinced we should obsess over that.
To be absolutely crystal clear here.
The choice of hash algorithm(s) are determined by the OEM and the platform, not by Linux.
Failing to (at least) cap a PCR in a bank which the OEM/platform left active is a security vulnerability. It permits the unsealing of secrets if an attacker can replay a good set of measurements into an unused bank.
The only way to get rid of the requirement for SHA-1 here is to lobby the IHVs/OEMs, or perhaps the TCG, to produce/spec a platform where the SHA-1 banks can be disabled. There are no known such platforms in the market today, to the best of our knowledge.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
OK, so mainline Linux does not support secure launch at all today. At this point, we need to decide whether or not tomorrow's mainline Linux will support secure launch with SHA1 or without, right?
I'd argue that's a slightly unfair characterisation.
Fair enough. I'm genuinely trying to have a precise understanding of this, not trying to be dismissive.
Sure, and neither am I. (And frankly, I vastly prefer this reasoned discussion to prior ones.)
Secure Launch technology really is used today as out-of-tree code, and it has taken ~15y to get to this point of doing it nicely in an ecosystem that is wider than just Linux. (Not a criticism, just an observation)
We're looking not to get blocked with a brand new objection which approximates to "it's now not perfect, therefore you can't have something that's still a lot better than nothing".
A major reason why the hardware ecosystem is out of date is because almost no-one uses it, because it's horribly complicated to configure, because it's a set of large out-of-tree patche series against your bootloader, hypervisor and kernel.
The goal of the Trenchboot project is to make it easy to use (i.e. upstream support in the relevant projects), so that more people can use it, in order to drive the hardware ecosystem forward.
Very seriously - Linux taking this series, even off by default and with a "SHA-1 considered hazardous for your health" warning somewhere, will still have a material positive impact in getting the hardware ecosystem to improve. It is, by far and away, the best thing that we (Trenchboot) can do in order to move towards a SHA-1-less future.
Trenchboot do have a specific intent to get to that future, and beyond, but it's a multi-year task.
Quoted 10 lines
Quoted 3 lines
We want tomorrow's mainline to support Secure Launch. What that entails under the hood is largely outside of the control of the end user.
So the debate is really whether it makes sense at all to support Secure Launch on systems that are stuck on an obsolete and broken hash algorithm. This is not hyperbole: SHA-1 is broken today and once these changes hit production 1-2 years down the line, the situation will only have deteriorated. And another 2-3 years later, we will be the ones chasing obscure bugs on systems that were already obsolete when this support was added.
There are indeed collisions, and this will indeed get worse over time.
But right now it still takes nation-state (or certain corporation) resources to calculate a collision, and that would have to be specific to the exact firmware/settings/hypervisor/kernel/initrd configuration of the target device.
Google et al invested the effort in SHAttered in order to drive change in the industry, but that doesn't mean it's viable as a general attack yet. There are far more cost effective options, even a $4 wrench...
Quoted 4 lines
So what is the value proposition here? An end user today, who is mindful enough of security to actively invest the effort to migrate their system from ordinary measured boot to secure launch, is really going to do so on a system that only implements SHA-1 support?
Oh both Intel and AMD, the base technology is around in all platforms the support virt.
On Intel, it's SKU-limited to vPRO, but platforms with fTPM2.0 have been generally SHA1+SHA256 capable for years now. A security conscious end user would just want to cap the SHA1 banks and run with SHA256.
Furthermore, when the attestation is based on a SHA1+SHA256 measurement, the attestor can spot and reject SHA1 collisions, so this configuration really should be safe to the concerns raised here.
On AMD, it's not SKU-limited. However, their fTPM2.0 isn't SKINIT compatible, and we were basically told "show us people using SKINIT first". I'm not sure if we've got as far as trying to an LPC TPM 2.0 on AMD yet. Even bus interception attacks can be defended against with TPM encrypted sessions, but we put this in the "not for v1" bucket.
It's not a secret - the intent of getting this technology more-generally usable (and therefore used) is to be able to go back to Intel and say "hey notice how AMD give this technology to everyone", and to say AMD "hey notice how Intel have this working with TPM2". Both have been persuaded along this direction by Microsoft by virtue of including the Pluton IP blob in the main CPU package.
Quoted 42 lines
Quoted 10 lines
Quoted 7 lines
And the point you are making here is that we need SHA-1 not only to a) support systems that are on TPM 1.2 and support nothing else, but also to b) ensure that crypto agile TPM 2.0 with both SHA-1 and SHA-256 enabled can be supported in a safe manner, which would involve measuring some terminating event into the SHA-1 PCRs to ensure they are not left in a dangling state that might allow an adversary to trick the TPM into unsealing a secret that it shouldn't.
Yes. Also c) because if the end user wants to use SHA-1, they should be able to.
The end user can do whatever they want, of course. Whether it belongs in the upstream is an entirely different matter, though, especially because we will effectively be forced to support this forever.
Quoted 17 lines
Quoted 4 lines
So can we support b) without a), and if so, does measuring an arbitrary dummy event into a PCR that is only meant to keep sealed forever really require a SHA-1 implementation, or could we just use an arbitrary (not even random) sequence of 160 bits and use that instead?
a) and b) are in principle independent, but we cannot support b) without SHA-1.
To cap a PCR, the event log still needs to be kept accurate, and that's at least one SHA-1 calculation. If you were to simply extend a dummy value, the system hopefully fails safe, but the user gets "something went wrong, you're on your own", rather than "we intentionally blocked the use of SHA-1, everything is good".
And frankly, you need SHA-1 just to read the event log, if any component (including TXT itself) wrote a SHA-1 entry into it.
Quoted 6 lines
To be blunt. SHA-1 support is not viably optional today as far as Secure Launch is concerned. If there's a suitable
Kconfigsymbol to use for people who want a completely SHA-1-less kernel, then we can make Secure Launch depend on that until such time as the hardware ecosystem has caught up.Yes, this crossed my mind as well. There is a
KconfigsymbolCRYPTO_USER_API_ENABLE_OBSOLETEI added a while ago for a similar purpose.
Quoted 7 lines
I am still disappointed that we have to go down this path, but I understand the concerns now that you have explained them to me (again) in more detail.
These considerations need to be recorded in the documentation or commit logs as well, so that we can easily refer back to them without having to dig through the mail archives.
Yes, and I agree. We're not looking to try and force this in with underhand tactics.
But a blind "nack to any SHA-1" is similarly damaging in the opposite direction.
~Andrew
Eric Biggers
maintainerRe: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 7 lines · Andrew Cooper
Yes, and I agree. We're not looking to try and force this in with underhand tactics.
But a blind "nack to any SHA-1" is similarly damaging in the opposite direction.
Well, reviewers have said they'd prefer that SHA-1 not be included and given some thoughtful reasons for that. But also they've given suggestions on how to make the SHA-1 support more palatable, such as splitting it into a separate patch and giving it a proper justification.
All suggestions have been ignored.
- Eric
Re: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 7 lines · Eric Biggers
Quoted 6 lines · Andrew Cooper
Yes, and I agree. We're not looking to try and force this in with underhand tactics.
But a blind "nack to any SHA-1" is similarly damaging in the opposite direction.
Quoted 6 lines
Well, reviewers have said they'd prefer that SHA-1 not be included and given some thoughtful reasons for that. But also they've given suggestions on how to make the SHA-1 support more palatable, such as splitting it into a separate patch and giving it a proper justification.
All suggestions have been ignored.
The public record demonstrates otherwise.
But are you saying that you'd be happy if the commit message read something more like:
---8<---
For better or worse, Secure Launch needs SHA-1 and SHA-256.
The choice of hashes used lie with the platform firmware, not with software, and is often outside of the users control.
Even if we'd prefer to use SHA-256-only, if firmware elected to start us with the SHA-1 and SHA-256 backs active, we still need SHA-1 to parse the TPM event log thus far, and deliberately cap the SHA-1 PCRs in order to safely use SHA-256 for everything else.
---
?
~Andrew
Eric Biggers
maintainerRe: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 23 lines · Andrew Cooper
Quoted 7 lines · Eric Biggers
Quoted 6 lines · Andrew Cooper
Yes, and I agree. We're not looking to try and force this in with underhand tactics.
But a blind "nack to any SHA-1" is similarly damaging in the opposite direction.
Quoted 6 lines
Well, reviewers have said they'd prefer that SHA-1 not be included and given some thoughtful reasons for that. But also they've given suggestions on how to make the SHA-1 support more palatable, such as splitting it into a separate patch and giving it a proper justification.
All suggestions have been ignored.
The public record demonstrates otherwise.
But are you saying that you'd be happy if the commit message read something more like:
---8<---
For better or worse, Secure Launch needs SHA-1 and SHA-256.
Quoted 8 lines
The choice of hashes used lie with the platform firmware, not with software, and is often outside of the users control.
Even if we'd prefer to use SHA-256-only, if firmware elected to start us with the SHA-1 and SHA-256 backs active, we still need SHA-1 to parse the TPM event log thus far, and deliberately cap the SHA-1 PCRs in order to safely use SHA-256 for everything else.
---
Please take some time to read through the comments that reviewers have left on previous versions of the patchset.
- Eric
Re: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 27 lines · Eric Biggers
Quoted 26 lines · Andrew Cooper
Quoted 7 lines · Eric Biggers
Quoted 6 lines · Andrew Cooper
Yes, and I agree. We're not looking to try and force this in with underhand tactics.
But a blind "nack to any SHA-1" is similarly damaging in the opposite direction.
Quoted 6 lines
Well, reviewers have said they'd prefer that SHA-1 not be included and given some thoughtful reasons for that. But also they've given suggestions on how to make the SHA-1 support more palatable, such as splitting it into a separate patch and giving it a proper justification.
All suggestions have been ignored.
The public record demonstrates otherwise.
But are you saying that you'd be happy if the commit message read something more like:
---8<---
For better or worse, Secure Launch needs SHA-1 and SHA-256.The choice of hashes used lie with the platform firmware, not with software, and is often outside of the users control.
Quoted 8 lines
Quoted 5 lines
Even if we'd prefer to use SHA-256-only, if firmware elected to start us with the SHA-1 and SHA-256 backs active, we still need SHA-1 to parse the TPM event log thus far, and deliberately cap the SHA-1 PCRs in order to safely use SHA-256 for everything else.
---Please take some time to read through the comments that reviewers have left on previous versions of the patchset.
So I went and read through the old comments, and I'm lost. In brief summary:
If the hardware+firmware only supports SHA-1, then some reviewers would prefer Linux not to support DRTM. I personally think this is a bit silly, but it's not entirely unreasonable. Maybe it should be a config option?
If the hardware+firmware does support SHA-256, then it sounds (to me, reading this -- I haven't dug into the right spec pages) that, for optimal security, something still needs to effectively turn SHA-1 *off* at runtime by capping the event log properly. And that requires computing a SHA-1 hash. And, to be clear, (a) this is only on systems that already support SHA-256 and that we should support and (b) *not* doing so leaves us potentially more vulnerable to SHA-1 attacks than doing so. And no SHA-256-supporting tooling will actually be compromised by a SHA-1 compromise if we cap the event log.
So is there a way forward? Just saying "read through the comments" seems like a dead end.
Thanks,
Andy
Eric Biggers
maintainerRe: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 52 lines · Andy Lutomirski
Quoted 27 lines · Eric Biggers
Quoted 26 lines · Andrew Cooper
Quoted 7 lines · Eric Biggers
Quoted 6 lines · Andrew Cooper
Yes, and I agree. We're not looking to try and force this in with underhand tactics.
But a blind "nack to any SHA-1" is similarly damaging in the opposite direction.
Quoted 6 lines
Well, reviewers have said they'd prefer that SHA-1 not be included and given some thoughtful reasons for that. But also they've given suggestions on how to make the SHA-1 support more palatable, such as splitting it into a separate patch and giving it a proper justification.
All suggestions have been ignored.
The public record demonstrates otherwise.
But are you saying that you'd be happy if the commit message read something more like:
---8<---
For better or worse, Secure Launch needs SHA-1 and SHA-256.The choice of hashes used lie with the platform firmware, not with software, and is often outside of the users control.
Quoted 8 lines
Quoted 5 lines
Even if we'd prefer to use SHA-256-only, if firmware elected to start us with the SHA-1 and SHA-256 backs active, we still need SHA-1 to parse the TPM event log thus far, and deliberately cap the SHA-1 PCRs in order to safely use SHA-256 for everything else.
---Please take some time to read through the comments that reviewers have left on previous versions of the patchset.
So I went and read through the old comments, and I'm lost. In brief summary:
If the hardware+firmware only supports SHA-1, then some reviewers would prefer Linux not to support DRTM. I personally think this is a bit silly, but it's not entirely unreasonable. Maybe it should be a config option?
If the hardware+firmware does support SHA-256, then it sounds (to me, reading this -- I haven't dug into the right spec pages) that, for optimal security, something still needs to effectively turn SHA-1 *off* at runtime by capping the event log properly. And that requires computing a SHA-1 hash. And, to be clear, (a) this is only on systems that already support SHA-256 and that we should support and (b) *not* doing so leaves us potentially more vulnerable to SHA-1 attacks than doing so. And no SHA-256-supporting tooling will actually be compromised by a SHA-1 compromise if we cap the event log.
Quoted 3 lines
So is there a way forward? Just saying "read through the comments" seems like a dead end.
It seems there may be a justification for some form of SHA-1 support in this feature. As I've said, the problem is that it's not explained in the patchset itself. Rather, it just talks about "SHA" and pretends like SHA-1 and SHA-2 are basically the same. In fact, SHA-1 differs drastically from SHA-2 in terms of security. SHA-1 support should be added in a separate patch, with a clearly explained rationale *in the patch itself* for the SHA-1 support *specifically*.
- Eric
Re: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
Quoted 57 lines · Eric Biggers
Quoted 52 lines · Andy Lutomirski
Quoted 27 lines · Eric Biggers
Quoted 26 lines · Andrew Cooper
Quoted 7 lines · Eric Biggers
Quoted 6 lines · Andrew Cooper
Yes, and I agree. We're not looking to try and force this in with underhand tactics.
But a blind "nack to any SHA-1" is similarly damaging in the opposite direction.
Quoted 6 lines
Well, reviewers have said they'd prefer that SHA-1 not be included and given some thoughtful reasons for that. But also they've given suggestions on how to make the SHA-1 support more palatable, such as splitting it into a separate patch and giving it a proper justification.
All suggestions have been ignored.
The public record demonstrates otherwise.
But are you saying that you'd be happy if the commit message read something more like:
---8<---
For better or worse, Secure Launch needs SHA-1 and SHA-256.The choice of hashes used lie with the platform firmware, not with software, and is often outside of the users control.
Quoted 8 lines
Quoted 5 lines
Even if we'd prefer to use SHA-256-only, if firmware elected to start us with the SHA-1 and SHA-256 backs active, we still need SHA-1 to parse the TPM event log thus far, and deliberately cap the SHA-1 PCRs in order to safely use SHA-256 for everything else.
---Please take some time to read through the comments that reviewers have left on previous versions of the patchset.
So I went and read through the old comments, and I'm lost. In brief summary:
If the hardware+firmware only supports SHA-1, then some reviewers would prefer Linux not to support DRTM. I personally think this is a bit silly, but it's not entirely unreasonable. Maybe it should be a config option?
If the hardware+firmware does support SHA-256, then it sounds (to me, reading this -- I haven't dug into the right spec pages) that, for optimal security, something still needs to effectively turn SHA-1 *off* at runtime by capping the event log properly. And that requires computing a SHA-1 hash. And, to be clear, (a) this is only on systems that already support SHA-256 and that we should support and (b) *not* doing so leaves us potentially more vulnerable to SHA-1 attacks than doing so. And no SHA-256-supporting tooling will actually be compromised by a SHA-1 compromise if we cap the event log.
Quoted 3 lines
So is there a way forward? Just saying "read through the comments" seems like a dead end.
Quoted 6 lines
It seems there may be a justification for some form of SHA-1 support in this feature. As I've said, the problem is that it's not explained in the patchset itself. Rather, it just talks about "SHA" and pretends like SHA-1 and SHA-2 are basically the same. In fact, SHA-1 differs drastically from SHA-2 in terms of security. SHA-1 support should be added in a separate patch, with a clearly explained rationale *in the patch itself* for the SHA-1 support *specifically*.
For the record, we were never trying to "pretend" or obfuscate the use of SHA-1. It was simply expedient to put the hash algorithm changes in one patch. We have now separated the patches for clarity and will add any text that explains our use and/or explain the issues with its use.
We went back through the comments and tried to address everything that came up about the use of SHA-1. We will review it all again before posting another patch set.
Thank you for your feedback.
Ross
Quoted 2 lines
- Eric
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Jarkko Sakkinen
maintainerRe: [PATCH v8 06/15] x86: Add early SHA support for Secure Launch early measurements
In reply to Eric BiggersQuoted 57 lines · Eric Biggers
Quoted 52 lines · Andy Lutomirski
Quoted 27 lines · Eric Biggers
Quoted 26 lines · Andrew Cooper
Quoted 7 lines · Eric Biggers
Quoted 6 lines · Andrew Cooper
Yes, and I agree. We're not looking to try and force this in with underhand tactics.
But a blind "nack to any SHA-1" is similarly damaging in the opposite direction.
Quoted 6 lines
Well, reviewers have said they'd prefer that SHA-1 not be included and given some thoughtful reasons for that. But also they've given suggestions on how to make the SHA-1 support more palatable, such as splitting it into a separate patch and giving it a proper justification.
All suggestions have been ignored.
The public record demonstrates otherwise.
But are you saying that you'd be happy if the commit message read something more like:
---8<---
For better or worse, Secure Launch needs SHA-1 and SHA-256.The choice of hashes used lie with the platform firmware, not with software, and is often outside of the users control.
Quoted 8 lines
Quoted 5 lines
Even if we'd prefer to use SHA-256-only, if firmware elected to start us with the SHA-1 and SHA-256 backs active, we still need SHA-1 to parse the TPM event log thus far, and deliberately cap the SHA-1 PCRs in order to safely use SHA-256 for everything else.
---Please take some time to read through the comments that reviewers have left on previous versions of the patchset.
So I went and read through the old comments, and I'm lost. In brief summary:
If the hardware+firmware only supports SHA-1, then some reviewers would prefer Linux not to support DRTM. I personally think this is a bit silly, but it's not entirely unreasonable. Maybe it should be a config option?
If the hardware+firmware does support SHA-256, then it sounds (to me, reading this -- I haven't dug into the right spec pages) that, for optimal security, something still needs to effectively turn SHA-1 *off* at runtime by capping the event log properly. And that requires computing a SHA-1 hash. And, to be clear, (a) this is only on systems that already support SHA-256 and that we should support and (b) *not* doing so leaves us potentially more vulnerable to SHA-1 attacks than doing so. And no SHA-256-supporting tooling will actually be compromised by a SHA-1 compromise if we cap the event log.
Quoted 3 lines
So is there a way forward? Just saying "read through the comments" seems like a dead end.
Quoted 6 lines
It seems there may be a justification for some form of SHA-1 support in this feature. As I've said, the problem is that it's not explained in the patchset itself. Rather, it just talks about "SHA" and pretends like SHA-1 and SHA-2 are basically the same. In fact, SHA-1 differs drastically from SHA-2 in terms of security. SHA-1 support should be added in a separate patch, with a clearly explained rationale *in the patch itself* for the SHA-1 support *specifically*.
Yeah, this is important so that we don't end up deleting that support by accident. Just adding to denote that this more than just a "process issue".
Quoted 1 line
- Eric
BR, Jarkko
PATCH v8 7/15 x86: Secure Launch kernel early boot stub
In reply to Ross PhilipsonThe Secure Launch (SL) stub provides the entry point for Intel TXT (and later AMD SKINIT) to vector to during the late launch. The symbol sl_stub_entry is that entry point and its offset into the kernel is conveyed to the launching code using the MLE (Measured Launch Environment) header in the structure named mle_header. The offset of the MLE header is set in the kernel_info. The routine sl_stub contains the very early late launch setup code responsible for setting up the basic environment to allow the normal kernel startup_32 code to proceed. It is also responsible for properly waking and handling the APs on Intel platforms. The routine sl_main which runs after entering 64b mode is responsible for measuring configuration and module information before it is used like the boot params, the kernel command line, the TXT heap, an external initramfs, etc.
--- Documentation/arch/x86/boot.rst | 21 + arch/x86/boot/compressed/Makefile | 3 +- arch/x86/boot/compressed/head_64.S | 34 ++ arch/x86/boot/compressed/kernel_info.S | 34 ++ arch/x86/boot/compressed/sl_main.c | 582 ++++++++++++++++++++ arch/x86/boot/compressed/sl_stub.S | 705 +++++++++++++++++++++++++ arch/x86/include/asm/msr-index.h | 5 + arch/x86/include/uapi/asm/bootparam.h | 1 + arch/x86/kernel/asm-offsets.c | 20 + 9 files changed, 1404 insertions(+), 1 deletion(-) create mode 100644 arch/x86/boot/compressed/sl_main.c create mode 100644 arch/x86/boot/compressed/sl_stub.S
Documentation/arch/x86/boot.rst +21 -0
@@ -482,6 +482,14 @@ Protocol: 2.00+ - If 1, KASLR enabled. - If 0, KASLR disabled. + Bit 2 (kernel internal): SLAUNCH_FLAG + + - Used internally by the compressed kernel to communicate + Secure Launch status to kernel proper. + + - If 1, Secure Launch enabled. + - If 0, Secure Launch disabled. + Bit 5 (write): QUIET_FLAG - If 0, print early messages.
@@ -1027,6 +1035,19 @@ Offset/size: 0x000c/4 This field contains maximal allowed type for setup_data and setup_indirect structs. +============ ================= +Field name: mle_header_offset +Offset/size: 0x0010/4 +============ ================= + + This field contains the offset to the Secure Launch Measured Launch Environment + (MLE) header. This offset is used to locate information needed during a secure + late launch using Intel TXT. If the offset is zero, the kernel does not have + Secure Launch capabilities. The MLE entry point is called from TXT on the BSP + following a success measured launch. The specific state of the processors is + outlined in the TXT Software Development Guide, the latest can be found here: + https://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-txt-software-development-guide.pdf + The Image Checksum ==================
arch/x86/boot/compressed/Makefile +2 -1
@@ -118,7 +118,8 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a -vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/early_sha1.o $(obj)/early_sha256.o +vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/early_sha1.o $(obj)/early_sha256.o \ + $(obj)/sl_main.o $(obj)/sl_stub.o $(obj)/vmlinux: $(vmlinux-objs-y) FORCE $(call if_changed,ld)
arch/x86/boot/compressed/head_64.S +34 -0
@@ -415,6 +415,17 @@ SYM_CODE_START(startup_64) pushq $0 popfq +#ifdef CONFIG_SECURE_LAUNCH + pushq %rsi + + /* Ensure the relocation region coverd by a PMR */ + movq %rbx, %rdi + movl $(_bss - startup_32), %esi + callq sl_check_region + + popq %rsi +#endif + /* * Copy the compressed kernel to the end of our buffer * where decompression in place becomes safe.
@@ -457,6 +468,29 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) shrq $3, %rcx rep stosq +#ifdef CONFIG_SECURE_LAUNCH + /* + * Have to do the final early sl stub work in 64b area. + * + * *********** NOTE *********** + * + * Several boot params get used before we get a chance to measure + * them in this call. This is a known issue and we currently don't + * have a solution. The scratch field doesn't matter. There is no + * obvious way to do anything about the use of kernel_alignment or + * init_size though these seem low risk with all the PMR and overlap + * checks in place. + */ + movq %r15, %rdi + callq sl_main + + /* Ensure the decompression location is coverd by a PMR */ + movq %rbp, %rdi + movq output_len(%rip), %rsi + callq sl_check_region +#endif + + pushq %rsi call load_stage2_idt /* Pass boot_params to initialize_identity_maps() */
arch/x86/boot/compressed/kernel_info.S +34 -0
@@ -28,6 +28,40 @@ SYM_DATA_START(kernel_info) /* Maximal allowed type for setup_data and setup_indirect structs. */ .long SETUP_TYPE_MAX + /* Offset to the MLE header structure */ +#if IS_ENABLED(CONFIG_SECURE_LAUNCH) + .long rva(mle_header) +#else + .long 0 +#endif + kernel_info_var_len_data: /* Empty for time being... */ SYM_DATA_END_LABEL(kernel_info, SYM_L_LOCAL, kernel_info_end) + +#if IS_ENABLED(CONFIG_SECURE_LAUNCH) + /* + * The MLE Header per the TXT Specification, section 2.1 + * MLE capabilities, see table 4. Capabilities set: + * bit 0: Support for GETSEC[WAKEUP] for RLP wakeup + * bit 1: Support for RLP wakeup using MONITOR address + * bit 2: The ECX register will contain the pointer to the MLE page table + * bit 5: TPM 1.2 family: Details/authorities PCR usage support + * bit 9: Supported format of TPM 2.0 event log - TCG compliant + */ +SYM_DATA_START(mle_header) + .long 0x9082ac5a /* UUID0 */ + .long 0x74a7476f /* UUID1 */ + .long 0xa2555c0f /* UUID2 */ + .long 0x42b651cb /* UUID3 */ + .long 0x00000034 /* MLE header size */ + .long 0x00020002 /* MLE version 2.2 */ + .long rva(sl_stub_entry) /* Linear entry point of MLE (virt. address) */ + .long 0x00000000 /* First valid page of MLE */ + .long 0x00000000 /* Offset within binary of first byte of MLE */ + .long rva(_edata) /* Offset within binary of last byte + 1 of MLE */ + .long 0x00000227 /* Bit vector of MLE-supported capabilities */ + .long 0x00000000 /* Starting linear address of command line (unused) */ + .long 0x00000000 /* Ending linear address of command line (unused) */ +SYM_DATA_END(mle_header) +#endif
arch/x86/boot/compressed/sl_main.c new file +582 -0
582 lines not on this page · raw message
arch/x86/boot/compressed/sl_stub.S new file +705 -0
705 lines not on this page · raw message
arch/x86/include/asm/msr-index.h +5 -0
@@ -323,6 +323,9 @@#define MSR_IA32_RTIT_OUTPUT_BASE 0x00000560#define MSR_IA32_RTIT_OUTPUT_MASK 0x00000561 +#define MSR_MTRRphysBase0 0x00000200 +#define MSR_MTRRphysMask0 0x00000201 +#define MSR_MTRRfix64K_00000 0x00000250#define MSR_MTRRfix16K_80000 0x00000258#define MSR_MTRRfix16K_A0000 0x00000259
@@ -804,6 +807,8 @@#define MSR_IA32_APICBASE_ENABLE (1<<11)#define MSR_IA32_APICBASE_BASE (0xfffff<<12) +#define MSR_IA32_X2APIC_APICID 0x00000802 +#define MSR_IA32_UCODE_WRITE 0x00000079#define MSR_IA32_UCODE_REV 0x0000008b
arch/x86/include/uapi/asm/bootparam.h +1 -0
@@ -26,6 +26,7 @@/* loadflags */ #define LOADED_HIGH (1<<0)#define KASLR_FLAG (1<<1) +#define SLAUNCH_FLAG (1<<2)#define QUIET_FLAG (1<<5)#define KEEP_SEGMENTS (1<<6)#define CAN_USE_HEAP (1<<7)
arch/x86/kernel/asm-offsets.c +20 -0
@@ -13,6 +13,8 @@#include <linux/hardirq.h> #include <linux/suspend.h> #include <linux/kbuild.h> +#include <linux/slr_table.h> +#include <linux/slaunch.h> #include <asm/processor.h> #include <asm/thread_info.h> #include <asm/sigframe.h>
@@ -120,4 +122,22 @@ static void __used common(void)OFFSET (ARIA_CTX_rounds, aria_ctx, rounds);#endif +#ifdef CONFIG_SECURE_LAUNCH +BLANK (); +OFFSET (SL_txt_info, txt_os_mle_data, txt_info); +OFFSET (SL_mle_scratch, txt_os_mle_data, mle_scratch); +OFFSET (SL_boot_params_addr, txt_os_mle_data, boot_params_addr); +OFFSET (SL_ap_wake_block, txt_os_mle_data, ap_wake_block); +OFFSET (SL_ap_wake_block_size, txt_os_mle_data, ap_wake_block_size); +OFFSET (SL_saved_misc_enable_msr, slr_entry_intel_info, saved_misc_enable_msr); +OFFSET (SL_saved_bsp_mtrrs, slr_entry_intel_info, saved_bsp_mtrrs); +OFFSET (SL_num_logical_procs, txt_bios_data, num_logical_procs); +OFFSET (SL_capabilities, txt_os_sinit_data, capabilities); +OFFSET (SL_mle_size, txt_os_sinit_data, mle_size); +OFFSET (SL_vtd_pmr_lo_base, txt_os_sinit_data, vtd_pmr_lo_base); +OFFSET (SL_vtd_pmr_lo_size, txt_os_sinit_data, vtd_pmr_lo_size); +OFFSET (SL_rlp_wakeup_addr, txt_sinit_mle_data, rlp_wakeup_addr); +OFFSET (SL_rlp_gdt_base, smx_rlp_mle_join, rlp_gdt_base); +OFFSET (SL_rlp_entry_point, smx_rlp_mle_join, rlp_entry_point); +#endif }
Signature · 1 line
2.39.3
Ard Biesheuvel
maintainerRe: [PATCH v8 07/15] x86: Secure Launch kernel early boot stub
Quoted 35 lines · Ross Philipson
The Secure Launch (SL) stub provides the entry point for Intel TXT (and later AMD SKINIT) to vector to during the late launch. The symbol
sl_stub_entryis that entry point and its offset into the kernel is conveyed to the launching code using the MLE (Measured Launch Environment) header in the structure namedmle_header. The offset of the MLE header is set in thekernel_info. The routinesl_stubcontains the very early late launch setup code responsible for setting up the basic environment to allow the normal kernelstartup_32code to proceed. It is also responsible for properly waking and handling the APs on Intel platforms. The routinesl_mainwhich runs after entering 64b mode is responsible for measuring configuration and module information before it is used like the boot params, the kernel command line, the TXT heap, an external initramfs, etc.Signed-off-by Ross Philipson <[email protected]>--- Documentation/arch/x86/boot.rst | 21 + arch/x86/boot/compressed/Makefile | 3 +- arch/x86/boot/compressed/head_64.S | 34 ++ arch/x86/boot/compressed/kernel_info.S | 34 ++ arch/x86/boot/compressed/sl_main.c | 582 ++++++++++++++++++++ arch/x86/boot/compressed/sl_stub.S | 705 +++++++++++++++++++++++++ arch/x86/include/asm/msr-index.h | 5 + arch/x86/include/uapi/asm/bootparam.h | 1 + arch/x86/kernel/asm-offsets.c | 20 + 9 files changed, 1404 insertions(+), 1 deletion(-) create mode 100644 arch/x86/boot/compressed/sl_main.c create mode 100644 arch/x86/boot/compressed/sl_stub.SDocumentation/arch/x86/boot.rst +0
-0
Documentation/arch/x86/boot.rst Protocol: 2.00+ · line 487
Quoted 6 lines
Documentation/arch/x86/boot.rst +3
-0@@ -482,6 +482,14 @@ Protocol: 2.00+ - If 1, KASLR enabled. - If 0, KASLR disabled. + Bit 2 (kernel internal): SLAUNCH_FLAG + + - Used internally by the compressed kernel to communicate
decompressor
Quoted 47 lines
Documentation/arch/x86/boot.rst +18
-0+ Secure Launch status to kernel proper. + + - If 1, Secure Launch enabled. + - If 0, Secure Launch disabled. + Bit 5 (write): QUIET_FLAG - If 0, print early messages.@@ -1027,6 +1035,19 @@ Offset/size: 0x000c/4 This field contains maximal allowed type for setup_data and setup_indirect structs. +============ ================= +Field name: mle_header_offset +Offset/size: 0x0010/4 +============ ================= + + This field contains the offset to the Secure Launch Measured Launch Environment + (MLE) header. This offset is used to locate information needed during a secure + late launch using Intel TXT. If the offset is zero, the kernel does not have + Secure Launch capabilities. The MLE entry point is called from TXT on the BSP + following a success measured launch. The specific state of the processors is + outlined in the TXT Software Development Guide, the latest can be found here: + https://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-txt-software-development-guide.pdf + The Image Checksum ==================arch/x86/boot/compressed/Makefile +2
-1@@ -118,7 +118,8 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a -vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/early_sha1.o $(obj)/early_sha256.o +vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/early_sha1.o $(obj)/early_sha256.o \ + $(obj)/sl_main.o $(obj)/sl_stub.o $(obj)/vmlinux: $(vmlinux-objs-y) FORCE $(call if_changed,ld)arch/x86/boot/compressed/head_64.S +0
-0
arch/x86/boot/compressed/head_64.S SYM_CODE_START(startup_64) · line 420
Quoted 6 lines
arch/x86/boot/compressed/head_64.S +3
-0@@ -415,6 +415,17 @@ SYM_CODE_START(startup_64) pushq $0 popfq +#ifdef CONFIG_SECURE_LAUNCH + pushq %rsi +
This push and the associated pop are no longer needed.
arch/x86/boot/compressed/head_64.S SYM_CODE_START(startup_64) · line 421
Quoted 1 line
arch/x86/boot/compressed/head_64.S +1
-0+ /* Ensure the relocation region coverd by a PMR */
'is covered'
Quoted 21 lines
arch/x86/boot/compressed/head_64.S +14
-0+ movq %rbx, %rdi + movl $(_bss - startup_32), %esi + callq sl_check_region + + popq %rsi +#endif + /* * Copy the compressed kernel to the end of our buffer * where decompression in place becomes safe.@@ -457,6 +468,29 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) shrq $3, %rcx rep stosq +#ifdef CONFIG_SECURE_LAUNCH + /* + * Have to do the final early sl stub work in 64b area. + * + * *********** NOTE *********** + * + * Several boot params get used before we get a chance to measure
arch/x86/boot/compressed/head_64.S SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) · line 487
Quoted 10 lines
arch/x86/boot/compressed/head_64.S +10
-0+ * them in this call. This is a known issue and we currently don't + * have a solution. The scratch field doesn't matter. There is no + * obvious way to do anything about the use of kernel_alignment or + * init_size though these seem low risk with all the PMR and overlap + * checks in place. + */ + movq %r15, %rdi + callq sl_main + + /* Ensure the decompression location is coverd by a PMR */
covered
Quoted 128 lines
arch/x86/boot/compressed/head_64.S +6
-0+ movq %rbp, %rdi + movq output_len(%rip), %rsi + callq sl_check_region +#endif + + pushq %rsi call load_stage2_idt /* Pass boot_params to initialize_identity_maps() */arch/x86/boot/compressed/kernel_info.S +34
-0@@ -28,6 +28,40 @@ SYM_DATA_START(kernel_info) /* Maximal allowed type for setup_data and setup_indirect structs. */ .long SETUP_TYPE_MAX + /* Offset to the MLE header structure */ +#if IS_ENABLED(CONFIG_SECURE_LAUNCH) + .long rva(mle_header) +#else + .long 0 +#endif + kernel_info_var_len_data: /* Empty for time being... */ SYM_DATA_END_LABEL(kernel_info, SYM_L_LOCAL, kernel_info_end) + +#if IS_ENABLED(CONFIG_SECURE_LAUNCH) + /* + * The MLE Header per the TXT Specification, section 2.1 + * MLE capabilities, see table 4. Capabilities set: + * bit 0: Support for GETSEC[WAKEUP] for RLP wakeup + * bit 1: Support for RLP wakeup using MONITOR address + * bit 2: The ECX register will contain the pointer to the MLE page table + * bit 5: TPM 1.2 family: Details/authorities PCR usage support + * bit 9: Supported format of TPM 2.0 event log - TCG compliant + */ +SYM_DATA_START(mle_header) + .long 0x9082ac5a /* UUID0 */ + .long 0x74a7476f /* UUID1 */ + .long 0xa2555c0f /* UUID2 */ + .long 0x42b651cb /* UUID3 */ + .long 0x00000034 /* MLE header size */ + .long 0x00020002 /* MLE version 2.2 */ + .long rva(sl_stub_entry) /* Linear entry point of MLE (virt. address) */ + .long 0x00000000 /* First valid page of MLE */ + .long 0x00000000 /* Offset within binary of first byte of MLE */ + .long rva(_edata) /* Offset within binary of last byte + 1 of MLE */ + .long 0x00000227 /* Bit vector of MLE-supported capabilities */ + .long 0x00000000 /* Starting linear address of command line (unused) */ + .long 0x00000000 /* Ending linear address of command line (unused) */ +SYM_DATA_END(mle_header) +#endifarch/x86/boot/compressed/sl_main.c new file +68
-0@@ -0,0 +1,582 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Secure Launch early measurement and validation routines. +* +* Copyright (c) 2022, Oracle and/or its affiliates. +*/ + +#include <linux/init.h> +#include <linux/string.h> +#include <linux/linkage.h> +#include <asm/segment.h> +#include <asm/boot.h> +#include <asm/msr.h> +#include <asm/mtrr.h> +#include <asm/processor-flags.h> +#include <asm/asm-offsets.h> +#include <asm/bootparam.h> +#include <asm/bootparam_utils.h> +#include <linux/slr_table.h> +#include <linux/slaunch.h> +#include <crypto/sha1.h> +#include <crypto/sha2.h> + +#define CAPS_VARIABLE_MTRR_COUNT_MASK 0xff + +#define SL_TPM12_LOG 1 +#define SL_TPM20_LOG 2 + +#define SL_TPM20_MAX_ALGS 2 + +#define SL_MAX_EVENT_DATA 64 +#define SL_TPM12_LOG_SIZE (sizeof(struct tcg_pcr_event) + \ + SL_MAX_EVENT_DATA) +#define SL_TPM20_LOG_SIZE (sizeof(struct tcg_pcr_event2_head) + \ + SHA1_DIGEST_SIZE + SHA256_DIGEST_SIZE + \ + sizeof(struct tcg_event_field) + \ + SL_MAX_EVENT_DATA) + +static void *evtlog_base; +static u32 evtlog_size; +static struct txt_heap_event_log_pointer2_1_element *log20_elem; +static u32 tpm_log_ver =SL_TPM12_LOG ; +static struct tcg_efi_specid_event_algs tpm_algs[SL_TPM20_MAX_ALGS ] = {0 }; + +extern u32 sl_cpu_type; +extern u32 sl_mle_start; + +static u64 sl_txt_read (u32 reg) +{ +return readq ((void *)(u64)(TXT_PRIV_CONFIG_REGS_BASE + reg)); +} + +static void sl_txt_write (u32 reg,u64 val) +{ +writeq (val, (void *)(u64)(TXT_PRIV_CONFIG_REGS_BASE + reg)); +} + +static void __noreturn sl_txt_reset (u64 error) +{ +/* Reading the E2STS register acts as a barrier for TXT registers */ +sl_txt_write (TXT_CR_ERRORCODE , error); +sl_txt_read (TXT_CR_E2STS ); +sl_txt_write (TXT_CR_CMD_UNLOCK_MEM_CONFIG ,1 ); +sl_txt_read (TXT_CR_E2STS ); +sl_txt_write (TXT_CR_CMD_RESET ,1 ); + +for ( ; ; ) + asmvolatile ("hlt" );
arch/x86/boot/compressed/sl_main.c line 78
Quoted 10 lines
arch/x86/boot/compressed/sl_main.c new file +10
-0+ +unreachable (); +} + +static u64 sl_rdmsr (u32 reg) +{ +u64 lo, hi; + + asmvolatile ("rdmsr" :"=a" (lo),"=d" (hi) :"c" (reg)); +
No need for volatile.
Quoted 1,289 lines
arch/x86/boot/compressed/sl_main.c new file +504
-0+return (hi <<32 ) | lo; +} + +static struct slr_table *sl_locate_and_validate_slrt (void ) +{ +struct txt_os_mle_data *os_mle_data; +struct slr_table *slrt; +void *txt_heap; + + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + os_mle_data =txt_os_mle_data_start (txt_heap); + +if (!os_mle_data->slrt) +sl_txt_reset (SL_ERROR_INVALID_SLRT ); + + slrt = (struct slr_table *)os_mle_data->slrt; + +if (slrt->magic !=SLR_TABLE_MAGIC ) +sl_txt_reset (SL_ERROR_INVALID_SLRT ); + +if (slrt->architecture !=SLR_INTEL_TXT ) +sl_txt_reset (SL_ERROR_INVALID_SLRT ); + +return slrt; +} + +static void sl_check_pmr_coverage (void *base,u32 size,bool allow_hi) +{ +struct txt_os_sinit_data *os_sinit_data; +void *end = base + size; +void *txt_heap; + +if (!(sl_cpu_type &SL_CPU_INTEL )) +return ; + + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + os_sinit_data =txt_os_sinit_data_start (txt_heap); + +if ((end >= (void *)0x100000000ULL ) && (base < (void *)0x100000000ULL )) +sl_txt_reset (SL_ERROR_REGION_STRADDLE_4GB ); + +/* +* Note that the late stub code validates that the hi PMR covers +* all memory above 4G. At this point the code can only check that +* regions are within the hi PMR but that is sufficient. +*/ +if ((end > (void *)0x100000000ULL ) && (base >= (void *)0x100000000ULL )) { +if (allow_hi) { +if (end >= (void *)(os_sinit_data->vtd_pmr_hi_base + + os_sinit_data->vtd_pmr_hi_size)) +sl_txt_reset (SL_ERROR_BUFFER_BEYOND_PMR ); + }else { +sl_txt_reset (SL_ERROR_REGION_ABOVE_4GB ); + } + } + +if (end >= (void *)os_sinit_data->vtd_pmr_lo_size) +sl_txt_reset (SL_ERROR_BUFFER_BEYOND_PMR ); +} + +/* +* Some MSRs are modified by the pre-launch code including the MTRRs. +* The early MLE code has to restore these values. This code validates +* the values after they are measured. +*/ +static void sl_txt_validate_msrs (struct txt_os_mle_data *os_mle_data) +{ +struct slr_txt_mtrr_state *saved_bsp_mtrrs; +u64 mtrr_caps, mtrr_def_type, mtrr_var; +struct slr_entry_intel_info *txt_info; +u64 misc_en_msr; +u32 vcnt, i; + + txt_info = (struct slr_entry_intel_info *)os_mle_data->txt_info; + saved_bsp_mtrrs = &txt_info->saved_bsp_mtrrs; + + mtrr_caps =sl_rdmsr (MSR_MTRRcap); + vcnt = (u32)(mtrr_caps &CAPS_VARIABLE_MTRR_COUNT_MASK ); + +if (saved_bsp_mtrrs->mtrr_vcnt > vcnt) +sl_txt_reset (SL_ERROR_MTRR_INV_VCNT ); +if (saved_bsp_mtrrs->mtrr_vcnt >TXT_OS_MLE_MAX_VARIABLE_MTRRS ) +sl_txt_reset (SL_ERROR_MTRR_INV_VCNT ); + + mtrr_def_type =sl_rdmsr (MSR_MTRRdefType); +if (saved_bsp_mtrrs->default_mem_type != mtrr_def_type) +sl_txt_reset (SL_ERROR_MTRR_INV_DEF_TYPE ); + +for (i =0 ; i < saved_bsp_mtrrs->mtrr_vcnt; i++) { + mtrr_var =sl_rdmsr (MTRRphysBase_MSR (i)); +if (saved_bsp_mtrrs->mtrr_pair[i].mtrr_physbase != mtrr_var) +sl_txt_reset (SL_ERROR_MTRR_INV_BASE ); + mtrr_var =sl_rdmsr (MTRRphysMask_MSR (i)); +if (saved_bsp_mtrrs->mtrr_pair[i].mtrr_physmask != mtrr_var) +sl_txt_reset (SL_ERROR_MTRR_INV_MASK ); + } + + misc_en_msr =sl_rdmsr (MSR_IA32_MISC_ENABLE ); +if (txt_info->saved_misc_enable_msr != misc_en_msr) +sl_txt_reset (SL_ERROR_MSR_INV_MISC_EN ); +} + +static void sl_find_drtm_event_log (struct slr_table *slrt) +{ +struct txt_os_sinit_data *os_sinit_data; +struct slr_entry_log_info *log_info; +void *txt_heap; + + log_info = (struct slr_entry_log_info *) +slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_LOG_INFO ); +if (!log_info) +sl_txt_reset (SL_ERROR_SLRT_MISSING_ENTRY ); + + evtlog_base = (void *)log_info->addr; + evtlog_size = log_info->size; + + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + +/* +* For TPM 2.0, the event log 2.1 extended data structure has to also +* be located and fixed up. +*/ + os_sinit_data =txt_os_sinit_data_start (txt_heap); + +/* +* Only support version 6 and later that properly handle the +* list of ExtDataElements in the OS-SINIT structure. +*/ +if (os_sinit_data->version <6 ) +sl_txt_reset (SL_ERROR_OS_SINIT_BAD_VERSION ); + +/* Find the TPM2.0 logging extended heap element */ + log20_elem =tpm20_find_log2_1_element (os_sinit_data); + +/* If found, this implies TPM20 log and family */ +if (log20_elem) + tpm_log_ver =SL_TPM20_LOG ; +} + +static void sl_validate_event_log_buffer (void ) +{ +struct txt_os_sinit_data *os_sinit_data; +void *txt_heap, *txt_end; +void *mle_base, *mle_end; +void *evtlog_end; + +if ((u64 )evtlog_size > (LLONG_MAX - (u64 )evtlog_base)) +sl_txt_reset (SL_ERROR_INTEGER_OVERFLOW ); + evtlog_end = evtlog_base + evtlog_size; + + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + txt_end = txt_heap +sl_txt_read (TXT_CR_HEAP_SIZE ); + os_sinit_data =txt_os_sinit_data_start (txt_heap); + + mle_base = (void *)(u64 )sl_mle_start; + mle_end = mle_base + os_sinit_data->mle_size; + +/* +* This check is to ensure the event log buffer does not overlap with +* the MLE image. +*/ +if (evtlog_base >= mle_end && evtlog_end > mle_end) + goto pmr_check;/* above */ + +if (evtlog_end <= mle_base && evtlog_base < mle_base) + goto pmr_check;/* below */ + +sl_txt_reset (SL_ERROR_MLE_BUFFER_OVERLAP ); + +pmr_check: +/* +* The TXT heap is protected by the DPR. If the TPM event log is +* inside the TXT heap, there is no need for a PMR check. +*/ +if (evtlog_base > txt_heap && evtlog_end < txt_end) +return ; + +sl_check_pmr_coverage (evtlog_base, evtlog_size, true); +} + +static void sl_find_event_log_algorithms (void ) +{ +struct tcg_efi_specid_event_head *efi_head = + (struct tcg_efi_specid_event_head *)(evtlog_base + + log20_elem->first_record_offset + +sizeof (struct tcg_pcr_event )); + +if (efi_head->num_algs ==0 || efi_head->num_algs >2 ) +sl_txt_reset (SL_ERROR_TPM_NUMBER_ALGS ); + +memcpy (&tpm_algs[0 ], &efi_head->digest_sizes[0 ], +sizeof (struct tcg_efi_specid_event_algs ) * efi_head->num_algs); +} + +static void sl_tpm12_log_event (u32 pcr,u32 event_type, +const u8 *data,u32 length, +const u8 *event_data,u32 event_size) +{ +u8 sha1_hash[SHA1_DIGEST_SIZE ] = {0 }; +u8 log_buf[SL_TPM12_LOG_SIZE ] = {0 }; +struct tcg_pcr_event *pcr_event; +u32 total_size; + + pcr_event = (struct tcg_pcr_event *)log_buf; + pcr_event->pcr_idx = pcr; + pcr_event->event_type = event_type; +if (length >0 ) { +sha1 (data, length, &sha1_hash[0 ]); +memcpy (&pcr_event->digest[0 ], &sha1_hash[0 ],SHA1_DIGEST_SIZE ); + } + pcr_event->event_size = event_size; +if (event_size >0 ) +memcpy ((u8 *)pcr_event +sizeof (struct tcg_pcr_event ), + event_data, event_size); + + total_size =sizeof (struct tcg_pcr_event ) + event_size; + +if (tpm12_log_event (evtlog_base, evtlog_size, total_size, pcr_event)) +sl_txt_reset (SL_ERROR_TPM_LOGGING_FAILED ); +} + +static void sl_tpm20_log_event (u32 pcr,u32 event_type, +const u8 *data,u32 length, +const u8 *event_data,u32 event_size) +{ +u8 sha256_hash[SHA256_DIGEST_SIZE ] = {0 }; +u8 sha1_hash[SHA1_DIGEST_SIZE ] = {0 }; +u8 log_buf[SL_TPM20_LOG_SIZE ] = {0 }; +struct sha256_state sctx256 = {0 }; +struct tcg_pcr_event2_head *head; +struct tcg_event_field *event; +u32 total_size; +u16 *alg_ptr; +u8 *dgst_ptr; + + head = (struct tcg_pcr_event2_head *)log_buf; + head->pcr_idx = pcr; + head->event_type = event_type; + total_size =sizeof (struct tcg_pcr_event2_head ); + alg_ptr = (u16 *)(log_buf +sizeof (struct tcg_pcr_event2_head )); + +for ( ; head->count <2 ; head->count++) { +if (!tpm_algs[head->count].alg_id) +break ; + + *alg_ptr = tpm_algs[head->count].alg_id; + dgst_ptr = (u8 *)alg_ptr +sizeof (u16); + +if (tpm_algs[head->count].alg_id ==TPM_ALG_SHA256 && + length) { +sha256_init (&sctx256); +sha256_update (&sctx256, data, length); +sha256_final (&sctx256, &sha256_hash[0 ]); + }else if (tpm_algs[head->count].alg_id ==TPM_ALG_SHA1 && + length) { +sha1 (data, length, &sha1_hash[0 ]); + } + +if (tpm_algs[head->count].alg_id ==TPM_ALG_SHA256 ) { +memcpy (dgst_ptr, &sha256_hash[0 ],SHA256_DIGEST_SIZE ); + total_size +=SHA256_DIGEST_SIZE +sizeof (u16); + alg_ptr = (u16 *)((u8 *)alg_ptr +SHA256_DIGEST_SIZE +sizeof (u16)); + }else if (tpm_algs[head->count].alg_id ==TPM_ALG_SHA1 ) { +memcpy (dgst_ptr, &sha1_hash[0 ],SHA1_DIGEST_SIZE ); + total_size +=SHA1_DIGEST_SIZE +sizeof (u16); + alg_ptr = (u16 *)((u8 *)alg_ptr +SHA1_DIGEST_SIZE +sizeof (u16)); + }else { +sl_txt_reset (SL_ERROR_TPM_UNKNOWN_DIGEST ); + } + } + + event = (struct tcg_event_field *)(log_buf + total_size); + event->event_size = event_size; +if (event_size >0 ) +memcpy ((u8 *)event +sizeof (struct tcg_event_field ), event_data, event_size); + total_size +=sizeof (struct tcg_event_field ) + event_size; + +if (tpm20_log_event (log20_elem, evtlog_base, evtlog_size, total_size, &log_buf[0 ])) +sl_txt_reset (SL_ERROR_TPM_LOGGING_FAILED ); +} + +static void sl_tpm_extend_evtlog (u32 pcr,u32 type, +const u8 *data,u32 length,const char *desc) +{ +if (tpm_log_ver ==SL_TPM20_LOG ) +sl_tpm20_log_event (pcr, type, data, length, + (const u8 *)desc,strlen (desc)); +else +sl_tpm12_log_event (pcr, type, data, length, + (const u8 *)desc,strlen (desc)); +} + +static struct setup_data *sl_handle_setup_data (struct setup_data *curr, +struct slr_policy_entry *entry) +{ +struct setup_indirect *ind; +struct setup_data *next; + +if (!curr) +return NULL ; + + next = (struct setup_data *)(unsigned long )curr->next; + +/* SETUP_INDIRECT instances have to be handled differently */ +if (curr->type ==SETUP_INDIRECT ) { + ind = (struct setup_indirect *)((u8 *)curr + offsetof(struct setup_data , data)); + +sl_check_pmr_coverage ((void *)ind->addr, ind->len, true); + +sl_tpm_extend_evtlog (entry->pcr,TXT_EVTYPE_SLAUNCH , + (void *)ind->addr, ind->len, + entry->evt_info); + +return next; + } + +sl_check_pmr_coverage (((u8 *)curr) +sizeof (struct setup_data ), + curr->len, true); + +sl_tpm_extend_evtlog (entry->pcr,TXT_EVTYPE_SLAUNCH , + ((u8 *)curr) +sizeof (struct setup_data ), + curr->len, + entry->evt_info); + +return next; +} + +static void sl_extend_setup_data (struct slr_policy_entry *entry) +{ +struct setup_data *data; + +/* +* Measuring the boot params measured the fixed e820 memory map. +* Measure any setup_data entries including e820 extended entries. +*/ + data = (struct setup_data *)(unsigned long )entry->entity; +while (data) + data =sl_handle_setup_data (data, entry); +} + +static void sl_extend_slrt (struct slr_policy_entry *entry) +{ +struct slr_table *slrt = (struct slr_table *)entry->entity; +struct slr_entry_intel_info *intel_info; + +/* +* In revision one of the SLRT, the only table that needs to be +* measured is the Intel info table. Everything else is meta-data, +* addresses and sizes. Note the size of what to measure is not set. +* The flag SLR_POLICY_IMPLICIT_SIZE leaves it to the measuring code +* to sort out. +*/ +if (slrt->revision ==1 ) { + intel_info = (struct slr_entry_intel_info *)slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_INTEL_INFO ); +if (!intel_info) +sl_txt_reset (SL_ERROR_SLRT_MISSING_ENTRY ); + +sl_tpm_extend_evtlog (entry->pcr,TXT_EVTYPE_SLAUNCH , + (void *)entry->entity,sizeof (struct slr_entry_intel_info ), + entry->evt_info); + } +} + +static void sl_extend_txt_os2mle (struct slr_policy_entry *entry) +{ +struct txt_os_mle_data *os_mle_data; +void *txt_heap; + + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + os_mle_data =txt_os_mle_data_start (txt_heap); + +/* +* Version 1 of the OS-MLE heap structure has no fields to measure. It just +* has addresses and sizes and a scratch buffer. +*/ +if (os_mle_data->version ==1 ) +return ; +} + +static void sl_process_extend_policy (struct slr_table *slrt) +{ +struct slr_entry_policy *policy; +struct slr_policy_entry *entry; +u16 i; + + policy = (struct slr_entry_policy *)slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_ENTRY_POLICY ); +if (!policy) +sl_txt_reset (SL_ERROR_SLRT_MISSING_ENTRY ); + + entry = (struct slr_policy_entry *)((u8 *)policy +sizeof (*policy)); + +for (i =0 ; i < policy->nr_entries; i++, entry++) { +switch (entry->entity_type) { +case SLR_ET_SETUP_DATA : +sl_extend_setup_data (entry); +break ; +case SLR_ET_SLRT : +sl_extend_slrt (entry); +break ; +case SLR_ET_TXT_OS2MLE : +sl_extend_txt_os2mle (entry); +break ; +case SLR_ET_UNUSED : +continue ; +default : +sl_tpm_extend_evtlog (entry->pcr,TXT_EVTYPE_SLAUNCH , + (void *)entry->entity, entry->size, + entry->evt_info); + } + } +} + +static void sl_process_extend_uefi_config (struct slr_table *slrt) +{ +struct slr_entry_uefi_config *uefi_config; +struct slr_uefi_cfg_entry *uefi_entry; +u64 i; + + uefi_config =(struct slr_entry_uefi_config *)slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_UEFI_CONFIG ); + +/* Optionally here depending on how SL kernel was booted */ +if (!uefi_config) +return ; + + uefi_entry = (struct slr_uefi_cfg_entry *)((u8 *)uefi_config +sizeof (*uefi_config)); + +for (i =0 ; i < uefi_config->nr_entries; i++, uefi_entry++) { +sl_tpm_extend_evtlog (uefi_entry->pcr,TXT_EVTYPE_SLAUNCH , + (void *)uefi_entry->cfg, uefi_entry->size, + uefi_entry->evt_info); + } +} + +asmlinkage __visible void sl_check_region(void *base, u32 size) +{ +sl_check_pmr_coverage (base, size, false); +} + +asmlinkage __visible void sl_main(void *bootparams) +{ +struct boot_params *bp = (struct boot_params *)bootparams; +struct txt_os_mle_data *os_mle_data; +struct slr_table *slrt; +void *txt_heap; + +/* +* Ensure loadflags do not indicate a secure launch was done +* unless it really was. +*/ + bp->hdr.loadflags &= ~SLAUNCH_FLAG ; + +/* +* Currently only Intel TXT is supported for Secure Launch. Testing +* this value also indicates that the kernel was booted successfully +* through the Secure Launch entry point and is in SMX mode. +*/ +if (!(sl_cpu_type &SL_CPU_INTEL )) +return ; + + slrt =sl_locate_and_validate_slrt (); + +/* Locate the TPM event log. */ +sl_find_drtm_event_log (slrt); + +/* Validate the location of the event log buffer before using it */ +sl_validate_event_log_buffer (); + +/* +* Find the TPM hash algorithms used by the ACM and recorded in the +* event log. +*/ +if (tpm_log_ver ==SL_TPM20_LOG ) +sl_find_event_log_algorithms (); + +/* +* Sanitize them before measuring. Set the SLAUNCH_FLAG early since if +* anything fails, the system will reset anyway. +*/ +sanitize_boot_params (bp); + bp->hdr.loadflags |=SLAUNCH_FLAG ; + +sl_check_pmr_coverage (bootparams,PAGE_SIZE , false); + +/* Place event log SL specific tags before and after measurements */ +sl_tpm_extend_evtlog (17 ,TXT_EVTYPE_SLAUNCH_START ,NULL ,0 ,"" ); + +/* Process all policy entries and extend the measurements to the evtlog */ +sl_process_extend_policy (slrt); + +/* Process all EFI config entries and extend the measurements to the evtlog */ +sl_process_extend_uefi_config (slrt); + +sl_tpm_extend_evtlog (17 ,TXT_EVTYPE_SLAUNCH_END ,NULL ,0 ,"" ); + +/* No PMR check is needed, the TXT heap is covered by the DPR */ + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + os_mle_data =txt_os_mle_data_start (txt_heap); + +/* +* Now that the OS-MLE data is measured, ensure the MTRR and +* misc enable MSRs are what we expect. +*/ +sl_txt_validate_msrs (os_mle_data); +}arch/x86/boot/compressed/sl_stub.S new file +705
-0@@ -0,0 +1,705 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Secure Launch protected mode entry point. + * + * Copyright (c) 2022, Oracle and/or its affiliates. + */ + .code32 + .text +#include <linux/linkage.h> +#include <asm/segment.h> +#include <asm/msr.h> +#include <asm/apicdef.h> +#include <asm/trapnr.h> +#include <asm/processor-flags.h> +#include <asm/asm-offsets.h> +#include <asm/bootparam.h> +#include <asm/page_types.h> +#include <asm/irq_vectors.h> +#include <linux/slr_table.h> +#include <linux/slaunch.h> + +/* CPUID: leaf 1, ECX, SMX feature bit */ +#define X86_FEATURE_BIT_SMX (1 << 6) + +#define IDT_VECTOR_LO_BITS 0 +#define IDT_VECTOR_HI_BITS 6 + +/* + * See the comment in head_64.S for detailed information on what this macro + * and others like it are used for. The comment appears right at the top of + * the file. + */ +#define rva(X) ((X) - sl_stub_entry) + +/* + * The GETSEC op code is open coded because older versions of + * GCC do not support the getsec mnemonic. + */ +.macro GETSEC leaf + pushl %ebx + xorl %ebx, %ebx /* Must be zero for SMCTRL */ + movl \leaf, %eax /* Leaf function */ + .byte 0x0f, 0x37 /* GETSEC opcode */ + popl %ebx +.endm + +.macro TXT_RESET error + /* + * Set a sticky error value and reset. Note the movs to %eax act as + * TXT register barriers. + */ + movl \error, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ERRORCODE) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_NO_SECRETS) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_UNLOCK_MEM_CONFIG) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_RESET) +1: + hlt + jmp 1b +.endm + + .code32 +SYM_FUNC_START(sl_stub_entry) + cli + cld + + /* + * On entry, %ebx has the entry abs offset to sl_stub_entry. This + * will be correctly scaled using the rva macro and avoid causing + * relocations. Only %cs and %ds segments are known good. + */ + + /* Load GDT, set segment regs and lret to __SL32_CS */ + leal rva(sl_gdt_desc)(%ebx), %eax + addl %eax, 2(%eax) + lgdt (%eax) + + movl $(__SL32_DS), %eax + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movw %ax, %ss + + /* + * Now that %ss is known good, take the first stack for the BSP. The + * AP stacks are only used on Intel. + */ + leal rva(sl_stacks_end)(%ebx), %esp + + leal rva(.Lsl_cs)(%ebx), %eax + pushl $(__SL32_CS) + pushl %eax + lret + +.Lsl_cs: + /* Save our base pointer reg and page table for MLE */ + pushl %ebx + pushl %ecx + + /* See if SMX feature is supported. */ + movl $1, %eax + cpuid + testl $(X86_FEATURE_BIT_SMX), %ecx + jz .Ldo_unknown_cpu + + popl %ecx + popl %ebx + + /* Know it is Intel */ + movl $(SL_CPU_INTEL), rva(sl_cpu_type)(%ebx) + + /* Locate the base of the MLE using the page tables in %ecx */ + call sl_find_mle_base + + /* Increment CPU count for BSP */ + incl rva(sl_txt_cpu_count)(%ebx) + + /* + * Enable SMI with GETSEC[SMCTRL] which were disabled by SENTER. + * NMIs were also disabled by SENTER. Since there is no IDT for the BSP, + * allow the mainline kernel re-enable them in the normal course of + * booting. + */ + GETSEC $(SMX_X86_GETSEC_SMCTRL) + + /* Clear the TXT error registers for a clean start of day */ + movl $0, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ERRORCODE) + movl $0xffffffff, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ESTS) + + /* On Intel, the zero page address is passed in the TXT heap */ + /* Read physical base of heap into EAX */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* Read the size of the BIOS data into ECX (first 8 bytes) */ + movl (%eax), %ecx + /* Skip over BIOS data and size of OS to MLE data section */ + leal 8(%eax, %ecx), %eax + + /* Need to verify the values in the OS-MLE struct passed in */ + call sl_txt_verify_os_mle_struct + + /* + * Get the boot params address from the heap. Note %esi and %ebx MUST + * be preserved across calls and operations. + */ + movl SL_boot_params_addr(%eax), %esi + + /* Save %ebx so the APs can find their way home */ + movl %ebx, (SL_mle_scratch + SL_SCRATCH_AP_EBX)(%eax) + + /* Fetch the AP wake code block address from the heap */ + movl SL_ap_wake_block(%eax), %edi + movl %edi, rva(sl_txt_ap_wake_block)(%ebx) + + /* Store the offset in the AP wake block to the jmp address */ + movl $(sl_ap_jmp_offset - sl_txt_ap_wake_begin), \ + (SL_mle_scratch + SL_SCRATCH_AP_JMP_OFFSET)(%eax) + + /* Store the offset in the AP wake block to the AP stacks block */ + movl $(sl_stacks - sl_txt_ap_wake_begin), \ + (SL_mle_scratch + SL_SCRATCH_AP_STACKS_OFFSET)(%eax) + + /* %eax still is the base of the OS-MLE block, save it */ + pushl %eax + + /* Relocate the AP wake code to the safe block */ + call sl_txt_reloc_ap_wake + + /* + * Wake up all APs that are blocked in the ACM and wait for them to + * halt. This should be done before restoring the MTRRs so the ACM is + * still properly in WB memory. + */ + call sl_txt_wake_aps + + /* Restore OS-MLE in %eax */ + popl %eax + + /* + * %edi is used by this routine to find the MTRRs which are in the SLRT + * in the Intel info. + */ + movl SL_txt_info(%eax), %edi + call sl_txt_load_regs + + jmp .Lcpu_setup_done + +.Ldo_unknown_cpu: + /* Non-Intel CPUs are not yet supported */ + ud2 + +.Lcpu_setup_done: + /* + * Don't enable MCE at this point. The kernel will enable + * it on the BSP later when it is ready. + */ + + /* Done, jump to normal 32b pm entry */ + jmp startup_32 +SYM_FUNC_END(sl_stub_entry) + +SYM_FUNC_START(sl_find_mle_base) + /* %ecx has PDPT, get first PD */ + movl (%ecx), %eax + andl $(PAGE_MASK), %eax + /* Get first PT from first PDE */ + movl (%eax), %eax + andl $(PAGE_MASK), %eax + /* Get MLE base from first PTE */ + movl (%eax), %eax + andl $(PAGE_MASK), %eax + + movl %eax, rva(sl_mle_start)(%ebx) + ret +SYM_FUNC_END(sl_find_mle_base) + +SYM_FUNC_START(sl_check_buffer_mle_overlap) + /* %ecx: buffer begin %edx: buffer end */ + /* %ebx: MLE begin %edi: MLE end */ + + cmpl %edi, %ecx + jb .Lnext_check + cmpl %edi, %edx + jbe .Lnext_check + jmp .Lvalid /* Buffer above MLE */ + +.Lnext_check: + cmpl %ebx, %edx + ja .Linvalid + cmpl %ebx, %ecx + jae .Linvalid + jmp .Lvalid /* Buffer below MLE */ + +.Linvalid: + TXT_RESET $(SL_ERROR_MLE_BUFFER_OVERLAP) + +.Lvalid: + ret +SYM_FUNC_END(sl_check_buffer_mle_overlap) + +SYM_FUNC_START(sl_txt_verify_os_mle_struct) + pushl %ebx + /* + * %eax points to the base of the OS-MLE struct. Need to also + * read some values from the OS-SINIT struct too. + */ + movl -8(%eax), %ecx + /* Skip over OS to MLE data section and size of OS-SINIT structure */ + leal (%eax, %ecx), %edx + + /* Load MLE image base absolute offset */ + movl rva(sl_mle_start)(%ebx), %ebx + + /* Verify the value of the low PMR base. It should always be 0. */ + movl SL_vtd_pmr_lo_base(%edx), %esi + cmpl $0, %esi + jz .Lvalid_pmr_base + TXT_RESET $(SL_ERROR_LO_PMR_BASE) + +.Lvalid_pmr_base: + /* Grab some values from OS-SINIT structure */ + movl SL_mle_size(%edx), %edi + addl %ebx, %edi + jc .Loverflow_detected + movl SL_vtd_pmr_lo_size(%edx), %esi + + /* Check the AP wake block */ + movl SL_ap_wake_block(%eax), %ecx + movl SL_ap_wake_block_size(%eax), %edx + addl %ecx, %edx + jc .Loverflow_detected + call sl_check_buffer_mle_overlap + cmpl %esi, %edx + ja .Lbuffer_beyond_pmr + + /* Check the boot params */ + movl SL_boot_params_addr(%eax), %ecx + movl $(PAGE_SIZE), %edx + addl %ecx, %edx + jc .Loverflow_detected + call sl_check_buffer_mle_overlap + cmpl %esi, %edx + ja .Lbuffer_beyond_pmr + + /* Check that the AP wake block is big enough */ + cmpl $(sl_txt_ap_wake_end - sl_txt_ap_wake_begin), \ + SL_ap_wake_block_size(%eax) + jae .Lwake_block_ok + TXT_RESET $(SL_ERROR_WAKE_BLOCK_TOO_SMALL) + +.Lwake_block_ok: + popl %ebx + ret + +.Loverflow_detected: + TXT_RESET $(SL_ERROR_INTEGER_OVERFLOW) + +.Lbuffer_beyond_pmr: + TXT_RESET $(SL_ERROR_BUFFER_BEYOND_PMR) +SYM_FUNC_END(sl_txt_verify_os_mle_struct) + +SYM_FUNC_START(sl_txt_ap_entry) + cli + cld + /* + * The %cs and %ds segments are known good after waking the AP. + * First order of business is to find where we are and + * save it in %ebx. + */ + + /* Read physical base of heap into EAX */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* Read the size of the BIOS data into ECX (first 8 bytes) */ + movl (%eax), %ecx + /* Skip over BIOS data and size of OS to MLE data section */ + leal 8(%eax, %ecx), %eax + + /* Saved %ebx from the BSP and stash OS-MLE pointer */ + movl (SL_mle_scratch + SL_SCRATCH_AP_EBX)(%eax), %ebx + + /* Save TXT info ptr in %edi for call to sl_txt_load_regs */ + movl SL_txt_info(%eax), %edi + + /* Lock and get our stack index */ + movl $1, %ecx +.Lspin: + xorl %eax, %eax + lock cmpxchgl %ecx, rva(sl_txt_spin_lock)(%ebx) + pause + jnz .Lspin + + /* Increment the stack index and use the next value inside lock */ + incl rva(sl_txt_stack_index)(%ebx) + movl rva(sl_txt_stack_index)(%ebx), %eax + + /* Unlock */ + movl $0, rva(sl_txt_spin_lock)(%ebx) + + /* Location of the relocated AP wake block */ + movl rva(sl_txt_ap_wake_block)(%ebx), %ecx + + /* Load reloc GDT, set segment regs and lret to __SL32_CS */ + lgdt (sl_ap_gdt_desc - sl_txt_ap_wake_begin)(%ecx) + + movl $(__SL32_DS), %edx + movw %dx, %ds + movw %dx, %es + movw %dx, %fs + movw %dx, %gs + movw %dx, %ss + + /* Load our reloc AP stack */ + movl $(TXT_BOOT_STACK_SIZE), %edx + mull %edx + leal (sl_stacks_end - sl_txt_ap_wake_begin)(%ecx), %esp + subl %eax, %esp + + /* Switch to AP code segment */ + leal rva(.Lsl_ap_cs)(%ebx), %eax + pushl $(__SL32_CS) + pushl %eax + lret + +.Lsl_ap_cs: + /* Load the relocated AP IDT */ + lidt (sl_ap_idt_desc - sl_txt_ap_wake_begin)(%ecx) + + /* Fixup MTRRs and misc enable MSR on APs too */ + call sl_txt_load_regs + + /* Enable SMI with GETSEC[SMCTRL] */ + GETSEC $(SMX_X86_GETSEC_SMCTRL) + + /* IRET-to-self can be used to enable NMIs which SENTER disabled */ + leal rva(.Lnmi_enabled_ap)(%ebx), %eax + pushfl + pushl $(__SL32_CS) + pushl %eax + iret + +.Lnmi_enabled_ap: + /* Put APs in X2APIC mode like the BSP */ + movl $(MSR_IA32_APICBASE), %ecx + rdmsr + orl $(XAPIC_ENABLE | X2APIC_ENABLE), %eax + wrmsr + + /* + * Basically done, increment the CPU count and jump off to the AP + * wake block to wait. + */ + lock incl rva(sl_txt_cpu_count)(%ebx) + + movl rva(sl_txt_ap_wake_block)(%ebx), %eax + jmp *%eax +SYM_FUNC_END(sl_txt_ap_entry) + +SYM_FUNC_START(sl_txt_reloc_ap_wake) + /* Save boot params register */ + pushl %esi + + movl rva(sl_txt_ap_wake_block)(%ebx), %edi + + /* Fixup AP IDT and GDT descriptor before relocating */ + leal rva(sl_ap_idt_desc)(%ebx), %eax + addl %edi, 2(%eax) + leal rva(sl_ap_gdt_desc)(%ebx), %eax + addl %edi, 2(%eax) + + /* + * Copy the AP wake code and AP GDT/IDT to the protected wake block + * provided by the loader. Destination already in %edi. + */ + movl $(sl_txt_ap_wake_end - sl_txt_ap_wake_begin), %ecx + leal rva(sl_txt_ap_wake_begin)(%ebx), %esi + rep movsb + + /* Setup the IDT for the APs to use in the relocation block */ + movl rva(sl_txt_ap_wake_block)(%ebx), %ecx + addl $(sl_ap_idt - sl_txt_ap_wake_begin), %ecx + xorl %edx, %edx + + /* Form the default reset vector relocation address */ + movl rva(sl_txt_ap_wake_block)(%ebx), %esi + addl $(sl_txt_int_reset - sl_txt_ap_wake_begin), %esi + +1: + cmpw $(NR_VECTORS), %dx + jz .Lap_idt_done + + cmpw $(X86_TRAP_NMI), %dx + jz 2f + + /* Load all other fixed vectors with reset handler */ + movl %esi, %eax + movw %ax, (IDT_VECTOR_LO_BITS)(%ecx) + shrl $16, %eax + movw %ax, (IDT_VECTOR_HI_BITS)(%ecx) + jmp 3f + +2: + /* Load single wake NMI IPI vector at the relocation address */ + movl rva(sl_txt_ap_wake_block)(%ebx), %eax + addl $(sl_txt_int_nmi - sl_txt_ap_wake_begin), %eax + movw %ax, (IDT_VECTOR_LO_BITS)(%ecx) + shrl $16, %eax + movw %ax, (IDT_VECTOR_HI_BITS)(%ecx) + +3: + incw %dx + addl $8, %ecx + jmp 1b + +.Lap_idt_done: + popl %esi + ret +SYM_FUNC_END(sl_txt_reloc_ap_wake) + +SYM_FUNC_START(sl_txt_load_regs) + /* Save base pointer register */ + pushl %ebx + + /* + * On Intel, the original variable MTRRs and Misc Enable MSR are + * restored on the BSP at early boot. Each AP will also restore + * its MTRRs and Misc Enable MSR. + */ + pushl %edi + addl $(SL_saved_bsp_mtrrs), %edi + movl (%edi), %ebx + pushl %ebx /* default_mem_type lo */ + addl $4, %edi + movl (%edi), %ebx + pushl %ebx /* default_mem_type hi */ + addl $4, %edi + movl (%edi), %ebx /* mtrr_vcnt lo, don't care about hi part */ + addl $8, %edi /* now at MTRR pair array */ + /* Write the variable MTRRs */ + movl $(MSR_MTRRphysBase0), %ecx +1: + cmpl $0, %ebx + jz 2f + + movl (%edi), %eax /* MTRRphysBaseX lo */ + addl $4, %edi + movl (%edi), %edx /* MTRRphysBaseX hi */ + wrmsr + addl $4, %edi + incl %ecx + movl (%edi), %eax /* MTRRphysMaskX lo */ + addl $4, %edi + movl (%edi), %edx /* MTRRphysMaskX hi */ + wrmsr + addl $4, %edi + incl %ecx + + decl %ebx + jmp 1b +2: + /* Write the default MTRR register */ + popl %edx + popl %eax + movl $(MSR_MTRRdefType), %ecx + wrmsr + + /* Return to beginning and write the misc enable msr */ + popl %edi + addl $(SL_saved_misc_enable_msr), %edi + movl (%edi), %eax /* saved_misc_enable_msr lo */ + addl $4, %edi + movl (%edi), %edx /* saved_misc_enable_msr hi */ + movl $(MSR_IA32_MISC_ENABLE), %ecx + wrmsr + + popl %ebx + ret +SYM_FUNC_END(sl_txt_load_regs) + +SYM_FUNC_START(sl_txt_wake_aps) + /* Save boot params register */ + pushl %esi + + /* First setup the MLE join structure and load it into TXT reg */ + leal rva(sl_gdt)(%ebx), %eax + leal rva(sl_txt_ap_entry)(%ebx), %ecx + leal rva(sl_smx_rlp_mle_join)(%ebx), %edx + movl %eax, SL_rlp_gdt_base(%edx) + movl %ecx, SL_rlp_entry_point(%edx) + movl %edx, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_MLE_JOIN) + + /* Another TXT heap walk to find various values needed to wake APs */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* At BIOS data size, find the number of logical processors */ + movl (SL_num_logical_procs + 8)(%eax), %edx + /* Skip over BIOS data */ + movl (%eax), %ecx + addl %ecx, %eax + /* Skip over OS to MLE */ + movl (%eax), %ecx + addl %ecx, %eax + /* At OS-SNIT size, get capabilities to know how to wake up the APs */ + movl (SL_capabilities + 8)(%eax), %esi + /* Skip over OS to SNIT */ + movl (%eax), %ecx + addl %ecx, %eax + /* At SINIT-MLE size, get the AP wake MONITOR address */ + movl (SL_rlp_wakeup_addr + 8)(%eax), %edi + + /* Determine how to wake up the APs */ + testl $(1 << TXT_SINIT_MLE_CAP_WAKE_MONITOR), %esi + jz .Lwake_getsec + + /* Wake using MWAIT MONITOR */ + movl $1, (%edi) + jmp .Laps_awake + +.Lwake_getsec: + /* Wake using GETSEC(WAKEUP) */ + GETSEC $(SMX_X86_GETSEC_WAKEUP) + +.Laps_awake: + /* + * All of the APs are woken up and rendesvous in the relocated wake + * block starting at sl_txt_ap_wake_begin. Wait for all of them to + * halt. + */ + pause + cmpl rva(sl_txt_cpu_count)(%ebx), %edx + jne .Laps_awake + + popl %esi + ret +SYM_FUNC_END(sl_txt_wake_aps) + +/* This is the beginning of the relocated AP wake code block */ + .global sl_txt_ap_wake_begin +sl_txt_ap_wake_begin: + + /* Get the LAPIC ID for each AP and stash it on the stack */ + movl $(MSR_IA32_X2APIC_APICID), %ecx + rdmsr + pushl %eax + + /* + * Get a pointer to the monitor location on this APs stack to test below + * after mwait returns. Currently %esp points to just past the pushed APIC + * ID value. + */ + movl %esp, %eax + subl $(TXT_BOOT_STACK_SIZE - 4), %eax + movl $0, (%eax) + + /* Clear ecx/edx so no invalid extensions or hints are passed to monitor */ + xorl %ecx, %ecx + xorl %edx, %edx + + /* + * Arm the monitor and wait for it to be poked by he SMP bringup code. The mwait + * instruction can return for a number of reasons. Test to see if it returned + * because the monitor was written to. + */ + monitor + +1: + mfence + mwait + movl (%eax), %edx + testl %edx, %edx + jz 1b + + /* + * This is the long absolute jump to the 32b Secure Launch protected mode stub + * code in sl_trampoline_start32() in the rmpiggy. The jump address will be + * fixed in the SMP boot code when the first AP is brought up. This whole area + * is provided and protected in the memory map by the prelaunch code. + */ + .byte 0xea +sl_ap_jmp_offset: + .long 0x00000000 + .word __SL32_CS + +SYM_FUNC_START(sl_txt_int_nmi) + /* NMI context, just IRET */ + iret +SYM_FUNC_END(sl_txt_int_nmi) + +SYM_FUNC_START(sl_txt_int_reset) + TXT_RESET $(SL_ERROR_INV_AP_INTERRUPT) +SYM_FUNC_END(sl_txt_int_reset) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_idt_desc) + .word sl_ap_idt_end - sl_ap_idt - 1 /* Limit */ + .long sl_ap_idt - sl_txt_ap_wake_begin /* Base */ +SYM_DATA_END_LABEL(sl_ap_idt_desc, SYM_L_LOCAL, sl_ap_idt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_idt) + .rept NR_VECTORS + .word 0x0000 /* Offset 15 to 0 */ + .word __SL32_CS /* Segment selector */ + .word 0x8e00 /* Present, DPL=0, 32b Vector, Interrupt */ + .word 0x0000 /* Offset 31 to 16 */ + .endr +SYM_DATA_END_LABEL(sl_ap_idt, SYM_L_LOCAL, sl_ap_idt_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_gdt_desc) + .word sl_ap_gdt_end - sl_ap_gdt - 1 + .long sl_ap_gdt - sl_txt_ap_wake_begin +SYM_DATA_END_LABEL(sl_ap_gdt_desc, SYM_L_LOCAL, sl_ap_gdt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_gdt) + .quad 0x0000000000000000 /* NULL */ + .quad 0x00cf9a000000ffff /* __SL32_CS */ + .quad 0x00cf92000000ffff /* __SL32_DS */ +SYM_DATA_END_LABEL(sl_ap_gdt, SYM_L_LOCAL, sl_ap_gdt_end) + + /* Small stacks for BSP and APs to work with */ + .balign 64 +SYM_DATA_START_LOCAL(sl_stacks) + .fill (TXT_MAX_CPUS * TXT_BOOT_STACK_SIZE), 1, 0 +SYM_DATA_END_LABEL(sl_stacks, SYM_L_LOCAL, sl_stacks_end) + +/* This is the end of the relocated AP wake code block */ + .global sl_txt_ap_wake_end +sl_txt_ap_wake_end: + + .data + .balign 8 +SYM_DATA_START_LOCAL(sl_gdt_desc) + .word sl_gdt_end - sl_gdt - 1 + .long sl_gdt - sl_gdt_desc +SYM_DATA_END_LABEL(sl_gdt_desc, SYM_L_LOCAL, sl_gdt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_gdt) + .quad 0x0000000000000000 /* NULL */ + .quad 0x00cf9a000000ffff /* __SL32_CS */ + .quad 0x00cf92000000ffff /* __SL32_DS */ +SYM_DATA_END_LABEL(sl_gdt, SYM_L_LOCAL, sl_gdt_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_smx_rlp_mle_join) + .long sl_gdt_end - sl_gdt - 1 /* GDT limit */ + .long 0x00000000 /* GDT base */ + .long __SL32_CS /* Seg Sel - CS (DS, ES, SS = seg_sel+8) */ + .long 0x00000000 /* Entry point physical address */ +SYM_DATA_END(sl_smx_rlp_mle_join) + +SYM_DATA(sl_cpu_type, .long 0x00000000) + +SYM_DATA(sl_mle_start, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_spin_lock, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_stack_index, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_cpu_count, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_ap_wake_block, .long 0x00000000)arch/x86/include/asm/msr-index.h +5
-0@@ -323,6 +323,9 @@#define MSR_IA32_RTIT_OUTPUT_BASE 0x00000560#define MSR_IA32_RTIT_OUTPUT_MASK 0x00000561 +#define MSR_MTRRphysBase0 0x00000200 +#define MSR_MTRRphysMask0 0x00000201 +#define MSR_MTRRfix64K_00000 0x00000250#define MSR_MTRRfix16K_80000 0x00000258#define MSR_MTRRfix16K_A0000 0x00000259@@ -804,6 +807,8 @@#define MSR_IA32_APICBASE_ENABLE (1<<11)#define MSR_IA32_APICBASE_BASE (0xfffff<<12) +#define MSR_IA32_X2APIC_APICID 0x00000802 +#define MSR_IA32_UCODE_WRITE 0x00000079#define MSR_IA32_UCODE_REV 0x0000008barch/x86/include/uapi/asm/bootparam.h +1
-0@@ -26,6 +26,7 @@/* loadflags */ #define LOADED_HIGH (1<<0)#define KASLR_FLAG (1<<1) +#define SLAUNCH_FLAG (1<<2)#define QUIET_FLAG (1<<5)#define KEEP_SEGMENTS (1<<6)#define CAN_USE_HEAP (1<<7)arch/x86/kernel/asm-offsets.c +20
-1@@ -13,6 +13,8 @@#include <linux/hardirq.h> #include <linux/suspend.h> #include <linux/kbuild.h> +#include <linux/slr_table.h> +#include <linux/slaunch.h> #include <asm/processor.h> #include <asm/thread_info.h> #include <asm/sigframe.h> @@ -120,4 +122,22 @@ static void __used common(void)OFFSET (ARIA_CTX_rounds, aria_ctx, rounds);#endif +#ifdef CONFIG_SECURE_LAUNCH +BLANK (); +OFFSET (SL_txt_info, txt_os_mle_data, txt_info); +OFFSET (SL_mle_scratch, txt_os_mle_data, mle_scratch); +OFFSET (SL_boot_params_addr, txt_os_mle_data, boot_params_addr); +OFFSET (SL_ap_wake_block, txt_os_mle_data, ap_wake_block); +OFFSET (SL_ap_wake_block_size, txt_os_mle_data, ap_wake_block_size); +OFFSET (SL_saved_misc_enable_msr, slr_entry_intel_info, saved_misc_enable_msr); +OFFSET (SL_saved_bsp_mtrrs, slr_entry_intel_info, saved_bsp_mtrrs); +OFFSET (SL_num_logical_procs, txt_bios_data, num_logical_procs); +OFFSET (SL_capabilities, txt_os_sinit_data, capabilities); +OFFSET (SL_mle_size, txt_os_sinit_data, mle_size); +OFFSET (SL_vtd_pmr_lo_base, txt_os_sinit_data, vtd_pmr_lo_base); +OFFSET (SL_vtd_pmr_lo_size, txt_os_sinit_data, vtd_pmr_lo_size); +OFFSET (SL_rlp_wakeup_addr, txt_sinit_mle_data, rlp_wakeup_addr); +OFFSET (SL_rlp_gdt_base, smx_rlp_mle_join, rlp_gdt_base); +OFFSET (SL_rlp_entry_point, smx_rlp_mle_join, rlp_entry_point); +#endif } --2.39.3
Re: [PATCH v8 07/15] x86: Secure Launch kernel early boot stub
Quoted 39 lines · Ard Biesheuvel
Quoted 38 lines · Ross Philipson
The Secure Launch (SL) stub provides the entry point for Intel TXT (and later AMD SKINIT) to vector to during the late launch. The symbol
sl_stub_entryis that entry point and its offset into the kernel is conveyed to the launching code using the MLE (Measured Launch Environment) header in the structure namedmle_header. The offset of the MLE header is set in thekernel_info. The routinesl_stubcontains the very early late launch setup code responsible for setting up the basic environment to allow the normal kernelstartup_32code to proceed. It is also responsible for properly waking and handling the APs on Intel platforms. The routinesl_mainwhich runs after entering 64b mode is responsible for measuring configuration and module information before it is used like the boot params, the kernel command line, the TXT heap, an external initramfs, etc.Signed-off-by Ross Philipson <[email protected]>--- Documentation/arch/x86/boot.rst | 21 + arch/x86/boot/compressed/Makefile | 3 +- arch/x86/boot/compressed/head_64.S | 34 ++ arch/x86/boot/compressed/kernel_info.S | 34 ++ arch/x86/boot/compressed/sl_main.c | 582 ++++++++++++++++++++ arch/x86/boot/compressed/sl_stub.S | 705 +++++++++++++++++++++++++ arch/x86/include/asm/msr-index.h | 5 + arch/x86/include/uapi/asm/bootparam.h | 1 + arch/x86/kernel/asm-offsets.c | 20 + 9 files changed, 1404 insertions(+), 1 deletion(-)create mode 100644
arch/x86/boot/compressed/sl_main.ccreate mode 100644arch/x86/boot/compressed/sl_stub.SDocumentation/arch/x86/boot.rst +0
-0@@ -482,6 +482,14 @@ Protocol: 2.00+ - If 1, KASLR enabled. - If 0, KASLR disabled.
Quoted 5 lines
Documentation/arch/x86/boot.rst Protocol: 2.00+ · line 487
Quoted 3 lines
Documentation/arch/x86/boot.rst +3
-0+ Bit 2 (kernel internal): SLAUNCH_FLAG + + - Used internally by the compressed kernel to communicatedecompressor
Yea or I will switch it to setup kernel to keep it consistent with other instances.
Quoted 51 lines
Quoted 51 lines
Documentation/arch/x86/boot.rst +18
-0+ Secure Launch status to kernel proper. + + - If 1, Secure Launch enabled. + - If 0, Secure Launch disabled. + Bit 5 (write): QUIET_FLAG - If 0, print early messages.@@ -1027,6 +1035,19 @@ Offset/size: 0x000c/4 This field contains maximal allowed type for setup_data and setup_indirect structs. +============ ================= +Field name: mle_header_offset +Offset/size: 0x0010/4 +============ ================= + + This field contains the offset to the Secure Launch Measured Launch Environment + (MLE) header. This offset is used to locate information needed during a secure + late launch using Intel TXT. If the offset is zero, the kernel does not have + Secure Launch capabilities. The MLE entry point is called from TXT on the BSP + following a success measured launch. The specific state of the processors is + outlined in the TXT Software Development Guide, the latest can be found here: + https://urldefense.com/v3/__https://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-txt-software-development-guide.pdf__;!!ACWV5N9M2RV99hQ!LHWSKdqHGtnUNYJyVgZfPeQnsg3uWmOJqKGAFDxrHk040zu928199hWhzHehPJzI9IkV4InNQZI5yIX4$ + The Image Checksum ==================arch/x86/boot/compressed/Makefile +2
-1@@ -118,7 +118,8 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o vmlinux-objs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a -vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/early_sha1.o $(obj)/early_sha256.o +vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/early_sha1.o $(obj)/early_sha256.o \ + $(obj)/sl_main.o $(obj)/sl_stub.o $(obj)/vmlinux: $(vmlinux-objs-y) FORCE $(call if_changed,ld)arch/x86/boot/compressed/head_64.S +0
-0@@ -415,6 +415,17 @@ SYM_CODE_START(startup_64) pushq $0 popfq
Quoted 3 lines
Quoted 3 lines
arch/x86/boot/compressed/head_64.S +2
-0+#ifdef CONFIG_SECURE_LAUNCH + pushq %rsi >> +This push and the associated pop are no longer needed.
Hmm, I thought I got rid of that when I saw boot params had been moved to r15. Will fix.
Quoted 4 lines
Quoted 2 lines
+ /* Ensure the relocation region coverd by a PMR */
'is covered'
Ack
Quoted 26 lines
Quoted 26 lines
arch/x86/boot/compressed/head_64.S +18
-0+ movq %rbx, %rdi + movl $(_bss - startup_32), %esi + callq sl_check_region + + popq %rsi +#endif + /* * Copy the compressed kernel to the end of our buffer * where decompression in place becomes safe.@@ -457,6 +468,29 @@ SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) shrq $3, %rcx rep stosq +#ifdef CONFIG_SECURE_LAUNCH + /* + * Have to do the final early sl stub work in 64b area. + * + * *********** NOTE *********** + * + * Several boot params get used before we get a chance to measure + * them in this call. This is a known issue and we currently don't + * have a solution. The scratch field doesn't matter. There is no + * obvious way to do anything about the use of kernel_alignment or + * init_size though these seem low risk with all the PMR and overlap
Quoted 8 lines
arch/x86/boot/compressed/head_64.S SYM_FUNC_START_LOCAL_NOALIGN(.Lrelocated) · line 487
Quoted 6 lines
arch/x86/boot/compressed/head_64.S +6
-0+ * checks in place. + */ + movq %r15, %rdi + callq sl_main + + /* Ensure the decompression location is coverd by a PMR */covered
Ack
Quoted 133 lines
Quoted 133 lines
arch/x86/boot/compressed/head_64.S +6
-0+ movq %rbp, %rdi + movq output_len(%rip), %rsi + callq sl_check_region +#endif + + pushq %rsi call load_stage2_idt /* Pass boot_params to initialize_identity_maps() */arch/x86/boot/compressed/kernel_info.S +34
-0@@ -28,6 +28,40 @@ SYM_DATA_START(kernel_info) /* Maximal allowed type for setup_data and setup_indirect structs. */ .long SETUP_TYPE_MAX + /* Offset to the MLE header structure */ +#if IS_ENABLED(CONFIG_SECURE_LAUNCH) + .long rva(mle_header) +#else + .long 0 +#endif + kernel_info_var_len_data: /* Empty for time being... */ SYM_DATA_END_LABEL(kernel_info, SYM_L_LOCAL, kernel_info_end) + +#if IS_ENABLED(CONFIG_SECURE_LAUNCH) + /* + * The MLE Header per the TXT Specification, section 2.1 + * MLE capabilities, see table 4. Capabilities set: + * bit 0: Support for GETSEC[WAKEUP] for RLP wakeup + * bit 1: Support for RLP wakeup using MONITOR address + * bit 2: The ECX register will contain the pointer to the MLE page table + * bit 5: TPM 1.2 family: Details/authorities PCR usage support + * bit 9: Supported format of TPM 2.0 event log - TCG compliant + */ +SYM_DATA_START(mle_header) + .long 0x9082ac5a /* UUID0 */ + .long 0x74a7476f /* UUID1 */ + .long 0xa2555c0f /* UUID2 */ + .long 0x42b651cb /* UUID3 */ + .long 0x00000034 /* MLE header size */ + .long 0x00020002 /* MLE version 2.2 */ + .long rva(sl_stub_entry) /* Linear entry point of MLE (virt. address) */ + .long 0x00000000 /* First valid page of MLE */ + .long 0x00000000 /* Offset within binary of first byte of MLE */ + .long rva(_edata) /* Offset within binary of last byte + 1 of MLE */ + .long 0x00000227 /* Bit vector of MLE-supported capabilities */ + .long 0x00000000 /* Starting linear address of command line (unused) */ + .long 0x00000000 /* Ending linear address of command line (unused) */ +SYM_DATA_END(mle_header) +#endifarch/x86/boot/compressed/sl_main.c new file +72
-0@@ -0,0 +1,582 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Secure Launch early measurement and validation routines. +* +* Copyright (c) 2022, Oracle and/or its affiliates. +*/ + +#include <linux/init.h> +#include <linux/string.h> +#include <linux/linkage.h> +#include <asm/segment.h> +#include <asm/boot.h> +#include <asm/msr.h> +#include <asm/mtrr.h> +#include <asm/processor-flags.h> +#include <asm/asm-offsets.h> +#include <asm/bootparam.h> +#include <asm/bootparam_utils.h> +#include <linux/slr_table.h> +#include <linux/slaunch.h> +#include <crypto/sha1.h> +#include <crypto/sha2.h> + +#define CAPS_VARIABLE_MTRR_COUNT_MASK 0xff + +#define SL_TPM12_LOG 1 +#define SL_TPM20_LOG 2 + +#define SL_TPM20_MAX_ALGS 2 + +#define SL_MAX_EVENT_DATA 64 +#define SL_TPM12_LOG_SIZE (sizeof(struct tcg_pcr_event) + \ + SL_MAX_EVENT_DATA) +#define SL_TPM20_LOG_SIZE (sizeof(struct tcg_pcr_event2_head) + \ + SHA1_DIGEST_SIZE + SHA256_DIGEST_SIZE + \ + sizeof(struct tcg_event_field) + \ + SL_MAX_EVENT_DATA) + +static void *evtlog_base; +static u32 evtlog_size; +static struct txt_heap_event_log_pointer2_1_element *log20_elem; +static u32 tpm_log_ver =SL_TPM12_LOG ; +static struct tcg_efi_specid_event_algs tpm_algs[SL_TPM20_MAX_ALGS ] = {0 }; + +extern u32 sl_cpu_type; +extern u32 sl_mle_start; + +static u64 sl_txt_read (u32 reg) +{ +return readq ((void *)(u64)(TXT_PRIV_CONFIG_REGS_BASE + reg)); +} + +static void sl_txt_write (u32 reg,u64 val) +{ +writeq (val, (void *)(u64)(TXT_PRIV_CONFIG_REGS_BASE + reg)); +} + +static void __noreturn sl_txt_reset (u64 error) +{ +/* Reading the E2STS register acts as a barrier for TXT registers */ +sl_txt_write (TXT_CR_ERRORCODE , error); +sl_txt_read (TXT_CR_E2STS ); +sl_txt_write (TXT_CR_CMD_UNLOCK_MEM_CONFIG ,1 ); +sl_txt_read (TXT_CR_E2STS ); +sl_txt_write (TXT_CR_CMD_RESET ,1 ); + +for ( ; ; ) + asmvolatile ("hlt" ); + +unreachable (); +} +
Quoted 8 lines
arch/x86/boot/compressed/sl_main.c line 78
Quoted 6 lines
arch/x86/boot/compressed/sl_main.c new file +6
-0+static u64 sl_rdmsr (u32 reg) +{ +u64 lo, hi; + + asmvolatile ("rdmsr" :"=a" (lo),"=d" (hi) :"c" (reg)); +No need for volatile.
Ok.
Thanks
Ross
Quoted 1,290 lines
Quoted 1,290 lines
arch/x86/boot/compressed/sl_main.c new file +504
-0+return (hi <<32 ) | lo; +} + +static struct slr_table *sl_locate_and_validate_slrt (void ) +{ +struct txt_os_mle_data *os_mle_data; +struct slr_table *slrt; +void *txt_heap; + + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + os_mle_data =txt_os_mle_data_start (txt_heap); + +if (!os_mle_data->slrt) +sl_txt_reset (SL_ERROR_INVALID_SLRT ); + + slrt = (struct slr_table *)os_mle_data->slrt; + +if (slrt->magic !=SLR_TABLE_MAGIC ) +sl_txt_reset (SL_ERROR_INVALID_SLRT ); + +if (slrt->architecture !=SLR_INTEL_TXT ) +sl_txt_reset (SL_ERROR_INVALID_SLRT ); + +return slrt; +} + +static void sl_check_pmr_coverage (void *base,u32 size,bool allow_hi) +{ +struct txt_os_sinit_data *os_sinit_data; +void *end = base + size; +void *txt_heap; + +if (!(sl_cpu_type &SL_CPU_INTEL )) +return ; + + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + os_sinit_data =txt_os_sinit_data_start (txt_heap); + +if ((end >= (void *)0x100000000ULL ) && (base < (void *)0x100000000ULL )) +sl_txt_reset (SL_ERROR_REGION_STRADDLE_4GB ); + +/* +* Note that the late stub code validates that the hi PMR covers +* all memory above 4G. At this point the code can only check that +* regions are within the hi PMR but that is sufficient. +*/ +if ((end > (void *)0x100000000ULL ) && (base >= (void *)0x100000000ULL )) { +if (allow_hi) { +if (end >= (void *)(os_sinit_data->vtd_pmr_hi_base + + os_sinit_data->vtd_pmr_hi_size)) +sl_txt_reset (SL_ERROR_BUFFER_BEYOND_PMR ); + }else { +sl_txt_reset (SL_ERROR_REGION_ABOVE_4GB ); + } + } + +if (end >= (void *)os_sinit_data->vtd_pmr_lo_size) +sl_txt_reset (SL_ERROR_BUFFER_BEYOND_PMR ); +} + +/* +* Some MSRs are modified by the pre-launch code including the MTRRs. +* The early MLE code has to restore these values. This code validates +* the values after they are measured. +*/ +static void sl_txt_validate_msrs (struct txt_os_mle_data *os_mle_data) +{ +struct slr_txt_mtrr_state *saved_bsp_mtrrs; +u64 mtrr_caps, mtrr_def_type, mtrr_var; +struct slr_entry_intel_info *txt_info; +u64 misc_en_msr; +u32 vcnt, i; + + txt_info = (struct slr_entry_intel_info *)os_mle_data->txt_info; + saved_bsp_mtrrs = &txt_info->saved_bsp_mtrrs; + + mtrr_caps =sl_rdmsr (MSR_MTRRcap); + vcnt = (u32)(mtrr_caps &CAPS_VARIABLE_MTRR_COUNT_MASK ); + +if (saved_bsp_mtrrs->mtrr_vcnt > vcnt) +sl_txt_reset (SL_ERROR_MTRR_INV_VCNT ); +if (saved_bsp_mtrrs->mtrr_vcnt >TXT_OS_MLE_MAX_VARIABLE_MTRRS ) +sl_txt_reset (SL_ERROR_MTRR_INV_VCNT ); + + mtrr_def_type =sl_rdmsr (MSR_MTRRdefType); +if (saved_bsp_mtrrs->default_mem_type != mtrr_def_type) +sl_txt_reset (SL_ERROR_MTRR_INV_DEF_TYPE ); + +for (i =0 ; i < saved_bsp_mtrrs->mtrr_vcnt; i++) { + mtrr_var =sl_rdmsr (MTRRphysBase_MSR (i)); +if (saved_bsp_mtrrs->mtrr_pair[i].mtrr_physbase != mtrr_var) +sl_txt_reset (SL_ERROR_MTRR_INV_BASE ); + mtrr_var =sl_rdmsr (MTRRphysMask_MSR (i)); +if (saved_bsp_mtrrs->mtrr_pair[i].mtrr_physmask != mtrr_var) +sl_txt_reset (SL_ERROR_MTRR_INV_MASK ); + } + + misc_en_msr =sl_rdmsr (MSR_IA32_MISC_ENABLE ); +if (txt_info->saved_misc_enable_msr != misc_en_msr) +sl_txt_reset (SL_ERROR_MSR_INV_MISC_EN ); +} + +static void sl_find_drtm_event_log (struct slr_table *slrt) +{ +struct txt_os_sinit_data *os_sinit_data; +struct slr_entry_log_info *log_info; +void *txt_heap; + + log_info = (struct slr_entry_log_info *) +slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_LOG_INFO ); +if (!log_info) +sl_txt_reset (SL_ERROR_SLRT_MISSING_ENTRY ); + + evtlog_base = (void *)log_info->addr; + evtlog_size = log_info->size; + + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + +/* +* For TPM 2.0, the event log 2.1 extended data structure has to also +* be located and fixed up. +*/ + os_sinit_data =txt_os_sinit_data_start (txt_heap); + +/* +* Only support version 6 and later that properly handle the +* list of ExtDataElements in the OS-SINIT structure. +*/ +if (os_sinit_data->version <6 ) +sl_txt_reset (SL_ERROR_OS_SINIT_BAD_VERSION ); + +/* Find the TPM2.0 logging extended heap element */ + log20_elem =tpm20_find_log2_1_element (os_sinit_data); + +/* If found, this implies TPM20 log and family */ +if (log20_elem) + tpm_log_ver =SL_TPM20_LOG ; +} + +static void sl_validate_event_log_buffer (void ) +{ +struct txt_os_sinit_data *os_sinit_data; +void *txt_heap, *txt_end; +void *mle_base, *mle_end; +void *evtlog_end; + +if ((u64 )evtlog_size > (LLONG_MAX - (u64 )evtlog_base)) +sl_txt_reset (SL_ERROR_INTEGER_OVERFLOW ); + evtlog_end = evtlog_base + evtlog_size; + + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + txt_end = txt_heap +sl_txt_read (TXT_CR_HEAP_SIZE ); + os_sinit_data =txt_os_sinit_data_start (txt_heap); + + mle_base = (void *)(u64 )sl_mle_start; + mle_end = mle_base + os_sinit_data->mle_size; + +/* +* This check is to ensure the event log buffer does not overlap with +* the MLE image. +*/ +if (evtlog_base >= mle_end && evtlog_end > mle_end) + goto pmr_check;/* above */ + +if (evtlog_end <= mle_base && evtlog_base < mle_base) + goto pmr_check;/* below */ + +sl_txt_reset (SL_ERROR_MLE_BUFFER_OVERLAP ); + +pmr_check: +/* +* The TXT heap is protected by the DPR. If the TPM event log is +* inside the TXT heap, there is no need for a PMR check. +*/ +if (evtlog_base > txt_heap && evtlog_end < txt_end) +return ; + +sl_check_pmr_coverage (evtlog_base, evtlog_size, true); +} + +static void sl_find_event_log_algorithms (void ) +{ +struct tcg_efi_specid_event_head *efi_head = + (struct tcg_efi_specid_event_head *)(evtlog_base + + log20_elem->first_record_offset + +sizeof (struct tcg_pcr_event )); + +if (efi_head->num_algs ==0 || efi_head->num_algs >2 ) +sl_txt_reset (SL_ERROR_TPM_NUMBER_ALGS ); + +memcpy (&tpm_algs[0 ], &efi_head->digest_sizes[0 ], +sizeof (struct tcg_efi_specid_event_algs ) * efi_head->num_algs); +} + +static void sl_tpm12_log_event (u32 pcr,u32 event_type, +const u8 *data,u32 length, +const u8 *event_data,u32 event_size) +{ +u8 sha1_hash[SHA1_DIGEST_SIZE ] = {0 }; +u8 log_buf[SL_TPM12_LOG_SIZE ] = {0 }; +struct tcg_pcr_event *pcr_event; +u32 total_size; + + pcr_event = (struct tcg_pcr_event *)log_buf; + pcr_event->pcr_idx = pcr; + pcr_event->event_type = event_type; +if (length >0 ) { +sha1 (data, length, &sha1_hash[0 ]); +memcpy (&pcr_event->digest[0 ], &sha1_hash[0 ],SHA1_DIGEST_SIZE ); + } + pcr_event->event_size = event_size; +if (event_size >0 ) +memcpy ((u8 *)pcr_event +sizeof (struct tcg_pcr_event ), + event_data, event_size); + + total_size =sizeof (struct tcg_pcr_event ) + event_size; + +if (tpm12_log_event (evtlog_base, evtlog_size, total_size, pcr_event)) +sl_txt_reset (SL_ERROR_TPM_LOGGING_FAILED ); +} + +static void sl_tpm20_log_event (u32 pcr,u32 event_type, +const u8 *data,u32 length, +const u8 *event_data,u32 event_size) +{ +u8 sha256_hash[SHA256_DIGEST_SIZE ] = {0 }; +u8 sha1_hash[SHA1_DIGEST_SIZE ] = {0 }; +u8 log_buf[SL_TPM20_LOG_SIZE ] = {0 }; +struct sha256_state sctx256 = {0 }; +struct tcg_pcr_event2_head *head; +struct tcg_event_field *event; +u32 total_size; +u16 *alg_ptr; +u8 *dgst_ptr; + + head = (struct tcg_pcr_event2_head *)log_buf; + head->pcr_idx = pcr; + head->event_type = event_type; + total_size =sizeof (struct tcg_pcr_event2_head ); + alg_ptr = (u16 *)(log_buf +sizeof (struct tcg_pcr_event2_head )); + +for ( ; head->count <2 ; head->count++) { +if (!tpm_algs[head->count].alg_id) +break ; + + *alg_ptr = tpm_algs[head->count].alg_id; + dgst_ptr = (u8 *)alg_ptr +sizeof (u16); + +if (tpm_algs[head->count].alg_id ==TPM_ALG_SHA256 && + length) { +sha256_init (&sctx256); +sha256_update (&sctx256, data, length); +sha256_final (&sctx256, &sha256_hash[0 ]); + }else if (tpm_algs[head->count].alg_id ==TPM_ALG_SHA1 && + length) { +sha1 (data, length, &sha1_hash[0 ]); + } + +if (tpm_algs[head->count].alg_id ==TPM_ALG_SHA256 ) { +memcpy (dgst_ptr, &sha256_hash[0 ],SHA256_DIGEST_SIZE ); + total_size +=SHA256_DIGEST_SIZE +sizeof (u16); + alg_ptr = (u16 *)((u8 *)alg_ptr +SHA256_DIGEST_SIZE +sizeof (u16)); + }else if (tpm_algs[head->count].alg_id ==TPM_ALG_SHA1 ) { +memcpy (dgst_ptr, &sha1_hash[0 ],SHA1_DIGEST_SIZE ); + total_size +=SHA1_DIGEST_SIZE +sizeof (u16); + alg_ptr = (u16 *)((u8 *)alg_ptr +SHA1_DIGEST_SIZE +sizeof (u16)); + }else { +sl_txt_reset (SL_ERROR_TPM_UNKNOWN_DIGEST ); + } + } + + event = (struct tcg_event_field *)(log_buf + total_size); + event->event_size = event_size; +if (event_size >0 ) +memcpy ((u8 *)event +sizeof (struct tcg_event_field ), event_data, event_size); + total_size +=sizeof (struct tcg_event_field ) + event_size; + +if (tpm20_log_event (log20_elem, evtlog_base, evtlog_size, total_size, &log_buf[0 ])) +sl_txt_reset (SL_ERROR_TPM_LOGGING_FAILED ); +} + +static void sl_tpm_extend_evtlog (u32 pcr,u32 type, +const u8 *data,u32 length,const char *desc) +{ +if (tpm_log_ver ==SL_TPM20_LOG ) +sl_tpm20_log_event (pcr, type, data, length, + (const u8 *)desc,strlen (desc)); +else +sl_tpm12_log_event (pcr, type, data, length, + (const u8 *)desc,strlen (desc)); +} + +static struct setup_data *sl_handle_setup_data (struct setup_data *curr, +struct slr_policy_entry *entry) +{ +struct setup_indirect *ind; +struct setup_data *next; + +if (!curr) +return NULL ; + + next = (struct setup_data *)(unsigned long )curr->next; + +/* SETUP_INDIRECT instances have to be handled differently */ +if (curr->type ==SETUP_INDIRECT ) { + ind = (struct setup_indirect *)((u8 *)curr + offsetof(struct setup_data , data)); + +sl_check_pmr_coverage ((void *)ind->addr, ind->len, true); + +sl_tpm_extend_evtlog (entry->pcr,TXT_EVTYPE_SLAUNCH , + (void *)ind->addr, ind->len, + entry->evt_info); + +return next; + } + +sl_check_pmr_coverage (((u8 *)curr) +sizeof (struct setup_data ), + curr->len, true); + +sl_tpm_extend_evtlog (entry->pcr,TXT_EVTYPE_SLAUNCH , + ((u8 *)curr) +sizeof (struct setup_data ), + curr->len, + entry->evt_info); + +return next; +} + +static void sl_extend_setup_data (struct slr_policy_entry *entry) +{ +struct setup_data *data; + +/* +* Measuring the boot params measured the fixed e820 memory map. +* Measure any setup_data entries including e820 extended entries. +*/ + data = (struct setup_data *)(unsigned long )entry->entity; +while (data) + data =sl_handle_setup_data (data, entry); +} + +static void sl_extend_slrt (struct slr_policy_entry *entry) +{ +struct slr_table *slrt = (struct slr_table *)entry->entity; +struct slr_entry_intel_info *intel_info; + +/* +* In revision one of the SLRT, the only table that needs to be +* measured is the Intel info table. Everything else is meta-data, +* addresses and sizes. Note the size of what to measure is not set. +* The flag SLR_POLICY_IMPLICIT_SIZE leaves it to the measuring code +* to sort out. +*/ +if (slrt->revision ==1 ) { + intel_info = (struct slr_entry_intel_info *)slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_INTEL_INFO ); +if (!intel_info) +sl_txt_reset (SL_ERROR_SLRT_MISSING_ENTRY ); + +sl_tpm_extend_evtlog (entry->pcr,TXT_EVTYPE_SLAUNCH , + (void *)entry->entity,sizeof (struct slr_entry_intel_info ), + entry->evt_info); + } +} + +static void sl_extend_txt_os2mle (struct slr_policy_entry *entry) +{ +struct txt_os_mle_data *os_mle_data; +void *txt_heap; + + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + os_mle_data =txt_os_mle_data_start (txt_heap); + +/* +* Version 1 of the OS-MLE heap structure has no fields to measure. It just +* has addresses and sizes and a scratch buffer. +*/ +if (os_mle_data->version ==1 ) +return ; +} + +static void sl_process_extend_policy (struct slr_table *slrt) +{ +struct slr_entry_policy *policy; +struct slr_policy_entry *entry; +u16 i; + + policy = (struct slr_entry_policy *)slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_ENTRY_POLICY ); +if (!policy) +sl_txt_reset (SL_ERROR_SLRT_MISSING_ENTRY ); + + entry = (struct slr_policy_entry *)((u8 *)policy +sizeof (*policy)); + +for (i =0 ; i < policy->nr_entries; i++, entry++) { +switch (entry->entity_type) { +case SLR_ET_SETUP_DATA : +sl_extend_setup_data (entry); +break ; +case SLR_ET_SLRT : +sl_extend_slrt (entry); +break ; +case SLR_ET_TXT_OS2MLE : +sl_extend_txt_os2mle (entry); +break ; +case SLR_ET_UNUSED : +continue ; +default : +sl_tpm_extend_evtlog (entry->pcr,TXT_EVTYPE_SLAUNCH , + (void *)entry->entity, entry->size, + entry->evt_info); + } + } +} + +static void sl_process_extend_uefi_config (struct slr_table *slrt) +{ +struct slr_entry_uefi_config *uefi_config; +struct slr_uefi_cfg_entry *uefi_entry; +u64 i; + + uefi_config =(struct slr_entry_uefi_config *)slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_UEFI_CONFIG ); + +/* Optionally here depending on how SL kernel was booted */ +if (!uefi_config) +return ; + + uefi_entry = (struct slr_uefi_cfg_entry *)((u8 *)uefi_config +sizeof (*uefi_config)); + +for (i =0 ; i < uefi_config->nr_entries; i++, uefi_entry++) { +sl_tpm_extend_evtlog (uefi_entry->pcr,TXT_EVTYPE_SLAUNCH , + (void *)uefi_entry->cfg, uefi_entry->size, + uefi_entry->evt_info); + } +} + +asmlinkage __visible void sl_check_region(void *base, u32 size) +{ +sl_check_pmr_coverage (base, size, false); +} + +asmlinkage __visible void sl_main(void *bootparams) +{ +struct boot_params *bp = (struct boot_params *)bootparams; +struct txt_os_mle_data *os_mle_data; +struct slr_table *slrt; +void *txt_heap; + +/* +* Ensure loadflags do not indicate a secure launch was done +* unless it really was. +*/ + bp->hdr.loadflags &= ~SLAUNCH_FLAG ; + +/* +* Currently only Intel TXT is supported for Secure Launch. Testing +* this value also indicates that the kernel was booted successfully +* through the Secure Launch entry point and is in SMX mode. +*/ +if (!(sl_cpu_type &SL_CPU_INTEL )) +return ; + + slrt =sl_locate_and_validate_slrt (); + +/* Locate the TPM event log. */ +sl_find_drtm_event_log (slrt); + +/* Validate the location of the event log buffer before using it */ +sl_validate_event_log_buffer (); + +/* +* Find the TPM hash algorithms used by the ACM and recorded in the +* event log. +*/ +if (tpm_log_ver ==SL_TPM20_LOG ) +sl_find_event_log_algorithms (); + +/* +* Sanitize them before measuring. Set the SLAUNCH_FLAG early since if +* anything fails, the system will reset anyway. +*/ +sanitize_boot_params (bp); + bp->hdr.loadflags |=SLAUNCH_FLAG ; + +sl_check_pmr_coverage (bootparams,PAGE_SIZE , false); + +/* Place event log SL specific tags before and after measurements */ +sl_tpm_extend_evtlog (17 ,TXT_EVTYPE_SLAUNCH_START ,NULL ,0 ,"" ); + +/* Process all policy entries and extend the measurements to the evtlog */ +sl_process_extend_policy (slrt); + +/* Process all EFI config entries and extend the measurements to the evtlog */ +sl_process_extend_uefi_config (slrt); + +sl_tpm_extend_evtlog (17 ,TXT_EVTYPE_SLAUNCH_END ,NULL ,0 ,"" ); + +/* No PMR check is needed, the TXT heap is covered by the DPR */ + txt_heap = (void *)sl_txt_read (TXT_CR_HEAP_BASE ); + os_mle_data =txt_os_mle_data_start (txt_heap); + +/* +* Now that the OS-MLE data is measured, ensure the MTRR and +* misc enable MSRs are what we expect. +*/ +sl_txt_validate_msrs (os_mle_data); +}arch/x86/boot/compressed/sl_stub.S new file +705
-0@@ -0,0 +1,705 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Secure Launch protected mode entry point. + * + * Copyright (c) 2022, Oracle and/or its affiliates. + */ + .code32 + .text +#include <linux/linkage.h> +#include <asm/segment.h> +#include <asm/msr.h> +#include <asm/apicdef.h> +#include <asm/trapnr.h> +#include <asm/processor-flags.h> +#include <asm/asm-offsets.h> +#include <asm/bootparam.h> +#include <asm/page_types.h> +#include <asm/irq_vectors.h> +#include <linux/slr_table.h> +#include <linux/slaunch.h> + +/* CPUID: leaf 1, ECX, SMX feature bit */ +#define X86_FEATURE_BIT_SMX (1 << 6) + +#define IDT_VECTOR_LO_BITS 0 +#define IDT_VECTOR_HI_BITS 6 + +/* + * See the comment in head_64.S for detailed information on what this macro + * and others like it are used for. The comment appears right at the top of + * the file. + */ +#define rva(X) ((X) - sl_stub_entry) + +/* + * The GETSEC op code is open coded because older versions of + * GCC do not support the getsec mnemonic. + */ +.macro GETSEC leaf + pushl %ebx + xorl %ebx, %ebx /* Must be zero for SMCTRL */ + movl \leaf, %eax /* Leaf function */ + .byte 0x0f, 0x37 /* GETSEC opcode */ + popl %ebx +.endm + +.macro TXT_RESET error + /* + * Set a sticky error value and reset. Note the movs to %eax act as + * TXT register barriers. + */ + movl \error, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ERRORCODE) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_NO_SECRETS) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_UNLOCK_MEM_CONFIG) + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_E2STS), %eax + movl $1, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_CMD_RESET) +1: + hlt + jmp 1b +.endm + + .code32 +SYM_FUNC_START(sl_stub_entry) + cli + cld + + /* + * On entry, %ebx has the entry abs offset to sl_stub_entry. This + * will be correctly scaled using the rva macro and avoid causing + * relocations. Only %cs and %ds segments are known good. + */ + + /* Load GDT, set segment regs and lret to __SL32_CS */ + leal rva(sl_gdt_desc)(%ebx), %eax + addl %eax, 2(%eax) + lgdt (%eax) + + movl $(__SL32_DS), %eax + movw %ax, %ds + movw %ax, %es + movw %ax, %fs + movw %ax, %gs + movw %ax, %ss + + /* + * Now that %ss is known good, take the first stack for the BSP. The + * AP stacks are only used on Intel. + */ + leal rva(sl_stacks_end)(%ebx), %esp + + leal rva(.Lsl_cs)(%ebx), %eax + pushl $(__SL32_CS) + pushl %eax + lret + +.Lsl_cs: + /* Save our base pointer reg and page table for MLE */ + pushl %ebx + pushl %ecx + + /* See if SMX feature is supported. */ + movl $1, %eax + cpuid + testl $(X86_FEATURE_BIT_SMX), %ecx + jz .Ldo_unknown_cpu + + popl %ecx + popl %ebx + + /* Know it is Intel */ + movl $(SL_CPU_INTEL), rva(sl_cpu_type)(%ebx) + + /* Locate the base of the MLE using the page tables in %ecx */ + call sl_find_mle_base + + /* Increment CPU count for BSP */ + incl rva(sl_txt_cpu_count)(%ebx) + + /* + * Enable SMI with GETSEC[SMCTRL] which were disabled by SENTER. + * NMIs were also disabled by SENTER. Since there is no IDT for the BSP, + * allow the mainline kernel re-enable them in the normal course of + * booting. + */ + GETSEC $(SMX_X86_GETSEC_SMCTRL) + + /* Clear the TXT error registers for a clean start of day */ + movl $0, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ERRORCODE) + movl $0xffffffff, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_ESTS) + + /* On Intel, the zero page address is passed in the TXT heap */ + /* Read physical base of heap into EAX */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* Read the size of the BIOS data into ECX (first 8 bytes) */ + movl (%eax), %ecx + /* Skip over BIOS data and size of OS to MLE data section */ + leal 8(%eax, %ecx), %eax + + /* Need to verify the values in the OS-MLE struct passed in */ + call sl_txt_verify_os_mle_struct + + /* + * Get the boot params address from the heap. Note %esi and %ebx MUST + * be preserved across calls and operations. + */ + movl SL_boot_params_addr(%eax), %esi + + /* Save %ebx so the APs can find their way home */ + movl %ebx, (SL_mle_scratch + SL_SCRATCH_AP_EBX)(%eax) + + /* Fetch the AP wake code block address from the heap */ + movl SL_ap_wake_block(%eax), %edi + movl %edi, rva(sl_txt_ap_wake_block)(%ebx) + + /* Store the offset in the AP wake block to the jmp address */ + movl $(sl_ap_jmp_offset - sl_txt_ap_wake_begin), \ + (SL_mle_scratch + SL_SCRATCH_AP_JMP_OFFSET)(%eax) + + /* Store the offset in the AP wake block to the AP stacks block */ + movl $(sl_stacks - sl_txt_ap_wake_begin), \ + (SL_mle_scratch + SL_SCRATCH_AP_STACKS_OFFSET)(%eax) + + /* %eax still is the base of the OS-MLE block, save it */ + pushl %eax + + /* Relocate the AP wake code to the safe block */ + call sl_txt_reloc_ap_wake + + /* + * Wake up all APs that are blocked in the ACM and wait for them to + * halt. This should be done before restoring the MTRRs so the ACM is + * still properly in WB memory. + */ + call sl_txt_wake_aps + + /* Restore OS-MLE in %eax */ + popl %eax + + /* + * %edi is used by this routine to find the MTRRs which are in the SLRT + * in the Intel info. + */ + movl SL_txt_info(%eax), %edi + call sl_txt_load_regs + + jmp .Lcpu_setup_done + +.Ldo_unknown_cpu: + /* Non-Intel CPUs are not yet supported */ + ud2 + +.Lcpu_setup_done: + /* + * Don't enable MCE at this point. The kernel will enable + * it on the BSP later when it is ready. + */ + + /* Done, jump to normal 32b pm entry */ + jmp startup_32 +SYM_FUNC_END(sl_stub_entry) + +SYM_FUNC_START(sl_find_mle_base) + /* %ecx has PDPT, get first PD */ + movl (%ecx), %eax + andl $(PAGE_MASK), %eax + /* Get first PT from first PDE */ + movl (%eax), %eax + andl $(PAGE_MASK), %eax + /* Get MLE base from first PTE */ + movl (%eax), %eax + andl $(PAGE_MASK), %eax + + movl %eax, rva(sl_mle_start)(%ebx) + ret +SYM_FUNC_END(sl_find_mle_base) + +SYM_FUNC_START(sl_check_buffer_mle_overlap) + /* %ecx: buffer begin %edx: buffer end */ + /* %ebx: MLE begin %edi: MLE end */ + + cmpl %edi, %ecx + jb .Lnext_check + cmpl %edi, %edx + jbe .Lnext_check + jmp .Lvalid /* Buffer above MLE */ + +.Lnext_check: + cmpl %ebx, %edx + ja .Linvalid + cmpl %ebx, %ecx + jae .Linvalid + jmp .Lvalid /* Buffer below MLE */ + +.Linvalid: + TXT_RESET $(SL_ERROR_MLE_BUFFER_OVERLAP) + +.Lvalid: + ret +SYM_FUNC_END(sl_check_buffer_mle_overlap) + +SYM_FUNC_START(sl_txt_verify_os_mle_struct) + pushl %ebx + /* + * %eax points to the base of the OS-MLE struct. Need to also + * read some values from the OS-SINIT struct too. + */ + movl -8(%eax), %ecx + /* Skip over OS to MLE data section and size of OS-SINIT structure */ + leal (%eax, %ecx), %edx + + /* Load MLE image base absolute offset */ + movl rva(sl_mle_start)(%ebx), %ebx + + /* Verify the value of the low PMR base. It should always be 0. */ + movl SL_vtd_pmr_lo_base(%edx), %esi + cmpl $0, %esi + jz .Lvalid_pmr_base + TXT_RESET $(SL_ERROR_LO_PMR_BASE) + +.Lvalid_pmr_base: + /* Grab some values from OS-SINIT structure */ + movl SL_mle_size(%edx), %edi + addl %ebx, %edi + jc .Loverflow_detected + movl SL_vtd_pmr_lo_size(%edx), %esi + + /* Check the AP wake block */ + movl SL_ap_wake_block(%eax), %ecx + movl SL_ap_wake_block_size(%eax), %edx + addl %ecx, %edx + jc .Loverflow_detected + call sl_check_buffer_mle_overlap + cmpl %esi, %edx + ja .Lbuffer_beyond_pmr + + /* Check the boot params */ + movl SL_boot_params_addr(%eax), %ecx + movl $(PAGE_SIZE), %edx + addl %ecx, %edx + jc .Loverflow_detected + call sl_check_buffer_mle_overlap + cmpl %esi, %edx + ja .Lbuffer_beyond_pmr + + /* Check that the AP wake block is big enough */ + cmpl $(sl_txt_ap_wake_end - sl_txt_ap_wake_begin), \ + SL_ap_wake_block_size(%eax) + jae .Lwake_block_ok + TXT_RESET $(SL_ERROR_WAKE_BLOCK_TOO_SMALL) + +.Lwake_block_ok: + popl %ebx + ret + +.Loverflow_detected: + TXT_RESET $(SL_ERROR_INTEGER_OVERFLOW) + +.Lbuffer_beyond_pmr: + TXT_RESET $(SL_ERROR_BUFFER_BEYOND_PMR) +SYM_FUNC_END(sl_txt_verify_os_mle_struct) + +SYM_FUNC_START(sl_txt_ap_entry) + cli + cld + /* + * The %cs and %ds segments are known good after waking the AP. + * First order of business is to find where we are and + * save it in %ebx. + */ + + /* Read physical base of heap into EAX */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* Read the size of the BIOS data into ECX (first 8 bytes) */ + movl (%eax), %ecx + /* Skip over BIOS data and size of OS to MLE data section */ + leal 8(%eax, %ecx), %eax + + /* Saved %ebx from the BSP and stash OS-MLE pointer */ + movl (SL_mle_scratch + SL_SCRATCH_AP_EBX)(%eax), %ebx + + /* Save TXT info ptr in %edi for call to sl_txt_load_regs */ + movl SL_txt_info(%eax), %edi + + /* Lock and get our stack index */ + movl $1, %ecx +.Lspin: + xorl %eax, %eax + lock cmpxchgl %ecx, rva(sl_txt_spin_lock)(%ebx) + pause + jnz .Lspin + + /* Increment the stack index and use the next value inside lock */ + incl rva(sl_txt_stack_index)(%ebx) + movl rva(sl_txt_stack_index)(%ebx), %eax + + /* Unlock */ + movl $0, rva(sl_txt_spin_lock)(%ebx) + + /* Location of the relocated AP wake block */ + movl rva(sl_txt_ap_wake_block)(%ebx), %ecx + + /* Load reloc GDT, set segment regs and lret to __SL32_CS */ + lgdt (sl_ap_gdt_desc - sl_txt_ap_wake_begin)(%ecx) + + movl $(__SL32_DS), %edx + movw %dx, %ds + movw %dx, %es + movw %dx, %fs + movw %dx, %gs + movw %dx, %ss + + /* Load our reloc AP stack */ + movl $(TXT_BOOT_STACK_SIZE), %edx + mull %edx + leal (sl_stacks_end - sl_txt_ap_wake_begin)(%ecx), %esp + subl %eax, %esp + + /* Switch to AP code segment */ + leal rva(.Lsl_ap_cs)(%ebx), %eax + pushl $(__SL32_CS) + pushl %eax + lret + +.Lsl_ap_cs: + /* Load the relocated AP IDT */ + lidt (sl_ap_idt_desc - sl_txt_ap_wake_begin)(%ecx) + + /* Fixup MTRRs and misc enable MSR on APs too */ + call sl_txt_load_regs + + /* Enable SMI with GETSEC[SMCTRL] */ + GETSEC $(SMX_X86_GETSEC_SMCTRL) + + /* IRET-to-self can be used to enable NMIs which SENTER disabled */ + leal rva(.Lnmi_enabled_ap)(%ebx), %eax + pushfl + pushl $(__SL32_CS) + pushl %eax + iret + +.Lnmi_enabled_ap: + /* Put APs in X2APIC mode like the BSP */ + movl $(MSR_IA32_APICBASE), %ecx + rdmsr + orl $(XAPIC_ENABLE | X2APIC_ENABLE), %eax + wrmsr + + /* + * Basically done, increment the CPU count and jump off to the AP + * wake block to wait. + */ + lock incl rva(sl_txt_cpu_count)(%ebx) + + movl rva(sl_txt_ap_wake_block)(%ebx), %eax + jmp *%eax +SYM_FUNC_END(sl_txt_ap_entry) + +SYM_FUNC_START(sl_txt_reloc_ap_wake) + /* Save boot params register */ + pushl %esi + + movl rva(sl_txt_ap_wake_block)(%ebx), %edi + + /* Fixup AP IDT and GDT descriptor before relocating */ + leal rva(sl_ap_idt_desc)(%ebx), %eax + addl %edi, 2(%eax) + leal rva(sl_ap_gdt_desc)(%ebx), %eax + addl %edi, 2(%eax) + + /* + * Copy the AP wake code and AP GDT/IDT to the protected wake block + * provided by the loader. Destination already in %edi. + */ + movl $(sl_txt_ap_wake_end - sl_txt_ap_wake_begin), %ecx + leal rva(sl_txt_ap_wake_begin)(%ebx), %esi + rep movsb + + /* Setup the IDT for the APs to use in the relocation block */ + movl rva(sl_txt_ap_wake_block)(%ebx), %ecx + addl $(sl_ap_idt - sl_txt_ap_wake_begin), %ecx + xorl %edx, %edx + + /* Form the default reset vector relocation address */ + movl rva(sl_txt_ap_wake_block)(%ebx), %esi + addl $(sl_txt_int_reset - sl_txt_ap_wake_begin), %esi + +1: + cmpw $(NR_VECTORS), %dx + jz .Lap_idt_done + + cmpw $(X86_TRAP_NMI), %dx + jz 2f + + /* Load all other fixed vectors with reset handler */ + movl %esi, %eax + movw %ax, (IDT_VECTOR_LO_BITS)(%ecx) + shrl $16, %eax + movw %ax, (IDT_VECTOR_HI_BITS)(%ecx) + jmp 3f + +2: + /* Load single wake NMI IPI vector at the relocation address */ + movl rva(sl_txt_ap_wake_block)(%ebx), %eax + addl $(sl_txt_int_nmi - sl_txt_ap_wake_begin), %eax + movw %ax, (IDT_VECTOR_LO_BITS)(%ecx) + shrl $16, %eax + movw %ax, (IDT_VECTOR_HI_BITS)(%ecx) + +3: + incw %dx + addl $8, %ecx + jmp 1b + +.Lap_idt_done: + popl %esi + ret +SYM_FUNC_END(sl_txt_reloc_ap_wake) + +SYM_FUNC_START(sl_txt_load_regs) + /* Save base pointer register */ + pushl %ebx + + /* + * On Intel, the original variable MTRRs and Misc Enable MSR are + * restored on the BSP at early boot. Each AP will also restore + * its MTRRs and Misc Enable MSR. + */ + pushl %edi + addl $(SL_saved_bsp_mtrrs), %edi + movl (%edi), %ebx + pushl %ebx /* default_mem_type lo */ + addl $4, %edi + movl (%edi), %ebx + pushl %ebx /* default_mem_type hi */ + addl $4, %edi + movl (%edi), %ebx /* mtrr_vcnt lo, don't care about hi part */ + addl $8, %edi /* now at MTRR pair array */ + /* Write the variable MTRRs */ + movl $(MSR_MTRRphysBase0), %ecx +1: + cmpl $0, %ebx + jz 2f + + movl (%edi), %eax /* MTRRphysBaseX lo */ + addl $4, %edi + movl (%edi), %edx /* MTRRphysBaseX hi */ + wrmsr + addl $4, %edi + incl %ecx + movl (%edi), %eax /* MTRRphysMaskX lo */ + addl $4, %edi + movl (%edi), %edx /* MTRRphysMaskX hi */ + wrmsr + addl $4, %edi + incl %ecx + + decl %ebx + jmp 1b +2: + /* Write the default MTRR register */ + popl %edx + popl %eax + movl $(MSR_MTRRdefType), %ecx + wrmsr + + /* Return to beginning and write the misc enable msr */ + popl %edi + addl $(SL_saved_misc_enable_msr), %edi + movl (%edi), %eax /* saved_misc_enable_msr lo */ + addl $4, %edi + movl (%edi), %edx /* saved_misc_enable_msr hi */ + movl $(MSR_IA32_MISC_ENABLE), %ecx + wrmsr + + popl %ebx + ret +SYM_FUNC_END(sl_txt_load_regs) + +SYM_FUNC_START(sl_txt_wake_aps) + /* Save boot params register */ + pushl %esi + + /* First setup the MLE join structure and load it into TXT reg */ + leal rva(sl_gdt)(%ebx), %eax + leal rva(sl_txt_ap_entry)(%ebx), %ecx + leal rva(sl_smx_rlp_mle_join)(%ebx), %edx + movl %eax, SL_rlp_gdt_base(%edx) + movl %ecx, SL_rlp_entry_point(%edx) + movl %edx, (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_MLE_JOIN) + + /* Another TXT heap walk to find various values needed to wake APs */ + movl (TXT_PRIV_CONFIG_REGS_BASE + TXT_CR_HEAP_BASE), %eax + /* At BIOS data size, find the number of logical processors */ + movl (SL_num_logical_procs + 8)(%eax), %edx + /* Skip over BIOS data */ + movl (%eax), %ecx + addl %ecx, %eax + /* Skip over OS to MLE */ + movl (%eax), %ecx + addl %ecx, %eax + /* At OS-SNIT size, get capabilities to know how to wake up the APs */ + movl (SL_capabilities + 8)(%eax), %esi + /* Skip over OS to SNIT */ + movl (%eax), %ecx + addl %ecx, %eax + /* At SINIT-MLE size, get the AP wake MONITOR address */ + movl (SL_rlp_wakeup_addr + 8)(%eax), %edi + + /* Determine how to wake up the APs */ + testl $(1 << TXT_SINIT_MLE_CAP_WAKE_MONITOR), %esi + jz .Lwake_getsec + + /* Wake using MWAIT MONITOR */ + movl $1, (%edi) + jmp .Laps_awake + +.Lwake_getsec: + /* Wake using GETSEC(WAKEUP) */ + GETSEC $(SMX_X86_GETSEC_WAKEUP) + +.Laps_awake: + /* + * All of the APs are woken up and rendesvous in the relocated wake + * block starting at sl_txt_ap_wake_begin. Wait for all of them to + * halt. + */ + pause + cmpl rva(sl_txt_cpu_count)(%ebx), %edx + jne .Laps_awake + + popl %esi + ret +SYM_FUNC_END(sl_txt_wake_aps) + +/* This is the beginning of the relocated AP wake code block */ + .global sl_txt_ap_wake_begin +sl_txt_ap_wake_begin: + + /* Get the LAPIC ID for each AP and stash it on the stack */ + movl $(MSR_IA32_X2APIC_APICID), %ecx + rdmsr + pushl %eax + + /* + * Get a pointer to the monitor location on this APs stack to test below + * after mwait returns. Currently %esp points to just past the pushed APIC + * ID value. + */ + movl %esp, %eax + subl $(TXT_BOOT_STACK_SIZE - 4), %eax + movl $0, (%eax) + + /* Clear ecx/edx so no invalid extensions or hints are passed to monitor */ + xorl %ecx, %ecx + xorl %edx, %edx + + /* + * Arm the monitor and wait for it to be poked by he SMP bringup code. The mwait + * instruction can return for a number of reasons. Test to see if it returned + * because the monitor was written to. + */ + monitor + +1: + mfence + mwait + movl (%eax), %edx + testl %edx, %edx + jz 1b + + /* + * This is the long absolute jump to the 32b Secure Launch protected mode stub + * code in sl_trampoline_start32() in the rmpiggy. The jump address will be + * fixed in the SMP boot code when the first AP is brought up. This whole area + * is provided and protected in the memory map by the prelaunch code. + */ + .byte 0xea +sl_ap_jmp_offset: + .long 0x00000000 + .word __SL32_CS + +SYM_FUNC_START(sl_txt_int_nmi) + /* NMI context, just IRET */ + iret +SYM_FUNC_END(sl_txt_int_nmi) + +SYM_FUNC_START(sl_txt_int_reset) + TXT_RESET $(SL_ERROR_INV_AP_INTERRUPT) +SYM_FUNC_END(sl_txt_int_reset) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_idt_desc) + .word sl_ap_idt_end - sl_ap_idt - 1 /* Limit */ + .long sl_ap_idt - sl_txt_ap_wake_begin /* Base */ +SYM_DATA_END_LABEL(sl_ap_idt_desc, SYM_L_LOCAL, sl_ap_idt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_idt) + .rept NR_VECTORS + .word 0x0000 /* Offset 15 to 0 */ + .word __SL32_CS /* Segment selector */ + .word 0x8e00 /* Present, DPL=0, 32b Vector, Interrupt */ + .word 0x0000 /* Offset 31 to 16 */ + .endr +SYM_DATA_END_LABEL(sl_ap_idt, SYM_L_LOCAL, sl_ap_idt_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_gdt_desc) + .word sl_ap_gdt_end - sl_ap_gdt - 1 + .long sl_ap_gdt - sl_txt_ap_wake_begin +SYM_DATA_END_LABEL(sl_ap_gdt_desc, SYM_L_LOCAL, sl_ap_gdt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_ap_gdt) + .quad 0x0000000000000000 /* NULL */ + .quad 0x00cf9a000000ffff /* __SL32_CS */ + .quad 0x00cf92000000ffff /* __SL32_DS */ +SYM_DATA_END_LABEL(sl_ap_gdt, SYM_L_LOCAL, sl_ap_gdt_end) + + /* Small stacks for BSP and APs to work with */ + .balign 64 +SYM_DATA_START_LOCAL(sl_stacks) + .fill (TXT_MAX_CPUS * TXT_BOOT_STACK_SIZE), 1, 0 +SYM_DATA_END_LABEL(sl_stacks, SYM_L_LOCAL, sl_stacks_end) + +/* This is the end of the relocated AP wake code block */ + .global sl_txt_ap_wake_end +sl_txt_ap_wake_end: + + .data + .balign 8 +SYM_DATA_START_LOCAL(sl_gdt_desc) + .word sl_gdt_end - sl_gdt - 1 + .long sl_gdt - sl_gdt_desc +SYM_DATA_END_LABEL(sl_gdt_desc, SYM_L_LOCAL, sl_gdt_desc_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_gdt) + .quad 0x0000000000000000 /* NULL */ + .quad 0x00cf9a000000ffff /* __SL32_CS */ + .quad 0x00cf92000000ffff /* __SL32_DS */ +SYM_DATA_END_LABEL(sl_gdt, SYM_L_LOCAL, sl_gdt_end) + + .balign 8 +SYM_DATA_START_LOCAL(sl_smx_rlp_mle_join) + .long sl_gdt_end - sl_gdt - 1 /* GDT limit */ + .long 0x00000000 /* GDT base */ + .long __SL32_CS /* Seg Sel - CS (DS, ES, SS = seg_sel+8) */ + .long 0x00000000 /* Entry point physical address */ +SYM_DATA_END(sl_smx_rlp_mle_join) + +SYM_DATA(sl_cpu_type, .long 0x00000000) + +SYM_DATA(sl_mle_start, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_spin_lock, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_stack_index, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_cpu_count, .long 0x00000000) + +SYM_DATA_LOCAL(sl_txt_ap_wake_block, .long 0x00000000)arch/x86/include/asm/msr-index.h +5
-0@@ -323,6 +323,9 @@#define MSR_IA32_RTIT_OUTPUT_BASE 0x00000560#define MSR_IA32_RTIT_OUTPUT_MASK 0x00000561 +#define MSR_MTRRphysBase0 0x00000200 +#define MSR_MTRRphysMask0 0x00000201 +#define MSR_MTRRfix64K_00000 0x00000250#define MSR_MTRRfix16K_80000 0x00000258#define MSR_MTRRfix16K_A0000 0x00000259@@ -804,6 +807,8 @@#define MSR_IA32_APICBASE_ENABLE (1<<11)#define MSR_IA32_APICBASE_BASE (0xfffff<<12) +#define MSR_IA32_X2APIC_APICID 0x00000802 +#define MSR_IA32_UCODE_WRITE 0x00000079#define MSR_IA32_UCODE_REV 0x0000008barch/x86/include/uapi/asm/bootparam.h +1
-0@@ -26,6 +26,7 @@/* loadflags */ #define LOADED_HIGH (1<<0)#define KASLR_FLAG (1<<1) +#define SLAUNCH_FLAG (1<<2)#define QUIET_FLAG (1<<5)#define KEEP_SEGMENTS (1<<6)#define CAN_USE_HEAP (1<<7)arch/x86/kernel/asm-offsets.c +20
-1@@ -13,6 +13,8 @@#include <linux/hardirq.h> #include <linux/suspend.h> #include <linux/kbuild.h> +#include <linux/slr_table.h> +#include <linux/slaunch.h> #include <asm/processor.h> #include <asm/thread_info.h> #include <asm/sigframe.h> @@ -120,4 +122,22 @@ static void __used common(void)OFFSET (ARIA_CTX_rounds, aria_ctx, rounds);#endif +#ifdef CONFIG_SECURE_LAUNCH +BLANK (); +OFFSET (SL_txt_info, txt_os_mle_data, txt_info); +OFFSET (SL_mle_scratch, txt_os_mle_data, mle_scratch); +OFFSET (SL_boot_params_addr, txt_os_mle_data, boot_params_addr); +OFFSET (SL_ap_wake_block, txt_os_mle_data, ap_wake_block); +OFFSET (SL_ap_wake_block_size, txt_os_mle_data, ap_wake_block_size); +OFFSET (SL_saved_misc_enable_msr, slr_entry_intel_info, saved_misc_enable_msr); +OFFSET (SL_saved_bsp_mtrrs, slr_entry_intel_info, saved_bsp_mtrrs); +OFFSET (SL_num_logical_procs, txt_bios_data, num_logical_procs); +OFFSET (SL_capabilities, txt_os_sinit_data, capabilities); +OFFSET (SL_mle_size, txt_os_sinit_data, mle_size); +OFFSET (SL_vtd_pmr_lo_base, txt_os_sinit_data, vtd_pmr_lo_base); +OFFSET (SL_vtd_pmr_lo_size, txt_os_sinit_data, vtd_pmr_lo_size); +OFFSET (SL_rlp_wakeup_addr, txt_sinit_mle_data, rlp_wakeup_addr); +OFFSET (SL_rlp_gdt_base, smx_rlp_mle_join, rlp_gdt_base); +OFFSET (SL_rlp_entry_point, smx_rlp_mle_join, rlp_entry_point); +#endif } --2.39.3
PATCH v8 8/15 x86: Secure Launch kernel late boot stub
In reply to Ross PhilipsonThe routine slaunch_setup is called out of the x86 specific setup_arch() routine during early kernel boot. After determining what platform is present, various operations specific to that platform occur. This includes finalizing setting for the platform late launch and verifying that memory protections are in place.
For TXT, this code also reserves the original compressed kernel setup area where the APs were left looping so that this memory cannot be used.
--- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/setup.c | 3 + arch/x86/kernel/slaunch.c | 525 +++++++++++++++++++++++++++++++++++++ drivers/iommu/intel/dmar.c | 4 + 4 files changed, 533 insertions(+) create mode 100644 arch/x86/kernel/slaunch.c
arch/x86/kernel/Makefile +1 -0
@@ -74,6 +74,7 @@ obj-$(CONFIG_X86_32) += tls.o obj-$(CONFIG_IA32_EMULATION) += tls.o obj-y += step.o obj-$(CONFIG_INTEL_TXT) += tboot.o +obj-$(CONFIG_SECURE_LAUNCH) += slaunch.o obj-$(CONFIG_ISA_DMA_API) += i8237.o obj-y += stacktrace.o obj-y += cpu/
arch/x86/kernel/setup.c +3 -0
@@ -21,6 +21,7 @@#include <linux/root_dev.h> #include <linux/hugetlb.h> #include <linux/tboot.h> +#include <linux/slaunch.h> #include <linux/usb/xhci-dbgp.h> #include <linux/static_call.h> #include <linux/swiotlb.h>
@@ -935,6 +936,8 @@ void __init setup_arch(char **cmdline_p)early_gart_iommu_check ();#endif +slaunch_setup_txt (); +/* * partially used pages are not usable - thus * we are rounding upwards:
arch/x86/kernel/slaunch.c new file +525 -0
525 lines not on this page · raw message
drivers/iommu/intel/dmar.c +4 -0
@@ -28,6 +28,7 @@#include <linux/iommu.h> #include <linux/numa.h> #include <linux/limits.h> +#include <linux/slaunch.h> #include <asm/irq_remapping.h> #include "iommu.h"
@@ -660,6 +661,9 @@ parse_dmar_table(void)*/ dmar_tbl =tboot_get_dmar_table (dmar_tbl); +/* If Secure Launch is active, it has similar logic */ + dmar_tbl =slaunch_get_dmar_table (dmar_tbl); + dmar = (struct acpi_table_dmar *)dmar_tbl;if (!dmar)return -ENODEV ;
Signature · 7 lines
2.39.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v8 9/15 x86: Secure Launch SMP bringup support
In reply to Ross PhilipsonOn Intel, the APs are left in a well documented state after TXT performs the late launch. Specifically they cannot have #INIT asserted on them so a standard startup via INIT/SIPI/SIPI cannot be performed. Instead the early SL stub code uses MONITOR and MWAIT to park the APs. The realmode/init.c code updates the jump address for the waiting APs with the location of the Secure Launch entry point in the RM piggy after it is loaded and fixed up. As the APs are woken up by writing the monitor, the APs jump to the Secure Launch entry point in the RM piggy which mimics what the real mode code would do then jumps to the standard RM piggy protected mode entry point.
--- arch/x86/include/asm/realmode.h | 3 ++ arch/x86/kernel/smpboot.c | 58 +++++++++++++++++++++++++++- arch/x86/realmode/init.c | 3 ++ arch/x86/realmode/rm/header.S | 3 ++ arch/x86/realmode/rm/trampoline_64.S | 32 +++++++++++++++ 5 files changed, 97 insertions(+), 2 deletions(-)
arch/x86/include/asm/realmode.h +3 -0
@@ -38,6 +38,9 @@ struct real_mode_header {#ifdef CONFIG_X86_64 u32 machine_real_restart_seg;#endif +#ifdef CONFIG_SECURE_LAUNCH +u32 sl_trampoline_start32; +#endif };/* This must match data at realmode/rm/trampoline_{32,64}.S */
arch/x86/kernel/smpboot.c +56 -2
87 lines not on this page · raw message
arch/x86/realmode/init.c +3 -0
@@ -4,6 +4,7 @@#include <linux/memblock.h> #include <linux/cc_platform.h> #include <linux/pgtable.h> +#include <linux/slaunch.h> #include <asm/set_memory.h> #include <asm/realmode.h>
@@ -210,6 +211,8 @@ void __init init_real_mode(void)setup_real_mode ();set_real_mode_permissions (); + +slaunch_fixup_jump_vector (); }static int __init do_init_real_mode (void )
arch/x86/realmode/rm/header.S +3 -0
@@ -37,6 +37,9 @@ SYM_DATA_START(real_mode_header) #ifdef CONFIG_X86_64 .long __KERNEL32_CS #endif +#ifdef CONFIG_SECURE_LAUNCH + .long pa_sl_trampoline_start32 +#endif SYM_DATA_END(real_mode_header) /* End signature, used to verify integrity */
arch/x86/realmode/rm/trampoline_64.S +32 -0
@@ -120,6 +120,38 @@ SYM_CODE_END(sev_es_trampoline_start) .section ".text32","ax" .code32 +#ifdef CONFIG_SECURE_LAUNCH + .balign 4 +SYM_CODE_START(sl_trampoline_start32) + /* + * The early secure launch stub AP wakeup code has taken care of all + * the vagaries of launching out of TXT. This bit just mimics what the + * 16b entry code does and jumps off to the real startup_32. + */ + cli + wbinvd + + /* + * The %ebx provided is not terribly useful since it is the physical + * address of tb_trampoline_start and not the base of the image. + * Use pa_real_mode_base, which is fixed up, to get a run time + * base register to use for offsets to location that do not have + * pa_ symbols. + */ + movl $pa_real_mode_base, %ebx + + LOCK_AND_LOAD_REALMODE_ESP lock_pa=1 + + lgdt tr_gdt(%ebx) + lidt tr_idt(%ebx) + + movw $__KERNEL_DS, %dx # Data segment descriptor + + /* Jump to where the 16b code would have jumped */ + ljmpl $__KERNEL32_CS, $pa_startup_32 +SYM_CODE_END(sl_trampoline_start32) +#endif + .balign 4 SYM_CODE_START(startup_32) movl %edx, %ss
Signature · 7 lines
2.39.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v8 10/15 kexec: Secure Launch kexec SEXIT support
In reply to Ross PhilipsonPrior to running the next kernel via kexec, the Secure Launch code closes down private SMX resources and does an SEXIT. This allows the next kernel to start normally without any issues starting the APs etc.
--- arch/x86/kernel/slaunch.c | 73 +++++++++++++++++++++++++++++++++++++++ kernel/kexec_core.c | 4 +++ 2 files changed, 77 insertions(+)
arch/x86/kernel/slaunch.c +73 -0
@@ -523,3 +523,76 @@ void __init slaunch_setup_txt(void)pr_info ("Intel TXT setup complete\n" ); } + +static inline void smx_getsec_sexit (void ) +{ + asmvolatile ("getsec\n" + : :"a" (SMX_X86_GETSEC_SEXIT )); +} + +/* +* Used during kexec and on reboot paths to finalize the TXT state +* and do an SEXIT exiting the DRTM and disabling SMX mode. +*/ +void slaunch_finalize (int do_sexit) +{ +u64 one =TXT_REGVALUE_ONE , val; +void __iomem *config; + +if ((slaunch_get_flags () & (SL_FLAG_ACTIVE |SL_FLAG_ARCH_TXT )) != + (SL_FLAG_ACTIVE |SL_FLAG_ARCH_TXT )) +return ; + + config =ioremap (TXT_PRIV_CONFIG_REGS_BASE ,TXT_NR_CONFIG_PAGES * +PAGE_SIZE ); +if (!config) { +pr_emerg ("Error SEXIT failed to ioremap TXT private reqs\n" ); +return ; + } + +/* Clear secrets bit for SEXIT */ +memcpy_toio (config +TXT_CR_CMD_NO_SECRETS , &one,sizeof (one)); +memcpy_fromio (&val, config +TXT_CR_E2STS ,sizeof (val)); + +/* Unlock memory configurations */ +memcpy_toio (config +TXT_CR_CMD_UNLOCK_MEM_CONFIG , &one,sizeof (one)); +memcpy_fromio (&val, config +TXT_CR_E2STS ,sizeof (val)); + +/* Close the TXT private register space */ +memcpy_toio (config +TXT_CR_CMD_CLOSE_PRIVATE , &one,sizeof (one)); +memcpy_fromio (&val, config +TXT_CR_E2STS ,sizeof (val)); + +/* +* Calls to iounmap are not being done because of the state of the +* system this late in the kexec process. Local IRQs are disabled and +* iounmap causes a TLB flush which in turn causes a warning. Leaving +* thse mappings is not an issue since the next kernel is going to +* completely re-setup memory management. +*/ + +/* Map public registers and do a final read fence */ + config =ioremap (TXT_PUB_CONFIG_REGS_BASE ,TXT_NR_CONFIG_PAGES * +PAGE_SIZE ); +if (!config) { +pr_emerg ("Error SEXIT failed to ioremap TXT public reqs\n" ); +return ; + } + +memcpy_fromio (&val, config +TXT_CR_E2STS ,sizeof (val)); + +pr_emerg ("TXT clear secrets bit and unlock memory complete.\n" ); + +if (!do_sexit) +return ; + +if (smp_processor_id () !=0 ) +panic ("Error TXT SEXIT must be called on CPU 0\n" ); + +/* In case SMX mode was disabled, enable it for SEXIT */ +cr4_set_bits (X86_CR4_SMXE ); + +/* Do the SEXIT SMX operation */ +smx_getsec_sexit (); + +pr_info ("TXT SEXIT complete.\n" ); +}
kernel/kexec_core.c +4 -0
@@ -40,6 +40,7 @@#include <linux/hugetlb.h> #include <linux/objtool.h> #include <linux/kmsg_dump.h> +#include <linux/slaunch.h> #include <asm/page.h> #include <asm/sections.h>
@@ -1268,6 +1269,9 @@ int kernel_kexec(void)cpu_hotplug_enable ();pr_notice ("Starting new kernel\n" );machine_shutdown (); + +/* Finalize TXT registers and do SEXIT */ +slaunch_finalize (1 ); }kmsg_dump (KMSG_DUMP_SHUTDOWN );
Signature · 7 lines
2.39.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v8 11/15 reboot: Secure Launch SEXIT support on reboot paths
In reply to Ross PhilipsonIf the MLE kernel is being powered off, rebooted or halted, then SEXIT must be called. Note that the SEXIT GETSEC leaf can only be called after a machine_shutdown() has been done on these paths. The machine_shutdown() is not called on a few paths like when poweroff action does not have a poweroff callback (into ACPI code) or when an emergency reset is done. In these cases, just the TXT registers are finalized but SEXIT is skipped.
--- arch/x86/kernel/reboot.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/x86/kernel/reboot.c +10 -0
@@ -12,6 +12,7 @@#include <linux/delay.h> #include <linux/objtool.h> #include <linux/pgtable.h> +#include <linux/slaunch.h> #include <acpi/reboot.h> #include <asm/io.h> #include <asm/apic.h>
@@ -766,6 +767,7 @@ static void native_machine_restart(char *__unused)if (!reboot_force)machine_shutdown (); +slaunch_finalize (!reboot_force);__machine_emergency_restart (0 ); }
@@ -776,6 +778,9 @@ static void native_machine_halt(void)tboot_shutdown (TB_SHUTDOWN_HALT ); +/* SEXIT done after machine_shutdown() to meet TXT requirements */ +slaunch_finalize (1 ); +stop_this_cpu (NULL ); }
@@ -784,8 +789,12 @@ static void native_machine_power_off(void)if (kernel_can_power_off ()) {if (!reboot_force)machine_shutdown (); +slaunch_finalize (!reboot_force);do_kernel_power_off (); + }else { +slaunch_finalize (0 ); } +/* A fallback in case there is no PM info available */ tboot_shutdown (TB_SHUTDOWN_HALT ); }
@@ -813,6 +822,7 @@ void machine_shutdown(void)void machine_emergency_restart (void ) { +slaunch_finalize (0 );__machine_emergency_restart (1 ); }
Signature · 7 lines
2.39.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v8 12/15 tpm: Add ability to set the preferred locality the TPM chip uses
In reply to Ross PhilipsonCurently the locality is hard coded to 0 but for DRTM support, access is needed to localities 1 through 4.
--- drivers/char/tpm/tpm-chip.c | 24 +++++++++++++++++++++++- drivers/char/tpm/tpm-interface.c | 15 +++++++++++++++ drivers/char/tpm/tpm.h | 1 + include/linux/tpm.h | 10 ++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm-chip.c +23 -1
@@ -44,7 +44,7 @@ static int tpm_request_locality(struct tpm_chip *chip)if (!chip->ops->request_locality)return 0 ; - rc = chip->ops->request_locality (chip,0 ); + rc = chip->ops->request_locality (chip, chip->pref_locality);if (rc <0 )return rc;
@@ -143,6 +143,27 @@ void tpm_chip_stop(struct tpm_chip *chip) }EXPORT_SYMBOL_GPL (tpm_chip_stop); +/** +* tpm_chip_preferred_locality() - set the TPM chip preferred locality to open +* @chip: a TPM chip to use +* @locality: the preferred locality +* +* Return: +* * true - Preferred locality set +* * false - Invalid locality specified +*/ +bool tpm_chip_preferred_locality (struct tpm_chip *chip,int locality) +{ +if (locality <0 || locality >=TPM_MAX_LOCALITY ) +return false; + +mutex_lock (&chip->tpm_mutex); + chip->pref_locality = locality; +mutex_unlock (&chip->tpm_mutex); +return true; +} +EXPORT_SYMBOL_GPL (tpm_chip_preferred_locality); +/** * tpm_try_get_ops() - Get a ref to the tpm_chip * @chip: Chip to ref
@@ -368,6 +389,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev, } chip->locality =-1 ; + chip->pref_locality =0 ;return chip; out:
drivers/char/tpm/tpm-interface.c +15 -0
@@ -273,6 +273,21 @@ int tpm_is_tpm2(struct tpm_chip *chip) }EXPORT_SYMBOL_GPL (tpm_is_tpm2); +/** +* tpm_preferred_locality() - set the TPM chip preferred locality to open +* @chip: a TPM chip to use +* @locality: the preferred locality +* +* Return: +* * true - Preferred locality set +* * false - Invalid locality specified +*/ +bool tpm_preferred_locality (struct tpm_chip *chip,int locality) +{ +return tpm_chip_preferred_locality (chip, locality); +} +EXPORT_SYMBOL_GPL (tpm_preferred_locality); +/** * tpm_pcr_read - read a PCR value from SHA1 bank * @chip: a &struct tpm_chip instance, %NULL for the default chip
drivers/char/tpm/tpm.h +1 -0
@@ -267,6 +267,7 @@ static inline void tpm_msleep(unsigned int delay_msec)int tpm_chip_bootstrap (struct tpm_chip *chip);int tpm_chip_start (struct tpm_chip *chip);void tpm_chip_stop (struct tpm_chip *chip); +bool tpm_chip_preferred_locality (struct tpm_chip *chip,int locality);struct tpm_chip *tpm_find_get_ops (struct tpm_chip *chip); struct tpm_chip *tpm_chip_alloc(struct device *dev,
include/linux/tpm.h +10 -0
@@ -116,6 +116,12 @@ struct tpm_chip_seqops {const struct seq_operations *seqops; }; +/* +* The maximum locality (0 - 4) for a TPM, as defined in section 3.2 of the +* Client Platform Profile Specification. +*/ +#define TPM_MAX_LOCALITY 4 +struct tpm_chip {struct device dev;struct device devs;
@@ -170,6 +176,9 @@ struct tpm_chip {/* active locality */ int locality; + +/* preferred locality - default 0 */ +int pref_locality; };#define TPM_HEADER_SIZE 10
@@ -421,6 +430,7 @@ static inline u32 tpm2_rc_value(u32 rc)#if defined(CONFIG_TCG_TPM ) || defined(CONFIG_TCG_TPM_MODULE )extern int tpm_is_tpm2 (struct tpm_chip *chip); +extern bool tpm_preferred_locality (struct tpm_chip *chip,int locality);extern __must_check int tpm_try_get_ops (struct tpm_chip *chip);extern void tpm_put_ops (struct tpm_chip *chip); extern ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
Signature · 7 lines
2.39.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v8 13/15 tpm: Add sysfs interface to allow setting and querying the preferred locality
In reply to Ross PhilipsonExpose a sysfs interface to allow user mode to set and query the preferred locality for the TPM chip.
--- drivers/char/tpm/tpm-sysfs.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/char/tpm/tpm-sysfs.c +30 -0
@@ -309,6 +309,34 @@ static ssize_t tpm_version_major_show(struct device *dev, }static DEVICE_ATTR_RO (tpm_version_major); +static ssize_t preferred_locality_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct tpm_chip *chip =to_tpm_chip (dev); + +return sprintf (buf,"%d\n" , chip->pref_locality); +} + +static ssize_t preferred_locality_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct tpm_chip *chip =to_tpm_chip (dev); +unsigned int locality; + +if (kstrtouint (buf,0 , &locality)) +return -ERANGE ; + +if (locality >=TPM_MAX_LOCALITY ) +return -ERANGE ; + +if (tpm_chip_preferred_locality (chip, (int )locality)) +return count; +else +return 0 ; +} + +static DEVICE_ATTR_RW (preferred_locality); +static struct attribute *tpm1_dev_attrs[] = { &dev_attr_pubek.attr, &dev_attr_pcrs.attr,
@@ -321,11 +349,13 @@ static struct attribute *tpm1_dev_attrs[] = { &dev_attr_durations.attr, &dev_attr_timeouts.attr, &dev_attr_tpm_version_major.attr, + &dev_attr_preferred_locality.attr, NULL, };static struct attribute *tpm2_dev_attrs[] = { &dev_attr_tpm_version_major.attr, + &dev_attr_preferred_locality.attr,NULL };
Signature · 7 lines
2.39.3 _______________________________________________ kexec mailing list [email protected] http://lists.infradead.org/mailman/listinfo/kexec
PATCH v8 14/15 x86: Secure Launch late initcall platform module
In reply to Ross PhilipsonFrom: "Daniel P. Smith" <[email protected]>
The Secure Launch platform module is a late init module. During the init call, the TPM event log is read and measurements taken in the early boot stub code are located. These measurements are extended into the TPM PCRs using the mainline TPM kernel driver.
The platform module also registers the securityfs nodes to allow access to TXT register fields on Intel along with the fetching of and writing events to the late launch TPM log.
--- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/slmodule.c | 511 +++++++++++++++++++++++++++++++++++++ 2 files changed, 512 insertions(+) create mode 100644 arch/x86/kernel/slmodule.c
arch/x86/kernel/Makefile +1 -0
@@ -75,6 +75,7 @@ obj-$(CONFIG_IA32_EMULATION) += tls.o obj-y += step.o obj-$(CONFIG_INTEL_TXT) += tboot.o obj-$(CONFIG_SECURE_LAUNCH) += slaunch.o +obj-$(CONFIG_SECURE_LAUNCH) += slmodule.o obj-$(CONFIG_ISA_DMA_API) += i8237.o obj-y += stacktrace.o obj-y += cpu/
arch/x86/kernel/slmodule.c new file +511 -0
511 lines not on this page · raw message
Signature · 1 line
2.39.3
Ard Biesheuvel
maintainerRe: [PATCH v8 14/15] x86: Secure Launch late initcall platform module
Quoted 8 lines · Ross Philipson
From: "Daniel P. Smith" <[email protected]>
The Secure Launch platform module is a late init module. During the init call, the TPM event log is read and measurements taken in the early boot stub code are located. These measurements are extended into the TPM PCRs using the mainline TPM kernel driver.
Quoted 7 lines
The platform module also registers the securityfs nodes to allow access to TXT register fields on Intel along with the fetching of and writing events to the late launch TPM log.
Signed-off-by Daniel P. Smith <[email protected]>Signed-off-by garnetgrimm <[email protected]>Signed-off-by Ross Philipson <[email protected]>
There is an awful amount of code that executes between the point where the measurements are taken and the point where they are loaded into the PCRs. All of this code could subvert the boot flow and hide this fact, by replacing the actual taken measurement values with the known 'blessed' ones that will unseal the keys and/or phone home to do a successful remote attestation.
At the very least, this should be documented somewhere. And if at all possible, it should also be documented why this is ok, and to what extent it limits the provided guarantees compared to a true D-RTM boot where the early boot code measures straight into the TPMs before proceeding.
Quoted 538 lines
--- arch/x86/kernel/Makefile | 1 + arch/x86/kernel/slmodule.c | 511 +++++++++++++++++++++++++++++++++++++ 2 files changed, 512 insertions(+) create mode 100644 arch/x86/kernel/slmodule.carch/x86/kernel/Makefile +1
-0@@ -75,6 +75,7 @@ obj-$(CONFIG_IA32_EMULATION) += tls.o obj-y += step.o obj-$(CONFIG_INTEL_TXT) += tboot.o obj-$(CONFIG_SECURE_LAUNCH) += slaunch.o +obj-$(CONFIG_SECURE_LAUNCH) += slmodule.o obj-$(CONFIG_ISA_DMA_API) += i8237.o obj-y += stacktrace.o obj-y += cpu/arch/x86/kernel/slmodule.c new file +511
-1@@ -0,0 +1,511 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Secure Launch late validation/setup, securityfs exposure and finalization. +* +* Copyright (c) 2022 Apertus Solutions, LLC +* Copyright (c) 2021 Assured Information Security, Inc. +* Copyright (c) 2022, Oracle and/or its affiliates. +* +* Co-developed-by: Garnet T. Grimm <[email protected]> +* Signed-off-by: Garnet T. Grimm <[email protected]> +* Signed-off-by: Daniel P. Smith <[email protected]> +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include <linux/fs.h> +#include <linux/init.h> +#include <linux/linkage.h> +#include <linux/mm.h> +#include <linux/io.h> +#include <linux/uaccess.h> +#include <linux/security.h> +#include <linux/memblock.h> +#include <asm/segment.h> +#include <asm/sections.h> +#include <crypto/sha2.h> +#include <linux/slr_table.h> +#include <linux/slaunch.h> + +/* +* The macro DECLARE_TXT_PUB_READ_U is used to read values from the TXT +* public registers as unsigned values. +*/ +#define DECLARE_TXT_PUB_READ_U (size, fmt, msg_size) \ +static ssize_t txt_pub_read_u##size(unsigned int offset, \ + loff_t *read_offset, \ + size_t read_len, \ + char __user *buf) \ +{ \ + char msg_buffer[msg_size]; \ + u##size reg_value = 0; \ + void __iomem *txt; \ + \ + txt = ioremap(TXT_PUB_CONFIG_REGS_BASE, \ + TXT_NR_CONFIG_PAGES * PAGE_SIZE); \ + if (!txt) \ + return -EFAULT; \ + memcpy_fromio(®_value, txt + offset, sizeof(u##size)); \ + iounmap(txt); \ + snprintf(msg_buffer, msg_size, fmt, reg_value); \ + return simple_read_from_buffer(buf, read_len, read_offset, \ + &msg_buffer, msg_size); \ +} + +DECLARE_TXT_PUB_READ_U (8 ,"%#04x\n" ,6 ); +DECLARE_TXT_PUB_READ_U (32 ,"%#010x\n" ,12 ); +DECLARE_TXT_PUB_READ_U (64 ,"%#018llx\n" ,20 ); + +#define DECLARE_TXT_FOPS (reg_name, reg_offset, reg_size) \ +static ssize_t txt_##reg_name##_read(struct file *flip, \ + char __user *buf, size_t read_len, loff_t *read_offset) \ +{ \ + return txt_pub_read_u##reg_size(reg_offset, read_offset, \ + read_len, buf); \ +} \ +static const struct file_operations reg_name##_ops = { \ + .read = txt_##reg_name##_read, \ +} + +DECLARE_TXT_FOPS (sts,TXT_CR_STS ,64 ); +DECLARE_TXT_FOPS (ests,TXT_CR_ESTS ,8 ); +DECLARE_TXT_FOPS (errorcode,TXT_CR_ERRORCODE ,32 ); +DECLARE_TXT_FOPS (didvid,TXT_CR_DIDVID ,64 ); +DECLARE_TXT_FOPS (e2sts,TXT_CR_E2STS ,64 ); +DECLARE_TXT_FOPS (ver_emif,TXT_CR_VER_EMIF ,32 ); +DECLARE_TXT_FOPS (scratchpad,TXT_CR_SCRATCHPAD ,64 ); + +/* +* Securityfs exposure +*/ +struct memfile { +char *name; +void *addr; +size_t size; +}; + +static struct memfile sl_evtlog = {"eventlog" ,NULL ,0 }; +static void *txt_heap; +static struct txt_heap_event_log_pointer2_1_element *evtlog20; +static DEFINE_MUTEX (sl_evt_log_mutex); + +static ssize_t sl_evtlog_read (struct file *file,char __user *buf, +size_t count,loff_t *pos) +{ +ssize_t size; + +if (!sl_evtlog.addr) +return 0 ; + +mutex_lock (&sl_evt_log_mutex); + size =simple_read_from_buffer (buf, count, pos, sl_evtlog.addr, + sl_evtlog.size); +mutex_unlock (&sl_evt_log_mutex); + +return size; +} + +static ssize_t sl_evtlog_write (struct file *file,const char __user *buf, +size_t datalen,loff_t *ppos) +{ +ssize_t result; +char *data; + +if (!sl_evtlog.addr) +return 0 ; + +/* No partial writes. */ + result = -EINVAL ; +if (*ppos !=0 ) + goto out; + + data =memdup_user (buf, datalen); +if (IS_ERR (data)) { + result =PTR_ERR (data); + goto out; + } + +mutex_lock (&sl_evt_log_mutex); +if (evtlog20) + result =tpm20_log_event (evtlog20, sl_evtlog.addr, + sl_evtlog.size, datalen, data); +else + result =tpm12_log_event (sl_evtlog.addr, sl_evtlog.size, + datalen, data); +mutex_unlock (&sl_evt_log_mutex); + +kfree (data); +out: +return result; +} + +static const struct file_operations sl_evtlog_ops = { + .read = sl_evtlog_read, + .write = sl_evtlog_write, + .llseek = default_llseek, +}; + +struct sfs_file { +const char *name; +const struct file_operations *fops; +}; + +#define SL_TXT_ENTRY_COUNT 7 +static const struct sfs_file sl_txt_files[] = { + {"sts" , &sts_ops }, + {"ests" , &ests_ops }, + {"errorcode" , &errorcode_ops }, + {"didvid" , &didvid_ops }, + {"ver_emif" , &ver_emif_ops }, + {"scratchpad" , &scratchpad_ops }, + {"e2sts" , &e2sts_ops } +}; + +/* sysfs file handles */ +static struct dentry *slaunch_dir; +static struct dentry *event_file; +static struct dentry *txt_dir; +static struct dentry *txt_entries[SL_TXT_ENTRY_COUNT ]; + +static long slaunch_expose_securityfs (void ) +{ +long ret =0 ; +int i; + + slaunch_dir =securityfs_create_dir ("slaunch" ,NULL ); +if (IS_ERR (slaunch_dir)) +return PTR_ERR (slaunch_dir); + +if (slaunch_get_flags () &SL_FLAG_ARCH_TXT ) { + txt_dir =securityfs_create_dir ("txt" , slaunch_dir); +if (IS_ERR (txt_dir)) { + ret =PTR_ERR (txt_dir); + goto remove_slaunch; + } + +for (i =0 ; i <ARRAY_SIZE (sl_txt_files); i++) { + txt_entries[i] =securityfs_create_file ( + sl_txt_files[i].name,0440 , + txt_dir,NULL , + sl_txt_files[i].fops); +if (IS_ERR (txt_entries[i])) { + ret =PTR_ERR (txt_entries[i]); + goto remove_files; + } + } + } + +if (sl_evtlog.addr) { + event_file =securityfs_create_file (sl_evtlog.name,0440 , + slaunch_dir,NULL , + &sl_evtlog_ops); +if (IS_ERR (event_file)) { + ret =PTR_ERR (event_file); + goto remove_files; + } + } + +return 0 ; + +remove_files: +if (slaunch_get_flags () &SL_FLAG_ARCH_TXT ) { +while (--i >=0 ) +securityfs_remove (txt_entries[i]); +securityfs_remove (txt_dir); + } + +remove_slaunch: +securityfs_remove (slaunch_dir); + +return ret; +} + +static void slaunch_teardown_securityfs (void ) +{ +int i; + +securityfs_remove (event_file); +if (sl_evtlog.addr) { +memunmap (sl_evtlog.addr); + sl_evtlog.addr =NULL ; + } + sl_evtlog.size =0 ; + +if (slaunch_get_flags () &SL_FLAG_ARCH_TXT ) { +for (i =0 ; i <ARRAY_SIZE (sl_txt_files); i++) +securityfs_remove (txt_entries[i]); + +securityfs_remove (txt_dir); + +if (txt_heap) { +memunmap (txt_heap); + txt_heap =NULL ; + } + } + +securityfs_remove (slaunch_dir); +} + +static void slaunch_intel_evtlog (void __iomem *txt) +{ +struct slr_entry_log_info *log_info; +struct txt_os_mle_data *params; +struct slr_table *slrt; +void *os_sinit_data; +u64 base, size; + +memcpy_fromio (&base, txt +TXT_CR_HEAP_BASE ,sizeof (base)); +memcpy_fromio (&size, txt +TXT_CR_HEAP_SIZE ,sizeof (size)); + +/* now map TXT heap */ + txt_heap =memremap (base, size,MEMREMAP_WB ); +if (!txt_heap) +slaunch_txt_reset (txt,"Error failed to memremap TXT heap\n" , +SL_ERROR_HEAP_MAP ); + + params = (struct txt_os_mle_data *)txt_os_mle_data_start (txt_heap); + +/* Get the SLRT and remap it */ + slrt =memremap (params->slrt,sizeof (*slrt),MEMREMAP_WB ); +if (!slrt) +slaunch_txt_reset (txt,"Error failed to memremap SLR Table\n" , +SL_ERROR_SLRT_MAP ); + size = slrt->size; +memunmap (slrt); + + slrt =memremap (params->slrt, size,MEMREMAP_WB ); +if (!slrt) +slaunch_txt_reset (txt,"Error failed to memremap SLR Table\n" , +SL_ERROR_SLRT_MAP ); + + log_info = (struct slr_entry_log_info *)slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_LOG_INFO ); +if (!log_info) +slaunch_txt_reset (txt,"Error failed to memremap SLR Table\n" , +SL_ERROR_SLRT_MISSING_ENTRY ); + + sl_evtlog.size = log_info->size; + sl_evtlog.addr =memremap (log_info->addr, log_info->size, +MEMREMAP_WB ); +if (!sl_evtlog.addr) +slaunch_txt_reset (txt,"Error failed to memremap TPM event log\n" , +SL_ERROR_EVENTLOG_MAP ); + +memunmap (slrt); + +/* Determine if this is TPM 1.2 or 2.0 event log */ +if (memcmp (sl_evtlog.addr +sizeof (struct tcg_pcr_event ), +TCG_SPECID_SIG ,sizeof (TCG_SPECID_SIG ))) +return ;/* looks like it is not 2.0 */ + +/* For TPM 2.0 logs, the extended heap element must be located */ + os_sinit_data =txt_os_sinit_data_start (txt_heap); + + evtlog20 =tpm20_find_log2_1_element (os_sinit_data); + +/* +* If this fails, things are in really bad shape. Any attempt to write +* events to the log will fail. +*/ +if (!evtlog20) +slaunch_txt_reset (txt,"Error failed to find TPM20 event log element\n" , +SL_ERROR_TPM_INVALID_LOG20 ); +} + +static void slaunch_tpm20_extend_event (struct tpm_chip *tpm,void __iomem *txt, +struct tcg_pcr_event2_head *event) +{ +u16 *alg_id_field = (u16 *)((u8 *)event +sizeof (struct tcg_pcr_event2_head )); +struct tpm_digest *digests; +u8 *dptr; +u32 i, j; +int ret; + + digests =kcalloc (tpm->nr_allocated_banks,sizeof (*digests), +GFP_KERNEL ); +if (!digests) +slaunch_txt_reset (txt,"Failed to allocate array of digests\n" , +SL_ERROR_GENERIC ); + +for (i =0 ; i < tpm->nr_allocated_banks; i++) + digests[i].alg_id = tpm->allocated_banks[i].alg_id; + +/* Early SL code ensured there was a max count of 2 digests */ +for (i =0 ; i < event->count; i++) { + dptr = (u8 *)alg_id_field +sizeof (u16); + +for (j =0 ; j < tpm->nr_allocated_banks; j++) { +if (digests[j].alg_id != *alg_id_field) +continue ; + +switch (digests[j].alg_id) { +case TPM_ALG_SHA256 : +memcpy (&digests[j].digest[0 ], dptr, +SHA256_DIGEST_SIZE ); + alg_id_field = (u16 *)((u8 *)alg_id_field + +SHA256_DIGEST_SIZE +sizeof (u16)); +break ; +case TPM_ALG_SHA1 : +memcpy (&digests[j].digest[0 ], dptr, +SHA1_DIGEST_SIZE ); + alg_id_field = (u16 *)((u8 *)alg_id_field + +SHA1_DIGEST_SIZE +sizeof (u16)); +default : +break ; + } + } + } + + 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 ); + } + +kfree (digests); +} + +static void slaunch_tpm20_extend (struct tpm_chip *tpm,void __iomem *txt) +{ +struct tcg_pcr_event *event_header; +struct tcg_pcr_event2_head *event; +int start =0 , end =0 , size; + + event_header = (struct tcg_pcr_event *)(sl_evtlog.addr + + evtlog20->first_record_offset); + +/* Skip first TPM 1.2 event to get to first TPM 2.0 event */ + event = (struct tcg_pcr_event2_head *)((u8 *)event_header + +sizeof (struct tcg_pcr_event ) + + event_header->event_size); + +while ((void *)event < sl_evtlog.addr + evtlog20->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 ); + +/* +* Marker events indicate where the Secure Launch early stub +* started and ended adding post launch events. +*/ +if (event->event_type ==TXT_EVTYPE_SLAUNCH_END ) { + end =1 ; +break ; + }else if (event->event_type ==TXT_EVTYPE_SLAUNCH_START ) { + start =1 ; + goto next; + } + +if (start) +slaunch_tpm20_extend_event (tpm, txt, event); + +next: + event = (struct tcg_pcr_event2_head *)((u8 *)event + size); + } + +if (!start || !end) +slaunch_txt_reset (txt,"Missing start or end events for extending TPM20 PCRs\n" , +SL_ERROR_TPM_EXTEND ); +} + +static void slaunch_tpm12_extend (struct tpm_chip *tpm,void __iomem *txt) +{ +struct tpm12_event_log_header *event_header; +struct tcg_pcr_event *event; +struct tpm_digest digest; +int start =0 , end =0 ; +int size, ret; + + event_header = (struct tpm12_event_log_header *)sl_evtlog.addr; + event = (struct tcg_pcr_event *)((u8 *)event_header + +sizeof (struct tpm12_event_log_header )); + +while ((void *)event < sl_evtlog.addr + event_header->next_event_offset) { + size =sizeof (struct tcg_pcr_event ) + event->event_size; + +/* +* Marker events indicate where the Secure Launch early stub +* started and ended adding post launch events. +*/ +if (event->event_type ==TXT_EVTYPE_SLAUNCH_END ) { + end =1 ; +break ; + }else if (event->event_type ==TXT_EVTYPE_SLAUNCH_START ) { + start =1 ; + goto next; + } + +if (start) { +memset (&digest.digest[0 ],0 ,TPM_MAX_DIGEST_SIZE ); + digest.alg_id =TPM_ALG_SHA1 ; +memcpy (&digest.digest[0 ], &event->digest[0 ], +SHA1_DIGEST_SIZE ); + + 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 ); + } + } + +next: + event = (struct tcg_pcr_event *)((u8 *)event + size); + } + +if (!start || !end) +slaunch_txt_reset (txt,"Missing start or end events for extending TPM12 PCRs\n" , +SL_ERROR_TPM_EXTEND ); +} + +static void slaunch_pcr_extend (void __iomem *txt) +{ +struct tpm_chip *tpm; + + tpm =tpm_default_chip (); +if (!tpm) +slaunch_txt_reset (txt,"Could not get default TPM chip\n" , +SL_ERROR_TPM_INIT ); + +if (!tpm_preferred_locality (tpm,2 )) +slaunch_txt_reset (txt,"Could not set TPM chip locality 2\n" , +SL_ERROR_TPM_INIT ); + +if (evtlog20) +slaunch_tpm20_extend (tpm, txt); +else +slaunch_tpm12_extend (tpm, txt); + +tpm_preferred_locality (tpm,0 ); +} + +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 )) +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" ); + +/* Only Intel TXT is supported at this point */ +slaunch_intel_evtlog (txt); +slaunch_pcr_extend (txt); +iounmap (txt); + +return slaunch_expose_securityfs (); +} + +static void __exit slaunch_module_exit(void) +{ +slaunch_teardown_securityfs (); +} + +late_initcall (slaunch_module_init); +__exitcall (slaunch_module_exit); --2.39.3
Re: [PATCH v8 14/15] x86: Secure Launch late initcall platform module
Quoted 17 lines · Ard Biesheuvel
Quoted 8 lines · Ross Philipson
From: "Daniel P. Smith" <[email protected]>
The Secure Launch platform module is a late init module. During the init call, the TPM event log is read and measurements taken in the early boot stub code are located. These measurements are extended into the TPM PCRs using the mainline TPM kernel driver.
Quoted 7 lines
The platform module also registers the securityfs nodes to allow access to TXT register fields on Intel along with the fetching of and writing events to the late launch TPM log.
Signed-off-by Daniel P. Smith <[email protected]>Signed-off-by garnetgrimm <[email protected]>Signed-off-by Ross Philipson <[email protected]>
Quoted 6 lines
There is an awful amount of code that executes between the point where the measurements are taken and the point where they are loaded into the PCRs. All of this code could subvert the boot flow and hide this fact, by replacing the actual taken measurement values with the known 'blessed' ones that will unseal the keys and/or phone home to do a successful remote attestation.
To set context, in general the motivation to employ an RTM, Static or Dynamic, integrity solution is to enable external platform validation, aka attestation. These trust chains are constructed from the principle of measure and execute that rely on the presence of a RoT for Storage (RTS) and a RoT for Reporting (RTR). Under the TCG architecture adopted by x86 vendors and now recently by Arm, those roles are fulfilled by the TPM. With this context, lets layout the assumptive trusts being made here,
1. The CPU GETSEC instruction functions correctly
2. The IOMMU, and by extension the PMRs, functions correctly
2. The ACM authentication process functions correctly
3. The ACM functions correctly
4. The TPM interactions function correctly
5. The TPM functions correctly
With this basis, let's explore your assertion here. The assertion breaks down into two scenarios. The first is that the at-rest kernel binary is corrupt, unintentionally (bug) or maliciously, either of which does not matter for the situation. For the sake of simplicity, corruption of the Linux kernel during loading or before the DRTM Event is considered an equivalent to corruption of the kernel at-rest. The second is that the kernel binary was corrupted in memory at some point after the DRTM event occurs.
For both scenarios, the ACM will correctly configure the IOMMU PMRs to ensure the kernel can no longer be tampered with in memory. After which, the ACM will then accurately measure the kernel (bzImage) and safely store the measurement in the TPM.
In the first scenario, the TPM will accurately report the kernel measurement in the attestation. The attestation authority will be able to detect if an invalid kernel was started and can take whatever remediation actions it may employ.
In the second scenario, any attempt to corrupt the binary after the ACM has configured the IOMMU PMR will fail.
Quoted 5 lines
At the very least, this should be documented somewhere. And if at all possible, it should also be documented why this is ok, and to what extent it limits the provided guarantees compared to a true D-RTM boot where the early boot code measures straight into the TPMs before proceeding.
I can add a rendition of the above into the existing section of the documentation patch that already discusses separation of the measurement from the TPM recording code. As to the limits it incurs on the DRTM integrity, as explained above, I submit there are none.
v/r,
dps
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Ard Biesheuvel
maintainerRe: [PATCH v8 14/15] x86: Secure Launch late initcall platform module
Quoted 54 lines · Daniel P. Smith
Quoted 17 lines · Ard Biesheuvel
Quoted 8 lines · Ross Philipson
From: "Daniel P. Smith" <[email protected]>
The Secure Launch platform module is a late init module. During the init call, the TPM event log is read and measurements taken in the early boot stub code are located. These measurements are extended into the TPM PCRs using the mainline TPM kernel driver.
Quoted 7 lines
The platform module also registers the securityfs nodes to allow access to TXT register fields on Intel along with the fetching of and writing events to the late launch TPM log.
Signed-off-by Daniel P. Smith <[email protected]>Signed-off-by garnetgrimm <[email protected]>Signed-off-by Ross Philipson <[email protected]>Quoted 6 lines
There is an awful amount of code that executes between the point where the measurements are taken and the point where they are loaded into the PCRs. All of this code could subvert the boot flow and hide this fact, by replacing the actual taken measurement values with the known 'blessed' ones that will unseal the keys and/or phone home to do a successful remote attestation.
To set context, in general the motivation to employ an RTM, Static or Dynamic, integrity solution is to enable external platform validation, aka attestation. These trust chains are constructed from the principle of measure and execute that rely on the presence of a RoT for Storage (RTS) and a RoT for Reporting (RTR). Under the TCG architecture adopted by x86 vendors and now recently by Arm, those roles are fulfilled by the TPM. With this context, lets layout the assumptive trusts being made here,
1. The CPU GETSEC instruction functions correctly
2. The IOMMU, and by extension the PMRs, functions correctly
2. The ACM authentication process functions correctly
3. The ACM functions correctly
4. The TPM interactions function correctly
5. The TPM functions correctlyWith this basis, let's explore your assertion here. The assertion breaks down into two scenarios. The first is that the at-rest kernel binary is corrupt, unintentionally (bug) or maliciously, either of which does not matter for the situation. For the sake of simplicity, corruption of the Linux kernel during loading or before the DRTM Event is considered an equivalent to corruption of the kernel at-rest. The second is that the kernel binary was corrupted in memory at some point after the DRTM event occurs.
For both scenarios, the ACM will correctly configure the IOMMU PMRs to ensure the kernel can no longer be tampered with in memory. After which, the ACM will then accurately measure the kernel (bzImage) and safely store the measurement in the TPM.
Quoted 9 lines
In the first scenario, the TPM will accurately report the kernel measurement in the attestation. The attestation authority will be able to detect if an invalid kernel was started and can take whatever remediation actions it may employ.
In the second scenario, any attempt to corrupt the binary after the ACM has configured the IOMMU PMR will fail.
This protects the memory image from external masters after the measurement has been taken.
So any external influences in the time window between taking the measurements and loading them into the PCRs are out of scope here, I guess?
Maybe it would help (or if I missed it - apologies) to include a threat model here. I suppose physical tampering is out of scope?
Quoted 11 lines
Quoted 5 lines
At the very least, this should be documented somewhere. And if at all possible, it should also be documented why this is ok, and to what extent it limits the provided guarantees compared to a true D-RTM boot where the early boot code measures straight into the TPMs before proceeding.
I can add a rendition of the above into the existing section of the documentation patch that already discusses separation of the measurement from the TPM recording code. As to the limits it incurs on the DRTM integrity, as explained above, I submit there are none.
Thanks for the elaborate explananation. And yes, please document this with the changes.
Re: [PATCH v8 14/15] x86: Secure Launch late initcall platform module
Hi Ard,
Quoted 61 lines · Ard Biesheuvel
Quoted 59 lines · Daniel P. Smith
Quoted 17 lines · Ard Biesheuvel
Quoted 8 lines · Ross Philipson
From: "Daniel P. Smith" <[email protected]>
The Secure Launch platform module is a late init module. During the init call, the TPM event log is read and measurements taken in the early boot stub code are located. These measurements are extended into the TPM PCRs using the mainline TPM kernel driver.
Quoted 7 lines
The platform module also registers the securityfs nodes to allow access to TXT register fields on Intel along with the fetching of and writing events to the late launch TPM log.
Signed-off-by Daniel P. Smith <[email protected]>Signed-off-by garnetgrimm <[email protected]>Signed-off-by Ross Philipson <[email protected]>Quoted 6 lines
There is an awful amount of code that executes between the point where the measurements are taken and the point where they are loaded into the PCRs. All of this code could subvert the boot flow and hide this fact, by replacing the actual taken measurement values with the known 'blessed' ones that will unseal the keys and/or phone home to do a successful remote attestation.
To set context, in general the motivation to employ an RTM, Static or Dynamic, integrity solution is to enable external platform validation, aka attestation. These trust chains are constructed from the principle of measure and execute that rely on the presence of a RoT for Storage (RTS) and a RoT for Reporting (RTR). Under the TCG architecture adopted by x86 vendors and now recently by Arm, those roles are fulfilled by the TPM. With this context, lets layout the assumptive trusts being made here,
1. The CPU GETSEC instruction functions correctly
2. The IOMMU, and by extension the PMRs, functions correctly
2. The ACM authentication process functions correctly
3. The ACM functions correctly
4. The TPM interactions function correctly
5. The TPM functions correctlyWith this basis, let's explore your assertion here. The assertion breaks down into two scenarios. The first is that the at-rest kernel binary is corrupt, unintentionally (bug) or maliciously, either of which does not matter for the situation. For the sake of simplicity, corruption of the Linux kernel during loading or before the DRTM Event is considered an equivalent to corruption of the kernel at-rest. The second is that the kernel binary was corrupted in memory at some point after the DRTM event occurs.
For both scenarios, the ACM will correctly configure the IOMMU PMRs to ensure the kernel can no longer be tampered with in memory. After which, the ACM will then accurately measure the kernel (bzImage) and safely store the measurement in the TPM.
In the first scenario, the TPM will accurately report the kernel measurement in the attestation. The attestation authority will be able to detect if an invalid kernel was started and can take whatever remediation actions it may employ.
Quoted 7 lines
Quoted 4 lines
In the second scenario, any attempt to corrupt the binary after the ACM has configured the IOMMU PMR will fail.
This protects the memory image from external masters after the measurement has been taken.
It blocks access before the measurement is taken.
Quoted 3 lines
So any external influences in the time window between taking the measurements and loading them into the PCRs are out of scope here, I guess?
Correct, as long as the assumption that the user configured the kernel to program the IOMMU correctly after gaining control. In early versions of this series the correct IOMMU configuration was enforced. This was changed due to objections that the user should be free to configure the system how they see fit, even if it results in an insecure system.
Quoted 2 lines
Maybe it would help (or if I missed it - apologies) to include a threat model here. I suppose physical tampering is out of scope?
I can take a look at what other security capabilities have documented in this area and provide a similar level of explanation.
I would not say physical tampering is out, I would say that it is supported to the degree to which the TPM was designed to mitigate it.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
At the very least, this should be documented somewhere. And if at all possible, it should also be documented why this is ok, and to what extent it limits the provided guarantees compared to a true D-RTM boot where the early boot code measures straight into the TPMs before proceeding.
Quoted 8 lines
Quoted 5 lines
I can add a rendition of the above into the existing section of the documentation patch that already discusses separation of the measurement from the TPM recording code. As to the limits it incurs on the DRTM integrity, as explained above, I submit there are none.
Thanks for the elaborate explananation. And yes, please document this with the changes.
Ack.
V/r,
Daniel
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
kernel test robot
build botRe: [PATCH v8 14/15] x86: Secure Launch late initcall platform module
In reply to Ross Philipsonkernel test robot noticed the following build warnings:
Hi Ross,
kernel test robot noticed the following build warnings:
[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on char-misc/char-misc-next char-misc/char-misc-linus herbert-cryptodev-2.6/master herbert-crypto-2.6/master linus/master v6.8-rc4 next-20240215] [cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ross-Philipson/x86-boot-Place-kernel_info-at-a-fixed-offset/20240215-064712 base: char-misc/char-misc-testing patch link: https://lore.kernel.org/r/20240214221847.2066632-15-ross.philipson%40oracle.com patch subject: [PATCH v8 14/15] x86: Secure Launch late initcall platform module config: x86_64-allmodconfig (https://download.01.org/0day-ci/archive/20240216/[email protected]/config) compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240216/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In file included from arch/x86/kernel/slmodule.c:28:
In file included from include/linux/slaunch.h:185:
include/linux/tpm_eventlog.h:167:6: warning: variable 'mapping_size' set but not used [-Wunused-but-set-variable]
167 | int mapping_size;
| ^
>> arch/x86/kernel/slmodule.c:352:4: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
352 | default:
| ^
arch/x86/kernel/slmodule.c:352:4: note: insert 'break;' to avoid fall-through
352 | default:
| ^
| break; 2 warnings generated.
vim +352 arch/x86/kernel/slmodule.c
313
314 static void slaunch_tpm20_extend_event(struct tpm_chip *tpm, void __iomem *txt,
315 struct tcg_pcr_event2_head *event)
316 {
317 u16 *alg_id_field = (u16 *)((u8 *)event + sizeof(struct tcg_pcr_event2_head));
318 struct tpm_digest *digests;
319 u8 *dptr;
320 u32 i, j;
321 int ret;
322
323 digests = kcalloc(tpm->nr_allocated_banks, sizeof(*digests),
324 GFP_KERNEL);
325 if (!digests)
326 slaunch_txt_reset(txt, "Failed to allocate array of digests\n",
327 SL_ERROR_GENERIC);
328
329 for (i = 0; i < tpm->nr_allocated_banks; i++)
330 digests[i].alg_id = tpm->allocated_banks[i].alg_id;
331
332 /* Early SL code ensured there was a max count of 2 digests */
333 for (i = 0; i < event->count; i++) {
334 dptr = (u8 *)alg_id_field + sizeof(u16);
335
336 for (j = 0; j < tpm->nr_allocated_banks; j++) {
337 if (digests[j].alg_id != *alg_id_field)
338 continue;
339
340 switch (digests[j].alg_id) {
341 case TPM_ALG_SHA256:
342 memcpy(&digests[j].digest[0], dptr,
343 SHA256_DIGEST_SIZE);
344 alg_id_field = (u16 *)((u8 *)alg_id_field +
345 SHA256_DIGEST_SIZE + sizeof(u16));
346 break;
347 case TPM_ALG_SHA1:
348 memcpy(&digests[j].digest[0], dptr,
349 SHA1_DIGEST_SIZE);
350 alg_id_field = (u16 *)((u8 *)alg_id_field +
351 SHA1_DIGEST_SIZE + sizeof(u16));
> 352 default:
353 break;
354 }
355 }
356 }
357
358 ret = tpm_pcr_extend(tpm, event->pcr_idx, digests);
359 if (ret) {
360 pr_err("Error extending TPM20 PCR, result: %d\n", ret);
361 slaunch_txt_reset(txt, "Failed to extend TPM20 PCR\n",
362 SL_ERROR_TPM_EXTEND);
363 }
364
365 kfree(digests);
366 }
367
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v8 14/15] x86: Secure Launch late initcall platform module
In reply to Ross Philipsonkernel test robot noticed the following build errors:
Hi Ross,
kernel test robot noticed the following build errors:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on char-misc/char-misc-next char-misc/char-misc-linus herbert-cryptodev-2.6/master herbert-crypto-2.6/master linus/master v6.8-rc4 next-20240216] [cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ross-Philipson/x86-boot-Place-kernel_info-at-a-fixed-offset/20240215-064712 base: char-misc/char-misc-testing patch link: https://lore.kernel.org/r/20240214221847.2066632-15-ross.philipson%40oracle.com patch subject: [PATCH v8 14/15] x86: Secure Launch late initcall platform module config: x86_64-randconfig-r061-20240216 (https://download.01.org/0day-ci/archive/20240217/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240217/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
arch/x86/kernel/slmodule.c: In function 'slaunch_pcr_extend':
>> arch/x86/kernel/slmodule.c:471:14: error: implicit declaration of function 'tpm_preferred_locality' [-Werror=implicit-function-declaration]
471 | if (!tpm_preferred_locality(tpm, 2))
| ^~~~~~~~~~~~~~~~~~~~~~cc1: some warnings being treated as errors
vim +/tpm_preferred_locality +471 arch/x86/kernel/slmodule.c
461
462 static void slaunch_pcr_extend(void __iomem *txt)
463 {
464 struct tpm_chip *tpm;
465
466 tpm = tpm_default_chip();
467 if (!tpm)
468 slaunch_txt_reset(txt, "Could not get default TPM chip\n",
469 SL_ERROR_TPM_INIT);
470
> 471 if (!tpm_preferred_locality(tpm, 2))
472 slaunch_txt_reset(txt, "Could not set TPM chip locality 2\n",
473 SL_ERROR_TPM_INIT);
474
475 if (evtlog20)
476 slaunch_tpm20_extend(tpm, txt);
477 else
478 slaunch_tpm12_extend(tpm, txt);
479
480 tpm_preferred_locality(tpm, 0);
481 }
482
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v8 15/15 x86: EFI stub DRTM launch support for Secure Launch
In reply to Ross PhilipsonThis support allows the DRTM launch to be initiated after an EFI stub launch of the Linux kernel is done. This is accomplished by providing a handler to jump to when a Secure Launch is in progress. This has to be called after the EFI stub does Exit Boot Services.
--- drivers/firmware/efi/libstub/x86-stub.c | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
drivers/firmware/efi/libstub/x86-stub.c +55 -0
@@ -9,6 +9,7 @@#include <linux/efi.h> #include <linux/pci.h> #include <linux/stddef.h> +#include <linux/slr_table.h> #include <asm/efi.h> #include <asm/e820/types.h>
@@ -810,6 +811,57 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)return EFI_SUCCESS ; } +static void efi_secure_launch (struct boot_params *boot_params) +{ +struct slr_entry_uefi_config *uefi_config; +struct slr_uefi_cfg_entry *uefi_entry; +struct slr_entry_dl_info *dlinfo; +efi_guid_t guid =SLR_TABLE_GUID ; +struct slr_table *slrt; +u64 memmap_hi; +void *table; +u8 buf[64 ] = {0 }; + + table =get_efi_config_table (guid); + +/* +* The presence of this table indicated a Secure Launch +* is being requested. +*/ +if (!table) +return ; + + slrt = (struct slr_table *)table; + +if (slrt->magic !=SLR_TABLE_MAGIC ) +return ; + +/* Add config information to measure the UEFI memory map */ + uefi_config = (struct slr_entry_uefi_config *)buf; + uefi_config->hdr.tag =SLR_ENTRY_UEFI_CONFIG ; + uefi_config->hdr.size =sizeof (*uefi_config) +sizeof (*uefi_entry); + uefi_config->revision =SLR_UEFI_CONFIG_REVISION ; + uefi_config->nr_entries =1 ; + uefi_entry = (struct slr_uefi_cfg_entry *)(buf +sizeof (*uefi_config)); + uefi_entry->pcr =18 ; + uefi_entry->cfg = boot_params->efi_info.efi_memmap; + memmap_hi = boot_params->efi_info.efi_memmap_hi; + uefi_entry->cfg |= memmap_hi <<32 ; + uefi_entry->size = boot_params->efi_info.efi_memmap_size; +memcpy (&uefi_entry->evt_info[0 ],"Measured UEFI memory map" , +strlen ("Measured UEFI memory map" )); + +if (slr_add_entry (slrt, (struct slr_entry_hdr *)uefi_config)) +return ; + +/* Jump through DL stub to initiate Secure Launch */ + dlinfo = (struct slr_entry_dl_info *) +slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_DL_INFO ); + + asmvolatile ("jmp *%%rax" + : :"a" (dlinfo->dl_handler),"D" (&dlinfo->bl_context)); +} +static void __noreturn enter_kernel (unsigned long kernel_addr,struct boot_params *boot_params) {
@@ -934,6 +986,9 @@ void __noreturn efi_stub_entry(efi_handle_t handle, goto fail; } +/* If a Secure Launch is in progress, this never returns */ +efi_secure_launch (boot_params); +/* * Call the SEV init code while still running with the firmware's * GDT/IDT, so #VC exceptions will be handled by EFI.
Signature · 1 line
2.39.3
Ard Biesheuvel
maintainerRe: [PATCH v8 15/15] x86: EFI stub DRTM launch support for Secure Launch
Quoted 28 lines · Ross Philipson
This support allows the DRTM launch to be initiated after an EFI stub launch of the Linux kernel is done. This is accomplished by providing a handler to jump to when a Secure Launch is in progress. This has to be called after the EFI stub does Exit Boot Services.
Signed-off-by Ross Philipson <[email protected]>--- drivers/firmware/efi/libstub/x86-stub.c | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+)drivers/firmware/efi/libstub/x86-stub.c +2
-0@@ -9,6 +9,7 @@#include <linux/efi.h> #include <linux/pci.h> #include <linux/stddef.h> +#include <linux/slr_table.h> #include <asm/efi.h> #include <asm/e820/types.h> @@ -810,6 +811,57 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)return EFI_SUCCESS ; } +static void efi_secure_launch (struct boot_params *boot_params)
drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 824
Quoted 10 lines
drivers/firmware/efi/libstub/x86-stub.c +10
-0+{ +struct slr_entry_uefi_config *uefi_config; +struct slr_uefi_cfg_entry *uefi_entry; +struct slr_entry_dl_info *dlinfo; +efi_guid_t guid =SLR_TABLE_GUID ; +struct slr_table *slrt; +u64 memmap_hi; +void *table; +u8 buf[64 ] = {0 }; +
If you add a flex array to slr_entry_uefi_config as I suggested in response to the other patch, we could simplify this substantially
static struct slr_entry_uefi_config cfg = {
.hdr.tag = SLR_ENTRY_UEFI_CONFIG,
.hdr.size = sizeof(cfg),
.revision = SLR_UEFI_CONFIG_REVISION,
.nr_entries = 1,
.entries[0] = {
.pcr = 18, .evt_info = "Measured UEFI memory map",
},
};
cfg.entries[0].cfg = boot_params->efi_info.efi_memmap |
(u64)boot_params->efi_info.efi_memmap_hi << 32;
cfg.entries[0].size = boot_params->efi_info.efi_memmap_size;
Quoted 4 lines
drivers/firmware/efi/libstub/x86-stub.c +4
-0+ table =get_efi_config_table (guid); + +/* +* The presence of this table indicated a Secure Launch
drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 838
Quoted 10 lines
drivers/firmware/efi/libstub/x86-stub.c +10
-0+* is being requested. +*/ +if (!table) +return ; + + slrt = (struct slr_table *)table; + +if (slrt->magic !=SLR_TABLE_MAGIC ) +return ; +
slrt = (struct slr_table *)get_efi_config_table(guid); if (!slrt || slrt->magic != SLR_TABLE_MAGIC)
return;
Quoted 5 lines
drivers/firmware/efi/libstub/x86-stub.c +5
-0+/* Add config information to measure the UEFI memory map */ + uefi_config = (struct slr_entry_uefi_config *)buf; + uefi_config->hdr.tag =SLR_ENTRY_UEFI_CONFIG ; + uefi_config->hdr.size =sizeof (*uefi_config) +sizeof (*uefi_entry); + uefi_config->revision =SLR_UEFI_CONFIG_REVISION ;
drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 853
Quoted 10 lines
drivers/firmware/efi/libstub/x86-stub.c +10
-0+ uefi_config->nr_entries =1 ; + uefi_entry = (struct slr_uefi_cfg_entry *)(buf +sizeof (*uefi_config)); + uefi_entry->pcr =18 ; + uefi_entry->cfg = boot_params->efi_info.efi_memmap; + memmap_hi = boot_params->efi_info.efi_memmap_hi; + uefi_entry->cfg |= memmap_hi <<32 ; + uefi_entry->size = boot_params->efi_info.efi_memmap_size; +memcpy (&uefi_entry->evt_info[0 ],"Measured UEFI memory map" , +strlen ("Measured UEFI memory map" )); +
Drop all of this
drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 854
Quoted 1 line
drivers/firmware/efi/libstub/x86-stub.c +1
-0+if (slr_add_entry (slrt, (struct slr_entry_hdr *)uefi_config))
if (slr_add_entry(slrt, &uefi_config.hdr))
drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 862
Quoted 8 lines
drivers/firmware/efi/libstub/x86-stub.c +8
-0+return ; + +/* Jump through DL stub to initiate Secure Launch */ + dlinfo = (struct slr_entry_dl_info *) +slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_DL_INFO ); + + asmvolatile ("jmp *%%rax" + : :"a" (dlinfo->dl_handler),"D" (&dlinfo->bl_context));
Fix the prototype and just do
dlinfo->dl_handler(&dlinfo->bl_context);unreachable();
So in summary, this becomes
static void efi_secure_launch(struct boot_params *boot_params)
{
static struct slr_entry_uefi_config cfg = {
.hdr.tag = SLR_ENTRY_UEFI_CONFIG,
.hdr.size = sizeof(cfg),
.revision = SLR_UEFI_CONFIG_REVISION,
.nr_entries = 1,
.entries[0] = {
.pcr = 18,
.evt_info = "Measured UEFI memory map",
},
};
struct slr_entry_dl_info *dlinfo;
efi_guid_t guid = SLR_TABLE_GUID;
struct slr_table *slrt;
/*
* The presence of this table indicated a Secure Launch
* is being requested.
*/
slrt = (struct slr_table *)get_efi_config_table(guid);
if (!slrt || slrt->magic != SLR_TABLE_MAGIC)
return;
cfg.entries[0].cfg = boot_params->efi_info.efi_memmap |
(u64)boot_params->efi_info.efi_memmap_hi << 32;
cfg.entries[0].size = boot_params->efi_info.efi_memmap_size;
if (slr_add_entry(slrt, &cfg.hdr))
return;
/* Jump through DL stub to initiate Secure Launch */
dlinfo = (struct slr_entry_dl_info *)
slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_DL_INFO);
dlinfo->dl_handler(&dlinfo->bl_context);
unreachable();
}drivers/firmware/efi/libstub/x86-stub.c void __noreturn efi_stub_entry(efi_handle_t handle, · line 989
Quoted 10 lines
drivers/firmware/efi/libstub/x86-stub.c +3
-0+} +static void __noreturn enter_kernel (unsigned long kernel_addr,struct boot_params *boot_params) {@@ -934,6 +986,9 @@ void __noreturn efi_stub_entry(efi_handle_t handle, goto fail; } +/* If a Secure Launch is in progress, this never returns */
if (IS_ENABLED(CONFIG_SECURE_LAUNCH))
Quoted 8 lines
drivers/firmware/efi/libstub/x86-stub.c +2
-1+efi_secure_launch (boot_params); +/* * Call the SEV init code while still running with the firmware's * GDT/IDT, so #VC exceptions will be handled by EFI. -- 2.39.3
Re: [PATCH v8 15/15] x86: EFI stub DRTM launch support for Secure Launch
Quoted 28 lines · Ard Biesheuvel
Quoted 27 lines · Ross Philipson
This support allows the DRTM launch to be initiated after an EFI stub launch of the Linux kernel is done. This is accomplished by providing a handler to jump to when a Secure Launch is in progress. This has to be called after the EFI stub does Exit Boot Services.
Signed-off-by Ross Philipson <[email protected]>--- drivers/firmware/efi/libstub/x86-stub.c | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+)drivers/firmware/efi/libstub/x86-stub.c +1
-0@@ -9,6 +9,7 @@#include <linux/efi.h> #include <linux/pci.h> #include <linux/stddef.h> +#include <linux/slr_table.h> #include <asm/efi.h> #include <asm/e820/types.h> @@ -810,6 +811,57 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)return EFI_SUCCESS ; }
Quoted 14 lines
drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 824
Quoted 11 lines
drivers/firmware/efi/libstub/x86-stub.c +11
-0+static void efi_secure_launch (struct boot_params *boot_params) +{ +struct slr_entry_uefi_config *uefi_config; +struct slr_uefi_cfg_entry *uefi_entry; +struct slr_entry_dl_info *dlinfo; +efi_guid_t guid =SLR_TABLE_GUID ; +struct slr_table *slrt; +u64 memmap_hi; +void *table; +u8 buf[64 ] = {0 }; +If you add a flex array to
slr_entry_uefi_configas I suggested in response to the other patch, we could simplify this substantially
I feel like there is some reason why we did not use flex arrays. We were talking and we seem to remember we used to use them and someone asked us to remove them. We are still looking into it. But if we can go back to them, I will take all the changes you recommended here.
Thanks
Ross
Quoted 127 lines
static struct
slr_entry_uefi_configcfg = {.hdr.tag = SLR_ENTRY_UEFI_CONFIG, .hdr.size = sizeof(cfg), .revision = SLR_UEFI_CONFIG_REVISION, .nr_entries = 1, .entries[0] = { .pcr = 18,.evt_info = "Measured UEFI memory map",
},
};cfg.entries[0].cfg =
boot_params->efi_info.efi_memmap|(u64)boot_params->efi_info.efi_memmap_hi << 32;cfg.entries[0].size =
boot_params->efi_info.efi_memmap_size;Quoted 4 lines
drivers/firmware/efi/libstub/x86-stub.c +4
-0+ table =get_efi_config_table (guid); + +/* +* The presence of this table indicated a Secure Launch drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 838
Quoted 10 lines
drivers/firmware/efi/libstub/x86-stub.c +10
-0+* is being requested. +*/ +if (!table) +return ; + + slrt = (struct slr_table *)table; + +if (slrt->magic !=SLR_TABLE_MAGIC ) +return ; +slrt = (struct
slr_table*)get_efi_config_table(guid); if (!slrt ||slrt->magic!=SLR_TABLE_MAGIC)return;Quoted 5 lines
drivers/firmware/efi/libstub/x86-stub.c +5
-0+/* Add config information to measure the UEFI memory map */ + uefi_config = (struct slr_entry_uefi_config *)buf; + uefi_config->hdr.tag =SLR_ENTRY_UEFI_CONFIG ; + uefi_config->hdr.size =sizeof (*uefi_config) +sizeof (*uefi_entry); + uefi_config->revision =SLR_UEFI_CONFIG_REVISION ;drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 853
Quoted 10 lines
drivers/firmware/efi/libstub/x86-stub.c +10
-0+ uefi_config->nr_entries =1 ; + uefi_entry = (struct slr_uefi_cfg_entry *)(buf +sizeof (*uefi_config)); + uefi_entry->pcr =18 ; + uefi_entry->cfg = boot_params->efi_info.efi_memmap; + memmap_hi = boot_params->efi_info.efi_memmap_hi; + uefi_entry->cfg |= memmap_hi <<32 ; + uefi_entry->size = boot_params->efi_info.efi_memmap_size; +memcpy (&uefi_entry->evt_info[0 ],"Measured UEFI memory map" , +strlen ("Measured UEFI memory map" )); +Drop all of this
drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 854
Quoted 1 line
drivers/firmware/efi/libstub/x86-stub.c +1
-0+if (slr_add_entry (slrt, (struct slr_entry_hdr *)uefi_config))if (
slr_add_entry(slrt, &uefi_config.hdr))drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 862
Quoted 8 lines
drivers/firmware/efi/libstub/x86-stub.c +8
-0+return ; + +/* Jump through DL stub to initiate Secure Launch */ + dlinfo = (struct slr_entry_dl_info *) +slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_DL_INFO ); + + asmvolatile ("jmp *%%rax" + : :"a" (dlinfo->dl_handler),"D" (&dlinfo->bl_context));Fix the prototype and just do
dlinfo->dl_handler(&dlinfo->bl_context);unreachable();So in summary, this becomes
static void
efi_secure_launch(struct boot_params *boot_params){ static struct slr_entry_uefi_config cfg = { .hdr.tag = SLR_ENTRY_UEFI_CONFIG, .hdr.size = sizeof(cfg), .revision = SLR_UEFI_CONFIG_REVISION, .nr_entries = 1, .entries[0] = { .pcr = 18, .evt_info = "Measured UEFI memory map", }, }; struct slr_entry_dl_info *dlinfo; efi_guid_t guid = SLR_TABLE_GUID; struct slr_table *slrt; /* * The presence of this table indicated a Secure Launch * is being requested. */ slrt = (struct slr_table *)get_efi_config_table(guid); if (!slrt || slrt->magic != SLR_TABLE_MAGIC) return; cfg.entries[0].cfg = boot_params->efi_info.efi_memmap | (u64)boot_params->efi_info.efi_memmap_hi << 32; cfg.entries[0].size = boot_params->efi_info.efi_memmap_size; if (slr_add_entry(slrt, &cfg.hdr)) return; /* Jump through DL stub to initiate Secure Launch */ dlinfo = (struct slr_entry_dl_info *) slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_DL_INFO); dlinfo->dl_handler(&dlinfo->bl_context); unreachable(); }Quoted 9 lines
drivers/firmware/efi/libstub/x86-stub.c +2
-0+} +static void __noreturn enter_kernel (unsigned long kernel_addr,struct boot_params *boot_params) {@@ -934,6 +986,9 @@ void __noreturn efi_stub_entry(efi_handle_t handle, goto fail; }
Quoted 13 lines
drivers/firmware/efi/libstub/x86-stub.c void __noreturn efi_stub_entry(efi_handle_t handle, · line 989
Quoted 1 line
drivers/firmware/efi/libstub/x86-stub.c +1
-0+/* If a Secure Launch is in progress, this never returns */ if (
IS_ENABLED(CONFIG_SECURE_LAUNCH))Quoted 8 lines
drivers/firmware/efi/libstub/x86-stub.c +2
-1+efi_secure_launch (boot_params); +/* * Call the SEV init code while still running with the firmware's * GDT/IDT, so #VC exceptions will be handled by EFI. -- 2.39.3
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
H. Peter Anvin
reviewerRe: [PATCH v8 15/15] x86: EFI stub DRTM launch support for Secure Launch
Quoted 44 lines · On February 21, 2024 12:17:30 PM PST, [email protected] wrote:
Quoted 28 lines · Ard Biesheuvel
Quoted 27 lines · Ross Philipson
This support allows the DRTM launch to be initiated after an EFI stub launch of the Linux kernel is done. This is accomplished by providing a handler to jump to when a Secure Launch is in progress. This has to be called after the EFI stub does Exit Boot Services.
Signed-off-by Ross Philipson <[email protected]>--- drivers/firmware/efi/libstub/x86-stub.c | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+)drivers/firmware/efi/libstub/x86-stub.c +1
-0@@ -9,6 +9,7 @@#include <linux/efi.h> #include <linux/pci.h> #include <linux/stddef.h> +#include <linux/slr_table.h> #include <asm/efi.h> #include <asm/e820/types.h> @@ -810,6 +811,57 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)return EFI_SUCCESS ; }Quoted 14 lines
drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 824
Quoted 11 lines
drivers/firmware/efi/libstub/x86-stub.c +11
-0+static void efi_secure_launch (struct boot_params *boot_params) +{ +struct slr_entry_uefi_config *uefi_config; +struct slr_uefi_cfg_entry *uefi_entry; +struct slr_entry_dl_info *dlinfo; +efi_guid_t guid =SLR_TABLE_GUID ; +struct slr_table *slrt; +u64 memmap_hi; +void *table; +u8 buf[64 ] = {0 }; +If you add a flex array to
slr_entry_uefi_configas I suggested in response to the other patch, we could simplify this substantially
Quoted 146 lines
I feel like there is some reason why we did not use flex arrays. We were talking and we seem to remember we used to use them and someone asked us to remove them. We are still looking into it. But if we can go back to them, I will take all the changes you recommended here.
Thanks
RossQuoted 140 lines
static struct
slr_entry_uefi_configcfg = {.hdr.tag = SLR_ENTRY_UEFI_CONFIG, .hdr.size = sizeof(cfg), .revision = SLR_UEFI_CONFIG_REVISION, .nr_entries = 1, .entries[0] = { .pcr = 18,.evt_info = "Measured UEFI memory map",
},
};cfg.entries[0].cfg =
boot_params->efi_info.efi_memmap|(u64)boot_params->efi_info.efi_memmap_hi << 32;cfg.entries[0].size =
boot_params->efi_info.efi_memmap_size;Quoted 4 lines
drivers/firmware/efi/libstub/x86-stub.c +4
-0+ table =get_efi_config_table (guid); + +/* +* The presence of this table indicated a Secure Launch drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 838
Quoted 10 lines
drivers/firmware/efi/libstub/x86-stub.c +10
-0+* is being requested. +*/ +if (!table) +return ; + + slrt = (struct slr_table *)table; + +if (slrt->magic !=SLR_TABLE_MAGIC ) +return ; +slrt = (struct
slr_table*)get_efi_config_table(guid); if (!slrt ||slrt->magic!=SLR_TABLE_MAGIC)return;Quoted 5 lines
drivers/firmware/efi/libstub/x86-stub.c +5
-0+/* Add config information to measure the UEFI memory map */ + uefi_config = (struct slr_entry_uefi_config *)buf; + uefi_config->hdr.tag =SLR_ENTRY_UEFI_CONFIG ; + uefi_config->hdr.size =sizeof (*uefi_config) +sizeof (*uefi_entry); + uefi_config->revision =SLR_UEFI_CONFIG_REVISION ;drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 853
Quoted 10 lines
drivers/firmware/efi/libstub/x86-stub.c +10
-0+ uefi_config->nr_entries =1 ; + uefi_entry = (struct slr_uefi_cfg_entry *)(buf +sizeof (*uefi_config)); + uefi_entry->pcr =18 ; + uefi_entry->cfg = boot_params->efi_info.efi_memmap; + memmap_hi = boot_params->efi_info.efi_memmap_hi; + uefi_entry->cfg |= memmap_hi <<32 ; + uefi_entry->size = boot_params->efi_info.efi_memmap_size; +memcpy (&uefi_entry->evt_info[0 ],"Measured UEFI memory map" , +strlen ("Measured UEFI memory map" )); +Drop all of this
drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 854
Quoted 1 line
drivers/firmware/efi/libstub/x86-stub.c +1
-0+if (slr_add_entry (slrt, (struct slr_entry_hdr *)uefi_config))if (
slr_add_entry(slrt, &uefi_config.hdr))drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 862
Quoted 8 lines
drivers/firmware/efi/libstub/x86-stub.c +8
-0+return ; + +/* Jump through DL stub to initiate Secure Launch */ + dlinfo = (struct slr_entry_dl_info *) +slr_next_entry_by_tag (slrt,NULL ,SLR_ENTRY_DL_INFO ); + + asmvolatile ("jmp *%%rax" + : :"a" (dlinfo->dl_handler),"D" (&dlinfo->bl_context));Fix the prototype and just do
dlinfo->dl_handler(&dlinfo->bl_context);unreachable();So in summary, this becomes
static void
efi_secure_launch(struct boot_params *boot_params){ static struct slr_entry_uefi_config cfg = { .hdr.tag = SLR_ENTRY_UEFI_CONFIG, .hdr.size = sizeof(cfg), .revision = SLR_UEFI_CONFIG_REVISION, .nr_entries = 1, .entries[0] = { .pcr = 18, .evt_info = "Measured UEFI memory map", }, }; struct slr_entry_dl_info *dlinfo; efi_guid_t guid = SLR_TABLE_GUID; struct slr_table *slrt; /* * The presence of this table indicated a Secure Launch * is being requested. */ slrt = (struct slr_table *)get_efi_config_table(guid); if (!slrt || slrt->magic != SLR_TABLE_MAGIC) return; cfg.entries[0].cfg = boot_params->efi_info.efi_memmap | (u64)boot_params->efi_info.efi_memmap_hi << 32; cfg.entries[0].size = boot_params->efi_info.efi_memmap_size; if (slr_add_entry(slrt, &cfg.hdr)) return; /* Jump through DL stub to initiate Secure Launch */ dlinfo = (struct slr_entry_dl_info *) slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_DL_INFO); dlinfo->dl_handler(&dlinfo->bl_context); unreachable(); }drivers/firmware/efi/libstub/x86-stub.c void __noreturn efi_stub_entry(efi_handle_t handle, · line 989
Quoted 10 lines
drivers/firmware/efi/libstub/x86-stub.c +3
-0+} +static void __noreturn enter_kernel (unsigned long kernel_addr,struct boot_params *boot_params) {@@ -934,6 +986,9 @@ void __noreturn efi_stub_entry(efi_handle_t handle, goto fail; } +/* If a Secure Launch is in progress, this never returns */ if (
IS_ENABLED(CONFIG_SECURE_LAUNCH))Quoted 8 lines
drivers/firmware/efi/libstub/x86-stub.c +2
-1+efi_secure_launch (boot_params); +/* * Call the SEV init code while still running with the firmware's * GDT/IDT, so #VC exceptions will be handled by EFI. -- 2.39.3
Linux kernel code doesn't use VLAs because of the limited stack size, and VLAs or alloca() makes stack size tracking impossible. Although this technically speaking runs in a different environment, it is easier to enforce the constraint globally.
_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Ard Biesheuvel
maintainerRe: [PATCH v8 15/15] x86: EFI stub DRTM launch support for Secure Launch
Quoted 46 lines · H. Peter Anvin
Quoted 44 lines · On February 21, 2024 12:17:30 PM PST, [email protected] wrote:
Quoted 42 lines · Ard Biesheuvel
Quoted 28 lines · Ross Philipson
This support allows the DRTM launch to be initiated after an EFI stub launch of the Linux kernel is done. This is accomplished by providing a handler to jump to when a Secure Launch is in progress. This has to be called after the EFI stub does Exit Boot Services.
Signed-off-by Ross Philipson <[email protected]>--- drivers/firmware/efi/libstub/x86-stub.c | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+)drivers/firmware/efi/libstub/x86-stub.c +2
-0@@ -9,6 +9,7 @@#include <linux/efi.h> #include <linux/pci.h> #include <linux/stddef.h> +#include <linux/slr_table.h> #include <asm/efi.h> #include <asm/e820/types.h> @@ -810,6 +811,57 @@ static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry)return EFI_SUCCESS ; } +static void efi_secure_launch (struct boot_params *boot_params)drivers/firmware/efi/libstub/x86-stub.c static efi_status_t efi_decompress_kernel(unsigned long *kernel_entry) · line 824
Quoted 10 lines
drivers/firmware/efi/libstub/x86-stub.c +10
-0+{ +struct slr_entry_uefi_config *uefi_config; +struct slr_uefi_cfg_entry *uefi_entry; +struct slr_entry_dl_info *dlinfo; +efi_guid_t guid =SLR_TABLE_GUID ; +struct slr_table *slrt; +u64 memmap_hi; +void *table; +u8 buf[64 ] = {0 }; +If you add a flex array to
slr_entry_uefi_configas I suggested in response to the other patch, we could simplify this substantially
Quoted 4 lines
Quoted 2 lines
I feel like there is some reason why we did not use flex arrays. We were talking and we seem to remember we used to use them and someone asked us to remove them. We are still looking into it. But if we can go back to them, I will take all the changes you recommended here.
Linux kernel code doesn't use VLAs because of the limited stack size, and VLAs or
alloca()makes stack size tracking impossible. Although this technically speaking runs in a different environment, it is easier to enforce the constraint globally.
Flex array != VLA
VLAs were phased out because of this reason (and VLAISs [VLAs in structs] were phased out before that because they are a GNU extension and not supported by Clang)
Today, VLAs are not supported anywhere in the kernel.
Flex arrays are widely used in the kernel. A flex array is a trailing array of unspecified size in a struct that makes the entire *type* have a variable size. But that does not make them VLAs (or VLAISs) - a VLA is a stack allocated *variable* whose size is based on a function parameter.
Instances of types containing flex arrays can be allocated statically, or dynamically on the heap. This is common practice in the kernel, and even supported by instrumentation to help the compiler track the runtime size and flag overruns. We are even in the process of adding compiler support to annotate struct members as carrying the number of elements in an associated flex arrays, to improve the coverage of the instrumentation.
I am not asking for a VLA here, only a flex array.
kernel test robot
build botRe: [PATCH v8 15/15] x86: EFI stub DRTM launch support for Secure Launch
In reply to Ross Philipsonkernel test robot noticed the following build errors:
Hi Ross,
kernel test robot noticed the following build errors:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on char-misc/char-misc-next char-misc/char-misc-linus herbert-cryptodev-2.6/master herbert-crypto-2.6/master linus/master v6.8-rc4 next-20240216] [cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ross-Philipson/x86-boot-Place-kernel_info-at-a-fixed-offset/20240215-064712 base: char-misc/char-misc-testing patch link: https://lore.kernel.org/r/20240214221847.2066632-16-ross.philipson%40oracle.com patch subject: [PATCH v8 15/15] x86: EFI stub DRTM launch support for Secure Launch config: i386-randconfig-052-20240215 (https://download.01.org/0day-ci/archive/20240217/[email protected]/config) compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240217/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/firmware/efi/libstub/x86-stub.c:862:18: error: invalid input size for constraint 'a'
862 | : : "a" (dlinfo->dl_handler), "D" (&dlinfo->bl_context));
| ^1 error generated.
vim +/a +862 drivers/firmware/efi/libstub/x86-stub.c
813
814 static void efi_secure_launch(struct boot_params *boot_params)
815 {
816 struct slr_entry_uefi_config *uefi_config;
817 struct slr_uefi_cfg_entry *uefi_entry;
818 struct slr_entry_dl_info *dlinfo;
819 efi_guid_t guid = SLR_TABLE_GUID;
820 struct slr_table *slrt;
821 u64 memmap_hi;
822 void *table;
823 u8 buf[64] = {0};
824
825 table = get_efi_config_table(guid);
826
827 /*
828 * The presence of this table indicated a Secure Launch
829 * is being requested.
830 */
831 if (!table)
832 return;
833
834 slrt = (struct slr_table *)table;
835
836 if (slrt->magic != SLR_TABLE_MAGIC)
837 return;
838
839 /* Add config information to measure the UEFI memory map */
840 uefi_config = (struct slr_entry_uefi_config *)buf;
841 uefi_config->hdr.tag = SLR_ENTRY_UEFI_CONFIG;
842 uefi_config->hdr.size = sizeof(*uefi_config) + sizeof(*uefi_entry);
843 uefi_config->revision = SLR_UEFI_CONFIG_REVISION;
844 uefi_config->nr_entries = 1;
845 uefi_entry = (struct slr_uefi_cfg_entry *)(buf + sizeof(*uefi_config));
846 uefi_entry->pcr = 18;
847 uefi_entry->cfg = boot_params->efi_info.efi_memmap;
848 memmap_hi = boot_params->efi_info.efi_memmap_hi;
849 uefi_entry->cfg |= memmap_hi << 32;
850 uefi_entry->size = boot_params->efi_info.efi_memmap_size;
851 memcpy(&uefi_entry->evt_info[0], "Measured UEFI memory map",
852 strlen("Measured UEFI memory map"));
853
854 if (slr_add_entry(slrt, (struct slr_entry_hdr *)uefi_config))
855 return;
856
857 /* Jump through DL stub to initiate Secure Launch */
858 dlinfo = (struct slr_entry_dl_info *)
859 slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_DL_INFO);
860
861 asm volatile ("jmp *%%rax"
> 862 : : "a" (dlinfo->dl_handler), "D" (&dlinfo->bl_context));
863 }
864
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v8 15/15] x86: EFI stub DRTM launch support for Secure Launch
In reply to Ross Philipsonkernel test robot noticed the following build errors:
Hi Ross,
kernel test robot noticed the following build errors:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on char-misc/char-misc-next char-misc/char-misc-linus herbert-cryptodev-2.6/master herbert-crypto-2.6/master linus/master v6.8-rc4 next-20240216] [cannot apply to tip/x86/core]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Ross-Philipson/x86-boot-Place-kernel_info-at-a-fixed-offset/20240215-064712 base: char-misc/char-misc-testing patch link: https://lore.kernel.org/r/20240214221847.2066632-16-ross.philipson%40oracle.com patch subject: [PATCH v8 15/15] x86: EFI stub DRTM launch support for Secure Launch config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20240218/[email protected]/config) compiler: gcc-12 (Debian 12.2.0-14) 12.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240218/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In function 'efi_secure_launch',
inlined from 'efi_stub_entry' at drivers/firmware/efi/libstub/x86-stub.c:990:2:
>> drivers/firmware/efi/libstub/x86-stub.c:861:9: error: inconsistent operand constraints in an 'asm'
861 | asm volatile ("jmp *%%rax"
| ^~~vim +/asm +861 drivers/firmware/efi/libstub/x86-stub.c
813
814 static void efi_secure_launch(struct boot_params *boot_params)
815 {
816 struct slr_entry_uefi_config *uefi_config;
817 struct slr_uefi_cfg_entry *uefi_entry;
818 struct slr_entry_dl_info *dlinfo;
819 efi_guid_t guid = SLR_TABLE_GUID;
820 struct slr_table *slrt;
821 u64 memmap_hi;
822 void *table;
823 u8 buf[64] = {0};
824
825 table = get_efi_config_table(guid);
826
827 /*
828 * The presence of this table indicated a Secure Launch
829 * is being requested.
830 */
831 if (!table)
832 return;
833
834 slrt = (struct slr_table *)table;
835
836 if (slrt->magic != SLR_TABLE_MAGIC)
837 return;
838
839 /* Add config information to measure the UEFI memory map */
840 uefi_config = (struct slr_entry_uefi_config *)buf;
841 uefi_config->hdr.tag = SLR_ENTRY_UEFI_CONFIG;
842 uefi_config->hdr.size = sizeof(*uefi_config) + sizeof(*uefi_entry);
843 uefi_config->revision = SLR_UEFI_CONFIG_REVISION;
844 uefi_config->nr_entries = 1;
845 uefi_entry = (struct slr_uefi_cfg_entry *)(buf + sizeof(*uefi_config));
846 uefi_entry->pcr = 18;
847 uefi_entry->cfg = boot_params->efi_info.efi_memmap;
848 memmap_hi = boot_params->efi_info.efi_memmap_hi;
849 uefi_entry->cfg |= memmap_hi << 32;
850 uefi_entry->size = boot_params->efi_info.efi_memmap_size;
851 memcpy(&uefi_entry->evt_info[0], "Measured UEFI memory map",
852 strlen("Measured UEFI memory map"));
853
854 if (slr_add_entry(slrt, (struct slr_entry_hdr *)uefi_config))
855 return;
856
857 /* Jump through DL stub to initiate Secure Launch */
858 dlinfo = (struct slr_entry_dl_info *)
859 slr_next_entry_by_tag(slrt, NULL, SLR_ENTRY_DL_INFO);
860
> 861 asm volatile ("jmp *%%rax" 862 : : "a" (dlinfo->dl_handler), "D" (&dlinfo->bl_context));
863 }
864
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki