aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/applets.src.h3
-rw-r--r--util-linux/Config.src10
-rw-r--r--util-linux/Kbuild.src1
-rw-r--r--util-linux/setarch.c54
4 files changed, 39 insertions, 29 deletions
diff --git a/include/applets.src.h b/include/applets.src.h
index 5b597202e..6e1b02fc3 100644
--- a/include/applets.src.h
+++ b/include/applets.src.h
@@ -192,8 +192,6 @@ IF_KILLALL5(APPLET_ODDNAME(killall5, kill, BB_DIR_USR_SBIN, BB_SUID_DROP, killal
192IF_LAST(APPLET(last, BB_DIR_USR_BIN, BB_SUID_DROP)) 192IF_LAST(APPLET(last, BB_DIR_USR_BIN, BB_SUID_DROP))
193//IF_LENGTH(APPLET_NOFORK(length, length, BB_DIR_USR_BIN, BB_SUID_DROP, length)) 193//IF_LENGTH(APPLET_NOFORK(length, length, BB_DIR_USR_BIN, BB_SUID_DROP, length))
194IF_LESS(APPLET(less, BB_DIR_USR_BIN, BB_SUID_DROP)) 194IF_LESS(APPLET(less, BB_DIR_USR_BIN, BB_SUID_DROP))
195IF_SETARCH(APPLET_ODDNAME(linux32, setarch, BB_DIR_BIN, BB_SUID_DROP, linux32))
196IF_SETARCH(APPLET_ODDNAME(linux64, setarch, BB_DIR_BIN, BB_SUID_DROP, linux64))
197IF_LN(APPLET_NOEXEC(ln, ln, BB_DIR_BIN, BB_SUID_DROP, ln)) 195IF_LN(APPLET_NOEXEC(ln, ln, BB_DIR_BIN, BB_SUID_DROP, ln))
198IF_LOAD_POLICY(APPLET(load_policy, BB_DIR_USR_SBIN, BB_SUID_DROP)) 196IF_LOAD_POLICY(APPLET(load_policy, BB_DIR_USR_SBIN, BB_SUID_DROP))
199IF_LOADFONT(APPLET(loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP)) 197IF_LOADFONT(APPLET(loadfont, BB_DIR_USR_SBIN, BB_SUID_DROP))
@@ -274,7 +272,6 @@ IF_SELINUXENABLED(APPLET(selinuxenabled, BB_DIR_USR_SBIN, BB_SUID_DROP))
274IF_SENDMAIL(APPLET(sendmail, BB_DIR_USR_SBIN, BB_SUID_DROP)) 272IF_SENDMAIL(APPLET(sendmail, BB_DIR_USR_SBIN, BB_SUID_DROP))
275IF_SEQ(APPLET_NOFORK(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq)) 273IF_SEQ(APPLET_NOFORK(seq, seq, BB_DIR_USR_BIN, BB_SUID_DROP, seq))
276IF_SESTATUS(APPLET(sestatus, BB_DIR_USR_SBIN, BB_SUID_DROP)) 274IF_SESTATUS(APPLET(sestatus, BB_DIR_USR_SBIN, BB_SUID_DROP))
277IF_SETARCH(APPLET(setarch, BB_DIR_BIN, BB_SUID_DROP))
278IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP)) 275IF_SETCONSOLE(APPLET(setconsole, BB_DIR_SBIN, BB_SUID_DROP))
279IF_SETENFORCE(APPLET(setenforce, BB_DIR_USR_SBIN, BB_SUID_DROP)) 276IF_SETENFORCE(APPLET(setenforce, BB_DIR_USR_SBIN, BB_SUID_DROP))
280IF_SETFILES(APPLET(setfiles, BB_DIR_SBIN, BB_SUID_DROP)) 277IF_SETFILES(APPLET(setfiles, BB_DIR_SBIN, BB_SUID_DROP))
diff --git a/util-linux/Config.src b/util-linux/Config.src
index 854b3682e..922cabdb8 100644
--- a/util-linux/Config.src
+++ b/util-linux/Config.src
@@ -489,16 +489,6 @@ config SCRIPTREPLAY
489 This program replays a typescript, using timing information 489 This program replays a typescript, using timing information
490 given by script -t. 490 given by script -t.
491 491
492config SETARCH
493 bool "setarch"
494 default y
495 select PLATFORM_LINUX
496 help
497 The linux32 utility is used to create a 32bit environment for the
498 specified program (usually a shell). It only makes sense to have
499 this util on a system that supports both 64bit and 32bit userland
500 (like amd64/x86, ppc64/ppc, sparc64/sparc, etc...).
501
502config SWAPONOFF 492config SWAPONOFF
503 bool "swaponoff" 493 bool "swaponoff"
504 default y 494 default y
diff --git a/util-linux/Kbuild.src b/util-linux/Kbuild.src
index 468fc6bc1..0b87c52ac 100644
--- a/util-linux/Kbuild.src
+++ b/util-linux/Kbuild.src
@@ -40,7 +40,6 @@ lib-$(CONFIG_READPROFILE) += readprofile.o
40lib-$(CONFIG_RTCWAKE) += rtcwake.o 40lib-$(CONFIG_RTCWAKE) += rtcwake.o
41lib-$(CONFIG_SCRIPT) += script.o 41lib-$(CONFIG_SCRIPT) += script.o
42lib-$(CONFIG_SCRIPTREPLAY) += scriptreplay.o 42lib-$(CONFIG_SCRIPTREPLAY) += scriptreplay.o
43lib-$(CONFIG_SETARCH) += setarch.o
44lib-$(CONFIG_SWAPONOFF) += swaponoff.o 43lib-$(CONFIG_SWAPONOFF) += swaponoff.o
45lib-$(CONFIG_SWITCH_ROOT) += switch_root.o 44lib-$(CONFIG_SWITCH_ROOT) += switch_root.o
46lib-$(CONFIG_UMOUNT) += umount.o 45lib-$(CONFIG_UMOUNT) += umount.o
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
27int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 47int setarch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
28int setarch_main(int argc UNUSED_PARAM, char **argv) 48int 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}