diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-19 23:26:50 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-19 23:26:50 +0200 |
commit | f2ccefb946c5de69ce6a51c9a8e95024d44c273b (patch) | |
tree | 0ed6e80ea0b1825c35ec471f9afb2e532c901752 /util-linux/setarch.c | |
parent | 0506e292b518a04846ae1f611ecc0633969a2801 (diff) | |
download | busybox-w32-f2ccefb946c5de69ce6a51c9a8e95024d44c273b.tar.gz busybox-w32-f2ccefb946c5de69ce6a51c9a8e95024d44c273b.tar.bz2 busybox-w32-f2ccefb946c5de69ce6a51c9a8e95024d44c273b.zip |
setarch: add support for '-R' (disable randomization)
This commit adds support for the -R flag of setarch, which disables
randomization of the virtual address space.
function old new delta
setarch_main 115 150 +35
packed_usage 30664 30651 -13
Signed-off-by: Jan Heylen <heyleke@gmail.com>
Signed-off-by: Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/setarch.c')
-rw-r--r-- | util-linux/setarch.c | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/util-linux/setarch.c b/util-linux/setarch.c index 7b9421af1..2e989ec2a 100644 --- a/util-linux/setarch.c +++ b/util-linux/setarch.c | |||
@@ -6,13 +6,30 @@ | |||
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
8 | */ | 8 | */ |
9 | //config:config SETARCH | ||
10 | //config: bool "setarch" | ||
11 | //config: default y | ||
12 | //config: select PLATFORM_LINUX | ||
13 | //config: help | ||
14 | //config: The linux32 utility is used to create a 32bit environment for the | ||
15 | //config: specified program (usually a shell). It only makes sense to have | ||
16 | //config: this util on a system that supports both 64bit and 32bit userland | ||
17 | //config: (like amd64/x86, ppc64/ppc, sparc64/sparc, etc...). | ||
18 | |||
19 | //applet:IF_SETARCH(APPLET(setarch, BB_DIR_BIN, BB_SUID_DROP)) | ||
20 | //applet:IF_SETARCH(APPLET_ODDNAME(linux32, setarch, BB_DIR_BIN, BB_SUID_DROP, linux32)) | ||
21 | //applet:IF_SETARCH(APPLET_ODDNAME(linux64, setarch, BB_DIR_BIN, BB_SUID_DROP, linux64)) | ||
22 | |||
23 | //kbuild:lib-$(CONFIG_SETARCH) += setarch.o | ||
9 | 24 | ||
10 | //usage:#define setarch_trivial_usage | 25 | //usage:#define setarch_trivial_usage |
11 | //usage: "personality PROG ARGS" | 26 | //usage: "PERSONALITY [-R] PROG ARGS" |
12 | //usage:#define setarch_full_usage "\n\n" | 27 | //usage:#define setarch_full_usage "\n\n" |
13 | //usage: "Personality may be:\n" | 28 | //usage: "PERSONALITY may be:" |
14 | //usage: " linux32 Set 32bit uname emulation\n" | 29 | //usage: "\n"" linux32 Set 32bit uname emulation" |
15 | //usage: " linux64 Set 64bit uname emulation" | 30 | //usage: "\n"" linux64 Set 64bit uname emulation" |
31 | //usage: "\n" | ||
32 | //usage: "\n"" -R Disable address space randomization" | ||
16 | //usage: | 33 | //usage: |
17 | //usage:#define linux32_trivial_usage NOUSAGE_STR | 34 | //usage:#define linux32_trivial_usage NOUSAGE_STR |
18 | //usage:#define linux32_full_usage "" | 35 | //usage:#define linux32_full_usage "" |
@@ -20,14 +37,18 @@ | |||
20 | //usage:#define linux64_trivial_usage NOUSAGE_STR | 37 | //usage:#define linux64_trivial_usage NOUSAGE_STR |
21 | //usage:#define linux64_full_usage "" | 38 | //usage:#define linux64_full_usage "" |
22 | 39 | ||
40 | #include "libbb.h" | ||
23 | #include <sys/personality.h> | 41 | #include <sys/personality.h> |
24 | 42 | ||
25 | #include "libbb.h" | 43 | #ifndef ADDR_NO_RANDOMIZE |
44 | # define ADDR_NO_RANDOMIZE 0x0040000 | ||
45 | #endif | ||
26 | 46 | ||
27 | int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 47 | int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
28 | int setarch_main(int argc UNUSED_PARAM, char **argv) | 48 | int setarch_main(int argc UNUSED_PARAM, char **argv) |
29 | { | 49 | { |
30 | int pers; | 50 | unsigned opts; |
51 | unsigned long pers; | ||
31 | 52 | ||
32 | /* Figure out what personality we are supposed to switch to ... | 53 | /* Figure out what personality we are supposed to switch to ... |
33 | * we can be invoked as either: | 54 | * we can be invoked as either: |
@@ -35,7 +56,7 @@ int setarch_main(int argc UNUSED_PARAM, char **argv) | |||
35 | * argv[0] == "personality" | 56 | * argv[0] == "personality" |
36 | */ | 57 | */ |
37 | if (ENABLE_SETARCH && applet_name[0] == 's' | 58 | if (ENABLE_SETARCH && applet_name[0] == 's' |
38 | && argv[1] && strncpy(argv[1], "linux", 5) | 59 | && argv[1] && is_prefixed_with(argv[1], "linux") |
39 | ) { | 60 | ) { |
40 | applet_name = argv[1]; | 61 | applet_name = argv[1]; |
41 | argv++; | 62 | argv++; |
@@ -47,15 +68,18 @@ int setarch_main(int argc UNUSED_PARAM, char **argv) | |||
47 | else | 68 | else |
48 | bb_show_usage(); | 69 | bb_show_usage(); |
49 | 70 | ||
50 | argv++; | 71 | opts = getopt32(argv, "+R"); /* '+': stop at first non-option */ |
51 | if (argv[0] == NULL) | 72 | if (opts) |
52 | bb_show_usage(); | 73 | pers |= ADDR_NO_RANDOMIZE; |
53 | 74 | ||
54 | /* Try to set personality */ | 75 | /* Try to set personality */ |
55 | if (personality(pers) >= 0) { | 76 | if (personality(pers) < 0) |
56 | /* Try to execute the program */ | 77 | bb_perror_msg_and_die("personality(0x%lx)", pers); |
57 | BB_EXECVP(argv[0], argv); | 78 | |
58 | } | 79 | argv += optind; |
80 | if (!argv[0]) | ||
81 | (--argv)[0] = (char*)"/bin/sh"; | ||
59 | 82 | ||
60 | bb_simple_perror_msg_and_die(argv[0]); | 83 | /* Try to execute the program */ |
84 | BB_EXECVP_or_die(argv); | ||
61 | } | 85 | } |