aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorPaul Burton <paul.burton@imgtec.com>2016-07-08 06:06:20 -0400
committerRalf Baechle <ralf@linux-mips.org>2016-08-02 03:29:27 -0400
commit1a770b85c1f1c1ee37afd7cef5237ffc4c970f04 (patch)
tree65522a64b03bf0389014b2f4bcc9918f5fdaba9d /arch
parent432c6bacbd0c16ec210c43da411ccc3855c4c010 (diff)
MIPS: non-exec stack & heap when non-exec PT_GNU_STACK is present
The stack and heap have both been executable by default on MIPS until now. This patch changes the default to be non-executable, but only for ELF binaries with a non-executable PT_GNU_STACK header present. This does apply to both the heap & the stack, despite the name PT_GNU_STACK, and this matches the behaviour of other architectures like ARM & x86. Current MIPS toolchains do not produce the PT_GNU_STACK header, which means that we can rely upon this patch not changing the behaviour of existing binaries. The new default will only take effect for newly compiled binaries once toolchains are updated to support PT_GNU_STACK, and since those binaries are newly compiled they can be compiled expecting the change in default behaviour. Again this matches the way in which the ARM & x86 architectures handled their implementations of non-executable memory. Signed-off-by: Paul Burton <paul.burton@imgtec.com> Cc: Leonid Yegoshin <leonid.yegoshin@imgtec.com> Cc: Maciej Rozycki <maciej.rozycki@imgtec.com> Cc: Faraz Shahbazker <faraz.shahbazker@imgtec.com> Cc: Raghu Gandham <raghu.gandham@imgtec.com> Cc: Matthew Fortune <matthew.fortune@imgtec.com> Cc: linux-mips@linux-mips.org Patchwork: https://patchwork.linux-mips.org/patch/13765/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/mips/include/asm/elf.h3
-rw-r--r--arch/mips/include/asm/page.h6
-rw-r--r--arch/mips/kernel/elf.c19
3 files changed, 26 insertions, 2 deletions
diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
index ede8c4ff56f7..2b3dc2973670 100644
--- a/arch/mips/include/asm/elf.h
+++ b/arch/mips/include/asm/elf.h
@@ -499,4 +499,7 @@ extern int arch_check_elf(void *ehdr, bool has_interpreter, void *interp_ehdr,
499extern void mips_set_personality_nan(struct arch_elf_state *state); 499extern void mips_set_personality_nan(struct arch_elf_state *state);
500extern void mips_set_personality_fp(struct arch_elf_state *state); 500extern void mips_set_personality_fp(struct arch_elf_state *state);
501 501
502#define elf_read_implies_exec(ex, stk) mips_elf_read_implies_exec(&(ex), stk)
503extern int mips_elf_read_implies_exec(void *elf_ex, int exstack);
504
502#endif /* _ASM_ELF_H */ 505#endif /* _ASM_ELF_H */
diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
index 21ed7150fec3..74cb004c2868 100644
--- a/arch/mips/include/asm/page.h
+++ b/arch/mips/include/asm/page.h
@@ -229,8 +229,10 @@ extern int __virt_addr_valid(const volatile void *kaddr);
229#define virt_addr_valid(kaddr) \ 229#define virt_addr_valid(kaddr) \
230 __virt_addr_valid((const volatile void *) (kaddr)) 230 __virt_addr_valid((const volatile void *) (kaddr))
231 231
232#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \ 232#define VM_DATA_DEFAULT_FLAGS \
233 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) 233 (VM_READ | VM_WRITE | \
234 ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
235 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
234 236
235#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE) 237#define UNCAC_ADDR(addr) ((addr) - PAGE_OFFSET + UNCAC_BASE)
236#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET) 238#define CAC_ADDR(addr) ((addr) - UNCAC_BASE + PAGE_OFFSET)
diff --git a/arch/mips/kernel/elf.c b/arch/mips/kernel/elf.c
index 891f5ee63983..824b0373ba71 100644
--- a/arch/mips/kernel/elf.c
+++ b/arch/mips/kernel/elf.c
@@ -8,9 +8,12 @@
8 * option) any later version. 8 * option) any later version.
9 */ 9 */
10 10
11#include <linux/binfmts.h>
11#include <linux/elf.h> 12#include <linux/elf.h>
13#include <linux/export.h>
12#include <linux/sched.h> 14#include <linux/sched.h>
13 15
16#include <asm/cpu-features.h>
14#include <asm/cpu-info.h> 17#include <asm/cpu-info.h>
15 18
16/* Whether to accept legacy-NaN and 2008-NaN user binaries. */ 19/* Whether to accept legacy-NaN and 2008-NaN user binaries. */
@@ -326,3 +329,19 @@ void mips_set_personality_nan(struct arch_elf_state *state)
326 BUG(); 329 BUG();
327 } 330 }
328} 331}
332
333int mips_elf_read_implies_exec(void *elf_ex, int exstack)
334{
335 if (exstack != EXSTACK_DISABLE_X) {
336 /* The binary doesn't request a non-executable stack */
337 return 1;
338 }
339
340 if (!cpu_has_rixi) {
341 /* The CPU doesn't support non-executable memory */
342 return 1;
343 }
344
345 return 0;
346}
347EXPORT_SYMBOL(mips_elf_read_implies_exec);