blob: adb3c5784dac92294253162970647d9bc0d134d7 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -07002#include <linux/spinlock.h>
3#include <linux/errno.h>
4#include <linux/init.h>
5
6#include <asm/pgtable.h>
H. Peter Anvin4763ed42009-11-13 15:28:16 -08007#include <asm/proto.h>
Borislav Petkovcd4d09e2016-01-26 22:12:04 +01008#include <asm/cpufeature.h>
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -07009
Paul Gortmaker148f9bb2013-06-18 18:23:59 -040010static int disable_nx;
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070011
12/*
13 * noexec = on|off
14 *
15 * Control non-executable mappings for processes.
16 *
17 * on Enable
18 * off Disable
19 */
20static int __init noexec_setup(char *str)
21{
22 if (!str)
23 return -EINVAL;
24 if (!strncmp(str, "on", 2)) {
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070025 disable_nx = 0;
26 } else if (!strncmp(str, "off", 3)) {
27 disable_nx = 1;
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070028 }
H. Peter Anvin4763ed42009-11-13 15:28:16 -080029 x86_configure_nx();
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070030 return 0;
31}
32early_param("noexec", noexec_setup);
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070033
Paul Gortmaker148f9bb2013-06-18 18:23:59 -040034void x86_configure_nx(void)
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070035{
Andy Lutomirskie16d8a62016-04-26 08:52:44 -070036 if (boot_cpu_has(X86_FEATURE_NX) && !disable_nx)
37 __supported_pte_mask |= _PAGE_NX;
38 else
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070039 __supported_pte_mask &= ~_PAGE_NX;
40}
Kees Cook4b0f3b82009-11-13 15:28:17 -080041
42void __init x86_report_nx(void)
43{
Borislav Petkov362f9242015-12-07 10:39:41 +010044 if (!boot_cpu_has(X86_FEATURE_NX)) {
Kees Cook4b0f3b82009-11-13 15:28:17 -080045 printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
Kees Cook6036f372010-11-10 10:35:54 -080046 "missing in CPU!\n");
Kees Cook4b0f3b82009-11-13 15:28:17 -080047 } else {
48#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
49 if (disable_nx) {
50 printk(KERN_INFO "NX (Execute Disable) protection: "
51 "disabled by kernel command line option\n");
52 } else {
53 printk(KERN_INFO "NX (Execute Disable) protection: "
54 "active\n");
55 }
56#else
57 /* 32bit non-PAE kernel, NX cannot be used */
58 printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
59 "cannot be enabled: non-PAE kernel!\n");
60#endif
61 }
62}