* [gentoo-dev] [PATCH 1/2] kernel-install.eclass: verify against SECUREBOOT_SIGN_CERT
@ 2025-09-11 20:18 Nowa Ammerlaan
2025-09-11 20:18 ` [gentoo-dev] [PATCH 2/2] kernel-build.eclass: replace cert with pubkey in generic-uki .pcrpkey Nowa Ammerlaan
0 siblings, 1 reply; 2+ messages in thread
From: Nowa Ammerlaan @ 2025-09-11 20:18 UTC (permalink / raw
To: gentoo-dev; +Cc: Nowa Ammerlaan
The .pcrpkey section of the UKI should not contain a full certificate.
And therefore it is not correct to use it in sbverify. Instead use
the set SECUREBOOT_SIGN_CERT which will contain the certificate that
was used for signing in kernel-build.eclass. For gentoo-kernel-bin
we set this variable to the certificate that was used during build
and is included in the gpkg.
Signed-off-by: Nowa Ammerlaan <nowa@gentoo.org>
---
eclass/kernel-install.eclass | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
diff --git a/eclass/kernel-install.eclass b/eclass/kernel-install.eclass
index e753592c46fc..35254b357005 100644
--- a/eclass/kernel-install.eclass
+++ b/eclass/kernel-install.eclass
@@ -674,27 +674,16 @@ kernel-install_extract_from_uki() {
die "Failed to extract ${extract_type}"
# Sanity checks for kernel images
- if [[ ${extract_type} == linux ]] &&
+ if [[ -n ${SECUREBOOT_SIGN_CERT} && ${extract_type} == linux ]] &&
{ ! in_iuse secureboot || use secureboot ;}
then
- # Extract the used SECUREBOOT_SIGN_CERT to verify the kernel image
- local cert=${T}/pcrpkey
- kernel-install_extract_from_uki pcrpkey "${uki}" "${cert}"
- if [[ $(head -n1 "${cert}") != "-----BEGIN CERTIFICATE-----" ]]; then
- # This is a DER format certificate, convert it to PEM
- openssl x509 \
- -inform DER -in "${cert}" \
- -outform PEM -out "${cert}" ||
- die "Failed to convert pcrpkey to PEM format"
- fi
-
# Check if the signature on the UKI is valid
- sbverify --cert "${cert}" "${uki}" ||
+ sbverify --cert "${SECUREBOOT_SIGN_CERT}" "${uki}" ||
die "ERROR: UKI signature is invalid"
# Check if the signature on the kernel image is valid
local sbverify_err=$(
- sbverify --cert "${cert}" "${out_temp}" 2>&1 >/dev/null
+ sbverify --cert "${SECUREBOOT_SIGN_CERT}" "${out_temp}" 2>&1 >/dev/null
)
# Check if there was a padding warning
@@ -708,7 +697,7 @@ kernel-install_extract_from_uki() {
>"${out_temp}_trimmed" || die
# Check if the signature verifies now
sbverify_err=$(
- sbverify --cert "${cert}" "${out_temp}_trimmed" 2>&1 >/dev/null
+ sbverify --cert "${SECUREBOOT_SIGN_CERT}" "${out_temp}_trimmed" 2>&1 >/dev/null
)
[[ -z ${sbverify_err} ]] && out_temp=${out_temp}_trimmed
fi
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [gentoo-dev] [PATCH 2/2] kernel-build.eclass: replace cert with pubkey in generic-uki .pcrpkey
2025-09-11 20:18 [gentoo-dev] [PATCH 1/2] kernel-install.eclass: verify against SECUREBOOT_SIGN_CERT Nowa Ammerlaan
@ 2025-09-11 20:18 ` Nowa Ammerlaan
0 siblings, 0 replies; 2+ messages in thread
From: Nowa Ammerlaan @ 2025-09-11 20:18 UTC (permalink / raw
To: gentoo-dev; +Cc: Nowa Ammerlaan
This is the final piece in the Measured Boot puzzle, we have been
putting the full certificate in the pcrpkey section. But though the
certificate does contain the public key, the tools downstream get
confused by the incorrect format. We now resolve the problem by
extracting the public key from the certificate and using that instead.
See-also: https://github.com/systemd/systemd/issues/38833
Closes: https://bugs.gentoo.org/960276
Signed-off-by: Nowa Ammerlaan <nowa@gentoo.org>
---
eclass/kernel-build.eclass | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 7a5c80cfd6a6..2b16d0a226dd 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -609,14 +609,13 @@ kernel-build_src_install() {
done
if [[ ${KERNEL_IUSE_MODULES_SIGN} ]] && use secureboot; then
- # --pcrpkey is appended as is. If the certificate and key
- # are in the same file, we could accidentally leak the key
- # into the UKI. Pass the certificate through openssl to ensure
- # that it truly contains *only* the certificate.
+ # The PCR public key option should contain *only* the
+ # public key, not the full certificate containing the
+ # public key. Bug #960276
openssl x509 \
-in "${SECUREBOOT_SIGN_CERT}" -inform PEM \
- -out "${T}/pcrpkey.pem" -outform PEM ||
- die "Failed to extract certificate"
+ -noout -pubkey > "${T}/pcrpkey.pem" ||
+ die "Failed to extract public key"
ukify_args+=(
--secureboot-private-key="${SECUREBOOT_SIGN_KEY}"
--secureboot-certificate="${SECUREBOOT_SIGN_CERT}"
@@ -627,17 +626,19 @@ kernel-build_src_install() {
ukify_args+=(
--signing-engine="pkcs11"
--pcr-private-key="${SECUREBOOT_SIGN_KEY}"
- --pcr-public-key="${SECUREBOOT_SIGN_CERT}"
+ --pcr-public-key="${T}/pcrpkey.pem"
--phases="enter-initrd"
--pcr-private-key="${SECUREBOOT_SIGN_KEY}"
- --pcr-public-key="${SECUREBOOT_SIGN_CERT}"
+ --pcr-public-key="${T}/pcrpkey.pem"
--phases="enter-initrd:leave-initrd enter-initrd:leave-initrd:sysinit enter-initrd:leave-initrd:sysinit:ready"
)
else
ukify_args+=(
--pcr-private-key="${SECUREBOOT_SIGN_KEY}"
+ --pcr-public-key="${T}/pcrpkey.pem"
--phases="enter-initrd"
--pcr-private-key="${SECUREBOOT_SIGN_KEY}"
+ --pcr-public-key="${T}/pcrpkey.pem"
--phases="enter-initrd:leave-initrd enter-initrd:leave-initrd:sysinit enter-initrd:leave-initrd:sysinit:ready"
)
fi
--
2.51.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-11 20:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-11 20:18 [gentoo-dev] [PATCH 1/2] kernel-install.eclass: verify against SECUREBOOT_SIGN_CERT Nowa Ammerlaan
2025-09-11 20:18 ` [gentoo-dev] [PATCH 2/2] kernel-build.eclass: replace cert with pubkey in generic-uki .pcrpkey Nowa Ammerlaan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox