SECURITY: Unbreak “set +p”, broken by OpenBSD ksh change.
TODO: I am seriously considering following Chet and changing the way this works, by explicitly dropping privs unless the shell is run with -p. Every other shell does it like mksh, except Heirloom sh, which on the other hand doesn’t know any explicit set -p or set +p (though it doesn’t know set +foo for any foo either). ┌──┤ QUESTION: Do we need the ability to do this: │ tg@blau:~ $ ./suidmksh -p -c 'whoami; set +p; whoami' │ root │ tg If not, I’m seriously considering to drop set ±p as well, only parse -p on the command line, with +p being the default, and dropping FPRIVILEGED. Thanks to RT for noticing and jilles for initial follow-up discussion, as well as Chet Ramey for doing the sane/secure thing instead of following Debian.
This commit is contained in:
8
misc.c
8
misc.c
@ -30,7 +30,7 @@
|
||||
#include <grp.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.214 2013/08/11 14:57:09 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.215 2013/08/23 14:07:36 tg Exp $");
|
||||
|
||||
#define KSH_CHVT_FLAG
|
||||
#ifdef MKSH_SMALL
|
||||
@ -271,6 +271,7 @@ change_flag(enum sh_flag f, int what, bool newset)
|
||||
|
||||
/*XXX this can probably be optimised */
|
||||
kshegid = kshgid = getgid();
|
||||
ksheuid = kshuid = getuid();
|
||||
#if HAVE_SETRESUGID
|
||||
DO_SETUID(setresgid, (kshegid, kshegid, kshegid));
|
||||
#if HAVE_SETGROUPS
|
||||
@ -278,9 +279,8 @@ change_flag(enum sh_flag f, int what, bool newset)
|
||||
setgroups(1, &kshegid);
|
||||
#endif
|
||||
DO_SETUID(setresuid, (ksheuid, ksheuid, ksheuid));
|
||||
#else
|
||||
#else /* !HAVE_SETRESUGID */
|
||||
/* seteuid, setegid, setgid don't EAGAIN on Linux */
|
||||
ksheuid = kshuid = getuid();
|
||||
#ifndef MKSH__NO_SETEUGID
|
||||
seteuid(ksheuid);
|
||||
#endif
|
||||
@ -289,7 +289,7 @@ change_flag(enum sh_flag f, int what, bool newset)
|
||||
setegid(kshegid);
|
||||
#endif
|
||||
setgid(kshegid);
|
||||
#endif
|
||||
#endif /* !HAVE_SETRESUGID */
|
||||
} else if ((f == FPOSIX || f == FSH) && newval) {
|
||||
/* Turning on -o posix or -o sh? */
|
||||
Flag(FBRACEEXPAND) = 0;
|
||||
|
Reference in New Issue
Block a user