blob: a3250aa34086fce7d376e9e1e464fa2e996dbb6d [file] [log] [blame]
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -07001#include <linux/spinlock.h>
2#include <linux/errno.h>
3#include <linux/init.h>
4
5#include <asm/pgtable.h>
H. Peter Anvin4763ed42009-11-13 15:28:16 -08006#include <asm/proto.h>
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -07007
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -07008static int disable_nx __cpuinitdata;
9
10/*
11 * noexec = on|off
12 *
13 * Control non-executable mappings for processes.
14 *
15 * on Enable
16 * off Disable
17 */
18static int __init noexec_setup(char *str)
19{
20 if (!str)
21 return -EINVAL;
22 if (!strncmp(str, "on", 2)) {
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070023 disable_nx = 0;
24 } else if (!strncmp(str, "off", 3)) {
25 disable_nx = 1;
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070026 }
H. Peter Anvin4763ed42009-11-13 15:28:16 -080027 x86_configure_nx();
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070028 return 0;
29}
30early_param("noexec", noexec_setup);
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070031
H. Peter Anvin4763ed42009-11-13 15:28:16 -080032void __cpuinit x86_configure_nx(void)
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070033{
H. Peter Anvin4763ed42009-11-13 15:28:16 -080034 if (cpu_has_nx && !disable_nx)
35 __supported_pte_mask |= _PAGE_NX;
36 else
Jeremy Fitzhardingec44c9ec2009-09-21 13:40:42 -070037 __supported_pte_mask &= ~_PAGE_NX;
38}
Kees Cook4b0f3b82009-11-13 15:28:17 -080039
40void __init x86_report_nx(void)
41{
42 if (!cpu_has_nx) {
43 printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
44 "missing in CPU or disabled in BIOS!\n");
45 } else {
46#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
47 if (disable_nx) {
48 printk(KERN_INFO "NX (Execute Disable) protection: "
49 "disabled by kernel command line option\n");
50 } else {
51 printk(KERN_INFO "NX (Execute Disable) protection: "
52 "active\n");
53 }
54#else
55 /* 32bit non-PAE kernel, NX cannot be used */
56 printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
57 "cannot be enabled: non-PAE kernel!\n");
58#endif
59 }
60}