Linux kbuild/kconfig development
 help / color / mirror / Atom feed
From: Jeremy Linton <jeremy.linton@arm.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, hch@lst.de,
	gregkh@linuxfoundation.org, graf@amazon.com, lukas@wunner.de,
	wufan@linux.microsoft.com, brauner@kernel.org,
	jsperbeck@google.com, ardb@kernel.org,
	linux-crypto@vger.kernel.org, linux-kbuild@vger.kernel.org,
	keyrings@vger.kernel.org, Jeremy Linton <jeremy.linton@arm.com>
Subject: [RFC 5/5] initramfs: Enforce initramfs signature
Date: Tue, 15 Oct 2024 17:22:35 -0500	[thread overview]
Message-ID: <20241015222235.71040-6-jeremy.linton@arm.com> (raw)
In-Reply-To: <20241015222235.71040-1-jeremy.linton@arm.com>

Now that the infrastructure is in place to verify and sign initramfs
images, let's refuse them if the signature is invalid. Additionally, a
command-line option `initrdsig=[enforcing|checking]` is provided to
switch between failing to boot or reporting signature failures.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
 init/initramfs.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/init/initramfs.c b/init/initramfs.c
index d2d2c68016c2..bb42ba6c0730 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -573,6 +573,20 @@ static int __init initramfs_async_setup(char *str)
 }
 __setup("initramfs_async=", initramfs_async_setup);
 
+static bool  __initdata enforce_initrd_sig = IS_ENABLED(CONFIG_INITRAMFS_SIG);
+#ifdef CONFIG_INITRAMFS_SIG
+static int __init initrd_sig_setup(char *str)
+{
+	if (!strcmp(str, "enforcing"))
+		enforce_initrd_sig = true;
+	else if (!strcmp(str, "checking"))
+		enforce_initrd_sig = false;
+	return 1;
+}
+__setup("initrdsig=", initrd_sig_setup);
+#endif
+
+
 extern char __initramfs_start[];
 extern unsigned long __initramfs_size;
 #include <linux/initrd.h>
@@ -766,7 +780,10 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie)
 	else
 		printk(KERN_INFO "Unpacking initramfs...\n");
 
-	initrd_signature_check(&initrd_len);
+	if (initrd_signature_check(&initrd_len) && enforce_initrd_sig) {
+		printk(KERN_EMERG "Initramfs signature required\n");
+		goto done;
+	}
 
 	err = unpack_to_rootfs((char *)initrd_start, initrd_len);
 	if (err) {
-- 
2.46.0


      parent reply	other threads:[~2024-10-15 22:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-15 22:22 [RFC 0/5] Another initramfs signature checking set Jeremy Linton
2024-10-15 22:22 ` [RFC 1/5] initramfs: Add initramfs signature checking Jeremy Linton
2024-10-15 22:22 ` [RFC 2/5] KEYS/certs: Start the builtin key and cert system earlier Jeremy Linton
2024-10-15 22:22 ` [RFC 3/5] initramfs: Use existing module signing infrastructure Jeremy Linton
2024-10-15 22:22 ` [RFC 4/5] sign-file: Add -i option to sign initramfs images Jeremy Linton
2024-10-15 22:22 ` Jeremy Linton [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241015222235.71040-6-jeremy.linton@arm.com \
    --to=jeremy.linton@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=brauner@kernel.org \
    --cc=graf@amazon.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=jsperbeck@google.com \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=wufan@linux.microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox