LCOV - code coverage report
Current view: top level - arch/x86/mm - setup_nx.c (source / functions) Hit Total Coverage
Test: landlock.info Lines: 9 20 45.0 %
Date: 2021-04-22 12:43:58 Functions: 2 3 66.7 %

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

Generated by: LCOV version 1.14