[PATCH] setarch: add support for '-R' (disable randomization)

Thomas De Schampheleire patrickdepinguin at gmail.com
Mon Oct 19 14:55:36 UTC 2015


From: Jan Heylen <heyleke at gmail.com>

This commit adds support for the -R flag of setarch, which disables
randomization of the virtual address space.

Signed-off-by: Jan Heylen <heyleke at gmail.com>
Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>
---
 util-linux/setarch.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/util-linux/setarch.c b/util-linux/setarch.c
index 7b9421a..5cbfdcd 100644
--- a/util-linux/setarch.c
+++ b/util-linux/setarch.c
@@ -8,11 +8,12 @@
  */
 
 //usage:#define setarch_trivial_usage
-//usage:       "personality PROG ARGS"
+//usage:       "personality [-R] PROG ARGS"
 //usage:#define setarch_full_usage "\n\n"
 //usage:       "Personality may be:\n"
 //usage:       "	linux32		Set 32bit uname emulation\n"
-//usage:       "	linux64		Set 64bit uname emulation"
+//usage:       "	linux64		Set 64bit uname emulation\n"
+//usage:       "\n	-R	Disables randomization of the virtual address space"
 //usage:
 //usage:#define linux32_trivial_usage NOUSAGE_STR
 //usage:#define linux32_full_usage ""
@@ -20,14 +21,20 @@
 //usage:#define linux64_trivial_usage NOUSAGE_STR
 //usage:#define linux64_full_usage ""
 
+#include <unistd.h>
 #include <sys/personality.h>
 
 #include "libbb.h"
 
+#ifndef ADDR_NO_RANDOMIZE
+# define ADDR_NO_RANDOMIZE       0x0040000
+#endif
+
 int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int setarch_main(int argc UNUSED_PARAM, char **argv)
 {
-	int pers;
+	unsigned long pers;
+	unsigned long options = 0;
 
 	/* Figure out what personality we are supposed to switch to ...
 	 * we can be invoked as either:
@@ -40,6 +47,7 @@ int setarch_main(int argc UNUSED_PARAM, char **argv)
 		applet_name = argv[1];
 		argv++;
 	}
+
 	if (applet_name[5] == '6') /* linux64 */
 		pers = PER_LINUX;
 	else if (applet_name[5] == '3') /* linux32 */
@@ -48,9 +56,16 @@ int setarch_main(int argc UNUSED_PARAM, char **argv)
 		bb_show_usage();
 
 	argv++;
+	if(argv[0] && argv[0][0]=='-' && argv[0][1]=='R'){
+		options |= ADDR_NO_RANDOMIZE;
+		argv++;
+	}
+
 	if (argv[0] == NULL)
 		bb_show_usage();
 
+	pers |= options;
+
 	/* Try to set personality */
 	if (personality(pers) >= 0) {
 		/* Try to execute the program */
-- 
1.9.5



More information about the busybox mailing list