-
-
Notifications
You must be signed in to change notification settings - Fork 211
WIP: Add TCG Opal disk unlock support #2196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Sean-StarLabs
wants to merge
2
commits into
linuxboot:master
Choose a base branch
from
StarLabsLtd:sean/heads-opal-qemu-20260826
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
boards/qemu-coreboot-fbwhiptail-tpm2-opal/initrd/bin/heads-opal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| #!/bin/bash | ||
|
|
||
| state_file=/tmp/heads-opal-qemu-unlocked | ||
| device=/dev/nvme0n1 | ||
|
|
||
| log_serial() { | ||
| printf '%s\n' "$*" >/dev/ttyS0 2>/dev/null || true | ||
| } | ||
|
|
||
| case "${1:-}" in | ||
| scan) | ||
| log_serial "HEADS_OPAL_QEMU: mock scan completed" | ||
| if [ -e "$state_file" ]; then | ||
| printf '%s unlocked\n' "$device" | ||
| else | ||
| printf '%s locked\n' "$device" | ||
| fi | ||
| ;; | ||
| status) | ||
| [ "${2:-}" = "$device" ] || exit 1 | ||
| if [ -e "$state_file" ]; then | ||
| printf '%s\n' unlocked | ||
| log_serial "HEADS_OPAL_QEMU: post-unlock state confirmed" | ||
| else | ||
| printf '%s\n' locked | ||
| fi | ||
| ;; | ||
| unlock) | ||
| [ "${2:-}" = "$device" ] || exit 1 | ||
| [ "$#" -eq 2 ] || exit 1 | ||
| if [ -e /tmp/secret/heads-opal-password ]; then | ||
| log_serial "HEADS_OPAL_QEMU: password file remained linked during unlock" | ||
| exit 1 | ||
| fi | ||
| password=$(cat) | ||
| case "$(tr '\0' ' ' </proc/$$/cmdline)" in | ||
| *qemu-opal-password*) | ||
| log_serial "HEADS_OPAL_QEMU: password leaked through argv" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| if env | grep -q 'qemu-opal-password'; then | ||
| log_serial "HEADS_OPAL_QEMU: password leaked through environment" | ||
| exit 1 | ||
| fi | ||
| if [ "$password" != "qemu-opal-password" ]; then | ||
| unset password | ||
| exit 3 | ||
| fi | ||
| unset password | ||
| touch "$state_file" | ||
| log_serial "HEADS_OPAL_QEMU: unlock and S3 handoff accepted" | ||
| ;; | ||
| lock) | ||
| [ "${2:-}" = "$device" ] || exit 1 | ||
| [ "$#" -eq 2 ] || exit 1 | ||
| password=$(cat) | ||
| [ "$password" = "qemu-opal-password" ] || exit 3 | ||
| unset password | ||
| rm -f "$state_file" | ||
| log_serial "HEADS_OPAL_QEMU: rollback lock and S3 clear accepted" | ||
| ;; | ||
| *) | ||
| exit 64 | ||
| ;; | ||
| esac |
3 changes: 3 additions & 0 deletions
3
boards/qemu-coreboot-fbwhiptail-tpm2-opal/initrd/bin/heads-opal-prompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/bash | ||
|
|
||
| printf '%s' 'qemu-opal-password' |
8 changes: 8 additions & 0 deletions
8
boards/qemu-coreboot-fbwhiptail-tpm2-opal/qemu-coreboot-fbwhiptail-tpm2-opal.config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # QEMU fixture for the Heads TCG Opal boot gate. QEMU does not emulate an | ||
| # Opal drive, so board overlays provide a stateful mock backend and prompt. | ||
| include $(pwd)/boards/qemu-coreboot-fbwhiptail-tpm2/qemu-coreboot-fbwhiptail-tpm2.config | ||
|
|
||
| export CONFIG_BOARD_NAME="qemu-coreboot-fbwhiptail-tpm2-opal" | ||
| export CONFIG_HEADS_OPAL=y | ||
| export CONFIG_HEADS_OPAL_S3_APMC_V1=y | ||
| export CONFIG_HEADS_OPAL_TEST_FIXTURE=y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # TCG Opal disk unlock | ||
|
|
||
| Heads can unlock TCG Opal disks before any normal, basic, or network boot | ||
| script starts. Enable the boot gate with: | ||
|
|
||
| ```make | ||
| export CONFIG_HEADS_OPAL=y | ||
| ``` | ||
|
|
||
| The board must use Linux 6.1 or later and its Linux configuration must enable | ||
| `CONFIG_BLK_SED_OPAL=y`. The build rejects a production configuration that | ||
| enables the gate without this kernel support. The `heads-opal` helper uses the | ||
| kernel's `IOC_OPAL_GET_STATUS` and `IOC_OPAL_LOCK_UNLOCK` interfaces. It | ||
| unlocks the global locking range as `Admin1`. | ||
|
|
||
| The gate is keyed to the helper installed in the immutable initrd, not the | ||
| mutable runtime user configuration. Production always uses `/bin/heads-opal` | ||
| and the built-in password dialog. A board may replace those fixed paths in its | ||
| initrd overlay for a fixture, but user configuration cannot select another | ||
| backend or disable the gate. | ||
|
|
||
| The prompt completes before the unlock begins. Heads opens and unlinks its | ||
| mode-0600 password file before passing the anonymous file descriptor to the C | ||
| helper, so the password is not placed in command arguments, the environment, | ||
| or a production Bash variable. The helper locks and clears its credential | ||
| buffers. If a later disk or S3 handoff fails, Heads uses the retained anonymous | ||
| descriptors to relock earlier disks before recovery. A rollback failure powers | ||
| the machine off instead of exposing an unlocked disk to a recovery shell. | ||
|
|
||
| coreboot provides the optional OPAL S3 APMC service through | ||
| [change 91045](https://review.coreboot.org/c/coreboot/+/91045). Boards built | ||
| with that service can explicitly select its version 1 ABI with: | ||
|
|
||
| ```make | ||
| export CONFIG_HEADS_OPAL_S3_APMC_V1=y | ||
| ``` | ||
|
|
||
| Only enable this option when the running coreboot contains that ABI: APMC port | ||
| `0xb2`, command `0xee`, context signature `OPS3`, and context version 1. The | ||
| option makes failure to install or clear the password in coreboot SMM fatal. | ||
| The Linux configuration must additionally enable `CONFIG_PROC_PAGE_MONITOR=y`, | ||
| and the ABI limits passwords to 32 bytes. This selection is compiled into the | ||
| helper and cannot be disabled through runtime user configuration. The S3 | ||
| handoff path currently supports NVMe devices only; ordinary cold-boot unlock | ||
| uses the kernel OPAL interface for any supported block device. | ||
|
|
||
| ## QEMU fixture | ||
|
|
||
| `qemu-coreboot-fbwhiptail-tpm2-opal` overlays the fixed helper and prompt paths | ||
| with deterministic fixtures. Its explicit `CONFIG_HEADS_OPAL_TEST_FIXTURE=y` | ||
| setting is the only exception to the production kernel-configuration check. It | ||
| exercises Heads' | ||
| scan parsing, secret transport, unlock and rollback gates, post-unlock status | ||
| check, S3-handoff request, and transition to the boot script. | ||
|
|
||
| Upstream QEMU does not emulate a TCG Opal device or this SMM service. The | ||
| fixture therefore does not exercise the production OPAL ioctls, NVMe Security | ||
| Receive, physical-address lookup, or SMI handler. Those operations and S3 | ||
| resume require hardware validation on a system with an Opal SSD. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be built with Oz?