Skip to content

Commit 0bd7feb

Browse files
jovanbulckbp3tk0v
authored andcommitted
x86/pti: Fix kernel warnings for pti= and nopti cmdline options
Parse the pti= and nopti cmdline options using early_param to fix 'Unknown kernel command line parameters "nopti", will be passed to user space' warnings in the kernel log when nopti or pti= are passed to the kernel cmdline on x86 platforms. Additionally allow the kernel to warn for malformed pti= options. Signed-off-by: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be> Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Reviewed-by: Sohil Mehta <sohil.mehta@intel.com> Link: https://lore.kernel.org/r/20230819080921.5324-2-jo.vanbulck@cs.kuleuven.be
1 parent 99ee56c commit 0bd7feb

1 file changed

Lines changed: 29 additions & 29 deletions

File tree

arch/x86/mm/pti.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static void __init pti_print_if_secure(const char *reason)
6969
pr_info("%s\n", reason);
7070
}
7171

72+
/* Assume mode is auto unless overridden via cmdline below. */
7273
static enum pti_mode {
7374
PTI_AUTO = 0,
7475
PTI_FORCE_OFF,
@@ -77,50 +78,49 @@ static enum pti_mode {
7778

7879
void __init pti_check_boottime_disable(void)
7980
{
80-
char arg[5];
81-
int ret;
82-
83-
/* Assume mode is auto unless overridden. */
84-
pti_mode = PTI_AUTO;
85-
8681
if (hypervisor_is_type(X86_HYPER_XEN_PV)) {
8782
pti_mode = PTI_FORCE_OFF;
8883
pti_print_if_insecure("disabled on XEN PV.");
8984
return;
9085
}
9186

92-
ret = cmdline_find_option(boot_command_line, "pti", arg, sizeof(arg));
93-
if (ret > 0) {
94-
if (ret == 3 && !strncmp(arg, "off", 3)) {
95-
pti_mode = PTI_FORCE_OFF;
96-
pti_print_if_insecure("disabled on command line.");
97-
return;
98-
}
99-
if (ret == 2 && !strncmp(arg, "on", 2)) {
100-
pti_mode = PTI_FORCE_ON;
101-
pti_print_if_secure("force enabled on command line.");
102-
goto enable;
103-
}
104-
if (ret == 4 && !strncmp(arg, "auto", 4)) {
105-
pti_mode = PTI_AUTO;
106-
goto autosel;
107-
}
108-
}
109-
110-
if (cmdline_find_option_bool(boot_command_line, "nopti") ||
111-
cpu_mitigations_off()) {
87+
if (cpu_mitigations_off())
11288
pti_mode = PTI_FORCE_OFF;
89+
if (pti_mode == PTI_FORCE_OFF) {
11390
pti_print_if_insecure("disabled on command line.");
11491
return;
11592
}
11693

117-
autosel:
118-
if (!boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN))
94+
if (pti_mode == PTI_FORCE_ON)
95+
pti_print_if_secure("force enabled on command line.");
96+
97+
if (pti_mode == PTI_AUTO && !boot_cpu_has_bug(X86_BUG_CPU_MELTDOWN))
11998
return;
120-
enable:
99+
121100
setup_force_cpu_cap(X86_FEATURE_PTI);
122101
}
123102

103+
static int __init pti_parse_cmdline(char *arg)
104+
{
105+
if (!strcmp(arg, "off"))
106+
pti_mode = PTI_FORCE_OFF;
107+
else if (!strcmp(arg, "on"))
108+
pti_mode = PTI_FORCE_ON;
109+
else if (!strcmp(arg, "auto"))
110+
pti_mode = PTI_AUTO;
111+
else
112+
return -EINVAL;
113+
return 0;
114+
}
115+
early_param("pti", pti_parse_cmdline);
116+
117+
static int __init pti_parse_cmdline_nopti(char *arg)
118+
{
119+
pti_mode = PTI_FORCE_OFF;
120+
return 0;
121+
}
122+
early_param("nopti", pti_parse_cmdline_nopti);
123+
124124
pgd_t __pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd)
125125
{
126126
/*

0 commit comments

Comments
 (0)