hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/arch/arm/kernel/elf.c
....@@ -78,13 +78,32 @@
7878 EXPORT_SYMBOL(elf_set_personality);
7979
8080 /*
81
- * Set READ_IMPLIES_EXEC if:
82
- * - the binary requires an executable stack
83
- * - we're running on a CPU which doesn't support NX.
81
+ * An executable for which elf_read_implies_exec() returns TRUE will
82
+ * have the READ_IMPLIES_EXEC personality flag set automatically.
83
+ *
84
+ * The decision process for determining the results are:
85
+ *
86
+ *              CPU: | lacks NX*  | has NX |
87
+ * ELF:              |            |           |
88
+ * ---------------------|------------|------------|
89
+ * missing PT_GNU_STACK | exec-all   | exec-all  |
90
+ * PT_GNU_STACK == RWX  | exec-all   | exec-stack |
91
+ * PT_GNU_STACK == RW   | exec-all  | exec-none |
92
+ *
93
+ * exec-all : all PROT_READ user mappings are executable, except when
94
+ * backed by files on a noexec-filesystem.
95
+ * exec-none : only PROT_EXEC user mappings are executable.
96
+ * exec-stack: only the stack and PROT_EXEC user mappings are executable.
97
+ *
98
+ * *this column has no architectural effect: NX markings are ignored by
99
+ * hardware, but may have behavioral effects when "wants X" collides with
100
+ * "cannot be X" constraints in memory permission flags, as in
101
+ * https://lkml.kernel.org/r/20190418055759.GA3155@mellanox.com
102
+ *
84103 */
85104 int arm_elf_read_implies_exec(int executable_stack)
86105 {
87
- if (executable_stack != EXSTACK_DISABLE_X)
106
+ if (executable_stack == EXSTACK_DEFAULT)
88107 return 1;
89108 if (cpu_architecture() < CPU_ARCH_ARMv6)
90109 return 1;