forked from xen-project/xen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
efi/boot: Add "unified Xen" support for SecureBoot
During UEFI boot, Xen can look to see if it has built-in PE sections for its configuration file, the Linux kernel, the initrd, and the XSM. By bundling all of these into a single file with the hypervisor, it is easier to integrate with UEFI SecureBoot, which supports validating a single signed EFI executable. The PE executable parser and unifed kernel idea is copied from systemd-boot and has been used by the safeboot project. The scripts/unify-xen shows how to use objcopy to bundle all of the components together; it requires better command line parsing to be robust. Signed-off-by: Trammell Hudson <[email protected]>
- Loading branch information
1 parent
81fd0d3
commit 765f0fe
Showing
2 changed files
with
238 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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,68 @@ | ||
#!/bin/bash | ||
# Merge a Linux kernel, initrd and commandline into xen.efi to produce a single signed | ||
# EFI executable. | ||
# | ||
# turn off "expressions don't expand in single quotes" | ||
# and "can't follow non-constant sources" | ||
# shellcheck disable=SC2016 disable=SC1090 | ||
set -e -o pipefail | ||
export LC_ALL=C | ||
|
||
die() { echo "$@" >&2 ; exit 1 ; } | ||
warn() { echo "$@" >&2 ; } | ||
debug() { [ "$VERBOSE" == 1 ] && echo "$@" >&2 ; } | ||
|
||
cleanup() { | ||
rm -rf "$TMP" | ||
} | ||
|
||
TMP=$(mktemp -d) | ||
TMP_MOUNT=n | ||
trap cleanup EXIT | ||
|
||
######################################## | ||
|
||
# Usage | ||
# unify xen.efi xen.cfg bzimage initrd | ||
# Xen goes up to a pad at 00400000 | ||
|
||
XEN="$1" | ||
CONFIG="$2" | ||
KERNEL="$3" | ||
RAMDISK="$4" | ||
# --change-section-vma .config=0x0500000 \ | ||
# --change-section-vma .kernel=0x0510000 \ | ||
# --change-section-vma .ramdisk=0x3000000 \ | ||
|
||
objcopy \ | ||
--add-section .kernel="$KERNEL" \ | ||
--add-section .ramdisk="$RAMDISK" \ | ||
--add-section .config="$CONFIG" \ | ||
--change-section-vma .config=0xffff82d041000000 \ | ||
--change-section-vma .kernel=0xffff82d041010000 \ | ||
--change-section-vma .ramdisk=0xffff82d042000000 \ | ||
"$XEN" \ | ||
"$TMP/xen.efi" \ | ||
|| die "$TMP/xen.efi: unable to create" | ||
|
||
KEY_ENGINE="" | ||
KEY="/etc/safeboot/signing.key" | ||
CERT="/etc/safeboot/cert.pem" | ||
|
||
for try in 1 2 3 ; do | ||
warn "$TMP/xen.efi: Signing (ignore warnings about gaps)" | ||
sbsign.safeboot \ | ||
$KEY_ENGINE \ | ||
--key "$KEY" \ | ||
--cert "$CERT" \ | ||
--output "xen.signed.efi" \ | ||
"$TMP/xen.efi" \ | ||
&& break | ||
|
||
if [ "$try" == 3 ]; then | ||
die "xen.signed.efi: failed after $try tries" | ||
fi | ||
|
||
warn "$OUTDIR/linux.efi: signature failed! Try $try." | ||
done | ||
|