From: Brent Cook Date: Tue, 15 Jul 2014 16:30:07 +0000 (+0000) Subject: add issetugid function to check for elevated privilege X-Git-Tag: v1.1.4~32 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ddddec106fd17c3aca3287005d21e92f742aa9d4;p=oweals%2Fmusl.git add issetugid function to check for elevated privilege this function provides a way for third-party library code to use the same logic that's used internally in libc for suppressing untrusted input/state (e.g. the environment) when the application is running with privleges elevated by the setuid or setgid bit or some other mechanism. its semantics are intended to match the openbsd function by the same name. there was some question as to whether this function is necessary: getauxval(AT_SECURE) was proposed as an alternative. however, this has several drawbacks. the most obvious is that it asks programmers to be aware of an implementation detail of ELF-based systems (the aux vector) rather than simply the semantic predicate to be checked. and trying to write a safe, reliable version of issetugid in terms of getauxval is difficult. for example, early versions of the glibc getauxval did not report ENOENT, which could lead to false negatives if AT_SECURE was not present in the aux vector (this could probably only happen when running on non-linux kernels under linux emulation, since glibc does not support linux versions old enough to lack AT_SECURE). as for musl, getauxval has always properly reported errors, but prior to commit 7bece9c2095ee81f14b1088f6b0ba2f37fecb283, the musl implementation did not emulate AT_SECURE if missing, which would result in a false positive. since musl actually does partially support kernels that lack AT_SECURE, this was problematic. the intent is that library authors will use issetugid if its availability is detected at build time, and only fall back to the unreliable alternatives on systems that lack it. patch by Brent Cook. commit message/rationale by Rich Felker. --- diff --git a/include/unistd.h b/include/unistd.h index bb19cd89..ac6055a5 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -178,6 +178,7 @@ char *getusershell(void); int acct(const char *); long syscall(long, ...); int execvpe(const char *, char *const [], char *const []); +int issetugid(void); #endif #ifdef _GNU_SOURCE diff --git a/src/misc/issetugid.c b/src/misc/issetugid.c new file mode 100644 index 00000000..6ffd9300 --- /dev/null +++ b/src/misc/issetugid.c @@ -0,0 +1,7 @@ +#include +#include "libc.h" + +int issetugid(void) +{ + return libc.secure; +}