🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.gentoo.dev
Article #240

[gentoo-dev] [PATCH 3/6] kernel-build.eclass: add MODULES_SIGN_EPHEMERAL

#240
From: David Seifert
Date: Tue, 01 Dec 2026 16:00
75 lines
4482 bytes
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 <soap@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
Technical Details
Message-ID: <O5yqR-fmyc-21@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!bofh.it!news.nic.it!robomod
References: <O5yqR-fmyc-3@gated-at.bofh.it>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!bofh.it!news.nic.it!robomod
From: David Seifert <soap@gentoo.org>
Newsgroups: linux.gentoo.dev
Subject: [gentoo-dev] [PATCH 3/6] kernel-build.eclass: add MODULES_SIGN_EPHEMERAL
Date: Tue, 01 Dec 2026 17:00:01 +0100
Message-ID: <O5yqR-fmyc-21@gated-at.bofh.it>
References: <O5yqR-fmyc-3@gated-at.bofh.it>
X-Mailer: git-send-email 2.56.1
List-ID: Gentoo Linux mail <gentoo-dev.gentoo.org>
Reply-To: gentoo-dev@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Approved: robomod@news.nic.it
Lines: 75
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Cc: David Seifert <soap@gentoo.org>
X-Original-Date: Tue,  1 Dec 2026 16:49:21 +0100
X-Original-Message-ID: <20261201154924.70252-3-soap@gentoo.org>
X-Original-References: <20261201154924.70252-1-soap@gentoo.org>