From nobody Thu Dec 18 21:12:10 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11B65C001B0 for ; Fri, 11 Aug 2023 21:37:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236958AbjHKVhp (ORCPT ); Fri, 11 Aug 2023 17:37:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235022AbjHKVhl (ORCPT ); Fri, 11 Aug 2023 17:37:41 -0400 Received: from icts-p-cavuit-1.kulnet.kuleuven.be (icts-p-cavuit-1.kulnet.kuleuven.be [IPv6:2a02:2c40:0:c0::25:132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA61F35A8 for ; Fri, 11 Aug 2023 14:37:23 -0700 (PDT) X-KULeuven-Envelope-From: jo.vanbulck@cs.kuleuven.be X-KULeuven-Scanned: Found to be clean X-KULeuven-ID: 4D89B2005B.AA26C X-KULeuven-Information: Katholieke Universiteit Leuven Received: from icts-p-ceifnet-smtps-1.kuleuven.be (icts-p-ceifnet-smtps.service.icts.svcd [IPv6:2a02:2c40:0:51:145:242:ac11:22]) by icts-p-cavuit-1.kulnet.kuleuven.be (Postfix) with ESMTP id 4D89B2005B; Fri, 11 Aug 2023 23:37:17 +0200 (CEST) BCmilterd-Mark-Subject: no BCmilterd-Errors: BCmilterd-Report: SA-HVU#DKIM_VALID_AU#0.00,SA-HVU#DKIM_VALID#0.00,SA-HVU#DKIM_SIGNED#0.00 X-CAV-Cluster: smtps DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cs.kuleuven.be; s=cav; t=1691789837; bh=fDJVNiHd9cRQYrbLpCEaIkTJKdNAE/jtSZPTUnIDrRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OCjil2cCHSKMct2sp4K72i8qo0LhZiKS0qcUfJLwtg3po0xff9/efeZ8jrBEYm0xu PMeo+lbXqAjQVBwxSVxuh8xy9goShCrJTkzu1Q2u1tP0Pl0ol88d7oHWbper3Qq6DA mtEEdpoPx71bfPxyAybB7cbAjBqfAhGqwvSIcnHw= Received: from localhost.localdomain (unknown [68.170.73.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by icts-p-ceifnet-smtps-1.kuleuven.be (Postfix) with ESMTPSA id 31853D4E699CC; Fri, 11 Aug 2023 23:37:15 +0200 (CEST) X-Kuleuven: This mail passed the K.U.Leuven mailcluster From: Jo Van Bulck To: linux-kernel@vger.kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, mingo@redhat.com, sohil.mehta@intel.com Cc: x86@kernel.org, bp@alien8.de, tglx@linutronix.de, hpa@zytor.com, Jo Van Bulck Subject: [PATCH 1/1] x86/pti: Fix kernel warnings for pti= and nopti cmdline options. Date: Fri, 11 Aug 2023 14:36:28 -0700 Message-Id: <20230811213628.40428-2-jo.vanbulck@cs.kuleuven.be> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230811213628.40428-1-jo.vanbulck@cs.kuleuven.be> References: <20230811213628.40428-1-jo.vanbulck@cs.kuleuven.be> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Parse the pti=3D 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=3D are passed to the kernel cmdline on x86 platforms. Additionally allow the kernel to warn for malformed pti=3D options. Signed-off-by: Jo Van Bulck --- arch/x86/mm/pti.c | 59 +++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index 78414c6d1..da42e75dc 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -69,47 +69,34 @@ static void __init pti_print_if_secure(const char *reas= on) pr_info("%s\n", reason); } =20 +/* + * Assume mode is auto unless overridden via cmdline below, where pti=3D t= akes + * priority over nopti and mitigations=3Doff. + */ static enum pti_mode { PTI_AUTO =3D 0, + PTI_FORCE_AUTO, PTI_FORCE_OFF, PTI_FORCE_ON } pti_mode; =20 void __init pti_check_boottime_disable(void) { - char arg[5]; - int ret; - - /* Assume mode is auto unless overridden. */ - pti_mode =3D PTI_AUTO; - if (hypervisor_is_type(X86_HYPER_XEN_PV)) { pti_mode =3D PTI_FORCE_OFF; pti_print_if_insecure("disabled on XEN PV."); return; } =20 - ret =3D cmdline_find_option(boot_command_line, "pti", arg, sizeof(arg)); - if (ret > 0) { - if (ret =3D=3D 3 && !strncmp(arg, "off", 3)) { - pti_mode =3D PTI_FORCE_OFF; - pti_print_if_insecure("disabled on command line."); - return; - } - if (ret =3D=3D 2 && !strncmp(arg, "on", 2)) { - pti_mode =3D PTI_FORCE_ON; - pti_print_if_secure("force enabled on command line."); - goto enable; - } - if (ret =3D=3D 4 && !strncmp(arg, "auto", 4)) { - pti_mode =3D PTI_AUTO; - goto autosel; - } + if (pti_mode =3D=3D PTI_FORCE_ON) { + pti_print_if_secure("force enabled on command line."); + goto enable; } - - if (cmdline_find_option_bool(boot_command_line, "nopti") || - cpu_mitigations_off()) { + if (pti_mode =3D=3D PTI_FORCE_AUTO) + goto autosel; + if (cpu_mitigations_off()) pti_mode =3D PTI_FORCE_OFF; + if (pti_mode =3D=3D PTI_FORCE_OFF) { pti_print_if_insecure("disabled on command line."); return; } @@ -121,6 +108,28 @@ void __init pti_check_boottime_disable(void) setup_force_cpu_cap(X86_FEATURE_PTI); } =20 +static int __init pti_parse_cmdline(char *arg) +{ + if (!strcmp(arg, "off")) + pti_mode =3D PTI_FORCE_OFF; + else if (!strcmp(arg, "on")) + pti_mode =3D PTI_FORCE_ON; + else if (!strcmp(arg, "auto")) + pti_mode =3D PTI_FORCE_AUTO; + else + return -EINVAL; + return 0; +} +early_param("pti", pti_parse_cmdline); + +static int __init pti_parse_cmdline_nopti(char *arg) +{ + if (cmdline_find_option(boot_command_line, "pti", NULL, 0) =3D=3D -1) + pti_mode =3D PTI_FORCE_OFF; + return 0; +} +early_param("nopti", pti_parse_cmdline_nopti); + pgd_t __pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd) { /* --=20 2.25.1