summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiodrag Dinic <miodrag.dinic@mips.com>2018-01-09 12:57:16 +0100
committerAmit Pundir <amit.pundir@linaro.org>2018-03-05 21:56:13 +0530
commitb90d0d1e68c075cf2e3c58cfc7c4020e22422716 (patch)
tree5666f243c40f807a4078d29e6a6e216a31abd6ec
parent71dfa5d9118bbd5f0999c5d2b3533b6329476a9b (diff)
FROMLIST: MIPS: Add noexec=on|off kernel parameter
Add a new kernel parameter to override the default behavior related to the decision whether to indicate stack as non-executable or executable (regardless of PT_GNU_STACK entry or CPU RIXI support) in function mips_elf_read_implies_exec(). Allowed values: noexec=on: force indicating non-exec stack & heap noexec=off: force indicating executable stack & heap If this parameter is omitted, kernel behavior remains the same as it was before this patch is applied. This functionality is convenient during debugging and is especially useful for Android development where indication of non-executable stack is required. NOTE: Using noexec=on on a system without CPU XI support is not recommended since there is no actual HW support that provide non-executable stack and heap. Use only for debugging purposes and not in a production environment. Signed-off-by: Miodrag Dinic <miodrag.dinic@mips.com> Signed-off-by: Aleksandar Markovic <aleksandar.markovic@mips.com> (cherry picked from: https://patchwork.linux-mips.org/patch/18218/) Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
-rw-r--r--Documentation/kernel-parameters.txt19
-rw-r--r--arch/mips/kernel/elf.c48
2 files changed, 67 insertions, 0 deletions
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 7691d63dbda1..a5958499e5c9 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -2470,6 +2470,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
noexec=on: enable non-executable mappings (default)
noexec=off: disable non-executable mappings
+ noexec [MIPS]
+ Force indicating stack and heap as non-executable or
+ executable regardless of PT_GNU_STACK entry or CPU XI
+ (execute inhibit) support. Valid valuess are: on, off.
+ noexec=on: force indicating non-executable
+ stack and heap
+ noexec=off: force indicating executable
+ stack and heap
+ If this parameter is omitted, stack and heap will be
+ indicated non-executable or executable as they are
+ actually set up, which depends on PT_GNU_STACK entry
+ and possibly other factors (for instance, CPU XI
+ support).
+ NOTE: Using noexec=on on a system without CPU XI
+ support is not recommended since there is no actual
+ HW support that provide non-executable stack/heap.
+ Use only for debugging purposes and not in a
+ production environment.
+
nosmap [X86]
Disable SMAP (Supervisor Mode Access Prevention)
even if it is supported by processor.
diff --git a/arch/mips/kernel/elf.c b/arch/mips/kernel/elf.c
index 2aaa0825e56d..624e15dbd405 100644
--- a/arch/mips/kernel/elf.c
+++ b/arch/mips/kernel/elf.c
@@ -330,8 +330,56 @@ void mips_set_personality_nan(struct arch_elf_state *state)
}
}
+static int noexec = EXSTACK_DEFAULT;
+
+/*
+ * kernel parameter: noexec=on|off
+ *
+ * Force indicating stack and heap as non-executable or
+ * executable regardless of PT_GNU_STACK entry or CPU XI
+ * (execute inhibit) support. Valid valuess are: on, off.
+ *
+ * noexec=on: force indicating non-executable
+ * stack and heap
+ * noexec=off: force indicating executable
+ * stack and heap
+ *
+ * If this parameter is omitted, stack and heap will be
+ * indicated non-executable or executable as they are
+ * actually set up, which depends on PT_GNU_STACK entry
+ * and possibly other factors (for instance, CPU XI
+ * support).
+ *
+ * NOTE: Using noexec=on on a system without CPU XI
+ * support is not recommended since there is no actual
+ * HW support that provide non-executable stack/heap.
+ * Use only for debugging purposes and not in a
+ * production environment.
+ */
+static int __init noexec_setup(char *str)
+{
+ if (!strcmp(str, "on"))
+ noexec = EXSTACK_DISABLE_X;
+ else if (!strcmp(str, "off"))
+ noexec = EXSTACK_ENABLE_X;
+ else
+ pr_err("Malformed noexec format! noexec=on|off\n");
+
+ return 1;
+}
+__setup("noexec=", noexec_setup);
+
int mips_elf_read_implies_exec(void *elf_ex, int exstack)
{
+ switch (noexec) {
+ case EXSTACK_DISABLE_X:
+ return 0;
+ case EXSTACK_ENABLE_X:
+ return 1;
+ default:
+ break;
+ }
+
if (exstack != EXSTACK_DISABLE_X) {
/* The binary doesn't request a non-executable stack */
return 1;