Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH v2] MIPS: Add nonxstack=on|off kernel parameter
@ 2017-11-21 13:56 Aleksandar Markovic
  2017-11-21 16:50 ` Randy Dunlap
  2017-11-21 20:53 ` David Daney
  0 siblings, 2 replies; 14+ messages in thread
From: Aleksandar Markovic @ 2017-11-21 13:56 UTC (permalink / raw)
  To: linux-mips
  Cc: Miodrag Dinic, Aleksandar Markovic, Andrew Morton, Dengcheng Zhu,
	Ding Tianhong, Douglas Leung, Frederic Weisbecker, Goran Ferenc,
	Ingo Molnar, James Cowgill, James Hogan, Jonathan Corbet,
	linux-doc, linux-kernel, Marc Zyngier, Matt Redfearn, Mimi Zohar,
	Paul Burton, Paul E. McKenney, Petar Jovanovic, Raghu Gandham,
	Ralf Baechle, Thomas Gleixner, Tom Saeger

From: Miodrag Dinic <miodrag.dinic@mips.com>

Add a new kernel parameter to override the default behavior related
to the decision whether to set up stack as non-executable in function
mips_elf_read_implies_exec().

The new parameter is used to control non executable stack and heap,
regardless of PT_GNU_STACK entry. This does apply to both stack and
heap, despite the name.

Allowed values:

nonxstack=on	Force non-exec stack & heap
nonxstack=off	Force 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 non-exec stack is required.

Signed-off-by: Miodrag Dinic <miodrag.dinic@mips.com>
Signed-off-by: Aleksandar Markovic <aleksandar.markovic@mips.com>
---
 Documentation/admin-guide/kernel-parameters.txt | 11 +++++++
 arch/mips/kernel/elf.c                          | 39 +++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index b74e133..99464ee 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -2614,6 +2614,17 @@
 			noexec32=off: disable non-executable mappings
 				read implies executable mappings
 
+	nonxstack	[MIPS]
+			Force setting up stack and heap as non-executable or
+			executable regardless of PT_GNU_STACK entry. Both
+			stack and heap are affected, despite the name. Valid
+			arguments: on, off.
+			nonxstack=on:	Force non-executable stack and heap
+			nonxstack=off:	Force executable stack and heap
+			If ommited, stack and heap will or will not be set
+			up as non-executable depending on PT_GNU_STACK
+			entry and possibly other factors.
+
 	nofpu		[MIPS,SH] Disable hardware FPU at boot time.
 
 	nofxsr		[BUGS=X86-32] Disables x86 floating point extended
diff --git a/arch/mips/kernel/elf.c b/arch/mips/kernel/elf.c
index 731325a..28ef7f3 100644
--- a/arch/mips/kernel/elf.c
+++ b/arch/mips/kernel/elf.c
@@ -326,8 +326,47 @@ void mips_set_personality_nan(struct arch_elf_state *state)
 	}
 }
 
+static int nonxstack = EXSTACK_DEFAULT;
+
+/*
+ * kernel parameter: nonxstack=on|off
+ *
+ *   Force setting up stack and heap as non-executable or
+ *   executable regardless of PT_GNU_STACK entry. Both
+ *   stack and heap are affected, despite the name. Valid
+ *   arguments: on, off.
+ *
+ *     nonxstack=on:   Force non-executable stack and heap
+ *     nonxstack=off:  Force executable stack and heap
+ *
+ *   If ommited, stack and heap will or will not be set
+ *   up as non-executable depending on PT_GNU_STACK
+ *   entry and possibly other factors.
+ */
+static int __init nonxstack_setup(char *str)
+{
+	if (!strcmp(str, "on"))
+		nonxstack = EXSTACK_DISABLE_X;
+	else if (!strcmp(str, "off"))
+		nonxstack = EXSTACK_ENABLE_X;
+	else
+		pr_err("Malformed nonxstack format! nonxstack=on|off\n");
+
+	return 1;
+}
+__setup("nonxstack=", nonxstack_setup);
+
 int mips_elf_read_implies_exec(void *elf_ex, int exstack)
 {
+	switch (nonxstack) {
+	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;
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-02-13 16:14 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-21 13:56 [PATCH v2] MIPS: Add nonxstack=on|off kernel parameter Aleksandar Markovic
2017-11-21 16:50 ` Randy Dunlap
2017-11-21 20:53 ` David Daney
2017-11-30  9:34   ` Miodrag Dinic
2017-11-30 10:09     ` James Hogan
2017-11-30 13:06       ` Miodrag Dinic
2017-12-01 11:35         ` Miodrag Dinic
2017-12-01 17:38         ` David Daney
2017-12-06 17:50         ` Maciej W. Rozycki
2017-12-06 18:24           ` Paul Burton
2017-12-07 11:33             ` Miodrag Dinic
2018-01-02 18:35               ` Maciej W. Rozycki
2018-02-08 11:55               ` James Hogan
2018-02-13 16:06                 ` Aleksandar Markovic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox