• B
    add issetugid function to check for elevated privilege · ddddec10
    Brent Cook 提交于
    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 7bece9c2,
    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.
    ddddec10
unistd.h 12.9 KB