Skip to contentSkip to conversation

x86: Trenchboot secure dynamic launch Linux kernel support

PATCH Superseded Ross Philipson 4 participants 34 messages Apr 10, 2025 – Apr 15, 2025

Subsystems (12)
Documentation x86 Crypto API IOMMU +8 more subsystems

v13 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v13 cover x86: Trenchboot secure dynamic launch Linux kernel support

This is a reposting of the recently posted Secure Launch v13 patch set. This version contains a summary of what is already reviewed in the patch set and what patches need reviews:

- Patches 1/8/14/15/16/17/19 already have reviews done for them.
- Patches 2/3/4/7/9/10/11/12/13/18 need to be reviewed by one of the x86 folks.
- Patches 5/6 need a review from a lib/crypto maintainer.

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.

Links:

The TrenchBoot project including documentation:

https://trenchboot.org

The TrenchBoot project on Github:

https://github.com/trenchboot

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

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:

torvalds/master/3a90a72aca0a98125f0c7350ffb7cc63665f8047

Finally we would like to thank everyone for their input and assistance. It has all been very helpful in improving the quality of our solution and in reviewing/strengthening our security posture.

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.

Changes in v9:
- Updated DL stub support for recent changes to EFI stub in the kernel.
- Added patches to fix locality changing support in the TPM driver (these patches originally were posted as a separate set).
- Enhanced Secure Launch TPM locality 2 setting in the TPM driver.
- Added locality setting support through sysfs for user land to access.
- Split up SHA1 and SHA256 changes into separate patches and updated the commit messages to be more clear (per request from upstream review).
- Fix Clang compile issues detected by kernel test robot.
- Modifications to the Secure Launch Resource Table ABI:
. Use flex arrays in table structures.
. Update and move fields in tables to make everything 8b aligned. . Add 2 new DLME fields and a txt_heap address field.
. Remove platform specific tables that are not defined yet (AMD/ARM).
- Update Kconfig dependencies for Secure Launch with SHA1/SHA256/TPM.
- Remove push/pop of rsi since boot params is now stored in r15.
- Update outdated kernel documentation.
- Misc. comment fixes for type-os and mispellings.

Changes in v10:
- Removed patch #1 from previous set that forced the kernel_info section at a fixed offset.
- Add changes from Ard Biesheuvel to use the link step to generate the proper relative offsets for the MLE header in the kernel_info section.
- Fix sizes and alignment slightly in the SLR table. Add comments to the SLR header to indicate it is defined by the TrenchBoot project.
- Remove incorrect extra pop instruction noted in the head_64.S changes.
- Use the prefix tpm/tpm2 to distinguish between TPM versions as is done in the rest of the TPM related code.
- Rework the TPM locality setting/reporting changes to use "default" locality as opposed to "preferred". Remove uneeded extra locality function in the TPM interface (call the chip function directly).
- Adopt comment/documentation changes to code and commit message per requests from the community.
- Use u64 for the boot params physical address to avoid truncating pointers during casts.
- Split adding of new MSR registers into its own patch.
- Attempt to further address justification for using SHA-1 algorithm. Pick up some code suggestions for the SHA-1 patch.
- Introduct slaunch_is_txt_launch() function per Jarkko Sakkinen's suggestion.
- Implement minor changes to the EFI stub code per suggestions.

Changes in v11:
- Add section to user documents about SHA-1 usage with Secure Launch as requested.
- General cleanup and grammar fixes to the Linux user documentation.
- Fix use of CONFIG_SECURE_LAUNCH in the EFI stub code to prevent 32b build failures.
- Cleanup of early event log handling code.

Changes in v12:
- Modify the event processing and PCR extending code to cap all unknown algorithm bank PCRs and extend the cap digest into those banks/PCRs.
- Fix documentation to have the correct NIST terminology and document links.
- Switch custom SL vendor specific TPM event types used as markers back to type NO_ACTION to allow proper event log parsing.
- Move boot_params_addr from the TXT heap into the SLRT Intel information table to make SLRT architecture specific table usage more consistent.
- Change SL Kconfig dependencies from TCG_TPM to TCG_TIS && TCG_CRB to more accurately depend of the underlying TPM driver components.
- Remove unwanted Unicode characters from documentation and comments plus minor documentation fix.

Changes in v13:
- Documentation rework:
* Make the documentation for Secure Launch (patch 1) more concise and readable.
* Fix and add comments to code.
* Update some commit messages to be clearer.

Daniel P. Smith (6):
Documentation/x86: Secure Launch kernel documentation
x86: Add early SHA-1 support for Secure Launch early measurements
x86: Add early SHA-256 support for Secure Launch early measurements tpm, tpm_tis: Close all localities
tpm, tpm_tis: Address positive localities in
tpm_tis_request_locality()
x86: Secure Launch late initcall platform module

Ross Philipson (13):
x86: Secure Launch Kconfig
x86: Secure Launch Resource Table header file
x86: Secure Launch main header file
x86/msr: Add variable MTRR base/mask and x2apic ID registers x86/boot: Place TXT MLE header in the kernel_info section
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 x86/reboot: Secure Launch SEXIT support on reboot paths tpm, tpm_tis: Allow locality to be set to a different value tpm, sysfs: Show locality used by kernel
x86/efi: 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  | 308 ++++++++
 .../secure_launch_details.rst                 | 587 ++++++++++++++
 .../secure_launch_overview.rst                | 240 ++++++
 arch/x86/Kconfig                              |  11 +
 arch/x86/boot/compressed/Makefile             |   3 +
 arch/x86/boot/compressed/head_64.S            |  29 +
 arch/x86/boot/compressed/kernel_info.S        |  50 +-
 arch/x86/boot/compressed/sha1.c               |   6 +
 arch/x86/boot/compressed/sha256.c             |   6 +
 arch/x86/boot/compressed/sl_main.c            | 597 ++++++++++++++
 arch/x86/boot/compressed/sl_stub.S            | 726 ++++++++++++++++++
 arch/x86/boot/compressed/vmlinux.lds.S        |   7 +
 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                     | 596 ++++++++++++++
 arch/x86/kernel/slmodule.c                    | 508 ++++++++++++
 arch/x86/kernel/smpboot.c                     |  43 +-
 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                   |  33 +-
 drivers/char/tpm/tpm-sysfs.c                  |  10 +
 drivers/char/tpm/tpm_tis_core.c               |  21 +-
 drivers/firmware/efi/libstub/efistub.h        |   8 +
 drivers/firmware/efi/libstub/x86-stub.c       |  94 +++
 drivers/iommu/intel/dmar.c                    |   4 +
 include/crypto/sha1.h                         |   1 +
 include/linux/slaunch.h                       | 562 ++++++++++++++
 include/linux/slr_table.h                     | 308 ++++++++
 include/linux/tpm.h                           |  10 +
 kernel/kexec_core.c                           |   4 +
 lib/crypto/sha1.c                             |  81 ++
 40 files changed, 4959 insertions(+), 9 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/sha1.c
 create mode 100644 arch/x86/boot/compressed/sha256.c
 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

Range-diff v12 -> v13:
-----------------------------------------------

