setup_nx.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <linux/spinlock.h>
  2. #include <linux/errno.h>
  3. #include <linux/init.h>
  4. #include <asm/pgtable.h>
  5. #include <asm/proto.h>
  6. static int disable_nx __cpuinitdata;
  7. /*
  8. * noexec = on|off
  9. *
  10. * Control non-executable mappings for processes.
  11. *
  12. * on Enable
  13. * off Disable
  14. */
  15. static int __init noexec_setup(char *str)
  16. {
  17. if (!str)
  18. return -EINVAL;
  19. if (!strncmp(str, "on", 2)) {
  20. disable_nx = 0;
  21. } else if (!strncmp(str, "off", 3)) {
  22. disable_nx = 1;
  23. }
  24. x86_configure_nx();
  25. return 0;
  26. }
  27. early_param("noexec", noexec_setup);
  28. void __cpuinit x86_configure_nx(void)
  29. {
  30. if (cpu_has_nx && !disable_nx)
  31. __supported_pte_mask |= _PAGE_NX;
  32. else
  33. __supported_pte_mask &= ~_PAGE_NX;
  34. }
  35. void __init x86_report_nx(void)
  36. {
  37. if (!cpu_has_nx) {
  38. printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
  39. "missing in CPU!\n");
  40. } else {
  41. #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
  42. if (disable_nx) {
  43. printk(KERN_INFO "NX (Execute Disable) protection: "
  44. "disabled by kernel command line option\n");
  45. } else {
  46. printk(KERN_INFO "NX (Execute Disable) protection: "
  47. "active\n");
  48. }
  49. #else
  50. /* 32bit non-PAE kernel, NX cannot be used */
  51. printk(KERN_NOTICE "Notice: NX (Execute Disable) protection "
  52. "cannot be enabled: non-PAE kernel!\n");
  53. #endif
  54. }
  55. }