From: Randy Dunlap <rdunlap@xxxxxxxxxxxxx> commit 05fe3c103f7e6b8b4fca8a7001dfc9ed4628085b upstream. __setup() handlers should return 1 if the command line option is handled and 0 if not (or maybe never return 0; it just pollutes init's environment). This prevents: Unknown kernel command line parameters \ "BOOT_IMAGE=/boot/bzImage-517rc5 hardened_usercopy=off", will be \ passed to user space. Run /sbin/init as init process with arguments: /sbin/init with environment: HOME=/ TERM=linux BOOT_IMAGE=/boot/bzImage-517rc5 hardened_usercopy=off or hardened_usercopy=on but when "hardened_usercopy=foo" is used, there is no Unknown kernel command line parameter. Return 1 to indicate that the boot option has been handled. Print a warning if strtobool() returns an error on the option string, but do not mark this as in unknown command line option and do not cause init's environment to be polluted with this string. Link: https://lkml.kernel.org/r/20220222034249.14795-1-rdunlap@xxxxxxxxxxxxx Link: lore.kernel.org/r/64644a2f-4a20-bab3-1e15-3b2cdd0defe3@xxxxxxxxxxxx Fixes: b5cb15d9372ab ("usercopy: Allow boot cmdline disabling of hardening") Signed-off-by: Randy Dunlap <rdunlap@xxxxxxxxxxxxx> Reported-by: Igor Zhbanov <i.zhbanov@xxxxxxxxxxxx> Acked-by: Chris von Recklinghausen <crecklin@xxxxxxxxxx> Cc: Kees Cook <keescook@xxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- mm/usercopy.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/mm/usercopy.c +++ b/mm/usercopy.c @@ -298,7 +298,10 @@ static bool enable_checks __initdata = t static int __init parse_hardened_usercopy(char *str) { - return strtobool(str, &enable_checks); + if (strtobool(str, &enable_checks)) + pr_warn("Invalid option string for hardened_usercopy: '%s'\n", + str); + return 1; } __setup("hardened_usercopy=", parse_hardened_usercopy); Patches currently in stable-queue which might be from rdunlap@xxxxxxxxxxxxx are queue-4.19/tomoyo-fix-__setup-handlers-return-values.patch queue-4.19/mm-mmap-return-1-from-stack_guard_gap-__setup-handler.patch queue-4.19/tty-hvc-fix-return-value-of-__setup-handler.patch queue-4.19/pm-suspend-fix-return-value-of-__setup-handler.patch queue-4.19/clocksource-acpi_pm-fix-return-value-of-__setup-hand.patch queue-4.19/mips-rb532-fix-return-value-of-__setup-handler.patch queue-4.19/acpi-apei-fix-return-value-of-__setup-handlers.patch queue-4.19/dma-debug-fix-return-value-of-__setup-handlers.patch queue-4.19/hv-utils-add-ptp_1588_clock-to-kconfig-to-fix-build.patch queue-4.19/printk-fix-return-value-of-printk.devkmsg-__setup-ha.patch queue-4.19/pm-hibernate-fix-__setup-handler-error-handling.patch queue-4.19/kgdboc-fix-return-value-of-__setup-handler.patch queue-4.19/mm-memcontrol-return-1-from-cgroup.memory-__setup-handler.patch queue-4.19/kgdbts-fix-return-value-of-__setup-handler.patch queue-4.19/mm-usercopy-return-1-from-hardened_usercopy-__setup-handler.patch