1: c21b641482ba ! 1: 06e0394c0802 Documentation/x86: Secure Launch kernel documentation
@@ Documentation/security/launch-integrity/index.rst (new)
## Documentation/security/launch-integrity/principles.rst (new) ##
@@
+.. SPDX-License-Identifier: GPL-2.0
-+.. Copyright (c) 2019-2024 Daniel P. Smith <[email protected]> ++.. Copyright (c) 2019-2025 Daniel P. Smith <[email protected]>
+
+=======================
+System Launch Integrity
+=======================
+
+:Author: Daniel P. Smith
-+:Date: August 2024
++:Date: March 2025
+
+This document serves to establish a common understanding of what a system +launch is, the integrity concern for system launch, and why using a Root of Trust +(RoT) from a Dynamic Launch may be desirable. Throughout this document, +terminology from the Trusted Computing Group (TCG) and National Institute for
-+Standards and Technology (NIST) is used to ensure that vendor natural language is -+used to describe and reference security-related concepts.
++Standards and Technology (NIST) is used to ensure that a vendor natural language ++describes and references security-related concepts.
+
+System Launch
+=============
+
-+There is a tendency to only consider the classical power-on boot as the only -+means to launch an Operating System (OS) on a computer system. In fact, most -+modern processors support two system launch methods. To provide clarity, -+it is important to establish a common definition of a system launch: during -+a single power life cycle of a system, a system launch consists of an initialization -+event, typically in hardware, that is followed by an executing software payload -+that takes the system from the initialized state to a running state. Driven by -+the Trusted Computing Group (TCG) architecture, modern processors are able to -+support two methods of system launch. These two methods of system launch are known -+as Static Launch and Dynamic Launch.
++There is a tendency to consider the classical power-on boot as the only means to ++launch an Operating System (OS) on a computer. In fact, driven by the ++Trusted Computing Group (TCG) architecture, modern processors are able to support ++two methods of system launch: Static Launch and Dynamic Launch.
+
+Static Launch
+-------------
@@ Documentation/security/launch-integrity/principles.rst (new)
+Dynamic Launch
+--------------
+
-+Modern CPUs architectures provides a mechanism to re-initialize the system to a -+"known good" state without requiring a power event. This re-initialization -+event is the event for a dynamic launch and is referred to as the Dynamic -+Launch Event (DLE). The DLE functions by accepting a software payload, referred ++Modern CPU architectures provide a mechanism to re-initialize the system to a ++"known good" state without requiring a power event. This re-initialization is the ++starting point for a dynamic launch and is referred to as The Dynamic Launch Event ++(DLE). The DLE functions by accepting a software payload, referred
+to as the Dynamic Configuration Environment (DCE), that execution is handed to +after the DLE is invoked. The DCE is responsible for bringing the system back
-+to a running state. Since the dynamic launch is not tied to a power event like -+the static launch, this enables a dynamic launch to be initiated at any time ++to a running state. Since the dynamic launch is not tied to a power event like the ++static launch is, this enables a dynamic launch to be initiated at any time
+and multiple times during a single power life cycle. This dynamism is the +reasoning behind referring to this system launch as "dynamic".
+
+Because a dynamic launch can be conducted at any time during a single power
-+life cycle, they are classified into one of two types: an early launch or a ++life cycle, it is classified as either one of two types: an early launch or a
+late launch.
+
-+:Early Launch: When a dynamic launch is used as a transition from a static ++:Early Launch: A dynamic launch that is used as a transition from a static
+ launch chain to the final Operating System.
+
-+:Late Launch: The usage of a dynamic launch by an executing Operating System to ++:Late Launch: A dynamic launch by an executing Operating System to
+ transition to a "known good" state to perform one or more operations, e.g. to
+ launch into a new Operating System.
+
+System Integrity
+================
+
-+A computer system can be considered a collection of mechanisms that work -+together to produce a result. The assurance that the mechanisms are functioning -+correctly and producing the expected result is the integrity of the system. To -+ensure a system's integrity, there is a subset of these mechanisms, commonly -+referred to as security mechanisms, that is present to help ensure the system -+produces the expected result or at least detects the potential of an unexpected -+result. Since the security mechanisms are relied upon to ensue the integrity of -+the system, these mechanisms are trusted. Upon inspection, these security -+mechanisms each have a set of properties and these properties can be evaluated -+to determine how susceptible a mechanism might be to failure. This assessment is -+referred to as the Strength of Mechanism, which allows the trustworthiness of -+that mechanism to be quantified.
-+
-+For software systems, there are two system states for which the integrity is -+critical: when the software is loaded into memory and when the software is -+executing on the hardware. Ensuring that the expected software is loaded into -+memory is referred to as load-time integrity while ensuring that the software -+executing is the expected software is the runtime integrity of that software. ++For software systems, there are two system states for which the integrity of the ++software is critical: when it is loaded into memory and when it is executing on the ++hardware. Ensuring that the expected software is loaded into memory is referred to ++as load-time integrity. Ensuring that the software executing is the expected ++payload is the runtime integrity of that software.
+
+Load-time Integrity
+-------------------
+
-+It is critical to understand what load-time integrity establishes about a -+system and what is assumed, i.e. what is being trusted. Load-time integrity is -+when a trusted entity, i.e. an entity with an assumed integrity, takes an -+action to assess an entity being loaded into memory before it is used. A -+variety of mechanisms may be used to conduct the assessment, each with -+different properties. A particular property is whether the mechanism creates an -+evidence of the assessment. Often either cryptographic signature checking or ++Load-time integrity is when a trusted entity, i.e. an entity with an assumed ++integrity, takes an action to assess an entity being loaded into memory before ++it is used. A variety of mechanisms may be used to conduct the assessment, each ++with different properties. A particular property is whether the mechanism creates ++an evidence of the assessment. Often either cryptographic signature checking or
+hashing are the common assessment operations used.
+
+A signature checking assessment functions by requiring a representation of the +accepted authorities and uses those representations to assess if the entity has
-+been signed by an accepted authority. The benefit to this process is that -+assessment process includes an adjudication of the assessment. The drawbacks -+are that 1) the adjudication is susceptible to tampering by the Trusted -+Computing Base (TCB), 2) there is no evidence to assert that an untampered -+adjudication was completed, and 3) the system must be an active participant in -+the key management infrastructure.
-+
-+A cryptographic hashing assessment does not adjudicate the assessment, but ++been signed by an accepted authority. The benefit of this process is that it ++includes an adjudication of the assessment. The drawbacks are that 1) the adjudication ++is susceptible to tampering by the Trusted Computing Base (TCB), 2) there is no ++evidence to assert that an untampered adjudication was completed, and 3) the system ++must be an active participant in the key management infrastructure.
++
++A cryptographic measurement does not adjudicate the assessment, but
+instead generates evidence of the assessment to be adjudicated independently.
-+The benefits to this approach is that the assessment may be simple such that it -+may be implemented in an immutable mechanism, e.g. in hardware. Additionally, ++The benefit to this approach is that the assessment may be simplified such that it ++can be implemented in an immutable mechanism, e.g. in hardware. Additionally,
+it is possible for the adjudication to be conducted where it cannot be tampered +with by the TCB. The drawback is that a compromised environment will be allowed +to execute until an adjudication can be completed.
@@ Documentation/security/launch-integrity/principles.rst (new)
+Runtime Integrity
+-----------------
+
-+Runtime integrity in the general sense is when a trusted entity makes an -+assessment of an entity at any point in time during the assessed entity's ++Runtime integrity, in the general sense, is when a trusted entity makes an ++assessment of another entity at any point in time during the assessed entity's
+execution. A more concrete explanation is the taking of an integrity assessment +of an active process executing on the system at any point during the process' +execution. Often the load-time integrity of an operating system's user-space,
@@ Documentation/security/launch-integrity/principles.rst (new)
+
+Building upon the understanding of security mechanisms to establish load-time +integrity of an entity, it is possible to chain together load-time integrity
-+assessments to establish the integrity of the whole system. This process is -+known as transitive trust and provides the concept of building a chain of -+load-time integrity assessments, commonly referred to as a trust chain. These -+assessments may be used to adjudicate the load-time integrity of the whole -+system. This trust chain is started by a trusted entity that does the first -+assessment. This first entity is referred to as the Root of Trust(RoT) with the -+entities name being derived from the mechanism used for the assessment, i.e. -+RoT for Verification (RTV) and RoT for Measurement (RTM).
++assessments to establish the integrity of the whole system. The process of ++creating this chain involves using a series of transitive trust assertions to ++establish confidence in the load-time integrity of each component loaded. ++
++This process is known as transitive trust and provides the concept of building ++a chain of load-time integrity assessments, commonly referred to as a trust ++chain. These assessments may be used to adjudicate the load-time integrity of ++the whole system. This trust chain is started by a trusted entity that does the ++first assessment. This first entity is referred to as the Root of Trust (RoT) ++with the entity's name being derived from the mechanism used for the assessment, ++i.e. RoT for Verification (RTV) and RoT for Measurement (RTM).
+
+A trust chain is itself a mechanism, specifically a mechanism of mechanisms, +and therefore it also has a Strength of Mechanism. The factors that contribute
@@ Documentation/security/launch-integrity/principles.rst (new)
+
+ - The strength of the chain's RoT
+ - The strength of each member of the trust chain
-+ - The length, i.e. the number of members, of the chain
++ - The length (i.e. the number of members) of the chain
+
-+Therefore, the strongest trust chains should start with a strong RoT and should -+consist of members being of low complexity and minimize the number of members ++Therefore, the strongest trust chains should start with a strong RoT, ++consist of members being of low complexity, and minimize the number of members
+participating. In a more colloquial sense, a trust chain is only as strong as its
-+weakest link, thus more links increase the probability of a weak link. ++weakest link, therefore more links increase the probability of a weak link.
+
+Dynamic Launch Components
+=========================
+
+The TCG architecture for dynamic launch is composed of a component series +used to set up and then carry out the launch. These components work together to
-+construct an RTM trust chain that is rooted in the dynamic launch and thus commonly ++construct an RTM trust chain rooted in the dynamic launch, commonly
+referred to as the Dynamic Root of Trust for Measurement (DRTM) chain. +
++.. note::
++ Intel TXT pre-dates the TCG Dynamic Launch specification. In the Intel TXT
++ documentation, Dynamic Root of Trust for Measurement was abbreviated as DRTM.
++ When Dynamic Launch was codified in the TCG specification, it was given
++ the acronym D-RTM. There is a similar situation with Static Root of Trust for
++ Measuremnt. In TCG documentation it will be given the acronym S-RTM but it is not
++ uncommon to see it as SRTM. For the purposes of the launch integrity documents,
++ DRTM and SRTM will be the preferred acronym.
++
+What follows is a brief explanation of each component in execution order. A
-+subset of these components are what establishes the dynamic launch's trust ++subset of these components is what establishes the dynamic launch's trust
+chain.
+
+Dynamic Configuration Environment Preamble
@@ Documentation/security/launch-integrity/principles.rst (new)
+final/target operating system, or it may be a bootloader that will load the +final/target operating system.
+
-+Why DRTM
-+========
++Why DRTM?
++=========
+
-+It is a fact that DRTM increases the load-time integrity of the system by -+providing a trust chain that has an immutable hardware RoT, uses a limited ++A DRTM solution increases the load-time integrity of the system by ++providing a trust chain that has an immutable hardware RoT and uses a limited
+number of small, special purpose code to establish the trust chain that starts +the target operating system. As mentioned in the Trust Chain section, these are
-+the main three factors in driving up the strength of a trust chain. As has been -+seen with the BootHole exploit, which in fact did not affect the integrity of -+DRTM solutions, the sophistication of attacks targeting system launch is at an ++three main factors in driving up the strength of a trust chain. As has been ++seen with the BootHole exploit (which in fact did not affect the integrity of ++DRTM solutions), the sophistication of attacks targeting system launch is at an
+all-time high. There is no reason a system should not employ every available +hardware integrity measure. This is the crux of a defense-in-depth
-+approach to system security. In the past, the now closed SMI gap was often -+pointed to as invalidating DRTM, which in fact was nothing but a straw man -+argument. As has continued to be demonstrated, if/when SMM is corrupted, it can ++approach to system security.
++
++In the past, the now closed SMI gap was often pointed to as invalidating DRTM. ++As has continued to be demonstrated, if/when SMM is corrupted, it can
+always circumvent all load-time integrity (SRTM and DRTM) because it is a +run-time integrity problem. Regardless, Intel and AMD have both deployed +runtime integrity for SMI and SMM which is tied directly to DRTM such that this
-+perceived deficiency is now non-existent and the world is moving forward with ++perceived deficiency is now non-existent. The world is moving forward with
+an expectation that DRTM must be present.
+
+Glossary
@@ Documentation/security/launch-integrity/principles.rst (new)
## Documentation/security/launch-integrity/secure_launch_details.rst (new) ##
@@
+.. SPDX-License-Identifier: GPL-2.0
-+.. Copyright (c) 2019-2024 Daniel P. Smith <[email protected]> ++.. Copyright (c) 2019-2025 Daniel P. Smith <[email protected]>
+
+===================================
+Secure Launch Config and Interfaces
+===================================
+
+:Author: Daniel P. Smith
-+:Date: August 2024
++:Date: March 2025
+
+Configuration
+=============
@@ Documentation/security/launch-integrity/secure_launch_details.rst (new)
+
+Description:
+
-+During early validation, a buffer or region was found to straddle the 4GB ++During early validation, a buffer or region was found to straddle the 4Gb
+boundary. Because of the way TXT provides DMA memory protection, this is an unsafe +configuration and is flagged as an error. This is most likely a configuration +issue in the pre-launch environment. It could also be the sign of an attempted
@@ Documentation/security/launch-integrity/secure_launch_details.rst (new)
+
+Description:
+
-+A memory region used by the MLE is above 4GB. In general this is not a problem ++A memory region used by the MLE is above 4Gb. In general this is not a problem
+because memory > 4Gb can be protected from DMA. There are certain buffers that +should never be above 4Gb, and one of these caused the violation. This is most +likely a configuration issue in the pre-launch environment. It could also be
@@ Documentation/security/launch-integrity/secure_launch_details.rst (new)
+
+Description:
+
-+On a system with more than 4G of RAM, the high PMR [2]_ base address should be -+set to 4G. This error is due to that not being the case. This PMR value is set ++On a system with more than 4Gb of RAM, the high PMR [2]_ base address should be ++set to 4Gb. This error is due to that not being the case. This PMR value is set
+by the pre-launch environment, so the issue most likely originates there. It +could also be the sign of an attempted attack.
+
@@ Documentation/security/launch-integrity/secure_launch_details.rst (new)
+
+Description:
+
-+On a system with more than 4G of RAM, the high PMR [2]_ size should be set to -+cover all RAM > 4G. This error is due to that not being the case. This PMR ++On a system with more than 4Gb of RAM, the high PMR [2]_ size should be set to ++cover all RAM > 4Gb. This error is due to that not being the case. This PMR
+value is set by the pre-launch environment, so the issue most likely originates +there. It could also be the sign of an attempted attack.
+
@@ Documentation/security/launch-integrity/secure_launch_details.rst (new)
## Documentation/security/launch-integrity/secure_launch_overview.rst (new) ##
@@
+.. SPDX-License-Identifier: GPL-2.0
-+.. Copyright (c) 2019-2024 Daniel P. Smith <[email protected]> ++.. Copyright (c) 2019-2025 Daniel P. Smith <[email protected]>
+
+======================
+Secure Launch Overview
+======================
+
+:Author: Daniel P. Smith
-+:Date: August 2024
++:Date: March 2025
+
+Overview
+========
+
-+Prior to the start of the TrenchBoot project, the only active Open Source -+project supporting dynamic launch was Intel's tboot project to support their -+implementation of dynamic launch known as Intel Trusted eXecution Technology -+(TXT). The approach taken by tboot was to provide an exokernel that could -+handle the launch protocol implemented by the Intel provided loader, the SINIT -+Authenticated Code Module (ACM [2]_), and remained in memory to manage the SMX -+CPU mode that a dynamic launch would put a system. While it is not precluded -+from being used for a late launch, tboot's primary use case was to be -+used as an early launch solution. As a result, the TrenchBoot project started -+the development of Secure Launch kernel feature to provide a more generalized -+approach. The focus of the effort is twofold: first, to make the Linux -+kernel directly aware of the launch protocol used by Intel, AMD/Hygon, Arm, and -+potentially OpenPOWER; second, to make the Linux kernel able to -+initiate a dynamic launch. It is through this approach that the Secure Launch -+kernel feature creates a basis for the Linux kernel to be used in a variety of -+dynamic launch use cases.
++The TrenchBoot project started the development of the Secure Launch kernel feature ++to provide a more generalized approach. The focus of the effort is twofold: first, ++to make the Linux kernel directly aware of the launch protocol used by platforms ++such as Intel, AMD/Hygon, Arm, and potentially OpenPOWER; second, to make the ++Linux kernel able to initiate a dynamic launch. It is through this approach that ++the Secure Launch kernel feature creates a basis for the Linux kernel to be used ++in a variety of dynamic launch use cases.
+
+.. note::
+ A quick note on terminology. The larger open source project itself is
@@ Documentation/security/launch-integrity/secure_launch_overview.rst (new)
+The first use case that the TrenchBoot project focused on was the ability for +the Linux kernel to be started by a dynamic launch, in particular as part of an +early launch sequence. In this case, the dynamic launch will be initiated by
-+any bootloader with associated support added to it. For example, the first -+targeted bootloader in this case was GRUB2. An integral part of establishing a -+measurement-based launch integrity involves measuring everything that is -+intended to be executed (kernel image, initrd, etc.) and everything that will -+configure that kernel to execute (command line, boot params, etc.), then -+storing those measurements in a protected manner. Both the Intel and AMD -+dynamic launch implementations leverage the Trusted Platform Module (TPM) to -+store those measurements. The TPM itself has been designed such that a dynamic -+launch unlocks a specific set of Platform Configuration Registers (PCR) for -+holding measurement taken during the dynamic launch. These are referred to as -+the DRTM PCRs, PCRs 17-22. Further details on this process can be found in the -+documentation for the GETSEC instruction provided by Intel's TXT and the SKINIT -+instruction provided by AMD's AMD-V. The documentation on these technologies -+can be readily found online; see the Resources_ section below for references. ++any bootloader with associated support added to it. The first targeted bootloader ++in this case was GRUB2. An integral part of establishing a measurement-based ++launch integrity involves measuring everything that is intended to be executed ++(kernel image, initrd, etc.) and everything that will configure that kernel to ++execute (command line, boot params, etc.), then storing those measurements in a ++protected manner. Both the Intel and AMD dynamic launch implementations leverage ++the Trusted Platform Module (TPM) to store those measurements. The TPM itself ++has been designed such that a dynamic launch unlocks a specific set of Platform ++Configuration Registers (PCR) for holding measurement taken during the dynamic ++launch. These are referred to as the DRTM PCRs, PCRs 17-22. Further details on this ++process can be found respectively in the documentation for the GETSEC instruction ++provided by Intel's TXT and the SKINIT instruction provided by AMD's AMD-V. The ++documentation on these technologies can be readily found online; see ++the Resources_ section below for references.
+
+.. note::
+ Currently, only Intel TXT is supported in this first release of the Secure
+ Launch feature. AMD/Hygon SKINIT and Arm support will be added in a
+ subsequent release.
+
-+To enable the kernel to be launched by GETSEC a stub, the Secure Launch stub ++To enable the kernel to be launched by GETSEC, the Secure Launch stub
+must be built into the setup section of the compressed kernel to handle the +specific state that the dynamic launch process leaves the BSP. Also, the Secure +Launch stub must measure everything that is going to be used as early as +possible. This stub code and subsequent code must also deal with the specific
-+state that the dynamic launch leaves the APs as well.
++state that the dynamic launch leaves the APs in.
+
+Design Decisions
+================
@@ Documentation/security/launch-integrity/secure_launch_overview.rst (new)
+ needed DRTM measurements.
+ - After the call to sl_main(), the main kernel is decompressed and boots as
+ it normally would.
++ - Support is introduced in the SMP boot code to properly wake the APs. This
++ is required due to the unique state the dynamic launch leaves the APs in
++ (i.e. they cannot be woken with the standard INIT-SIPI sequence).
+ - Final setup for the Secure Launch kernel is done in a separate Secure
+ Launch module that is loaded via a late initcall. This code is responsible
+ for extending the measurements taken earlier into the TPM DRTM PCRs and
@@ Documentation/security/launch-integrity/secure_launch_overview.rst (new)
+ - On the reboot and kexec paths, calls are made to a function to finalize the
+ state of the Secure Launch kernel.
+
-+The one place where Secure Launch code is mixed directly in with kernel code is -+in the SMP boot code. This is due to the unique state that the dynamic launch -+leaves the APs in. On Intel, this involves using a method other than the -+standard INIT-SIPI sequence.
-+
-+A final note is that originally the extending of the PCRs was completed in the -+Secure Launch stub when the measurements were taken. An alternative solution -+had to be implemented due to the TPM maintainers objecting to the PCR -+extensions being done with a minimal interface to the TPM that was an -+independent implementation of the mainline kernel driver. Since the mainline -+driver relies heavily on kernel interfaces not available in the compressed -+kernel, it was not possible to reuse the mainline TPM driver. This resulted in -+the decision to move the extension operations to the Secure Launch module in -+the mainline kernel, where the TPM driver would be available.
++A final note is that the original concept was to extend the DRTM PCRs in the ++Secure Launch stub when the measurements were taken. This requires access to the ++TPM early during boot time. Since the mainline kernel TPM driver relies heavily ++on kernel interfaces not available in the compressed kernel, it was not possible ++to reuse the mainline TPM driver. An alternate solution that has been implemented, ++moves the extension operations to the Secure Launch module in the mainline ++kernel, where the TPM driver would be available.
+
+Basic Boot Flow
+===============
+
+Outlined here is a summary of the boot flow for Secure Launch. A more detailed
-+review of Secure Launch process can be found in the Secure Launch ++review of the Secure Launch process can be found in the Secure Launch
+Specification (a link is located in the Resources_ section).
+
+Pre-launch: *Phase where the environment is prepared and configured to initiate
@@ Documentation/security/launch-integrity/secure_launch_overview.rst (new)
+ - Set up the TXT heap and page tables describing the MLE [1]_ per the
+ specification.
+ - If non-UEFI platform, dl_stub is called.
-+ - If UEFI platforms, SLRT registered with UEFI and efi-stub called.
++ - If UEFI platform, SLRT registered with UEFI and efi-stub called.
+ - Upon completion, efi-stub will call EBS followed by dl_stub.
+ - The dl_stub will prepare the CPU and the TPM for the launch.
+ - The secure launch is then initiated with the GETSET[SENTER] instruction.
@@ Documentation/security/launch-integrity/secure_launch_overview.rst (new)
+ and setup tasks.
+ - The SMP bring up code is modified to wake the waiting APs via the monitor
+ address.
-+ - APs vector to rmpiggy and start up normally from that point.
++ - APs jump to rmpiggy and start up normally from that point.
+ - SL platform module is registered as a late initcall module. It reads
+ the TPM event log and extends the measurements taken into the TPM PCRs.
+ - SL platform module initializes the securityfs interface to allow
@@ Documentation/security/launch-integrity/secure_launch_overview.rst (new)
+PCR Usage
+=========
+
-+The TCG DRTM architecture there are three PCRs defined for usage, PCR.Details ++In the TCG DRTM architecture there are three PCRs defined for usage: PCR.Details
+(PCR17), PCR.Authorities (PCR18), and PCR.DLME_Authority (PCR19). For a deeper
-+understanding of Detail and Authorities it is recommended to review the TCG -+DRTM architecture.
++understanding of Details and Authorities, review the TCG DRTM architecture ++documentation.
+
+To determine PCR usage, Linux Secure Launch follows the TrenchBoot Secure
-+Launch Specification of using a measurement policy stored in the SLRT. The -+policy details what should be measured and the PCR in which to store the ++Launch Specification of using a measurement policy stored in the Secure Launch ++Resource Table (SLRT), which is defined in the Secure Launch Specification. ++This policy details what should be measured and the PCR in which to store the
+measurement. The measurement policy provides the ability to select the +PCR.DLME_Detail (PCR20) PCR as the location for the DRTM components measured by
-+the kernel, e.g. external initrd image. This can then be combined with storing ++the kernel, e.g. external initrd image. This can be combined with storing
+the user authority in the PCR.DLME_Authority PCR to seal/attest to different +variations of platform details/authorities and user details/authorities. An +example of how this can be achieved was presented in the FOSDEM - 2021 talk
@@ Documentation/security/launch-integrity/secure_launch_overview.rst (new)
+
+Secure Launch is written to be compliant with the Intel TXT Measured Launch +Developer's Guide. The MLE Guide dictates that the system can be configured to
-+use both the SHA-1 and SHA-2 hashing algorithms. The choice is dictated by what ++use both the SHA-1 and SHA-2 hashing algorithms. The choice is dictated by the
+hash algorithm banks firmware enabled at system start time.
+
+Regardless of the preference towards SHA-2, if the firmware elected to start
@@ Documentation/security/launch-integrity/secure_launch_overview.rst (new)
+the firmware setup, then TXT and Secure Launch will only use the SHA-2 banks +while establishing the launch environment.
+
-+Ultimately, the security of an RTM solution is how and what measurements are ++Ultimately, the security of a RTM solution relies on how and what measurements are
+used to assess the health of a system. If SHA-1 measurements are made but not
-+used, i.e. the attestation enforcement only uses SHA-2, then it has zero impact ++used, i.e. the attestation enforcement only uses SHA-2, then it has no impact
+on the security of the system.
+
+Finally, there are older systems with TPM 1.2 chips that only support SHA-1. If +the system integrator (whether that be the OEM, employer, distro maintainer, +system administrator, or end user) chooses to use older hardware that only has
-+a TPM 1.2 chip, then they are accepting the risk it creates in their solution. ++a TPM 1.2 chip, then they accept the risk it creates in their solution.
+
+Resources
+=========

 2:  d3fe72680064 =  2:  46a88f15fda0 x86: Secure Launch Kconfig
 3:  c9f6c26d2b1e !  3:  ae37bd4578d8 x86: Secure Launch Resource Table header file

