aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-04 19:55:01 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-04 19:55:01 +0200
commit5c527dc57e74c1b60c910dc1a3f3ec9683fca43d (patch)
tree03bbbda1f4869c079f381bea45c1cdbf6fcd35a7
parent6514785f95878911b3ec88e2367234df74c14cd4 (diff)
downloadbusybox-w32-5c527dc57e74c1b60c910dc1a3f3ec9683fca43d.tar.gz
busybox-w32-5c527dc57e74c1b60c910dc1a3f3ec9683fca43d.tar.bz2
busybox-w32-5c527dc57e74c1b60c910dc1a3f3ec9683fca43d.zip
make 17 state-changing execing applets (ex: "nice PROG ARGS") noexec
The applets with "<applet> [opts] PROG ARGS" API very quickly exec another program, noexec is okay for them: chpst/envdir/envuidgid/softlimit/setuidgid chroot chrt ionice nice nohup setarch/linux32/linux64 taskset cttyhack "reset" and "sulogin" applets don't have this form, but also exec another program at once, thus made noexec too. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--NOFORK_NOEXEC.lst46
-rw-r--r--console-tools/reset.c2
-rw-r--r--coreutils/chroot.c3
-rw-r--r--coreutils/nice.c2
-rw-r--r--coreutils/nohup.c2
-rw-r--r--loginutils/sulogin.c4
-rw-r--r--runit/chpst.c12
-rw-r--r--shell/cttyhack.c2
-rw-r--r--util-linux/chrt.c2
-rw-r--r--util-linux/ionice.c2
-rw-r--r--util-linux/setarch.c8
-rw-r--r--util-linux/taskset.c2
12 files changed, 44 insertions, 43 deletions
diff --git a/NOFORK_NOEXEC.lst b/NOFORK_NOEXEC.lst
index ccd8f0c96..5ec9ae3fe 100644
--- a/NOFORK_NOEXEC.lst
+++ b/NOFORK_NOEXEC.lst
@@ -20,7 +20,7 @@ suid: runs under different uid - must fork+exec
20Why shouldn't be NOFORK/NOEXEC: 20Why shouldn't be NOFORK/NOEXEC:
21rare: not started often enough to bother optimizing (example: poweroff) 21rare: not started often enough to bother optimizing (example: poweroff)
22daemon: runs indefinitely; these are also always fit "rare" category 22daemon: runs indefinitely; these are also always fit "rare" category
23longterm: often runs for a long time (many seconds), execing would make 23longterm: often runs for a long time (many seconds), execing makes
24 memory footprint smaller 24 memory footprint smaller
25complex: no immediately obvious reason why NOFORK wouldn't work, 25complex: no immediately obvious reason why NOFORK wouldn't work,
26 but does some non-obvoius operations (example: fuser, lsof, losetup); 26 but does some non-obvoius operations (example: fuser, lsof, losetup);
@@ -66,9 +66,9 @@ chgrp - noexec. runner
66chmod - noexec. runner 66chmod - noexec. runner
67chown - noexec. runner 67chown - noexec. runner
68chpasswd - runner (list of "user:password"s from stdin) 68chpasswd - runner (list of "user:password"s from stdin)
69chpst - noexec candidate, spawner 69chpst - noexec. spawner
70chroot - noexec candidate, spawner 70chroot - noexec. spawner
71chrt - noexec candidate, spawner 71chrt - noexec. spawner
72chvt - leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds. Also, "rare" category. noexec candidate. 72chvt - leaks: get_console_fd_or_die() may open a new fd, or return one of stdio fds. Also, "rare" category. noexec candidate.
73cksum - noexec. runner 73cksum - noexec. runner
74clear - NOFORK 74clear - NOFORK
@@ -80,7 +80,7 @@ cpio - runner
80crond - daemon 80crond - daemon
81crontab 0 leaks: open+xasprintf 81crontab 0 leaks: open+xasprintf
82cryptpw - changes state: with --password-fd=N, moves N to stdin. Also, "rare" category. noexec candidate. 82cryptpw - changes state: with --password-fd=N, moves N to stdin. Also, "rare" category. noexec candidate.
83cttyhack - noexec candidate, spawner 83cttyhack - noexec. spawner
84cut - noexec. runner 84cut - noexec. runner
85date - noexec. nofork candidate(needs to stop messing up env, free xasprintf result, not use xfuncs after xasprintf) 85date - noexec. nofork candidate(needs to stop messing up env, free xasprintf result, not use xfuncs after xasprintf)
86dc - runner (eats stdin if no params) 86dc - runner (eats stdin if no params)
@@ -107,8 +107,8 @@ ed - interactive, longterm
107egrep - longterm runner ("CMD | egrep ..." may run indefinitely, better to exec to conserve memory) 107egrep - longterm runner ("CMD | egrep ..." may run indefinitely, better to exec to conserve memory)
108eject - leaks: open+ioctl_or_perror_and_die, changes state (moves fds) 108eject - leaks: open+ioctl_or_perror_and_die, changes state (moves fds)
109env - noexec. spawner, changes state (env) 109env - noexec. spawner, changes state (env)
110envdir - noexec candidate, spawner 110envdir - noexec. spawner
111envuidgid - noexec candidate, spawner 111envuidgid - noexec. spawner
112expand - runner 112expand - runner
113expr - leaks: nested allocs 113expr - leaks: nested allocs
114factor - runner (eats stdin if no params) 114factor - runner (eats stdin if no params)
@@ -128,7 +128,7 @@ flash_eraseall
128flash_lock 128flash_lock
129flash_unlock 129flash_unlock
130flashcp 130flashcp
131flock - spawner, changes state (file locks) 131flock - spawner, changes state (file locks), let's play safe and not be noexec
132fold - noexec. runner 132fold - noexec. runner
133free - nofork candidate(struct globals, needs to close /proc/meminfo fd) 133free - nofork candidate(struct globals, needs to close /proc/meminfo fd)
134freeramdisk - leaks: open+ioctl_or_perror_and_die 134freeramdisk - leaks: open+ioctl_or_perror_and_die
@@ -170,7 +170,7 @@ init - daemon
170inotifyd - daemon 170inotifyd - daemon
171insmod - noexec 171insmod - noexec
172install - runner 172install - runner
173ionice - spawner 173ionice - noexec. spawner
174iostat - runner 174iostat - runner
175ip - noexec candidate 175ip - noexec candidate
176ipaddr - noexec candidate 176ipaddr - noexec candidate
@@ -190,8 +190,8 @@ klogd - daemon
190last - runner (I've got 1300 lines of output when tried it) 190last - runner (I've got 1300 lines of output when tried it)
191less - interactive, longterm 191less - interactive, longterm
192link - NOFORK 192link - NOFORK
193linux32 - spawner 193linux32 - noexec. spawner
194linux64 - spawner 194linux64 - noexec. spawner
195linuxrc - daemon 195linuxrc - daemon
196ln - noexec 196ln - noexec
197loadfont - leaks: config_open+bb_error_msg_and_die("map format") 197loadfont - leaks: config_open+bb_error_msg_and_die("map format")
@@ -247,11 +247,11 @@ netstat - runner with -c
247nice - noexec candidate, spawner 247nice - noexec candidate, spawner
248nl - runner 248nl - runner
249nmeter - longterm 249nmeter - longterm
250nohup - noexec candidate (maybe free concat_path_file result?), spawner 250nohup - noexec. spawner
251nproc - NOFORK 251nproc - NOFORK
252ntpd - daemon 252ntpd - daemon
253od - runner 253od - runner
254openvt - spawner 254openvt - longterm: spawns a child and waits for it
255partprobe - noexec candidate (simple), leaks: open+ioctl_or_perror_and_die(BLKRRPART) 255partprobe - noexec candidate (simple), leaks: open+ioctl_or_perror_and_die(BLKRRPART)
256passwd - suid 256passwd - suid
257paste - noexec. runner 257paste - noexec. runner
@@ -304,15 +304,15 @@ scriptreplay
304sed - runner 304sed - runner
305sendmail - runner 305sendmail - runner
306seq - noexec. runner 306seq - noexec. runner
307setarch - spawner 307setarch - noexec. spawner
308setconsole 308setconsole
309setfont 309setfont
310setkeycodes 310setkeycodes
311setlogcons 311setlogcons
312setpriv - spawner 312setpriv - spawner, changes state, let's play safe and not be noexec
313setserial 313setserial
314setsid - spawner 314setsid - spawner, uses fork_or_rexec() [not audted to work in noexec], let's play safe and not be noexec
315setuidgid 315setuidgid - noexec. spawner
316sha1sum - noexec. runner 316sha1sum - noexec. runner
317sha256sum - noexec. runner 317sha256sum - noexec. runner
318sha3sum - noexec. runner 318sha3sum - noexec. runner
@@ -323,7 +323,7 @@ shuf - noexec. runner
323slattach 323slattach
324sleep - runner, longterm 324sleep - runner, longterm
325smemcap - runner 325smemcap - runner
326softlimit - noexec candidate, spawner 326softlimit - noexec. spawner
327sort - noexec. runner 327sort - noexec. runner
328split - runner 328split - runner
329ssl_client - longterm 329ssl_client - longterm
@@ -332,21 +332,21 @@ stat - nofork candidate(needs fewer allocs)
332strings - runner 332strings - runner
333stty - noexec/nofork candidate. has no allocs or opens except xmove_fd(xopen("-F DEVICE"),STDIN). tcsetattr(STDIN) is not a problem: it would work the same across processes sharing this fd 333stty - noexec/nofork candidate. has no allocs or opens except xmove_fd(xopen("-F DEVICE"),STDIN). tcsetattr(STDIN) is not a problem: it would work the same across processes sharing this fd
334su - suid, spawner 334su - suid, spawner
335sulogin - spawner 335sulogin - noexec. spawner
336sum - runner 336sum - runner
337sv - noexec candidate, needs ^C (uses usleep(420000)) 337sv - noexec candidate, needs ^C (uses usleep(420000))
338svc - noexec candidate, needs ^C (uses usleep(420000)) 338svc - noexec candidate, needs ^C (uses usleep(420000))
339svlogd - daemon 339svlogd - daemon
340swapoff - rare 340swapoff - rare
341swapon - rare 341swapon - rare
342switch_root - spawner, rare, changes state 342switch_root - spawner, rare, changes state (oh yes), execing may be important to free binary's inode
343sync - NOFORK 343sync - NOFORK
344sysctl - noexec candidate, leaks: xstrdup+xmalloc_read 344sysctl - noexec candidate, leaks: xstrdup+xmalloc_read
345syslogd - daemon 345syslogd - daemon
346tac - noexec. runner 346tac - noexec. runner
347tail - runner 347tail - runner
348tar - runner 348tar - runner
349taskset - spawner 349taskset - noexec. spawner
350tcpsvd - daemon 350tcpsvd - daemon
351tee - runner 351tee - runner
352telnet - interactive, longterm 352telnet - interactive, longterm
@@ -354,8 +354,8 @@ telnetd - daemon
354test - NOFORK 354test - NOFORK
355tftp - runner 355tftp - runner
356tftpd - daemon 356tftpd - daemon
357time - spawner, changes state (signals) 357time - spawner, longterm, changes state (signals)
358timeout - spawner, changes state (signals) 358timeout - spawner, longterm, changes state (signals)
359top - interactive, longterm 359top - interactive, longterm
360touch - NOFORK 360touch - NOFORK
361tr - runner 361tr - runner
diff --git a/console-tools/reset.c b/console-tools/reset.c
index 04e5b0ca1..f2b900ddb 100644
--- a/console-tools/reset.c
+++ b/console-tools/reset.c
@@ -16,7 +16,7 @@
16//config: This program is used to reset the terminal screen, if it 16//config: This program is used to reset the terminal screen, if it
17//config: gets messed up. 17//config: gets messed up.
18 18
19//applet:IF_RESET(APPLET(reset, BB_DIR_USR_BIN, BB_SUID_DROP)) 19//applet:IF_RESET(APPLET_NOEXEC(reset, reset, BB_DIR_USR_BIN, BB_SUID_DROP, reset))
20 20
21//kbuild:lib-$(CONFIG_RESET) += reset.o 21//kbuild:lib-$(CONFIG_RESET) += reset.o
22 22
diff --git a/coreutils/chroot.c b/coreutils/chroot.c
index 5645d72df..78751df84 100644
--- a/coreutils/chroot.c
+++ b/coreutils/chroot.c
@@ -13,7 +13,7 @@
13//config: chroot is used to change the root directory and run a command. 13//config: chroot is used to change the root directory and run a command.
14//config: The default command is '/bin/sh'. 14//config: The default command is '/bin/sh'.
15 15
16//applet:IF_CHROOT(APPLET(chroot, BB_DIR_USR_SBIN, BB_SUID_DROP)) 16//applet:IF_CHROOT(APPLET_NOEXEC(chroot, chroot, BB_DIR_USR_SBIN, BB_SUID_DROP, chroot))
17 17
18//kbuild:lib-$(CONFIG_CHROOT) += chroot.o 18//kbuild:lib-$(CONFIG_CHROOT) += chroot.o
19 19
@@ -40,6 +40,7 @@ int chroot_main(int argc UNUSED_PARAM, char **argv)
40 ++argv; 40 ++argv;
41 if (!*argv) 41 if (!*argv)
42 bb_show_usage(); 42 bb_show_usage();
43
43 xchroot(*argv); 44 xchroot(*argv);
44 45
45 ++argv; 46 ++argv;
diff --git a/coreutils/nice.c b/coreutils/nice.c
index 0bf055299..d6818cf00 100644
--- a/coreutils/nice.c
+++ b/coreutils/nice.c
@@ -12,7 +12,7 @@
12//config: help 12//config: help
13//config: nice runs a program with modified scheduling priority. 13//config: nice runs a program with modified scheduling priority.
14 14
15//applet:IF_NICE(APPLET(nice, BB_DIR_BIN, BB_SUID_DROP)) 15//applet:IF_NICE(APPLET_NOEXEC(nice, nice, BB_DIR_BIN, BB_SUID_DROP, nice))
16 16
17//kbuild:lib-$(CONFIG_NICE) += nice.o 17//kbuild:lib-$(CONFIG_NICE) += nice.o
18 18
diff --git a/coreutils/nohup.c b/coreutils/nohup.c
index df271c738..8a70ec4df 100644
--- a/coreutils/nohup.c
+++ b/coreutils/nohup.c
@@ -15,7 +15,7 @@
15//config: help 15//config: help
16//config: run a command immune to hangups, with output to a non-tty. 16//config: run a command immune to hangups, with output to a non-tty.
17 17
18//applet:IF_NOHUP(APPLET(nohup, BB_DIR_USR_BIN, BB_SUID_DROP)) 18//applet:IF_NOHUP(APPLET_NOEXEC(nohup, nohup, BB_DIR_USR_BIN, BB_SUID_DROP, nohup))
19 19
20//kbuild:lib-$(CONFIG_NOHUP) += nohup.o 20//kbuild:lib-$(CONFIG_NOHUP) += nohup.o
21 21
diff --git a/loginutils/sulogin.c b/loginutils/sulogin.c
index d5a463cac..27ea5dff0 100644
--- a/loginutils/sulogin.c
+++ b/loginutils/sulogin.c
@@ -12,7 +12,7 @@
12//config: sulogin is invoked when the system goes into single user 12//config: sulogin is invoked when the system goes into single user
13//config: mode (this is done through an entry in inittab). 13//config: mode (this is done through an entry in inittab).
14 14
15//applet:IF_SULOGIN(APPLET(sulogin, BB_DIR_SBIN, BB_SUID_DROP)) 15//applet:IF_SULOGIN(APPLET_NOEXEC(sulogin, sulogin, BB_DIR_SBIN, BB_SUID_DROP, sulogin))
16 16
17//kbuild:lib-$(CONFIG_SULOGIN) += sulogin.o 17//kbuild:lib-$(CONFIG_SULOGIN) += sulogin.o
18 18
@@ -34,7 +34,7 @@ int sulogin_main(int argc UNUSED_PARAM, char **argv)
34 34
35 /* Note: sulogin is not a suid app. It is meant to be run by init 35 /* Note: sulogin is not a suid app. It is meant to be run by init
36 * for single user / emergency mode. init starts it as root. 36 * for single user / emergency mode. init starts it as root.
37 * Normal users (potentially malisious ones) can only run it under 37 * Normal users (potentially malicious ones) can only run it under
38 * their UID, therefore no paranoia here is warranted: 38 * their UID, therefore no paranoia here is warranted:
39 * $LD_LIBRARY_PATH in env, TTY = /dev/sda 39 * $LD_LIBRARY_PATH in env, TTY = /dev/sda
40 * are no more dangerous here than in e.g. cp applet. 40 * are no more dangerous here than in e.g. cp applet.
diff --git a/runit/chpst.c b/runit/chpst.c
index ccc96539d..c061a91ea 100644
--- a/runit/chpst.c
+++ b/runit/chpst.c
@@ -59,12 +59,12 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59//config: help 59//config: help
60//config: Sets soft resource limits as specified by options 60//config: Sets soft resource limits as specified by options
61 61
62//applet:IF_CHPST(APPLET(chpst, BB_DIR_USR_BIN, BB_SUID_DROP)) 62//applet:IF_CHPST( APPLET_NOEXEC(chpst, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, chpst))
63// APPLET_ODDNAME:name main location suid_type help 63// APPLET_NOEXEC:name main location suid_type help
64//applet:IF_ENVDIR( APPLET_ODDNAME(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir)) 64//applet:IF_ENVDIR( APPLET_NOEXEC(envdir, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envdir))
65//applet:IF_ENVUIDGID(APPLET_ODDNAME(envuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envuidgid)) 65//applet:IF_ENVUIDGID(APPLET_NOEXEC(envuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, envuidgid))
66//applet:IF_SETUIDGID(APPLET_ODDNAME(setuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, setuidgid)) 66//applet:IF_SETUIDGID(APPLET_NOEXEC(setuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, setuidgid))
67//applet:IF_SOFTLIMIT(APPLET_ODDNAME(softlimit, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, softlimit)) 67//applet:IF_SOFTLIMIT(APPLET_NOEXEC(softlimit, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, softlimit))
68 68
69//kbuild:lib-$(CONFIG_CHPST) += chpst.o 69//kbuild:lib-$(CONFIG_CHPST) += chpst.o
70//kbuild:lib-$(CONFIG_ENVDIR) += chpst.o 70//kbuild:lib-$(CONFIG_ENVDIR) += chpst.o
diff --git a/shell/cttyhack.c b/shell/cttyhack.c
index 9004b4763..849fe9e48 100644
--- a/shell/cttyhack.c
+++ b/shell/cttyhack.c
@@ -6,7 +6,7 @@
6 */ 6 */
7#include "libbb.h" 7#include "libbb.h"
8 8
9//applet:IF_CTTYHACK(APPLET(cttyhack, BB_DIR_BIN, BB_SUID_DROP)) 9//applet:IF_CTTYHACK(APPLET_NOEXEC(cttyhack, cttyhack, BB_DIR_BIN, BB_SUID_DROP, cttyhack))
10 10
11//kbuild:lib-$(CONFIG_CTTYHACK) += cttyhack.o 11//kbuild:lib-$(CONFIG_CTTYHACK) += cttyhack.o
12 12
diff --git a/util-linux/chrt.c b/util-linux/chrt.c
index 4bc8b6cfa..52523df02 100644
--- a/util-linux/chrt.c
+++ b/util-linux/chrt.c
@@ -12,7 +12,7 @@
12//config: manipulate real-time attributes of a process. 12//config: manipulate real-time attributes of a process.
13//config: This requires sched_{g,s}etparam support in your libc. 13//config: This requires sched_{g,s}etparam support in your libc.
14 14
15//applet:IF_CHRT(APPLET(chrt, BB_DIR_USR_BIN, BB_SUID_DROP)) 15//applet:IF_CHRT(APPLET_NOEXEC(chrt, chrt, BB_DIR_USR_BIN, BB_SUID_DROP, chrt))
16 16
17//kbuild:lib-$(CONFIG_CHRT) += chrt.o 17//kbuild:lib-$(CONFIG_CHRT) += chrt.o
18 18
diff --git a/util-linux/ionice.c b/util-linux/ionice.c
index c7b7f0373..5b9664d25 100644
--- a/util-linux/ionice.c
+++ b/util-linux/ionice.c
@@ -14,7 +14,7 @@
14//config: Set/set program io scheduling class and priority 14//config: Set/set program io scheduling class and priority
15//config: Requires kernel >= 2.6.13 15//config: Requires kernel >= 2.6.13
16 16
17//applet:IF_IONICE(APPLET(ionice, BB_DIR_BIN, BB_SUID_DROP)) 17//applet:IF_IONICE(APPLET_NOEXEC(ionice, ionice, BB_DIR_BIN, BB_SUID_DROP, ionice))
18 18
19//kbuild:lib-$(CONFIG_IONICE) += ionice.o 19//kbuild:lib-$(CONFIG_IONICE) += ionice.o
20 20
diff --git a/util-linux/setarch.c b/util-linux/setarch.c
index d4b568832..520865318 100644
--- a/util-linux/setarch.c
+++ b/util-linux/setarch.c
@@ -30,10 +30,10 @@
30//config: help 30//config: help
31//config: Alias to "setarch linux64". 31//config: Alias to "setarch linux64".
32 32
33//applet:IF_SETARCH(APPLET(setarch, BB_DIR_BIN, BB_SUID_DROP)) 33//applet:IF_SETARCH(APPLET_NOEXEC(setarch, setarch, BB_DIR_BIN, BB_SUID_DROP, setarch))
34// APPLET_ODDNAME:name main location suid_type help 34// APPLET_NOEXEC:name main location suid_type help
35//applet:IF_LINUX32(APPLET_ODDNAME(linux32, setarch, BB_DIR_BIN, BB_SUID_DROP, linux32)) 35//applet:IF_LINUX32(APPLET_NOEXEC(linux32, setarch, BB_DIR_BIN, BB_SUID_DROP, linux32))
36//applet:IF_LINUX64(APPLET_ODDNAME(linux64, setarch, BB_DIR_BIN, BB_SUID_DROP, linux64)) 36//applet:IF_LINUX64(APPLET_NOEXEC(linux64, setarch, BB_DIR_BIN, BB_SUID_DROP, linux64))
37 37
38//kbuild:lib-$(CONFIG_SETARCH) += setarch.o 38//kbuild:lib-$(CONFIG_SETARCH) += setarch.o
39//kbuild:lib-$(CONFIG_LINUX32) += setarch.o 39//kbuild:lib-$(CONFIG_LINUX32) += setarch.o
diff --git a/util-linux/taskset.c b/util-linux/taskset.c
index 9957b1a71..89dea176e 100644
--- a/util-linux/taskset.c
+++ b/util-linux/taskset.c
@@ -22,7 +22,7 @@
22//config: affinity parameter 0xHHHHHHHHHHHHHHHHHHHH can be arbitrarily long 22//config: affinity parameter 0xHHHHHHHHHHHHHHHHHHHH can be arbitrarily long
23//config: in this case. Otherwise, it is limited to sizeof(long). 23//config: in this case. Otherwise, it is limited to sizeof(long).
24 24
25//applet:IF_TASKSET(APPLET(taskset, BB_DIR_USR_BIN, BB_SUID_DROP)) 25//applet:IF_TASKSET(APPLET_NOEXEC(taskset, taskset, BB_DIR_USR_BIN, BB_SUID_DROP, taskset))
26//kbuild:lib-$(CONFIG_TASKSET) += taskset.o 26//kbuild:lib-$(CONFIG_TASKSET) += taskset.o
27 27
28//usage:#define taskset_trivial_usage 28//usage:#define taskset_trivial_usage