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