@@ Metadata
## Commit message ##
x86: Secure Launch Resource Table header file

- Introduce the Secure Launch Resource Table which forms the formal
- interface between the pre and post launch code.
+ The Secure Launch Specification is an architectural agnostic, software neutral
+ API/ABI maintainted by the TrenchBoot project. It's function is to allow any
+ compliant boot loader to communicate the pre-launch configuration to any
+ compliant post-launch kernel. This API/ABI is referred to as the Secure Launch
+ Resource Table by the specification.

@@ include/linux/slr_table.h (new)
+/*
+ * TrenchBoot Secure Launch Resource Table
+ *
-+ * The Secure Launch Resource Table is TrenchBoot project defined
-+ * specfication to provide cross-architecture compatibility. See
-+ * TrenchBoot Secure Launch kernel documentation for details.
++ * The Secure Launch Resource Table (SLRT) is a TrenchBoot project defined
++ * specification to provide a cross-platform interface/ABI between
++ * the Secure Launch components. While most of the table is platform
++ * agnostic, platform or architecture specific entries can be added.
+ *
-+ * Copyright (c) 2024 Apertus Solutions, LLC
-+ * Copyright (c) 2024, Oracle and/or its affiliates.
++ * See TrenchBoot Secure Launch kernel documentation for details.
++ *
++ * Copyright (c) 2025 Apertus Solutions, LLC
++ * Copyright (c) 2025, 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 */
++/* SLR table GUID for registering as an EFI Configuration Table (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 */
@@ include/linux/slr_table.h (new)
+ struct slr_uefi_cfg_entry uefi_cfg_entries[];
+} __packed;
+
++/*
++ * The SLRT is laid out as a Tag-Length-Value (TLV) data structure
++ * allowing a flexible number of entries in the table. An instance
++ * of the slr_table structure is present as a header at the beginning.
++ *
++ * The following functions help to manipulate the SLRT structure
++ * and contents.
++ */
++
++/*
++ * Return the address of the end of the SLRT past the final entry.
++ */
+static inline void *slr_end_of_entries(struct slr_table *table)
+{
+ return (void *)table + table->size;
+}
+
++/*
++ * Return the next entry in the SLRT given the current entry passed
++ * to the function. NULL is returned if there are no entries to return.
++ */
+static inline void *
+slr_next_entry(struct slr_table *table,
+ struct slr_entry_hdr *curr)
@@ include/linux/slr_table.h (new)
+ return next;
+}
+
++/*
++ * Return the next entry with the given tag in the SLRT starting at the
++ * currenty entry. If entry is NULL, the search begins at the beginning of
++ * table.
++ */
+static inline void *
+slr_next_entry_by_tag(struct slr_table *table,
+ struct slr_entry_hdr *entry,
@@ include/linux/slr_table.h (new)
+ return NULL;
+}
+
++/*
++ * Add an entry to the SLRT. Entries are placed at the end.
++ */
+static inline int
+slr_add_entry(struct slr_table *table,
+ struct slr_entry_hdr *entry)
@@ include/linux/slr_table.h (new)
+ return 0;
+}
+
++/*
++ * Initialize the SLRT for use. This prepares the meta-data in the SLRT
++ * header section and the table end marker entry.
++ */
+static inline void
+slr_init_table(struct slr_table *slrt, u16 architecture, u32 max_size)
+{
4: 7d8585845365 ! 4: f4b61a95d4c4 x86: Secure Launch main header file
@@ Commit message
Introduce the main Secure Launch header file used in the early SL stub
and the early setup code.

+ This header file contains the following categories:
+ - Secure Launch implementation specific structures and definitions.
+ - Intel TXT architecture specific DRTM structures, definitions and functions
+ used by Secure Launch.
+ - DRTM TPM event logging definitions and helper functions.
+

## include/linux/slaunch.h (new) ##
@@ include/linux/slaunch.h (new)
+/*
+ * Main Secure Launch header file.
+ *
-+ * Copyright (c) 2024 Apertus Solutions, LLC
-+ * Copyright (c) 2024, Oracle and/or its affiliates.
++ * Copyright (c) 2025 Apertus Solutions, LLC
++ * Copyright (c) 2025, Oracle and/or its affiliates.
+ */
+
+#ifndef _LINUX_SLAUNCH_H
@@ include/linux/slaunch.h (new)
+/*
+ * TPM event logging functions.
+ */
++
++/*
++ * Find the TPM v2 event log element in the TXT heap. This element contains
++ * the information about the size and location of the DRTM event log. Note
++ * this is a TXT specific structure.
++ *
++ * See:
++ * Intel Trusted Execution Technology - Measured Launch Environment Developer's Guide - Appendix C.
++ */
+static inline struct txt_heap_event_log_pointer2_1_element* +tpm2_find_log2_1_element(struct txt_os_sinit_data *os_sinit_data)
+{
@@ include/linux/slaunch.h (new)
+ return NULL;
+}
+
++/*
++ * Log a TPM v1 formatted event to the given DRTM event log.
++ */
+static inline int tpm_log_event(void *evtlog_base, u32 evtlog_size,
+ u32 event_size, void *event)
+{
@@ include/linux/slaunch.h (new)
+ return 0;
+}
+
++/*
++ * Log a TPM v2 formatted event to the given DRTM event log.
++ */
+static inline int tpm2_log_event(struct txt_heap_event_log_pointer2_1_element *elem,
+ void *evtlog_base, u32 evtlog_size,
+ u32 event_size, void *event)
5: 1c3e03777864 ! 5: df284dc6df89 x86: Add early SHA-1 support for Secure Launch early measurements
@@ Commit message

The SHA-1 code here has its origins in the code from the main kernel:

- commit c4d5b9f ("crypto: sha1 - implement base layer for SHA-1")
+ 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 SHA-256 code and allow it to be pulled into the setup kernel
@@ arch/x86/boot/compressed/sha1.c (new)
@@
+// SPDX-License-Identifier: GPL-2.0
+/*
-+ * Copyright (c) 2024 Apertus Solutions, LLC.
++ * Copyright (c) 2025 Apertus Solutions, LLC.
+ */
+
+#include "../../../../lib/crypto/sha1.c"
6: a0f34a29290d ! 6: 4ecaf17a1139 x86: Add early SHA-256 support for Secure Launch early measurements

    @@ arch/x86/boot/compressed/sha256.c (new)
     @@
     +// SPDX-License-Identifier: GPL-2.0
     +/*
    -+ * Copyright (c) 2024 Apertus Solutions, LLC
    ++ * Copyright (c) 2025 Apertus Solutions, LLC
     + */
     +
     +#include "../../../../lib/crypto/sha256.c"

7: b6d784c0d28b ! 7: 3f47465e56c8 x86/msr: Add variable MTRR base/mask and x2apic ID registers
@@ Metadata
## Commit message ##
x86/msr: Add variable MTRR base/mask and x2apic ID registers

- These values are needed by Secure Launch to locate particular CPUs
- during AP startup and to restore the MTRR state after a TXT launch.
+ Add the MSR values required by Secure Launch to locate particular CPU cores
+ during application processor (AP) startup, and restore the MTRR state after
+ an Intel TXT launch.

8: bcad31b804ce ! 8: 7778624b27e0 x86/boot: Place TXT MLE header in the kernel_info section
@@ Metadata
## Commit message ##
x86/boot: Place TXT MLE header in the kernel_info section

- The MLE (measured launch environment) header must be locatable by the
- boot loader and TXT must be setup to do a launch with this header's
+ The Measured Launch Environment (MLE) header must be locatable by the
+ boot loader and Intel TXT must be setup to do a launch with this header's
location. While the offset to the kernel_info structure does not need to be at a fixed offset, the offsets in the header must be relative
- offsets from the start of the setup kernel. The support in the linker
- file achieves this.
+ offsets from the start of the setup kernel. Note that from the viewpoint
+ of the prelaunch phase and TXT, the setup kernel image as loaded into
+ memory is the MLE image.
+
+ The changes to the linker file achieve this by making available the
+ offset values which are updated in the MLE header structure. The following
+ are the needed offsets from the beginning of the setup kernel image:
+
+ - kernel_info_offset: Offset of the main kernel_info structure.
+ - mle_header_offset: Offset of the MLE header structure.
+ - sl_stub_entry_offset: Offset of the Secure Launch initial entry point.
+ - _edata_offset: Offset of the _edata label used as the end of the MLE image.

@@ arch/x86/boot/compressed/kernel_info.S: kernel_info:
+ * 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 roffset(sl_stub_entry_offset) /* 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 roffset(_edata_offset) /* 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) */
++ .long 0x9082ac5a /* UUID0 */
++ .long 0x74a7476f /* UUID1 */
++ .long 0xa2555c0f /* UUID2 */
++ .long 0x42b651cb /* UUID3 */
++ .long 0x00000034 /* MLE header size */
++ .long 0x00020002 /* MLE version 2.2 */
++ .long roffset(sl_stub_entry_offset) /* 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 roffset(_edata_offset) /* 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

9: 506bb834e7bd ! 9: 1b64a89e4e92 x86: Secure Launch kernel early boot stub
@@ Metadata
## Commit message ##
x86: Secure Launch kernel early boot stub

- 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_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.
+ The Secure Launch (SL) stub provides the entry point for Intel TXT to
+ jump to during the dynamic launch. The symbol sl_stub_entry is that entry
+ point and its offset into the kernel is conveyed to the launching code using
+ the Measured Launch Environment (MLE) 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 dynamic launch setup code
+ responsible for setting up the basic operating 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 in the setup kernel. It
+ is responsible for measuring configuration and module information before
+ it is used. An example of entities measured on Intel x86 are the boot params,
+ the kernel command line, the TXT heap, any external initramfs, etc. In addition
+ this routine does some early setup and validation of the environment like
+ locating the TPM event log and validating the location of various buffers to
+ ensure they are protected and not overlapping.

@@ Documentation/arch/x86/boot.rst: Protocol: 2.00+
+ Bit 2 (kernel internal): SLAUNCH_FLAG
+
+ - Used internally by the setup kernel to communicate
-+ Secure Launch status to kernel proper.
++ Secure Launch status to the kernel proper.
+
+ - If 1, Secure Launch enabled.
+ - If 0, Secure Launch disabled.
@@ Documentation/arch/x86/boot.rst: Offset/size: 0x000c/4
+ https://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-txt-software-development-guide.pdf
+

- The Image Checksum
- ==================
+ The Kernel Command Line
+ =======================

## arch/x86/boot/compressed/Makefile ##
@@ arch/x86/boot/compressed/Makefile: vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
@@ arch/x86/boot/compressed/sl_main.c (new)
+/*
+ * Secure Launch early measurement and validation routines.
+ *
-+ * Copyright (c) 2024, Oracle and/or its affiliates.
++ * Copyright (c) 2025, Oracle and/or its affiliates.
+ */
+
+#include <linux/init.h>
@@ arch/x86/boot/compressed/sl_stub.S (new)
+/*
+ * Secure Launch protected mode entry point.
+ *
-+ * Copyright (c) 2024, Oracle and/or its affiliates.
++ * Copyright (c) 2025, Oracle and/or its affiliates.
+ */
+ .code32
+ .text
@@ arch/x86/boot/compressed/sl_stub.S (new)
+ incl rva(sl_txt_cpu_count)(%ebx)
+
+ /*
-+ * Enable SMI with GETSEC[SMCTRL] which were disabled by SENTER.
++ * On the BSP, 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
++ * allow the mainline kernel to re-enable them in the normal course of
+ * booting.
+ */
+ GETSEC $(SMX_X86_GETSEC_SMCTRL)
10: adf97523eef7 ! 10: 76521086be4d x86: Secure Launch kernel late boot stub
@@ Metadata
## Commit message ##
x86: Secure Launch kernel late boot stub

- The routine slaunch_setup is called out of the x86 specific setup_arch()
+ The 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
@@ Commit message
See the Intel Trusted Execution Technology - Measured Launch Environment Developer's Guide for more details.

- 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.
+ In addition this routine reserves key memory regions used by Secure Launch
+ (e.g. the TXT heap, AP startup block etc) as well as fetching values needed
+ later from the TXT heap and SLRT.

@@ arch/x86/kernel/slaunch.c (new)
+/*
+ * Secure Launch late validation/setup and finalization support.
+ *
-+ * Copyright (c) 2024, Oracle and/or its affiliates. ++ * Copyright (c) 2025, Oracle and/or its affiliates.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

11:  00625a3db74f = 11:  ddcd40c272cf x86: Secure Launch SMP bringup support
12:  f3b926ea6881 = 12:  dd0cbb3a2beb kexec: Secure Launch kexec SEXIT support
13:  309f73b37d82 = 13:  132c9b109460 x86/reboot: Secure Launch SEXIT support on reboot paths
14:  59dd2c48d085 ! 14:  1597c2f5a685 tpm, tpm_tis: Close all localities

@@ drivers/char/tpm/tpm_tis_core.c: int tpm_tis_core_init(struct device *dev, struc
}

+ /*
-+ * There are environments, for example, those that comply with the TCG D-RTM
-+ * specification that requires the TPM to be left in Locality 2.
++ * In order to comply with the TCG D-RTM specification, relinquish all
++ * the localities.
+ */
+ for (i = 0; i <= TPM_MAX_LOCALITY; i++) {
+ if (check_locality(chip, i))
15: fd1eaa6970ce ! 15: 8b293cda5c6a tpm, tpm_tis: Address positive localities in tpm_tis_request_locality()

    @@ drivers/char/tpm/tpm_tis_core.c: static int tpm_tis_request_locality(struct tpm_
      	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
      	int ret = 0;
      
    -+	if (l < 0 || l > TPM_MAX_LOCALITY)
    ++	if (l < 0 || l > TPM_MAX_LOCALITY) {
    ++		dev_warn(&chip->dev, "%s: failed to request unknown locality: %d\n",
    ++			 __func__, l);
     +		return -EINVAL;
    ++	}
     +
      	mutex_lock(&priv->locality_count_mutex);
      	if (priv->locality_count == 0)
16:  ed163188e807 = 16:  3412ebf14614 tpm, tpm_tis: Allow locality to be set to a different value
17:  563c8f0ceac5 = 17:  84592ef2de33 tpm, sysfs: Show locality used by kernel
18:  341cb25e4cd0 ! 18:  942d40ea22f5 x86: Secure Launch late initcall platform module

@@ arch/x86/kernel/slmodule.c (new)
+/*
+ * Secure Launch late validation/setup, securityfs exposure and finalization.
+ *
-+ * Copyright (c) 2024 Apertus Solutions, LLC
-+ * Copyright (c) 2024 Assured Information Security, Inc.
-+ * Copyright (c) 2024, Oracle and/or its affiliates.
++ * Copyright (c) 2025 Apertus Solutions, LLC
++ * Copyright (c) 2025 Assured Information Security, Inc.
++ * Copyright (c) 2025, Oracle and/or its affiliates.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19: 78ad72b83303 = 19: fe557361a387 x86/efi: EFI stub DRTM launch support for Secure Launch

Signature · 1 line
2.39.3
#1 lore raw

PATCH v13 1/19 Documentation/x86: Secure Launch kernel documentation

From: "Daniel P. Smith" <[email protected]>

Introduce 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  | 308 +++++++++
 .../secure_launch_details.rst                 | 587 ++++++++++++++++++
 .../secure_launch_overview.rst                | 240 +++++++
 5 files changed, 1147 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
index 3e0a7114a862..f89741271ed0 100644
@@ -20,3 +20,4 @@ Security Documentation
    landlock
    secrets/index
    ipe
+   launch-integrity/index
Documentation/security/launch-integrity/index.rst new file +11 -0
new file mode 100644
index 000000000000..838328186dd2
@@ -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 +308 -0

308 lines not on this page · raw message

Documentation/security/launch-integrity/secure_launch_details.rst new file +587 -0

587 lines not on this page · raw message

Documentation/security/launch-integrity/secure_launch_overview.rst new file +240 -0

240 lines not on this page · raw message

Signature · 1 line
2.39.3
#2 lore raw

Re: [PATCH v13 01/19] Documentation/x86: Secure Launch kernel documentation

Quoted 5 lines · Ross Philipson

+
+ - Entry from the dynamic launch jumps to the SL stub.
+ - SL stub fixes up the world on the BSP.
+ - For TXT, SL stub wakes the APs, fixes up their worlds.
+ - For TXT, APs are left halted using MONITOR/MWAIT intructions.

typo intructions -> instruction

Documentation/security/launch-integrity/secure_launch_overview.rst line 135

Quoted 5 lines

+ - SL stub jumps to startup_32.
+ - SL main does validation of buffers and memory locations. It sets

Documentation/security/launch-integrity/secure_launch_overview.rst new file +3 -0
+   the boot parameter loadflag value SLAUNCH_FLAG to inform the main
+   kernel that a Secure Launch was done.
+ - SL main locates the TPM event log and writes the measurements of

Thanks,
Alok

#3 lore raw

Re: [PATCH v13 01/19] Documentation/x86: Secure Launch kernel documentation

Quoted 10 lines · ALOK TIWARI
Quoted 5 lines · Ross Philipson

+
+ - Entry from the dynamic launch jumps to the SL stub.
+ - SL stub fixes up the world on the BSP.
+ - For TXT, SL stub wakes the APs, fixes up their worlds.
+ - For TXT, APs are left halted using MONITOR/MWAIT intructions.

typo intructions -> instruction

Thanks for the review. They are two separate instructions so is this really incorrect?

Thanks
Ross

Quoted 8 lines
Quoted 5 lines

+ - SL stub jumps to startup_32.
+ - SL main does validation of buffers and memory locations. It sets +   the boot parameter loadflag value SLAUNCH_FLAG to inform the main +   kernel that a Secure Launch was done.
+ - SL main locates the TPM event log and writes the measurements of

Thanks,
Alok

#4 lore raw

Re: [PATCH v13 01/19] Documentation/x86: Secure Launch kernel documentation

Quoted 10 lines · On Fri, Apr 11, 2025, [email protected] wrote:
Quoted 9 lines · ALOK TIWARI
Quoted 5 lines · Ross Philipson

+
+ - Entry from the dynamic launch jumps to the SL stub.
+ - SL stub fixes up the world on the BSP.
+ - For TXT, SL stub wakes the APs, fixes up their worlds.
+ - For TXT, APs are left halted using MONITOR/MWAIT intructions.

Quoted 4 lines
Quoted 1 line

typo intructions -> instruction

Thanks for the review. They are two separate instructions so is this really incorrect?

From the peanut gallery, I'd just drop the "instruction(s)" qualifier, i.e.

- For TXT, APs are left halted using MONITOR/MWAIT.

Pedantically, it's the combination of MONTIOR+MWAIT that puts the CPU into a sleep state, not the individual instructions.

And while I'm picking nits, the documentation is also a bit misleading as the CPU isn't halted per se. I'd go with something like:

- For TXT, APs are left in an optimized (MONITOR/MWAIT) wait state.

#5 lore raw

Re: [PATCH v13 01/19] Documentation/x86: Secure Launch kernel documentation

Quoted 20 lines · Sean Christopherson' via trenchboot-devel
Quoted 10 lines · On Fri, Apr 11, 2025, [email protected] wrote:
Quoted 9 lines · ALOK TIWARI
Quoted 5 lines · Ross Philipson

+
+ - Entry from the dynamic launch jumps to the SL stub.
+ - SL stub fixes up the world on the BSP.
+ - For TXT, SL stub wakes the APs, fixes up their worlds.
+ - For TXT, APs are left halted using MONITOR/MWAIT intructions.

Quoted 4 lines
Quoted 1 line

typo intructions -> instruction

Thanks for the review. They are two separate instructions so is this really incorrect?

From the peanut gallery, I'd just drop the "instruction(s)" qualifier, i.e.

- For TXT, APs are left halted using MONITOR/MWAIT.

Quoted 8 lines

Pedantically, it's the combination of MONTIOR+MWAIT that puts the CPU into a sleep state, not the individual instructions.

And while I'm picking nits, the documentation is also a bit misleading as the CPU isn't halted per se. I'd go with something like:

- For TXT, APs are left in an optimized (MONITOR/MWAIT) wait state.

Good suggestion, thanks

Ross

#6 lore raw

Re: [PATCH v13 01/19] Documentation/x86: Secure Launch kernel documentation

In reply to Ross Philipson

Documentation/security/launch-integrity/principles.rst line 160

Quoted 6 lines · Ross Philipson

+.. note::

Documentation/security/launch-integrity/principles.rst new file +5 -0
+    Intel TXT pre-dates the TCG Dynamic Launch specification. In the Intel TXT
+    documentation, Dynamic Root of Trust for Measurement was abbreviated as DRTM.
+    When Dynamic Launch was codified in the TCG specification, it was given
+    the acronym D-RTM. There is a similar situation with Static Root of Trust for
+    Measuremnt. In TCG documentation it will be given the acronym S-RTM but it is not

typo Measuremnt -> Measurement

Documentation/security/launch-integrity/principles.rst line 162

Quoted 2 lines
Documentation/security/launch-integrity/principles.rst new file +2 -0
+    uncommon to see it as SRTM. For the purposes of the launch integrity documents,
+    DRTM and SRTM will be the preferred acronym.

Thanks,
Alok

#7 lore raw

Re: [PATCH v13 01/19] Documentation/x86: Secure Launch kernel documentation

Quoted 15 lines · ALOK TIWARI
Quoted 11 lines · Ross Philipson

+.. note::
+    Intel TXT pre-dates the TCG Dynamic Launch specification. In the Intel TXT
+    documentation, Dynamic Root of Trust for Measurement was abbreviated as DRTM.
+    When Dynamic Launch was codified in the TCG specification, it was given
+    the acronym D-RTM. There is a similar situation with Static Root of Trust for
+    Measuremnt. In TCG documentation it will be given the acronym S- RTM but it is not

Quoted 1 line

typo Measuremnt -> Measurement

Will fix thanks

Quoted 7 lines
Quoted 4 lines

+    uncommon to see it as SRTM. For the purposes of the launch integrity documents,
+    DRTM and SRTM will be the preferred acronym.

Thanks,
Alok

#8 lore raw

PATCH v13 2/19 x86: Secure Launch Kconfig

In reply to Ross Philipson

Initial bits to bring in Secure Launch functionality. Add Kconfig options for compiling in/out the Secure Launch code.

---
 arch/x86/Kconfig | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/x86/Kconfig +11 -0
index 9427b5292ca2..a92788060a05 100644
@@ -1990,6 +1990,17 @@ config EFI_RUNTIME_MAP
 
 	  See also Documentation/ABI/testing/sysfs-firmware-efi-runtime-map.
 
+config SECURE_LAUNCH
+	bool "Secure Launch support"
+	depends on X86_64 && X86_X2APIC && TCG_TIS && TCG_CRB && CRYPTO_LIB_SHA1 && CRYPTO_LIB_SHA256
+	help
+	   The Secure Launch feature allows a kernel to be loaded
+	   directly through an Intel TXT measured launch. Intel TXT
+	   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
#9 lore raw

PATCH v13 3/19 x86: Secure Launch Resource Table header file

In reply to Ross Philipson

The Secure Launch Specification is an architectural agnostic, software neutral API/ABI maintainted by the TrenchBoot project. It's function is to allow any compliant boot loader to communicate the pre-launch configuration to any compliant post-launch kernel. This API/ABI is referred to as the Secure Launch Resource Table by the specification.

---
 include/linux/slr_table.h | 308 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 308 insertions(+)
 create mode 100644 include/linux/slr_table.h
include/linux/slr_table.h new file +308 -0
new file mode 100644
index 000000000000..fea666250033
@@ -0,0 +1,308 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * TrenchBoot Secure Launch Resource Table
+ *
+ * The Secure Launch Resource Table (SLRT) is a TrenchBoot project defined
+ * specification to provide a cross-platform interface/ABI between
+ * the Secure Launch components. While most of the table is platform
+ * agnostic, platform or architecture specific entries can be added.
+ *
+ * See TrenchBoot Secure Launch kernel documentation for details.
+ *
+ * Copyright (c) 2025 Apertus Solutions, LLC
+ * Copyright (c) 2025, Oracle and/or its affiliates.
+ */
+
+#ifndef _LINUX_SLR_TABLE_H
+#define _LINUX_SLR_TABLE_H
+
+/* SLR table GUID for registering as an EFI Configuration Table (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 Secure Launch Resource Table Header
+ */
+struct slr_table {
+	u32 magic;
+	u16 revision;
+	u16 architecture;
+	u32 size;
+	u32 max_size;
+	/* table entries */
+} __packed;
+
+/*
+ * Common SLRT Table Header
+ */
+struct slr_entry_hdr {
+	u32 tag;
+	u32 size;
+} __packed;
+
+/*
+ * Boot loader context
+ */
+struct slr_bl_context {
+	u16 bootloader;
+	u16 reserved[3];
+	u64 context;
+} __packed;
+
+/*
+ * Dynamic Launch Callback Function type
+ */
+typedef void (*dl_handler_func)(struct slr_bl_context *bl_context);
+
+/*
+ * DRTM Dynamic Launch Configuration
+ */
+struct slr_entry_dl_info {
+	struct slr_entry_hdr hdr;
+	u64 dce_size;
+	u64 dce_base;
+	u64 dlme_size;
+	u64 dlme_base;
+	u64 dlme_entry;
+	struct slr_bl_context bl_context;
+	u64 dl_handler;
+} __packed;
+
+/*
+ * TPM Log Information
+ */
+struct slr_entry_log_info {
+	struct slr_entry_hdr hdr;
+	u16 format;
+	u16 reserved;
+	u32 size;
+	u64 addr;
+} __packed;
+
+/*
+ * DRTM Measurement Entry
+ */
+struct slr_policy_entry {
+	u16 pcr;
+	u16 entity_type;
+	u16 flags;
+	u16 reserved;
+	u64 size;
+	u64 entity;
+	char evt_info[TPM_EVENT_INFO_LENGTH];
+} __packed;
+
+/*
+ * DRTM Measurement Policy
+ */
+struct slr_entry_policy {
+	struct slr_entry_hdr hdr;
+	u16 reserved[2];
+	u16 revision;
+	u16 nr_entries;
+	struct slr_policy_entry policy_entries[];
+} __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 boot_params_addr;
+	u64 txt_heap;
+	u64 saved_misc_enable_msr;
+	struct slr_txt_mtrr_state saved_bsp_mtrrs;
+} __packed;
+
+/*
+ * UEFI config measurement entry
+ */
+struct slr_uefi_cfg_entry {
+	u16 pcr;
+	u16 reserved;
+	u32 size;
+	u64 cfg; /* address or value */
+	char evt_info[TPM_EVENT_INFO_LENGTH];
+} __packed;
+
+/*
+ * UEFI config measurements
+ */
+struct slr_entry_uefi_config {
+	struct slr_entry_hdr hdr;
+	u16 reserved[2];
+	u16 revision;
+	u16 nr_entries;
+	struct slr_uefi_cfg_entry uefi_cfg_entries[];
+} __packed;
+
+/*
+ * The SLRT is laid out as a Tag-Length-Value (TLV) data structure
+ * allowing a flexible number of entries in the table. An instance
+ * of the slr_table structure is present as a header at the beginning.
+ *
+ * The following functions help to manipulate the SLRT structure
+ * and contents.
+ */
+
+/*
+ * Return the address of the end of the SLRT past the final entry.
+ */
+static inline void *slr_end_of_entries(struct slr_table *table)
+{
+	return (void *)table + table->size;
+}
+
+/*
+ * Return the next entry in the SLRT given the current entry passed
+ * to the function. NULL is returned if there are no entries to return.
+ */
+static inline void *
+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_entries(table))
+		return NULL;
+	if (next->tag == SLR_ENTRY_END)
+		return NULL;
+
+	return next;
+}
+
+/*
+ * Return the next entry with the given tag in the SLRT starting at the
+ * currenty entry. If entry is NULL, the search begins at the beginning of
+ * table.
+ */
+static inline void *
+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;
+}
+
+/*
+ * Add an entry to the SLRT. Entries are placed at the end.
+ */
+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;
+}
+
+/*
+ * Initialize the SLRT for use. This prepares the meta-data in the SLRT
+ * header section and the table end marker entry.
+ */
+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 · 1 line
2.39.3
#10 lore raw

