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@xxxxxxx> --- 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