From 62d1e98fbd0cc1b008237411d8b2ddc20d3e55a7 Mon Sep 17 00:00:00 2001 From: Assaf Gordon Date: Wed, 14 Jun 2017 11:46:52 +0200 Subject: setpriv: new applet Add a minimal 'setpriv' implementation supporting the NO_NEW_PRIVS bit. Typical usage: $ busybox setpriv sudo uname Linux $ busybox setpriv --nnp sudo uname sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges? function old new delta packed_usage 31580 31685 +105 setpriv_main - 87 +87 prctl - 53 +53 static.setpriv_longopts - 22 +22 applet_names 2620 2628 +8 applet_main 1516 1520 +4 ------------------------------------------------------------------------------ (add/remove: 5/0 grow/shrink: 3/0 up/down: 279/0) Total: 279 bytes Signed-off-by: Assaf Gordon Signed-off-by: Denys Vlasenko --- util-linux/setpriv.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 util-linux/setpriv.c (limited to 'util-linux/setpriv.c') diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c new file mode 100644 index 000000000..6bd663bf4 --- /dev/null +++ b/util-linux/setpriv.c @@ -0,0 +1,73 @@ +/* vi: set sw=4 ts=4: */ +/* + * setpriv implementation for busybox based on linux-utils-ng 2.29 + * + * Copyright (C) 2017 by + * + * Licensed under GPLv2 or later, see file LICENSE in this source tree. + * + */ +//config:config SETPRIV +//config: bool "setpriv" +//config: default y +//config: select PLATFORM_LINUX +//config: select LONG_OPTS +//config: help +//config: Run a program with different Linux privilege settings. +//config: Requires kernel >= 3.5 + +//applet:IF_SETPRIV(APPLET(setpriv, BB_DIR_BIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_SETPRIV) += setpriv.o + +//usage:#define setpriv_trivial_usage +//usage: "[OPTIONS] PROG [ARGS]" +//usage:#define setpriv_full_usage "\n\n" +//usage: "Run PROG with different privilege settings\n" +//usage: "\n--nnp,--no-new-privs Ignore setuid/setgid bits and file capabilities" + +//setpriv from util-linux 2.28: +// -d, --dump show current state (and do not exec anything) +// --nnp, --no-new-privs disallow granting new privileges +// --inh-caps set inheritable capabilities +// --bounding-set set capability bounding set +// --ruid set real uid +// --euid set effective uid +// --rgid set real gid +// --egid set effective gid +// --reuid set real and effective uid +// --regid set real and effective gid +// --clear-groups clear supplementary groups +// --keep-groups keep supplementary groups +// --groups set supplementary groups +// --securebits set securebits +// --selinux-label