PATCH v13 4/19 x86: Secure Launch main header file

In reply to Ross Philipson

Introduce the main Secure Launch header file used in the early SL stub and the early setup code.

This header file contains the following categories:
- Secure Launch implementation specific structures and definitions.
- Intel TXT architecture specific DRTM structures, definitions and functions
used by Secure Launch.
- DRTM TPM event logging definitions and helper functions.

---
 include/linux/slaunch.h | 562 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 562 insertions(+)
 create mode 100644 include/linux/slaunch.h
include/linux/slaunch.h new file +562 -0
new file mode 100644
index 000000000000..25ac3c420a28
@@ -0,0 +1,562 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Main Secure Launch header file.
+ *
+ * Copyright (c) 2025 Apertus Solutions, LLC
+ * Copyright (c) 2025, 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_TXT	0x00000002
+
+/*
+ * Secure Launch CPU Type
+ */
+#define SL_CPU_INTEL	1
+
+#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"
+ *   Intel Trusted Execution Technology - Measured Launch Environment Developer's Guide
+ */
+
+/*
+ * 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_INVALID_ALGS	0xc000801f
+#define SL_ERROR_TPM_EVENT_COUNT	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)
+
+/*
+ * 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 reserved;
+	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 TPM_EVTLOG_SIGNATURE "TXT Event Container"
+
+struct tpm_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);
+}
+
+#if IS_ENABLED(CONFIG_SECURE_LAUNCH)
+
+/*
+ * TPM event logging functions.
+ */
+
+/*
+ * Find the TPM v2 event log element in the TXT heap. This element contains
+ * the information about the size and location of the DRTM event log. Note
+ * this is a TXT specific structure.
+ *
+ * See:
+ *   Intel Trusted Execution Technology - Measured Launch Environment Developer's Guide - Appendix C.
+ */
+static inline struct txt_heap_event_log_pointer2_1_element*
+tpm2_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;
+}
+
+/*
+ * Log a TPM v1 formatted event to the given DRTM event log.
+ */
+static inline int tpm_log_event(void *evtlog_base, u32 evtlog_size,
+				u32 event_size, void *event)
+{
+	struct tpm_event_log_header *evtlog =
+		(struct tpm_event_log_header *)evtlog_base;
+
+	if (memcmp(evtlog->signature, TPM_EVTLOG_SIGNATURE,
+		   sizeof(TPM_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;
+}
+
+/*
+ * Log a TPM v2 formatted event to the given DRTM event log.
+ */
+static inline int tpm2_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);
+void slaunch_finalize(int do_sexit);
+
+static inline bool slaunch_is_txt_launch(void)
+{
+	u32 mask =  SL_FLAG_ACTIVE | SL_FLAG_ARCH_TXT;
+
+	return (slaunch_get_flags() & mask) == mask;
+}
+
+#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)
+{
+}
+
+static inline bool slaunch_is_txt_launch(void)
+{
+	return false;
+}
+
+#endif /* !IS_ENABLED(CONFIG_SECURE_LAUNCH) */
+
+#endif /* !__ASSEMBLY */
+
+#endif /* _LINUX_SLAUNCH_H */
Signature · 1 line
2.39.3
#11 lore raw

Re: [PATCH v13 04/19] x86: Secure Launch main header file

Quoted 13 lines · Ross Philipson

Introduce the main Secure Launch header file used in the early SL stub and the early setup code.

This header file contains the following categories:
- Secure Launch implementation specific structures and definitions.
- Intel TXT architecture specific DRTM structures, definitions and functions
used by Secure Launch.
- DRTM TPM event logging definitions and helper functions.

---

include/linux/slaunch.h line 219

Quoted 6 lines
include/linux/slaunch.h new file +6 -0
+#define TXT_HEAP_EXTDATA_TYPE_TPM_EVENT_LOG_PTR		5
+
+struct txt_heap_event_log_element {
+	u64 event_log_phys_addr;
+} __packed;
+

can be consistence with PTR

Quoted 24 lines
(quoted diff) +21 -0
+#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;
 
 
 
+/*
+ * Find the TPM v2 event log element in the TXT heap. This element contains
+ * the information about the size and location of the DRTM event log. Note
+ * this is a TXT specific structure.
+ *
+ * See:
+ *   Intel Trusted Execution Technology - Measured Launch Environment Developer's Guide - Appendix C.
+ */
+static inline struct txt_heap_event_log_pointer2_1_element*
+tpm2_find_log2_1_element(struct txt_os_sinit_data *os_sinit_data)
+{
+	struct txt_heap_ext_data_element *ext_elem;
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+	/* 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));

indentation can be better here

include/linux/slaunch.h line 453

Quoted 9 lines
include/linux/slaunch.h new file +9 -0
+		}
+		ext_elem =
+			(struct txt_heap_ext_data_element *)
+			((u8 *)ext_elem + ext_elem->size);
+	}
+
+	return NULL;
+}
+

'
'

include/linux/slaunch.h line 511

Quoted 3 lines
include/linux/slaunch.h new file +3 -0
+
+/*
+ * External functions avalailable in mainline kernel.

typo avalailable -> available

include/linux/slaunch.h line 524

Quoted 13 lines

+ */

include/linux/slaunch.h new file +12 -0
+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);
+void slaunch_finalize(int do_sexit);
+
+static inline bool slaunch_is_txt_launch(void)
+{
+	u32 mask =  SL_FLAG_ACTIVE | SL_FLAG_ARCH_TXT;

extra ' ' after =

include/linux/slaunch.h line 527

Quoted 3 lines
include/linux/slaunch.h new file +3 -0
+
+	return (slaunch_get_flags() & mask) == mask;
+}

Thanks,
Alok

#12 lore raw

Re: [PATCH v13 04/19] x86: Secure Launch main header file

Quoted 16 lines · ALOK TIWARI
Quoted 11 lines · Ross Philipson

Introduce the main Secure Launch header file used in the early SL stub and the early setup code.

This header file contains the following categories:
  - Secure Launch implementation specific structures and definitions.
  - Intel TXT architecture specific DRTM structures, definitions and functions used by Secure Launch.
  - DRTM TPM event logging definitions and helper functions.

---

Quoted 8 lines

include/linux/slaunch.h line 219

Quoted 6 lines
include/linux/slaunch.h new file +6 -0
+#define TXT_HEAP_EXTDATA_TYPE_TPM_EVENT_LOG_PTR        5
+
+struct txt_heap_event_log_element {
+    u64 event_log_phys_addr;
+} __packed;
+

can be consistence with PTR

The names come from the TXT spec for the most part. But maybe it will look better if I change it. Will see.

Quoted 32 lines
Quoted 32 lines
include/linux/slaunch.h new file +10 -0
+#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;
 
 
 
+/*
+ * Find the TPM v2 event log element in the TXT heap. This element 

contains
+ * the information about the size and location of the DRTM event log. Note
+ * this is a TXT specific structure.
+ *
+ * See:
+ *   Intel Trusted Execution Technology - Measured Launch Environment Developer's Guide - Appendix C.
+ */

include/linux/slaunch.h new file +9 -0
+static inline struct txt_heap_event_log_pointer2_1_element*
+tpm2_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));
+
Quoted 8 lines
Quoted 6 lines

+    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));

indentation can be better here

Ack

Quoted 11 lines

include/linux/slaunch.h line 453

Quoted 10 lines

+        }
+        ext_elem =
+            (struct txt_heap_ext_data_element *)
+            ((u8 *)ext_elem + ext_elem->size);
+    }

include/linux/slaunch.h new file +4 -0
+
+    return NULL;
+}
+

'

Was there an extra empty space here? I will check.

Quoted 6 lines

'

include/linux/slaunch.h line 511

Quoted 3 lines
include/linux/slaunch.h new file +3 -0
+
+/*
+ * External functions avalailable in mainline kernel.

typo  avalailable -> available

Ack

Quoted 17 lines
Quoted 8 lines

+ */

include/linux/slaunch.h new file +5 -0
+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);

include/linux/slaunch.h line 524

Quoted 7 lines
include/linux/slaunch.h new file +7 -0
+void __noreturn slaunch_txt_reset(void __iomem *txt,
+                     const char *msg, u64 error);
+void slaunch_finalize(int do_sexit);
+
+static inline bool slaunch_is_txt_launch(void)
+{
+    u32 mask =  SL_FLAG_ACTIVE | SL_FLAG_ARCH_TXT;

extra ' ' after =

Ack will fix these.

Quoted 9 lines

include/linux/slaunch.h line 527

Quoted 4 lines
include/linux/slaunch.h new file +3 -0
+
+    return (slaunch_get_flags() & mask) == mask;
+}

