All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/mm: Use strtobool for noexec parsing
@ 2022-02-27 20:13 Dr. David Alan Gilbert
  2022-03-02 12:14 ` Borislav Petkov
  0 siblings, 1 reply; 3+ messages in thread
From: Dr. David Alan Gilbert @ 2022-02-27 20:13 UTC (permalink / raw)
  To: dave.hansen, luto, peterz, jeremy.fitzhardinge
  Cc: x86, linux-kernel, Dr. David Alan Gilbert

Use strtobool to parse the 'noexec' parameter rather than open coding
it.
'disable_nx' is changed to a bool and flipped to 'enable_nx'
so it's meaning follows the command line option.

There's no change in behaviour for noexec=on/off.
noexec=junk will now warn
strtobool allows 0/1 and y/n (etc) as well as the on/off.

Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org>
---
 arch/x86/mm/setup_nx.c | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)

diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
index ed5667f5169ff..77450b5889a0d 100644
--- a/arch/x86/mm/setup_nx.c
+++ b/arch/x86/mm/setup_nx.c
@@ -7,7 +7,7 @@
 #include <asm/proto.h>
 #include <asm/cpufeature.h>
 
-static int disable_nx;
+static bool enable_nx = true;
 
 /*
  * noexec = on|off
@@ -19,21 +19,15 @@ static int disable_nx;
  */
 static int __init noexec_setup(char *str)
 {
-	if (!str)
-		return -EINVAL;
-	if (!strncmp(str, "on", 2)) {
-		disable_nx = 0;
-	} else if (!strncmp(str, "off", 3)) {
-		disable_nx = 1;
-	}
+	int ret = strtobool(str, &enable_nx);
 	x86_configure_nx();
-	return 0;
+	return ret;
 }
 early_param("noexec", noexec_setup);
 
 void x86_configure_nx(void)
 {
-	if (boot_cpu_has(X86_FEATURE_NX) && !disable_nx)
+	if (boot_cpu_has(X86_FEATURE_NX) && enable_nx)
 		__supported_pte_mask |= _PAGE_NX;
 	else
 		__supported_pte_mask &= ~_PAGE_NX;
@@ -46,7 +40,7 @@ void __init x86_report_nx(void)
 		       "missing in CPU!\n");
 	} else {
 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
-		if (disable_nx) {
+		if (!enable_nx) {
 			printk(KERN_INFO "NX (Execute Disable) protection: "
 			       "disabled by kernel command line option\n");
 		} else {
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/mm: Use strtobool for noexec parsing
  2022-02-27 20:13 [PATCH] x86/mm: Use strtobool for noexec parsing Dr. David Alan Gilbert
@ 2022-03-02 12:14 ` Borislav Petkov
  2022-03-02 14:19   ` Dr. David Alan Gilbert
  0 siblings, 1 reply; 3+ messages in thread
From: Borislav Petkov @ 2022-03-02 12:14 UTC (permalink / raw)
  To: Dr. David Alan Gilbert
  Cc: dave.hansen, luto, peterz, jeremy.fitzhardinge, x86, linux-kernel

On Sun, Feb 27, 2022 at 08:13:56PM +0000, Dr. David Alan Gilbert wrote:
> Use strtobool to parse the 'noexec' parameter rather than open coding
> it.
> 'disable_nx' is changed to a bool and flipped to 'enable_nx'
> so it's meaning follows the command line option.
> 
> There's no change in behaviour for noexec=on/off.
> noexec=junk will now warn
> strtobool allows 0/1 and y/n (etc) as well as the on/off.
> 
> Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org>
> ---
>  arch/x86/mm/setup_nx.c | 16 +++++-----------
>  1 file changed, 5 insertions(+), 11 deletions(-)

https://lkml.kernel.org/r/20220127115626.14179-6-bp@alien8.de

-- 
Regards/Gruss,
    Boris.

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/mm: Use strtobool for noexec parsing
  2022-03-02 12:14 ` Borislav Petkov
@ 2022-03-02 14:19   ` Dr. David Alan Gilbert
  0 siblings, 0 replies; 3+ messages in thread
From: Dr. David Alan Gilbert @ 2022-03-02 14:19 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: dave.hansen, luto, peterz, jeremy.fitzhardinge, x86, linux-kernel

* Borislav Petkov (bp@alien8.de) wrote:
> On Sun, Feb 27, 2022 at 08:13:56PM +0000, Dr. David Alan Gilbert wrote:
> > Use strtobool to parse the 'noexec' parameter rather than open coding
> > it.
> > 'disable_nx' is changed to a bool and flipped to 'enable_nx'
> > so it's meaning follows the command line option.
> > 
> > There's no change in behaviour for noexec=on/off.
> > noexec=junk will now warn
> > strtobool allows 0/1 and y/n (etc) as well as the on/off.
> > 
> > Signed-off-by: Dr. David Alan Gilbert <linux@treblig.org>
> > ---
> >  arch/x86/mm/setup_nx.c | 16 +++++-----------
> >  1 file changed, 5 insertions(+), 11 deletions(-)
> 
> https://lkml.kernel.org/r/20220127115626.14179-6-bp@alien8.de

Oh well; good.

Thanks for the pointer.

Dave

> -- 
> Regards/Gruss,
>     Boris.
> 
> https://people.kernel.org/tglx/notes-about-netiquette
-- 
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-02 14:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-27 20:13 [PATCH] x86/mm: Use strtobool for noexec parsing Dr. David Alan Gilbert
2022-03-02 12:14 ` Borislav Petkov
2022-03-02 14:19   ` Dr. David Alan Gilbert

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.