From 9425bb84d48a84d8bc59dc33601c1d5f778a4032 Mon Sep 17 00:00:00 2001 From: Sebastiano Barezzi Date: Tue, 28 Jun 2022 23:10:29 +0200 Subject: [PATCH] init: Add CONFIG_INITRAMFS_IGNORE_SKIP_FLAG * Ignoring an ignore flag, yikes * Also replace skip_initramf with want_initramf (omitting last letter for Magisk since it binary patches that out of kernel, I'm not even sure why we're supporting that mess) Co-authored-by: Erfan Abdi Change-Id: Ifdf726f128bc66bf860bbb71024f94f56879710f --- fs/proc/cmdline.c | 31 +++++++++++++++++++++++++++++++ init/initramfs.c | 2 +- usr/Kconfig | 11 +++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c index cbd82dff7e81..57d2d15e88bc 100644 --- a/fs/proc/cmdline.c +++ b/fs/proc/cmdline.c @@ -2,10 +2,37 @@ #include #include #include +#ifdef CONFIG_INITRAMFS_IGNORE_SKIP_FLAG +#include +#endif + +#ifdef CONFIG_INITRAMFS_IGNORE_SKIP_FLAG +#define INITRAMFS_STR_FIND "skip_initramf" +#define INITRAMFS_STR_REPLACE "want_initramf" +#define INITRAMFS_STR_LEN (sizeof(INITRAMFS_STR_FIND) - 1) + +static char proc_command_line[COMMAND_LINE_SIZE]; + +static void proc_command_line_init(void) { + char *offset_addr; + + strcpy(proc_command_line, saved_command_line); + + offset_addr = strstr(proc_command_line, INITRAMFS_STR_FIND); + if (!offset_addr) + return; + + memcpy(offset_addr, INITRAMFS_STR_REPLACE, INITRAMFS_STR_LEN); +} +#endif static int cmdline_proc_show(struct seq_file *m, void *v) { +#ifdef CONFIG_INITRAMFS_IGNORE_SKIP_FLAG + seq_printf(m, "%s\n", proc_command_line); +#else seq_printf(m, "%s\n", saved_command_line); +#endif return 0; } @@ -23,6 +50,10 @@ static const struct file_operations cmdline_proc_fops = { static int __init proc_cmdline_init(void) { +#ifdef CONFIG_INITRAMFS_IGNORE_SKIP_FLAG + proc_command_line_init(); +#endif + proc_create("cmdline", 0, NULL, &cmdline_proc_fops); return 0; } diff --git a/init/initramfs.c b/init/initramfs.c index bf3af10c500a..b4a81e01fc28 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -613,7 +613,7 @@ static int __init skip_initramfs_param(char *str) { if (*str) return 0; - do_skip_initramfs = 1; + do_skip_initramfs = !IS_ENABLED(CONFIG_INITRAMFS_IGNORE_SKIP_FLAG); return 1; } __setup("skip_initramfs", skip_initramfs_param); diff --git a/usr/Kconfig b/usr/Kconfig index 572dcf7b6a44..e49fd6637f3a 100644 --- a/usr/Kconfig +++ b/usr/Kconfig @@ -21,6 +21,17 @@ config INITRAMFS_SOURCE If you are not sure, leave it blank. +config INITRAMFS_IGNORE_SKIP_FLAG + bool "Force initramfs even when skip_initramfs is set" + default n + help + Ignore skip_initramfs cmdline flag. + + This should only be used if you have no control over cmdline + passed by your bootloader yet you can't use CMDLINE_FORCE. + + If unsure say N. + config INITRAMFS_ROOT_UID int "User ID to map to 0 (user root)" depends on INITRAMFS_SOURCE!=""