Thanks,
Alok

Thanks
Ross

#13 lore raw

PATCH v13 5/19 x86: Add early SHA-1 support for Secure Launch early measurements

In reply to Ross Philipson

From: "Daniel P. Smith" <[email protected]>

Secure Launch is written to be compliant with the Intel TXT Measured Launch Developer's Guide. The MLE Guide dictates that the system can be configured to use both the SHA-1 and SHA-2 hashing algorithms.

Regardless of the preference towards SHA-2, if the firmware elected to start with the SHA-1 and SHA-2 banks active and the dynamic launch was configured to include SHA-1, Secure Launch is obligated to record measurements for all algorithms requested in the launch configuration.

The user environment or the integrity management does not desire to use SHA-1, it is free to just ignore the SHA-1 bank in any integrity operation with the TPM. If there is a larger concern about the SHA-1 bank being active, it is free to deliberately cap the SHA-1 PCRs, recording the event in the D-RTM log.

The SHA-1 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 SHA-256 code and allow it to be pulled into the setup kernel in the same manner as SHA-256 is.

---
 arch/x86/boot/compressed/Makefile |  2 +
 arch/x86/boot/compressed/sha1.c   |  6 +++
 include/crypto/sha1.h             |  1 +
 lib/crypto/sha1.c                 | 81 +++++++++++++++++++++++++++++++
 4 files changed, 90 insertions(+)
 create mode 100644 arch/x86/boot/compressed/sha1.c
arch/x86/boot/compressed/Makefile +2 -0
index 0e0b238e8363..4626e2f95254 100644
@@ -109,6 +109,8 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
 vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o
 vmlinux-libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
 
+vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/sha1.o
+
 $(obj)/vmlinux: $(vmlinux-objs-y) $(vmlinux-libs-y) FORCE
 	$(call if_changed,ld)
 
arch/x86/boot/compressed/sha1.c new file +6 -0
new file mode 100644
index 000000000000..f58ab7cadb46
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2025 Apertus Solutions, LLC.
+ */
+
+#include "../../../../lib/crypto/sha1.c"
include/crypto/sha1.h +1 -0
index 044ecea60ac8..d715dd5332e1 100644
@@ -42,5 +42,6 @@ extern int crypto_sha1_finup(struct shash_desc *desc, const u8 *data,
 #define SHA1_WORKSPACE_WORDS	16
 void 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

86 lines not on this page · raw message

Signature · 1 line
2.39.3
#14 lore raw

PATCH v13 6/19 x86: Add early SHA-256 support for Secure Launch early measurements

In reply to Ross Philipson

From: "Daniel P. Smith" <[email protected]>

The SHA-256 algorithm is 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-256 libraries directly in the code since the compressed kernel is not uncompressed at this point.

---
 arch/x86/boot/compressed/Makefile | 2 +-
 arch/x86/boot/compressed/sha256.c | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/boot/compressed/sha256.c
arch/x86/boot/compressed/Makefile +1 -1
index 4626e2f95254..b5c167285f6b 100644
@@ -109,7 +109,7 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
 vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o
 vmlinux-libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
 
-vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/sha1.o
+vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/sha1.o $(obj)/sha256.o
 
 $(obj)/vmlinux: $(vmlinux-objs-y) $(vmlinux-libs-y) FORCE
 	$(call if_changed,ld)
arch/x86/boot/compressed/sha256.c new file +6 -0
new file mode 100644
index 000000000000..7795926e7e1d
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2025 Apertus Solutions, LLC
+ */
+
+#include "../../../../lib/crypto/sha256.c"
Signature · 1 line
2.39.3
#15 lore raw

PATCH v13 7/19 x86/msr: Add variable MTRR base/mask and x2apic ID registers

In reply to Ross Philipson

Add the MSR values required by Secure Launch to locate particular CPU cores during application processor (AP) startup, and restore the MTRR state after an Intel TXT launch.

---
 arch/x86/include/asm/msr-index.h | 5 +++++
 1 file changed, 5 insertions(+)
arch/x86/include/asm/msr-index.h +5 -0
index e6134ef2263d..97cc926c6d1b 100644
@@ -366,6 +366,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
@@ -890,6 +893,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
 
Signature · 1 line
2.39.3
#16 lore raw

PATCH v13 8/19 x86/boot: Place TXT MLE header in the kernel_info section

In reply to Ross Philipson

The Measured Launch Environment (MLE) header must be locatable by the boot loader and Intel TXT must be setup to do a launch with this header's location. While the offset to the kernel_info structure does not need to be at a fixed offset, the offsets in the header must be relative offsets from the start of the setup kernel. Note that from the viewpoint of the prelaunch phase and TXT, the setup kernel image as loaded into memory is the MLE image.

The changes to the linker file achieve this by making available the offset values which are updated in the MLE header structure. The following are the needed offsets from the beginning of the setup kernel image:

- kernel_info_offset: Offset of the main kernel_info structure.
- mle_header_offset: Offset of the MLE header structure.
- sl_stub_entry_offset: Offset of the Secure Launch initial entry point.
- _edata_offset: Offset of the _edata label used as the end of the MLE image.

---
 arch/x86/boot/compressed/kernel_info.S | 50 +++++++++++++++++++++++---
 arch/x86/boot/compressed/vmlinux.lds.S |  7 ++++
 2 files changed, 53 insertions(+), 4 deletions(-)
arch/x86/boot/compressed/kernel_info.S +46 -4
index f818ee8fba38..2765b1786368 100644
@@ -1,12 +1,20 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 
+#include <linux/linkage.h>
 #include <asm/bootparam.h>
 
-	.section ".rodata.kernel_info", "a"
+/*
+ * The kernel_info structure is not placed at a fixed offest in the
+ * kernel image. So this macro and the support in the linker file
+ * allow the relative offsets for the MLE header within the kernel
+ * image to be configured at build time.
+ */
+#define roffset(X) ((X) - kernel_info)
 
-	.global kernel_info
+	.section ".rodata.kernel_info", "a"
 
-kernel_info:
+	.balign	16
+SYM_DATA_START(kernel_info)
 	/* Header, Linux top (structure). */
 	.ascii	"LToP"
 	/* Size. */
@@ -17,6 +25,40 @@ 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	roffset(mle_header_offset)
+#else
+	.long	0
+#endif
+
 kernel_info_var_len_data:
 	/* Empty for time being... */
-kernel_info_end:
+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	roffset(sl_stub_entry_offset)	/* 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	roffset(_edata_offset)		/* 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/vmlinux.lds.S +7 -0
index 3b2bc61c9408..eae9745f5a0b 100644
@@ -118,3 +118,10 @@ SECTIONS
 	}
 	ASSERT(SIZEOF(.rela.dyn) == 0, "Unexpected run-time relocations (.rela) detected!")
 }
+
+#ifdef CONFIG_SECURE_LAUNCH
+PROVIDE(kernel_info_offset      = ABSOLUTE(kernel_info - startup_32));
+PROVIDE(mle_header_offset       = kernel_info_offset + ABSOLUTE(mle_header - startup_32));
+PROVIDE(sl_stub_entry_offset    = kernel_info_offset + ABSOLUTE(sl_stub_entry - startup_32));
+PROVIDE(_edata_offset           = kernel_info_offset + ABSOLUTE(_edata - startup_32));
+#endif
Signature · 1 line
2.39.3
#17 lore raw

PATCH v13 9/19 x86: Secure Launch kernel early boot stub

In reply to Ross Philipson

The Secure Launch (SL) stub provides the entry point for Intel TXT to jump to during the dynamic launch. The symbol sl_stub_entry is that entry point and its offset into the kernel is conveyed to the launching code using the Measured Launch Environment (MLE) 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 dynamic launch setup code responsible for setting up the basic operating 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 in the setup kernel. It is responsible for measuring configuration and module information before it is used. An example of entities measured on Intel x86 are the boot params, the kernel command line, the TXT heap, any external initramfs, etc. In addition this routine does some early setup and validation of the environment like locating the TPM event log and validating the location of various buffers to ensure they are protected and not overlapping.

---
 Documentation/arch/x86/boot.rst       |  21 +
 arch/x86/boot/compressed/Makefile     |   3 +-
 arch/x86/boot/compressed/head_64.S    |  29 +
 arch/x86/boot/compressed/sl_main.c    | 597 +++++++++++++++++++++
 arch/x86/boot/compressed/sl_stub.S    | 726 ++++++++++++++++++++++++++
 arch/x86/include/uapi/asm/bootparam.h |   1 +
 arch/x86/kernel/asm-offsets.c         |  20 +
 7 files changed, 1396 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
index 77e6163288db..2317f8dbc0f1 100644
@@ -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 setup kernel to communicate
+	  Secure Launch status to the kernel proper.
+
+	    - If 1, Secure Launch enabled.
+	    - If 0, Secure Launch disabled.
+
   Bit 5 (write): QUIET_FLAG
 
 	- If 0, print early messages.
@@ -1037,6 +1045,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 Kernel Command Line
 =======================
arch/x86/boot/compressed/Makefile +2 -1
index b5c167285f6b..69e5e7bf8f39 100644
@@ -109,7 +109,8 @@ vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
 vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_mixed.o
 vmlinux-libs-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
 
-vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/sha1.o $(obj)/sha256.o
+vmlinux-objs-$(CONFIG_SECURE_LAUNCH) += $(obj)/sha1.o $(obj)/sha256.o \
+	$(obj)/sl_main.o $(obj)/sl_stub.o
 
 $(obj)/vmlinux: $(vmlinux-objs-y) $(vmlinux-libs-y) FORCE
 	$(call if_changed,ld)
arch/x86/boot/compressed/head_64.S +29 -0
index 3dc86352cdbe..fe3887d8fb46 100644
@@ -420,6 +420,13 @@ SYM_CODE_START(startup_64)
 	pushq	$0
 	popfq
 
+#ifdef CONFIG_SECURE_LAUNCH
+	/* Ensure the relocation region is covered by a PMR */
+	movq	%rbx, %rdi
+	movl	$(_bss - startup_32), %esi
+	callq	sl_check_region
+#endif
+
 /*
  * Copy the compressed kernel to the end of our buffer
  * where decompression in place becomes safe.
@@ -462,6 +469,28 @@ 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 covered by a PMR */
+	movq	%rbp, %rdi
+	movq	output_len(%rip), %rsi
+	callq	sl_check_region
+#endif
+
 	call	load_stage2_idt
 
 	/* Pass boot_params to initialize_identity_maps() */
arch/x86/boot/compressed/sl_main.c new file +597 -0

597 lines not on this page · raw message

arch/x86/boot/compressed/sl_stub.S new file +726 -0

726 lines not on this page · raw message

arch/x86/include/uapi/asm/bootparam.h +1 -0
index dafbf581c515..8155fa899f50 100644
@@ -12,6 +12,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
index ad4ea6fb3b6c..d11de24ffb63 100644
@@ -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>
@@ -115,4 +117,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_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_boot_params_addr, slr_entry_intel_info, boot_params_addr);
+	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
#18 lore raw

Re: [PATCH v13 09/19] x86: Secure Launch kernel early boot stub

Quoted 5 lines · Ross Philipson
arch/x86/boot/compressed/sl_stub.S new file +5 -0
+	/*
+	 * 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.
+	 */

arch/x86/boot/compressed/sl_stub.S line 622

Quoted 10 lines
arch/x86/boot/compressed/sl_stub.S new file +10 -0
+	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

s/he/the

arch/x86/boot/compressed/sl_stub.S line 631

Quoted 9 lines
arch/x86/boot/compressed/sl_stub.S new file +9 -0
+	 * 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

Why load the value into EDX? At a glance, the value is never consumed.

arch/x86/boot/compressed/sl_stub.S line 633

Quoted 2 lines
arch/x86/boot/compressed/sl_stub.S new file +2 -0
+	testl	%edx, %edx
+	jz	1b

This usage of MONITOR/MWAIT is flawed. The monitor needs to be re-armed in each loop, otherwise mwait will be a glorified nop.

More importantly, the exit condition needs to be checked before monitor, even on the first iteration. In the (probably extremely unlikely) scenario that the write to wake the CPU arrives before MONITOR is executed, this CPU may get stuck waiting indefinitely.

E.g. something like:

1:

	monitor
	cmpl	(%eax), 0
	jnz	2f
	mwait
	jmp	1b

2:

#19 lore raw

Re: [PATCH v13 09/19] x86: Secure Launch kernel early boot stub

Quoted 12 lines · Sean Christopherson

arch/x86/boot/compressed/sl_stub.S line 631

Quoted 9 lines · Ross Philipson
arch/x86/boot/compressed/sl_stub.S new file +9 -0
+	 * 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

Why load the value into EDX? At a glance, the value is never consumed.

Quoted 6 lines

arch/x86/boot/compressed/sl_stub.S line 633

Quoted 2 lines
arch/x86/boot/compressed/sl_stub.S new file +2 -0
+	testl	%edx, %edx
+	jz	1b

This usage of MONITOR/MWAIT is flawed. The monitor needs to be re-armed in each loop, otherwise mwait will be a glorified nop.

More importantly, the exit condition needs to be checked before monitor,

after monitor and before mwait.

But yes, the prior logic was definitely wonky.

Quoted 11 lines

even on
the first iteration. In the (probably extremely unlikely) scenario that the write to wake the CPU arrives before MONITOR is executed, this CPU may get stuck waiting indefinitely.

E.g. something like:

1:

	monitor
	cmpl	(%eax), 0

$0

Luckily, this will fail to assemble, rather than dereferencing 0.

~Andrew

Quoted 4 lines
	jnz	2f
	mwait
	jmp	1b

2:

#20 lore raw

Re: [PATCH v13 09/19] x86: Secure Launch kernel early boot stub

Quoted 13 lines · Andrew Cooper
Quoted 12 lines · Sean Christopherson

arch/x86/boot/compressed/sl_stub.S line 631

Quoted 9 lines · Ross Philipson
arch/x86/boot/compressed/sl_stub.S new file +9 -0
+	 * 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

Why load the value into EDX? At a glance, the value is never consumed.

Quoted 8 lines
Quoted 6 lines

arch/x86/boot/compressed/sl_stub.S line 633

Quoted 2 lines
arch/x86/boot/compressed/sl_stub.S new file +2 -0
+	testl	%edx, %edx
+	jz	1b

This usage of MONITOR/MWAIT is flawed. The monitor needs to be re-armed in each loop, otherwise mwait will be a glorified nop.

More importantly, the exit condition needs to be checked before monitor,

after monitor and before mwait.

Gah, yeah, I mean to say "before mwait".

#21 lore raw

Re: [PATCH v13 09/19] x86: Secure Launch kernel early boot stub

Quoted 19 lines · Sean Christopherson
Quoted 18 lines · Andrew Cooper
Quoted 17 lines · Sean Christopherson

arch/x86/boot/compressed/sl_stub.S line 631

Quoted 9 lines · Ross Philipson
arch/x86/boot/compressed/sl_stub.S new file +9 -0
+	 * 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

Why load the value into EDX? At a glance, the value is never consumed.

arch/x86/boot/compressed/sl_stub.S line 633

Quoted 2 lines
arch/x86/boot/compressed/sl_stub.S new file +2 -0
+	testl	%edx, %edx
+	jz	1b

This usage of MONITOR/MWAIT is flawed. The monitor needs to be re-armed in each loop, otherwise mwait will be a glorified nop.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

More importantly, the exit condition needs to be checked before monitor,

after monitor and before mwait.

Gah, yeah, I mean to say "before mwait".

Thanks Sean and Andy, I will fix this.

Ross

#22 lore raw

PATCH v13 10/19 x86: Secure Launch kernel late boot stub

In reply to Ross Philipson

The 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.

Intel VT-d/IOMMU hardware provides special registers called Protected Memory Regions (PMRs) that allow all memory to be protected from DMA during a TXT DRTM launch. This coverage is validated during the late setup process to ensure DMA protection is in place prior to the IOMMUs being initialized and configured by the mainline kernel. See the Intel Trusted Execution Technology - Measured Launch Environment Developer's Guide for more details.

In addition this routine reserves key memory regions used by Secure Launch (e.g. the TXT heap, AP startup block etc) as well as fetching values needed later from the TXT heap and SLRT.

---
 arch/x86/kernel/Makefile   |   1 +
 arch/x86/kernel/setup.c    |   3 +
 arch/x86/kernel/slaunch.c  | 524 +++++++++++++++++++++++++++++++++++++
 drivers/iommu/intel/dmar.c |   4 +
 4 files changed, 532 insertions(+)
 create mode 100644 arch/x86/kernel/slaunch.c
arch/x86/kernel/Makefile +1 -0
index 84cfa179802c..a7ca7ca16174 100644
@@ -82,6 +82,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
index c7164a8de983..9bfa11ee46d6 100644
@@ -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>
@@ -1000,6 +1001,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 +524 -0

524 lines not on this page · raw message

drivers/iommu/intel/dmar.c +4 -0
index e540092d664d..aad13f455160 100644
@@ -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"
@@ -661,6 +662,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 · 1 line
2.39.3
#23 lore raw

PATCH v13 11/19 x86: Secure Launch SMP bringup support

In reply to Ross Philipson

On 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            | 43 ++++++++++++++++++++++++++--
 arch/x86/realmode/init.c             |  3 ++
 arch/x86/realmode/rm/header.S        |  3 ++
 arch/x86/realmode/rm/trampoline_64.S | 32 +++++++++++++++++++++
 5 files changed, 82 insertions(+), 2 deletions(-)
arch/x86/include/asm/realmode.h +3 -0
index f607081a022a..84367bcec1a8 100644
@@ -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 +41 -2

72 lines not on this page · raw message

arch/x86/realmode/init.c +3 -0
index f9bc444a3064..d95776cb30d3 100644
@@ -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
index 2eb62be6d256..3b5cbcbbfc90 100644
@@ -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
index 14d9c7daf90f..b0ce6205d7ea 100644
@@ -122,6 +122,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 · 1 line
2.39.3
#24 lore raw

PATCH v13 12/19 kexec: Secure Launch kexec SEXIT support

In reply to Ross Philipson

Prior 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 | 72 +++++++++++++++++++++++++++++++++++++++
 kernel/kexec_core.c       |  4 +++
 2 files changed, 76 insertions(+)
arch/x86/kernel/slaunch.c +72 -0
index 94fe5e494034..b6ba4c526aa3 100644
@@ -522,3 +522,75 @@ void __init slaunch_setup_txt(void)
 
 	pr_info("Intel TXT setup complete\n");
 }
+
+static inline void smx_getsec_sexit(void)
+{
+	asm volatile ("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_is_txt_launch())
+		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
index c0bdc1686154..4bef8c5f58f3 100644
@@ -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>
@@ -1049,6 +1050,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 · 1 line
2.39.3
#25 lore raw

PATCH v13 13/19 x86/reboot: Secure Launch SEXIT support on reboot paths

In reply to Ross Philipson

If 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
index 964f6b0a3d68..9069415e0788 100644
@@ -13,6 +13,7 @@
 #include <linux/objtool.h>
 #include <linux/pgtable.h>
 #include <linux/kexec.h>
+#include <linux/slaunch.h>
 #include <acpi/reboot.h>
 #include <asm/io.h>
 #include <asm/apic.h>
@@ -778,6 +779,7 @@ static void native_machine_restart(char *__unused)
 
 	if (!reboot_force)
 		machine_shutdown();
+	slaunch_finalize(!reboot_force);
 	__machine_emergency_restart(0);
 }
 
@@ -788,6 +790,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);
 }
 
@@ -796,8 +801,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);
 }
@@ -825,6 +834,7 @@ void machine_shutdown(void)
 
 void machine_emergency_restart(void)
 {
+	slaunch_finalize(0);
 	__machine_emergency_restart(1);
 }
 
Signature · 1 line
2.39.3
#26 lore raw

PATCH v13 14/19 tpm, tpm_tis: Close all localities

In reply to Ross Philipson

From: "Daniel P. Smith" <[email protected]>

There are environments, for example, those that comply with the TCG D-RTM specification that requires the TPM to be left in locality 2. Prepare kernel for such environments by closing all the localities.

---
 drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++-
 include/linux/tpm.h             |  6 ++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +10 -1
index fdef214b9f6b..2edf0ac0f810 100644
@@ -1104,7 +1104,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
 	u32 intmask;
 	u32 clkrun_val;
 	u8 rid;
-	int rc, probe;
+	int rc, probe, i;
 	struct tpm_chip *chip;
 
 	chip = tpmm_chip_alloc(dev, &tpm_tis);
