Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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