init, arch: make command line size and init arg limit configurable
Subsystems (17)
v2 cover init, arch: make command line size and init arg limit configurable
This patch series promotes COMMAND_LINE_SIZE from arch/s390/Kconfig to init/Kconfig to be generally available to other architectures.
In some use cases, such as netboot kernels, rootfs configurations, larger initramfs setups, require larger sizes. While for embedded workloads, it can be reduced to save memory.
Since COMMAND_LINE_SIZE can be larger, it also makes sense to allow INIT_ENV_ARG_LIMIT to be configured.
v1 -> v2
* Squash the Kconfig promotion and architecture header updates into a single atomic commit.
* Replace Originally-by with Signed-off-by for Maciej Żenczykowski.
* Add architectural range constraints for ARM, M68K, NIOS2, PowerPC, SuperH, and Alpha based on hardware, buffer, and stack limits.
* Fix Kconfig symbol for PowerPC from POWERPC to PPC.
* Split pre-existing init/main.c logic bug fixes into a separate series.
v1: https://lore.kernel.org/all/[email protected]/
Wilson Felipe Pereira (2):
init, arch: make CONFIG_COMMAND_LINE_SIZE globally configurable init/Kconfig: make config INIT_ENV_ARG_LIMIT user-configurable
arch/alpha/include/uapi/asm/setup.h | 4 ++++ arch/arc/include/asm/setup.h | 2 +- arch/arm/include/uapi/asm/setup.h | 6 +++++- arch/arm64/include/uapi/asm/setup.h | 4 ++++ arch/loongarch/include/uapi/asm/setup.h | 4 ++++ arch/m68k/include/uapi/asm/setup.h | 6 +++++- arch/microblaze/include/uapi/asm/setup.h | 4 ++++ arch/mips/include/uapi/asm/setup.h | 4 ++++ arch/parisc/include/uapi/asm/setup.h | 4 ++++ arch/powerpc/include/uapi/asm/setup.h | 4 ++++ arch/riscv/include/uapi/asm/setup.h | 4 ++++ arch/s390/Kconfig | 8 -------- arch/sparc/include/uapi/asm/setup.h | 10 +++++++--- arch/um/include/asm/setup.h | 2 +- arch/x86/include/asm/setup.h | 2 +- arch/xtensa/include/uapi/asm/setup.h | 4 ++++ include/uapi/asm-generic/setup.h | 4 ++++ init/Kconfig | 19 ++++++++++++++++++- 18 files changed, 78 insertions(+), 17 deletions(-)
--
2.55.0.737.g08866a6d13-goog
PATCH v2 1/2 init, arch: make CONFIG_COMMAND_LINE_SIZE globally configurable
Currently, s390 has the ability to configure the maximum kernel command line size via Kconfig (CONFIG_COMMAND_LINE_SIZE). Other architectures define a hardcoded COMMAND_LINE_SIZE macro in their setup.h headers.
In some use cases, such as netboot kernels, rootfs configurations, or larger initramfs setups, a larger command line size is required. While for embedded workloads, it can be reduced to save memory.
Move CONFIG_COMMAND_LINE_SIZE out of arch/s390/Kconfig and into init/Kconfig under General setup, and update every architecture's setup.h header to define COMMAND_LINE_SIZE as CONFIG_COMMAND_LINE_SIZE.
For user-space API (uapi) headers, wrap the definition in an #ifdef __KERNEL__ guard and retain the historical hardcoded default in the #else block. When user-space headers are installed via make headers_install, unifdef strips out the kernel section, ensuring the same value as before for user-space applications including <asm/setup.h>.
For S390, the range is kept the same, but other architectures have varying constraints. S390 requires a minimum of 896 bytes to protect legacy bootloaders from overwriting the .text section. ARM, M68K, and NIOS2 allocate the command line directly on severely constrained decompressor stacks, so their ranges are strictly capped at 2048 bytes to prevent deterministic stack exhaustion and boot panics. PowerPC (PPC) boot wrappers silently truncate arguments past 2048 bytes, so it is also capped at 2048 to prevent silent parameter loss.
The SuperH (SUPERH) boot parameter page allocates exactly PAGE_SIZE (typically 4096 bytes), and placing a 4096-byte command line starting at offset 256 would cause strscpy() to read out of bounds; it is capped at 3840 bytes. Alpha physically limits its boot parameter block to 256 bytes, so its limit is strictly locked to 256. All other architectures are capped at 4096 bytes to prevent unreasonable allocations.
--- arch/alpha/include/uapi/asm/setup.h | 4 ++++ arch/arc/include/asm/setup.h | 2 +- arch/arm/include/uapi/asm/setup.h | 6 +++++- arch/arm64/include/uapi/asm/setup.h | 4 ++++ arch/loongarch/include/uapi/asm/setup.h | 4 ++++ arch/m68k/include/uapi/asm/setup.h | 6 +++++- arch/microblaze/include/uapi/asm/setup.h | 4 ++++ arch/mips/include/uapi/asm/setup.h | 4 ++++ arch/parisc/include/uapi/asm/setup.h | 4 ++++ arch/powerpc/include/uapi/asm/setup.h | 4 ++++ arch/riscv/include/uapi/asm/setup.h | 4 ++++ arch/s390/Kconfig | 8 -------- arch/sparc/include/uapi/asm/setup.h | 10 +++++++--- arch/um/include/asm/setup.h | 2 +- arch/x86/include/asm/setup.h | 2 +- arch/xtensa/include/uapi/asm/setup.h | 4 ++++ include/uapi/asm-generic/setup.h | 4 ++++ init/Kconfig | 16 ++++++++++++++++ 18 files changed, 76 insertions(+), 16 deletions(-)
arch/alpha/include/uapi/asm/setup.h +4 -0
@@ -2,6 +2,10 @@#ifndef _UAPI__ALPHA_SETUP_H#define _UAPI__ALPHA_SETUP_H +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else #define COMMAND_LINE_SIZE 256 +#endif #endif /* _UAPI__ALPHA_SETUP_H */
arch/arc/include/asm/setup.h +1 -1
@@ -9,7 +9,7 @@#include <linux/types.h> #include <uapi/asm/setup.h> -#define COMMAND_LINE_SIZE 256 +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE/* * Data structure to map a ID to string
arch/arm/include/uapi/asm/setup.h +5 -1
@@ -17,7 +17,11 @@#include <linux/types.h> -#define COMMAND_LINE_SIZE 1024 +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else +#define COMMAND_LINE_SIZE 1024 +#endif /* The list ends with an ATAG_NONE node. */ #define ATAG_NONE 0x00000000
arch/arm64/include/uapi/asm/setup.h +4 -0
@@ -22,6 +22,10 @@#include <linux/types.h> +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else #define COMMAND_LINE_SIZE 2048 +#endif #endif
arch/loongarch/include/uapi/asm/setup.h +4 -0
@@ -3,6 +3,10 @@#ifndef _UAPI_ASM_LOONGARCH_SETUP_H#define _UAPI_ASM_LOONGARCH_SETUP_H +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else #define COMMAND_LINE_SIZE 4096 +#endif #endif /* _UAPI_ASM_LOONGARCH_SETUP_H */
arch/m68k/include/uapi/asm/setup.h +5 -1
@@ -12,6 +12,10 @@#ifndef _UAPI_M68K_SETUP_H#define _UAPI_M68K_SETUP_H -#define COMMAND_LINE_SIZE 256 +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else +#define COMMAND_LINE_SIZE 256 +#endif #endif /* _UAPI_M68K_SETUP_H */
arch/microblaze/include/uapi/asm/setup.h +4 -0
@@ -12,6 +12,10 @@#ifndef _UAPI_ASM_MICROBLAZE_SETUP_H#define _UAPI_ASM_MICROBLAZE_SETUP_H +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else #define COMMAND_LINE_SIZE 256 +#endif #endif /* _UAPI_ASM_MICROBLAZE_SETUP_H */
arch/mips/include/uapi/asm/setup.h +4 -0
@@ -2,7 +2,11 @@#ifndef _UAPI_MIPS_SETUP_H#define _UAPI_MIPS_SETUP_H +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else #define COMMAND_LINE_SIZE 4096 +#endif #endif /* _UAPI_MIPS_SETUP_H */
arch/parisc/include/uapi/asm/setup.h +4 -0
@@ -2,6 +2,10 @@#ifndef _PARISC_SETUP_H#define _PARISC_SETUP_H +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else #define COMMAND_LINE_SIZE 1024 +#endif #endif /* _PARISC_SETUP_H */
arch/powerpc/include/uapi/asm/setup.h +4 -0
@@ -2,6 +2,10 @@#ifndef _UAPI_ASM_POWERPC_SETUP_H#define _UAPI_ASM_POWERPC_SETUP_H +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else #define COMMAND_LINE_SIZE 2048 +#endif #endif /* _UAPI_ASM_POWERPC_SETUP_H */
arch/riscv/include/uapi/asm/setup.h +4 -0
@@ -3,6 +3,10 @@#ifndef _UAPI_ASM_RISCV_SETUP_H#define _UAPI_ASM_RISCV_SETUP_H +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else #define COMMAND_LINE_SIZE 2048 +#endif #endif /* _UAPI_ASM_RISCV_SETUP_H */
arch/s390/Kconfig +0 -8
@@ -512,14 +512,6 @@ endchoice config 64BIT def_bool y -config COMMAND_LINE_SIZE - int "Maximum size of kernel command line" - default 4096 - range 896 1048576 - help - This allows you to specify the maximum length of the kernel command - line. - config SMP def_bool y
arch/sparc/include/uapi/asm/setup.h +7 -3
@@ -6,10 +6,14 @@#ifndef _UAPI_SPARC_SETUP_H#define _UAPI_SPARC_SETUP_H -#if defined(__sparc__) && defined(__arch64__) -# define COMMAND_LINE_SIZE 2048 +#ifdef __KERNEL__ +# define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE#else -# define COMMAND_LINE_SIZE 256 +# if defined(__sparc__) && defined(__arch64__) +# define COMMAND_LINE_SIZE 2048 +# else +# define COMMAND_LINE_SIZE 256 +# endif #endif
arch/um/include/asm/setup.h +1 -1
@@ -6,6 +6,6 @@* command line, so this choice is ok. */ -#define COMMAND_LINE_SIZE 4096 +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE#endif /* SETUP_H_INCLUDED */
arch/x86/include/asm/setup.h +1 -1
@@ -4,7 +4,7 @@#include <uapi/asm/setup.h> -#define COMMAND_LINE_SIZE 2048 +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE#include <linux/linkage.h> #include <asm/page_types.h>
arch/xtensa/include/uapi/asm/setup.h +4 -0
@@ -12,6 +12,10 @@#ifndef _XTENSA_SETUP_H#define _XTENSA_SETUP_H +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else #define COMMAND_LINE_SIZE 256 +#endif #endif
include/uapi/asm-generic/setup.h +4 -0
@@ -2,6 +2,10 @@#ifndef __ASM_GENERIC_SETUP_H#define __ASM_GENERIC_SETUP_H +#ifdef __KERNEL__ +#define COMMAND_LINE_SIZE CONFIG_COMMAND_LINE_SIZE +#else #define COMMAND_LINE_SIZE 512 +#endif #endif /* __ASM_GENERIC_SETUP_H */
init/Kconfig +16 -0
@@ -1569,6 +1569,22 @@ config BOOT_CONFIG_EMBED_FILE This bootconfig will be used if there is no initrd or no other bootconfig in the initrd. +config COMMAND_LINE_SIZE + int "Maximum size of kernel command line" + default 4096 if S390 || LOONGARCH || MIPS || UML + default 2048 if X86 || ARM64 || PPC || SPARC64 || RISCV + default 1024 if ARM || PARISC + default 256 if ALPHA || ARC || M68K || MICROBLAZE || SPARC32 || XTENSA + default 512 + range 896 1048576 if S390 + range 256 2048 if ARM || M68K || NIOS2 || PPC + range 256 3840 if SUPERH + range 256 256 if ALPHA + range 256 4096 + help + This allows you to specify the maximum length of the kernel command + line. + config CMDLINE_LOG_WRAP_IDEAL_LEN int "Length to try to wrap the cmdline when logged at boot" default 1021
Signature · 1 line
2.55.0.737.g08866a6d13-goog
[email protected]
AI reviewRe: [PATCH v2 1/2] init, arch: make CONFIG_COMMAND_LINE_SIZE globally configurable
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 19 lines
Currently, s390 has the ability to configure the maximum kernel command line size via
Kconfig(CONFIG_COMMAND_LINE_SIZE). Other architectures define a hardcodedCOMMAND_LINE_SIZEmacro in theirsetup.hheaders.In some use cases, such as netboot kernels, rootfs configurations, or larger initramfs setups, a larger command line size is required. While for embedded workloads, it can be reduced to save memory.
Move
CONFIG_COMMAND_LINE_SIZEout ofarch/s390/Kconfigand into init/Kconfig under General setup, and update every architecture'ssetup.hheader to defineCOMMAND_LINE_SIZEasCONFIG_COMMAND_LINE_SIZE.For user-space API (uapi) headers, wrap the definition in an
#ifdef __KERNEL__guard and retain the historical hardcoded default in the#elseblock. When user-space headers are installed via [ ... ]
architectures are capped at 4096 bytes to prevent unreasonable allocations.
Quoted 2 lines
Signed-off-by Maciej Żenczykowski <[email protected]>Signed-off-by Wilson Felipe Pereira <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v2 2/2 init/Kconfig: make config INIT_ENV_ARG_LIMIT user-configurable
In reply to Wilson Felipe PereiraINIT_ENV_ARG_LIMIT is defined without a prompt string (int), making it a hidden Kconfig symbol that defaults to 32 (or 128 for UML) and cannot be configured in make menuconfig.
Now that CONFIG_COMMAND_LINE_SIZE is configurable across all architectures, users who select larger kernel command lines (e.g., 4096 bytes) may pass more than 32 command-line arguments or environment variables (foo=bar) to /sbin/init. If INIT_ENV_ARG_LIMIT remains hardcoded at 32, any argument after the 32nd sets the panic_later flag and causes a hard kernel panic on boot.
Add a prompt string ("Maximum number of kernel command line arguments") and a range 32 4096 to config INIT_ENV_ARG_LIMIT so that users can configure their init argument and environment variable limit when needed, while preserving the existing default of 32 for standard builds.
--- init/Kconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
init/Kconfig +2 -1
@@ -231,9 +231,10 @@ config BROKEN_ON_SMP default y config INIT_ENV_ARG_LIMIT - int + int "Maximum number of kernel command line arguments" default 32 if !UML default 128 if UML + range 32 4096 help Maximum of each of the number of arguments and environment variables passed to init from the kernel command line.
Signature · 1 line
2.55.0.737.g08866a6d13-goog
[email protected]
AI reviewRe: [PATCH v2 2/2] init/Kconfig: make config INIT_ENV_ARG_LIMIT user-configurable
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines
INIT_ENV_ARG_LIMITis defined without a prompt string (int), making it a hiddenKconfigsymbol that defaults to 32 (or 128 for UML) and cannot be configured inmake menuconfig.Now that
CONFIG_COMMAND_LINE_SIZEis configurable across all architectures, users who select larger kernel command lines (e.g., 4096 bytes) may pass more than 32 command-line arguments or environment variables (foo=bar) to/sbin/init. IfINIT_ENV_ARG_LIMITremains hardcoded at 32, any argument after the 32nd sets thepanic_laterflag and causes a hard kernel panic on boot.
Quoted 7 lines
Add a prompt string ("Maximum number of kernel command line arguments") and a
range 32 4096toconfig INIT_ENV_ARG_LIMITso that users can configure their init argument and environment variable limit when needed, while preserving the existing default of 32 for standard builds.Signed-off-by Maciej Żenczykowski <[email protected]>Signed-off-by Wilson Felipe Pereira <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2