Discard the key generated by the kernel build instead of installing it into /usr/src, where root could use it to sign modules. In-tree modules only need it during the build, out-of-tree modules can use a separate MODULES_SIGN_KEY. Signed-off-by: David Seifert <so…@gentoo.org> --- eclass/kernel-build.eclass | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass index f8e5abbca4a92..2681be4781dd1 100644 --- a/eclass/kernel-build.eclass +++ b/eclass/kernel-build.eclass @@ -135,6 +135,21 @@ REQUIRED_USE="secureboot? ( modules-sign )" # key in PEM format to use. Must be specified if MODULES_SIGN_KEY # is set to a path of a file that only contains the private key. +# @ECLASS_VARIABLE: MODULES_SIGN_EPHEMERAL +# @USER_VARIABLE +# @DEFAULT_UNSET +# @DESCRIPTION: +# Used with USE=modules-sign when MODULES_SIGN_KEY is unset. If set to +# a non-empty value, the private key generated by the kernel build +# system is discarded after the in-tree modules have been signed, +# instead of being installed into the kernel source directory. +# +# Out-of-tree modules then need their own MODULES_SIGN_KEY (see +# linux-mod-r1.eclass), whose certificate the kernel must trust, e.g. +# via CONFIG_SYSTEM_TRUSTED_KEYS in /etc/kernel/config.d or a trusted +# MOK. With USE=secureboot, also set SECUREBOOT_SIGN_KEY, as the +# discarded key cannot serve as the Secure Boot signing key fallback. + # @ECLASS_VARIABLE: KERNEL_GENERIC_UKI_CMDLINE # @USER_VARIABLE # @DESCRIPTION: @@ -524,7 +539,12 @@ kernel-build_src_install() { # If a key was generated, exclude it from the binpkg local generated_key=${ED}${kernel_dir}/certs/signing_key.pem if [[ -r ${generated_key} ]]; then - mv "${generated_key}" "${T}/signing_key.pem" || die + if [[ ${MODULES_SIGN_EPHEMERAL} ]]; then + rm "${generated_key}" || die + else + # kernel-install_pkg_preinst moves it back into place + mv "${generated_key}" "${T}/signing_key.pem" || die + fi fi # building modules fails with 'vmlinux has no symtab?' if stripped @@ -775,7 +795,11 @@ kernel-build_pkg_postinst() { kernel-install_pkg_postinst savedconfig_pkg_postinst - if use modules-sign && [[ -z ${MODULES_SIGN_KEY} ]]; then + if use modules-sign && [[ -z ${MODULES_SIGN_KEY} && ${MODULES_SIGN_EPHEMERAL} ]]; then + elog "MODULES_SIGN_EPHEMERAL is set, the signing key generated by the" + elog "kernel build system was discarded. Out-of-tree modules must be" + elog "signed with MODULES_SIGN_KEY, whose certificate the kernel trusts." + elif use modules-sign && [[ -z ${MODULES_SIGN_KEY} ]]; then ewarn ewarn "MODULES_SIGN_KEY was not set, this means the kernel build system" ewarn "automatically generated the signing key. This key was installed" @@ -787,7 +811,8 @@ kernel-build_pkg_postinst() { ewarn "Use emerge @module-rebuild, or manually sign the modules as" ewarn "described on the wiki [1]" ewarn - ewarn "Consider using the MODULES_SIGN_KEY variable to use an external key." + ewarn "Consider using the MODULES_SIGN_KEY variable to use an external key," + ewarn "or MODULES_SIGN_EPHEMERAL to discard the generated key." ewarn ewarn "[1]: https://wiki.gentoo.org/wiki/Signed_kernel_module_support" fi
-- 2.56.1