Local Privilege Escalation in OpenBSD's Dynamic Loader
openwall.com
openwall.com
And their errata description linked from the CVE seems... sorta obfuscatory: "ld.so may fail to remove the LD_LIBRARY_PATH environment variable for set-user-ID and set-group-ID executables in low memory conditions."
This is true, but really fails to capture the fact that this is a trivially exploitable local root. "Low memory conditions" refers not to global system state but to the availability of memory to the process, which is under the control of the attacker via setrlimit().
Not good, folks.
OpenBSD through 6.6 allows local users to escalate to root because a check for LD_LIBRARY_PATH in setuid programs can be defeated by setting a very small RLIMIT_DATA resource limit. When executing chpass or passwd (which are setuid root), _dl_setup_env in ld.so tries to strip LD_LIBRARY_PATH from the environment, but fails when it cannot allocate memory. Thus, the attacker is able to execute their own library code as root.
Also, certain system calls like set(e)[gu]id should be pledged() opt-out rather than opt-in. It's probably a breaking change in a lot of software, but only some calls should ever be called in limited scopes where they're used and then prevented from being called ordinarily. You don't all the always doors unlocked, especially the ones that lead outside from the 11th floor without a fire escape, if you're only using a few of them.
Contrast with something like a service called over dbus: the caller has little to no control over the service's environment, and the most the caller can do is try to confuse it with nonsense dbus calls. It's a "whitelist" basis: only calls the service understands (or think it understands) can do anything, everything else is rejected by default.
Once you let a process run with root or other elevated capabilities, that process should be isolated so nothing about the process can be controlled by the unprivileged user. SUID root utilities violates that.
Now you want to do all legitimate local privilege escalations via IPC.
Wow!