@@ -1166,6 +1166,15 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
 		goto out_err;
 	}
 
+	/*
+	 * In order to comply with the TCG D-RTM specification, relinquish all
+	 * the localities.
+	 */
+	for (i = 0; i <= TPM_MAX_LOCALITY; i++) {
+		if (check_locality(chip, i))
+			tpm_tis_relinquish_locality(chip, i);
+	}
+
 	/* Take control of the TPM's interrupt hardware and shut it off */
 	rc = tpm_tis_read32(priv, TPM_INT_ENABLE(priv->locality), &intmask);
 	if (rc < 0)
include/linux/tpm.h +6 -0
index 20a40ade8030..c5a4a2d7dd15 100644
@@ -147,6 +147,12 @@ struct tpm_chip_seqops {
  */
 #define TPM2_MAX_CONTEXT_SIZE 4096
 
+/*
+ * 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;
Signature · 1 line
2.39.3
#27 lore raw

PATCH v13 15/19 tpm, tpm_tis: Address positive localities in tpm_tis_request_locality()

In reply to Ross Philipson

From: "Daniel P. Smith" <[email protected]>

Validate that the input locality is within the correct range, as specified by TCG standards, and increase the locality count also for the positive localities.

---
 drivers/char/tpm/tpm_tis_core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +7 -1
index 2edf0ac0f810..f9a3489313b4 100644
@@ -234,10 +234,16 @@ static int tpm_tis_request_locality(struct tpm_chip *chip, int l)
 	struct tpm_tis_data *priv = dev_get_drvdata(&chip->dev);
 	int ret = 0;
 
+	if (l < 0 || l > TPM_MAX_LOCALITY) {
+		dev_warn(&chip->dev, "%s: failed to request unknown locality: %d\n",
+			 __func__, l);
+		return -EINVAL;
+	}
+
 	mutex_lock(&priv->locality_count_mutex);
 	if (priv->locality_count == 0)
 		ret = __tpm_tis_request_locality(chip, l);
-	if (!ret)
+	if (ret >= 0)
 		priv->locality_count++;
 	mutex_unlock(&priv->locality_count_mutex);
 	return ret;
Signature · 1 line
2.39.3
#28 lore raw

PATCH v13 16/19 tpm, tpm_tis: Allow locality to be set to a different value

In reply to Ross Philipson

DRTM needs to be able to set the locality used by kernel. Provide a one-shot function tpm_chip_set_locality() for the purpose.

---
 drivers/char/tpm/tpm-chip.c     | 33 ++++++++++++++++++++++++++++++++-
 drivers/char/tpm/tpm_tis_core.c |  2 ++
 include/linux/tpm.h             |  4 ++++
 3 files changed, 38 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm-chip.c +32 -1
index 7df7abaf3e52..ac200514c4d7 100644
@@ -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->kernel_locality);
 	if (rc < 0)
 		return rc;
 
@@ -374,6 +374,7 @@ struct tpm_chip *tpm_chip_alloc(struct device *pdev,
 	}
 
 	chip->locality = -1;
+	chip->kernel_locality = 0;
 	return chip;
 
 out:
@@ -689,3 +690,33 @@ void tpm_chip_unregister(struct tpm_chip *chip)
 	tpm_del_char_device(chip);
 }
 EXPORT_SYMBOL_GPL(tpm_chip_unregister);
+
+/**
+ * tpm_chip_set_locality() - Set the TPM locality kernel uses
+ * @chip:	&tpm_chip instance
+ * @locality:   new locality
+ *
+ * This a one-shot function. Returns zero or POSIX error on failure.
+ */
+int tpm_chip_set_locality(struct tpm_chip *chip, u8 locality)
+{
+	int ret;
+
+	if (locality < 0 || locality >= TPM_MAX_LOCALITY)
+		return -EINVAL;
+
+	ret = tpm_try_get_ops(chip);
+	if (ret)
+		return ret;
+
+	if (!(chip->flags & TPM_CHIP_FLAG_SET_LOCALITY_ENABLED)) {
+		tpm_put_ops(chip);
+		return -EINVAL;
+	}
+
+	chip->kernel_locality = locality;
+	chip->flags &= ~TPM_CHIP_FLAG_SET_LOCALITY_ENABLED;
+	tpm_put_ops(chip);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(tpm_chip_set_locality);
drivers/char/tpm/tpm_tis_core.c +2 -0
index f9a3489313b4..fd17cccb8abf 100644
@@ -1117,6 +1117,8 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
 	if (IS_ERR(chip))
 		return PTR_ERR(chip);
 
+	chip->flags |= TPM_CHIP_FLAG_SET_LOCALITY_ENABLED;
+
 #ifdef CONFIG_ACPI
 	chip->acpi_dev_handle = acpi_dev_handle;
 #endif
include/linux/tpm.h +4 -0
index c5a4a2d7dd15..9f910d3bc2e4 100644
@@ -207,6 +207,8 @@ struct tpm_chip {
 
 	/* active locality */
 	int locality;
+	/* the locality used by kernel */
+	u8 kernel_locality;
 
 #ifdef CONFIG_TCG_TPM2_HMAC
 	/* details for communication security via sessions */
@@ -354,6 +356,7 @@ enum tpm_chip_flags {
 	TPM_CHIP_FLAG_SUSPENDED			= BIT(8),
 	TPM_CHIP_FLAG_HWRNG_DISABLED		= BIT(9),
 	TPM_CHIP_FLAG_DISABLE			= BIT(10),
+	TPM_CHIP_FLAG_SET_LOCALITY_ENABLED	= BIT(11),
 };
 
 #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev)
@@ -447,6 +450,7 @@ static inline u32 tpm2_rc_value(u32 rc)
 extern int tpm_is_tpm2(struct tpm_chip *chip);
 extern __must_check int tpm_try_get_ops(struct tpm_chip *chip);
 extern void tpm_put_ops(struct tpm_chip *chip);
+int tpm_chip_set_locality(struct tpm_chip *chip, u8 locality);
 extern ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_buf *buf,
 				size_t min_rsp_body_length, const char *desc);
 extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
Signature · 1 line
2.39.3
#29 lore raw

Re: [PATCH v13 16/19] tpm, tpm_tis: Allow locality to be set to a different value

Quoted 28 lines · Ross Philipson

DRTM needs to be able to set the locality used by kernel. Provide a one-shot function tpm_chip_set_locality() for the purpose.

---
  drivers/char/tpm/tpm-chip.c     | 33 ++++++++++++++++++++++++++++++++-
  drivers/char/tpm/tpm_tis_core.c |  2 ++
  include/linux/tpm.h             |  4 ++++
  3 files changed, 38 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm-chip.c +17 -0
+/**
+ * tpm_chip_set_locality() - Set the TPM locality kernel uses
+ * @chip:	&tpm_chip instance
+ * @locality:   new locality
+ *
+ * This a one-shot function. Returns zero or POSIX error on failure.
+ */
+int tpm_chip_set_locality(struct tpm_chip *chip, u8 locality)
+{
+	int ret;
+
+	if (locality < 0 || locality >= TPM_MAX_LOCALITY)
+		return -EINVAL;
+
+	ret = tpm_try_get_ops(chip);
+	if (ret)
+		return ret;

drivers/char/tpm/tpm-chip.c void tpm_chip_unregister(struct tpm_chip *chip) · line 720

Quoted 10 lines
drivers/char/tpm/tpm-chip.c +10 -0
+
+	if (!(chip->flags & TPM_CHIP_FLAG_SET_LOCALITY_ENABLED)) {
+		tpm_put_ops(chip);
+		return -EINVAL;
+	}
+
+	chip->kernel_locality = locality;
+	chip->flags &= ~TPM_CHIP_FLAG_SET_LOCALITY_ENABLED;
+	tpm_put_ops(chip);
+	return 0;

a '\n' before return is customary

drivers/char/tpm/tpm_tis_core.c

Quoted 3 lines
(quoted diff) +2 -0
+}
+EXPORT_SYMBOL_GPL(tpm_chip_set_locality);
drivers/char/tpm/tpm_tis_core.c +0 -0

Thanks,
Alok

#30 lore raw

Re: [PATCH v13 16/19] tpm, tpm_tis: Allow locality to be set to a different value

Quoted 35 lines · ALOK TIWARI
Quoted 32 lines · Ross Philipson

DRTM needs to be able to set the locality used by kernel. Provide a one-shot function tpm_chip_set_locality() for the purpose.

---
  drivers/char/tpm/tpm-chip.c     | 33 ++++++++++++++++++++++++++++++++- drivers/char/tpm/tpm_tis_core.c |  2 ++ include/linux/tpm.h             |  4 ++++

  3 files changed, 38 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm-chip.c +21 -0
+/**
+ * tpm_chip_set_locality() - Set the TPM locality kernel uses
+ * @chip:    &tpm_chip instance
+ * @locality:   new locality
+ *
+ * This a one-shot function. Returns zero or POSIX error on failure.
+ */
+int tpm_chip_set_locality(struct tpm_chip *chip, u8 locality)
+{
+    int ret;
+
+    if (locality < 0 || locality >= TPM_MAX_LOCALITY)
+        return -EINVAL;
+
+    ret = tpm_try_get_ops(chip);
+    if (ret)
+        return ret;
+
+    if (!(chip->flags & TPM_CHIP_FLAG_SET_LOCALITY_ENABLED)) {
+        tpm_put_ops(chip);
+        return -EINVAL;
Quoted 8 lines
Quoted 6 lines

+    }
+
+    chip->kernel_locality = locality;
+    chip->flags &= ~TPM_CHIP_FLAG_SET_LOCALITY_ENABLED; +    tpm_put_ops(chip);
+    return 0;

a '\n' before return is customary

Can do, thanks

Quoted 8 lines

drivers/char/tpm/ tpm_tis_core.c

Quoted 4 lines
(quoted diff) +2 -0
+}
+EXPORT_SYMBOL_GPL(tpm_chip_set_locality);
drivers/char/tpm/ tpm_tis_core.c renamed from drivers/char/tpm/tpm_tis_core.c +0 -0

Thanks,
Alok

#31 lore raw

PATCH v13 17/19 tpm, sysfs: Show locality used by kernel

In reply to Ross Philipson

Expose the locality used by the kernel to sysfs.

---
 drivers/char/tpm/tpm-sysfs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/char/tpm/tpm-sysfs.c +10 -0
index 94231f052ea7..2da5857e223b 100644
@@ -309,6 +309,14 @@ static ssize_t tpm_version_major_show(struct device *dev,
 }
 static DEVICE_ATTR_RO(tpm_version_major);
 
+static ssize_t locality_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct tpm_chip *chip = to_tpm_chip(dev);
+
+	return sprintf(buf, "%u\n", chip->kernel_locality);
+}
+static DEVICE_ATTR_RO(locality);
+
 #ifdef CONFIG_TCG_TPM2_HMAC
 static ssize_t null_name_show(struct device *dev, struct device_attribute *attr,
 			      char *buf)
@@ -336,6 +344,7 @@ static struct attribute *tpm1_dev_attrs[] = {
 	&dev_attr_durations.attr,
 	&dev_attr_timeouts.attr,
 	&dev_attr_tpm_version_major.attr,
+	&dev_attr_locality.attr,
 	NULL,
 };
 
@@ -344,6 +353,7 @@ static struct attribute *tpm2_dev_attrs[] = {
 #ifdef CONFIG_TCG_TPM2_HMAC
 	&dev_attr_null_name.attr,
 #endif
+	&dev_attr_locality.attr,
 	NULL
 };
 
Signature · 1 line
2.39.3
#32 lore raw

PATCH v13 18/19 x86: Secure Launch late initcall platform module

In reply to 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.

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 | 508 +++++++++++++++++++++++++++++++++++++
 2 files changed, 509 insertions(+)
 create mode 100644 arch/x86/kernel/slmodule.c
arch/x86/kernel/Makefile +1 -0
index a7ca7ca16174..bed87b1c49a2 100644
@@ -83,6 +83,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 +508 -0

508 lines not on this page · raw message

Signature · 1 line
2.39.3
#33 lore raw

PATCH v13 19/19 x86/efi: EFI stub DRTM launch support for Secure Launch

In reply to 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.

---
 drivers/firmware/efi/libstub/efistub.h  |  8 +++
 drivers/firmware/efi/libstub/x86-stub.c | 94 +++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
drivers/firmware/efi/libstub/efistub.h +8 -0
index d96d4494070d..bbbc4b327ce1 100644
@@ -135,6 +135,14 @@ void efi_set_u64_split(u64 data, u32 *lo, u32 *hi)
 	*hi = upper_32_bits(data);
 }
 
+static inline
+void efi_set_u64_form(u32 lo, u32 hi, u64 *data)
+{
+	u64 upper = hi;
+
+	*data = lo | upper << 32;
+}
+
 /*
  * Allocation types for calls to boottime->allocate_pages.
  */
drivers/firmware/efi/libstub/x86-stub.c +94 -0

112 lines not on this page · raw message

Signature · 1 line
2.39.3