lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y3Phi9mO2KSA0AkM@zn.tnic>
Date:   Tue, 15 Nov 2022 19:59:23 +0100
From:   Borislav Petkov <bp@...en8.de>
To:     Evgeniy Baskov <baskov@...ras.ru>
Cc:     Dave Hansen <dave.hansen@...ux.intel.com>,
        Ingo Molnar <mingo@...hat.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        linux-kernel@...r.kernel.org, x86@...nel.org,
        Alexey Khoroshilov <khoroshilov@...ras.ru>
Subject: [PATCH 1/2] x86/boot: Add a function for kernel command line
 preparation

From: Borislav Petkov <bp@...e.de>
Date: Mon, 14 Nov 2022 15:31:59 +0100

Since both the compressed kernel and kernel proper need to deal with the
command line, add a common helper which abstracts away all the details.

Signed-off-by: Borislav Petkov <bp@...e.de>
---
 arch/x86/include/asm/shared/cmdline.h | 34 +++++++++++++++++++++++++++
 arch/x86/kernel/setup.c               | 21 +++--------------
 2 files changed, 37 insertions(+), 18 deletions(-)
 create mode 100644 arch/x86/include/asm/shared/cmdline.h

diff --git a/arch/x86/include/asm/shared/cmdline.h b/arch/x86/include/asm/shared/cmdline.h
new file mode 100644
index 000000000000..e09c06338567
--- /dev/null
+++ b/arch/x86/include/asm/shared/cmdline.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_X86_SHARED_CMDLINE_H
+#define _ASM_X86_SHARED_CMDLINE_H
+
+#ifdef CONFIG_CMDLINE_BOOL
+#define BUILTIN_CMDLINE CONFIG_CMDLINE
+#else
+#define BUILTIN_CMDLINE ""
+#endif
+
+static inline void cmdline_prepare(char *dst,
+                                   const char *builtin_cmdline,
+                                   char *boot_command_line)
+{
+	/* Depends on CONFIG_CMDLINE_BOOL, overwrite with builtin cmdline */
+	if (IS_ENABLED(CONFIG_CMDLINE_OVERRIDE))
+		strscpy(dst, builtin_cmdline, COMMAND_LINE_SIZE);
+	else if (IS_ENABLED(CONFIG_CMDLINE_BOOL)) {
+		if (builtin_cmdline[0]) {
+			/* Add builtin cmdline */
+			strlcat(dst, builtin_cmdline, COMMAND_LINE_SIZE);
+			strlcat(dst, " ", COMMAND_LINE_SIZE);
+			/* Add boot cmdline */
+			strlcat(dst, boot_command_line, COMMAND_LINE_SIZE);
+		}
+	} else {
+		strscpy(dst, boot_command_line, COMMAND_LINE_SIZE);
+	}
+
+	/* Copy back into boot command line, see setup_command_line() */
+	strscpy(boot_command_line, dst, COMMAND_LINE_SIZE);
+}
+
+#endif /* _ASM_X86_SHARED_CMDLINE_H */
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index aacaa96f0195..c506807142a7 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -25,6 +25,7 @@
 #include <linux/static_call.h>
 #include <linux/swiotlb.h>
 #include <linux/random.h>
+#include <linux/vmalloc.h>
 
 #include <uapi/linux/mount.h>
 
@@ -50,10 +51,10 @@
 #include <asm/pci-direct.h>
 #include <asm/prom.h>
 #include <asm/proto.h>
+#include <asm/shared/cmdline.h>
 #include <asm/thermal.h>
 #include <asm/unwind.h>
 #include <asm/vsyscall.h>
-#include <linux/vmalloc.h>
 
 /*
  * max_low_pfn_mapped: highest directly mapped pfn < 4 GB
@@ -168,9 +169,6 @@ unsigned long saved_video_mode;
 #define RAMDISK_LOAD_FLAG		0x4000
 
 static char __initdata command_line[COMMAND_LINE_SIZE];
-#ifdef CONFIG_CMDLINE_BOOL
-static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
-#endif
 
 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
 struct edd edd;
@@ -970,20 +968,7 @@ void __init setup_arch(char **cmdline_p)
 	bss_resource.start = __pa_symbol(__bss_start);
 	bss_resource.end = __pa_symbol(__bss_stop)-1;
 
-#ifdef CONFIG_CMDLINE_BOOL
-#ifdef CONFIG_CMDLINE_OVERRIDE
-	strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-#else
-	if (builtin_cmdline[0]) {
-		/* append boot loader cmdline to builtin */
-		strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
-		strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
-		strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
-	}
-#endif
-#endif
-
-	strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
+	cmdline_prepare(command_line, BUILTIN_CMDLINE, boot_command_line);
 	*cmdline_p = command_line;
 
 	/*
-- 
2.35.1


-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