setup_nx.c 1.4 KB

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