14 ms·
Pwnkit: Local Privilege Escalation in polkit's pkexec (CVE-2021-4034)
- frankjr 5y agohttps://gitlab.freedesktop.org/polkit/polkit/-/commit/a2bf5c9c83b6ae46cbd5c779d3055bff81ded683 https://gitlab.freedesktop.org/polkit/polkit/-/commit/a2bf5c...
- southerntofu 5y agoI'm not good enough to guess the exploit, but the fix is simple enough that i consider that a nice find!
- deleted 5y ago[deleted]
- tptacek 5y agoWhat a glorious little bug. They're trying to scan arguments, and have a loop that starts with (effectively) argv[1]. But if argv is NULL, the loop terminates immediately --- with the maximum argument still set to 1, an out-of-bounds dereference to argv[1] that ends up pointing into the environment. Just beautiful.
- deleted 5y ago[deleted]
- pjmlp 5y agoBecause real C devs never make silly mistakes, nor everyone that reviewed the code, or the automatic unit tests. Beautiful indeed.
- Jasper_ 5y agoI'm surprised that the Linux kernel doesn't prevent execve with argc == 0. I know a lot of programs that would break on that too.
- Retr0id 5y agoChanging that now would break the core tenet of "never break userspace".
- mmis1000 5y agoI actually wonder what it could actually break. argv[0] always exists in normal means, it is either physical path of the executable or soft link position. Without accidents like run a program from code and forget about passing argv. That couldn't happen at all. And in fact, most cross platform program or shell even just assume argv[0] is the same as executable path (and don't give you a option to change it, because it is not possible on all platforms).
- Retr0id 5y agoI have personally written (lazy) code that calls execve with argv=NULL. So it'd break that.
- westurner 5y agoSo, all C/C++ code on {Linux,} but not {OpenBSD,} that handles argc/argv needs to at least just exit() on the conditions added by the like 8 lines in main() in the patch for this issue?: https://gitlab.freedesktop.org/polkit/polkit/-/commit/a2bf5c9c83b6ae46cbd5c779d3055bff81ded683 https://gitlab.freedesktop.org/polkit/polkit/-/commit/a2bf5c... if (argc < 1) { exit(126); } if (argv[n] == NULL) { exit(128) } // But this could never ever happen? if (argv == NULL)
- mmis1000 5y agoI did that once, but the target is a shell. Shells relies on argv[0] to determine what it is running as (login shell have prefix on argv[0]). So it end up blew up in a funny way. After a bit google I realize I need to repeat the file path by myself on *nix. In windows, the spawn equivalent take a long string, anything after file path is argument. So it can't be a bug since day 1.
- olliej 5y agoAnd it was spotted in 2013: https://ryiron.wordpress.com/2013/12/16/argv-silliness/ https://ryiron.wordpress.com/2013/12/16/argv-silliness/
- ncmncm 5y agoGood find!
- olliej 5y ago"find" I follow him on twitter and it told me :D
- Beltalowda 5y agoDid they tell the Polkit people about this? Or was it just posted on their website? Or to rephrase it: what are the reasons this wasn't this fixed in 2013?
- olliej 5y agofrom his twitter it sounds like he sent email+patch but presumably it got bounced as he can't find it in their archives - https://twitter.com/ryiron/status/1486207465918468097 https://twitter.com/ryiron/status/1486207465918468097
- tedunangst 5y agoFor people who don't like seclists formatting. https://marc.info/?l=oss-security&m=164313339424946&w=2 https://marc.info/?l=oss-security&m=164313339424946&w=2
- jwilk 5y agoFor people who don't like MARC formatting either: https://www.openwall.com/lists/oss-security/2022/01/25/11 https://www.openwall.com/lists/oss-security/2022/01/25/11 https://www.qualys.com/2022/01/25/cve-2021-4034/pwnkit.txt https://www.qualys.com/2022/01/25/cve-2021-4034/pwnkit.txt
- hsbauauvhabzb 5y agoI don’t mind seclists format, but the black text overflows onto a dark blue background on my iPhone 13 making it unusable. Thanks.
- getcrunk 5y agothis sounds like a bug class some type of source code scanner should be able to pick up?
- loeg 5y agoIt appears as if the maintainers are looking at Coverity at least some of the time: https://gitlab.freedesktop.org/polkit/polkit/-/merge_requests/94 https://gitlab.freedesktop.org/polkit/polkit/-/merge_request... I don't know if this was flagged or not.
- ape4 5y agoWow, it seems like there should be some iron clad / redundant argument parsing in sudo-like programs
- errcorrectcode 5y agoProper defensive C programming solves these problems. If argc is 0, don't look at argv. Sanity check argv != NULL before looking at it. Or, maybe write security-critical programs in safer languages like Rust.
- TillE 5y agoYeah I find it completely bizarre to not check everything for error conditions, unless you're writing some sloppy one-off code and don't care. People out there write some pretty funky C.
- errcorrectcode 5y agoIt's a safety / performance tradeoff that isn't well-constrained by the language or most tools. That's partially why it's a fragile and dangerous language. If you're writing a serious kernel in C, you ought to have programmatic debugging assertion constraints for every parameter.
- kator 5y ago> pkexec is installed by default on all major Linux distributions (we exploited Ubuntu, Debian, Fedora, CentOS, and other distributions are probably also exploitable); I don't find it on any of the servers I manage, it appears to be installed with graphical desktop only?
- throwaway984393 5y agoPolicykit's sole purpose is to provide an abstraction to let modern X server applications press a suspend or power off button. It's the same kind of garbage as DBus. The modern Linux desktop is absurd.
- skeptical1 5y agoYes, this is exactly why I don't run any of this crap on my distro. No dbus, no polkit, no systemd, nothing. Computer security is already enough of a nightmare without all this crap added on and linked in to everything.
- 400thecat 5y agoI also have my system without polkit and without systemd. But how do you get rid of dbus? It seems to be needed for many GUI applications
- skeptical1 5y agoSome programs can be configured to run without it. Others require patching to remove it. Some patches are trivial, others not so much. I've done a lot of patching, with still more required to get other applications running that I want to use. At some point I'm planning to build a "dummy" dbus library that can be linked against but actually does nothing at all, but I haven't gotten around to it yet.
- crazy_hombre 5y agoOh no, an application has bugs. Must get rid of it!
- shaded-enmity 5y agoI haven't touched this in a long time, but isn't the attack vector essentially the same as in Vortex lvl 4? https://overthewire.org/wargames/vortex/vortex4.html https://overthewire.org/wargames/vortex/vortex4.html
- Klasiaster 5y agoI wonder why it even is a setuid binary since there already is a privileged service it interacts with (through DBus). I think we should replace all setuid binaries with a scheme of having a privileged service that acts on the requests of unprivileged processes. With Unix Domain Sockets and SO_PEERCRED the unprivileged process user can be identified (but less info is available than with a setuid binary). This could even work with sudo but the difference is that the privileged service would not spawn a child process of the unprivileged process but rather hand out the stdin/err/out FDs of the spawned privileged process to the unprivileged process (or vice versa, get stdin/err/out FDs from the unprivileged process and set for the spawned privileged process), again this works with Unix Domain Sockets.
- floatboth 5y agopkexec is a setuid binary because pkexec is just a sudo-alike that uses polkit for authorization. > a scheme of having a privileged service that acts on the requests of unprivileged processes That is precisely what polkit is!
- Klasiaster 5y agoNope because pkexec already is a privileged process because it is a setuid binary. Being a setuid binary instantly makes it a privileged process, it's not related to whether it's similar to sudo and does authorization. What I'm saying is that the pkexec process itself doesn't need to be setuid, it should be an unprivileged process (also true for the /usr/libexec/polkit-agent-helper-1 helper it uses which is a setuid binary but doesn't really have to be when splitting this up in a daemon process). Edit: Maybe to make it clear, yes, in theory the polkit project does follow the scheme of a privileged daemon process and unprivileged clients but in practice it doesn't because of the setuid polkit-agent-helper-1 and setuid pkexec programs.
- floatboth 5y agoIt is a setuid binary because it does sudo. You cannot accomplish sudo without setuid. Note that sudo means gaining privilege in the current context, with all its environment (including inherited file descriptors, the process group, etc.), not doing a privileged action at a distance. > also true for the /usr/libexec/polkit-agent-helper-1 helper it uses which is a setuid binary but doesn't really have to be Try making it non-setuid and see what happens. (It will fail to check your password because most mechanisms for doing so, like the usual pam_unix, are only accessible to root.)
- staticassertion 5y agoPOC (tweet + direct link) https://twitter.com/bl4sty/status/1486092552755466242 https://twitter.com/bl4sty/status/1486092552755466242 https://haxx.in/files/blasty-vs-pkexec.c https://haxx.in/files/blasty-vs-pkexec.c
- aftbit 5y agoI get: [~] compile helper.. [~] maybe get shell now? The value for environment variable XAUTHORITY contains suscipious content This incident has been reported. And no root shell
- Pieman103021 5y agoAdding `GIO_USE_VFS=` to the end of `a_envp` (starting on line 56), fixes that for me on Fedora 34 with polkit-0.117-3. If anybody knows why that makes a difference, I would love to hear.
- deleted 5y ago[deleted]
- vrzh 5y agoRan into this while writing my exploit. I explain it here https://github.com/v-rzh/CVE-2021-4034/blob/master/README.md#whats-the-deal-with-gio_use_vfs https://github.com/v-rzh/CVE-2021-4034/blob/master/README.md... :)
- hakube 5y agoI've just updated my Arch system and tried this. No longer works
- makeworld 5y agoSame. Seems like the exploit wouldn't work for me. When I modify the XAUTHORITY line in the code, either to remove it or point it to my current XAUTHORITY value, I rightfully get a GUI password prompt before the root shell will open. On Arch Linux.
- invokestatic 5y agoI’ve really come to the conclusion that OS users are merely policy barriers and not security barriers (or at least, not strong barriers). This seems to be the position of Microsoft as well, given their stance on UAC and privilege escalation exploits in general. I think it’s akin to real-life locks. Keeps good guys out, but not a determined attacker.
- hsbauauvhabzb 5y agoI mostly agree but it’s also pretty hard to LPE on modern hardened windows or Linux. Not impossible, but enough that low tier attackers can’t do it.
- eternityforest 5y agoYou don't need to though. Most desktops only have one user, and you can do plenty of bad stuff without root.
- pengaru 5y agoEver since my first encounter with PolicyKit back in the early days of its inclusion in Debian, ages ago, I've had a very bad impression of its implementation quality. Back then it would segfault randomly for no apparent reason, idle freshly installed fairly minimalist headless fileservers. We immediately blacklisted it from our systems, but were lucky to not actually need anything it brought to the table. IIRC for quite some time there wasn't even a maintainer, but I think that was pre-polkit rename. Hopefully the situation has improved.
- dathinab 5y agoAs there seem to be misunderstandings about what polkit is: It's a way to let user processes communicate with privileged processes while potentially, action dependent also prompting the user for a password. pkexec on the other hand is separate program bundled with polkit which is kinda which let's you combine polkit with running predefined commands, or easily accidentally any command and IMHO should not exist. there are various programs which work with polkit (even if they don't necessary require it) including: - systemd, logind, NetworkManager, udisks, flatpack, fwupd, timedate(setting), and others It also allows rather flexible configurations about what users can do which actions under which conditions, which can be quite useful for a multi-user server (e.g. GPU server). While I think a program like polkit is a must have for a modern Linux OS I'm not a fan of it's design. - pkexec is a bad idea for many more reasons then this vulnerability - the way it's configured and how it handles caching is prone to accidentally make mistakes with security consequences - pkexec should not exist, even without the vulnerability it's really easy to mess up using it - having a embedded language for handling permission scripting, and not inventing your own language or pseudo-language config format is a good. But js? I guess there are simple embedded js interpreters.(1) (1): Note that it only runs small snippets, so no need to have a JS interpreter with modern features like classes, or an JIT ;=)
- dsr_ 5y agoIf you add pulseaudio to the list of - systemd, logind, NetworkManager, udisks, flatpack, fwupd, timedate(setting) you have a good start on the list of common programs that I distrust the most. Plus polkit itself, I guess.
- floatboth 5y ago> guess there are simple embedded js interpreters In fact a duktape backend has just landed: https://gitlab.freedesktop.org/polkit/polkit/-/merge_requests/97 https://gitlab.freedesktop.org/polkit/polkit/-/merge_request... Speaking of security though, I'd trust SpiderMonkey much more because it's battle-tested in the most hostile environment imaginable (millions of browser instances loading completely untrusted code 24/7). But in this context we don't execute untrusted code so whatever :) > pkexec should not exist Hmm. For things that do want "just a graphical sudo" for whatever reason, it is kinda the perfect answer. Reusing the per-desktop authorization UI that is used for more fine-grained actions for a sudo-like tool is the correct thing to do. No one wants to have more redundant authorization mechanisms and UIs…
- usr1106 5y agoThe simple work-around is not even possible on Fedora CoreOS: $ sudo chmod 0755 /usr/bin/pkexec chmod: changing permissions of '/usr/bin/pkexec': Read-only file system Security preventing security I guess...
- kirbyfan64sos 5y agoYou can `ostree admin unlock --hotfix` to allow editing the current deployment, designed with this use case in mind: https://www.mankier.com/1/ostree-admin-unlock#--hotfix https://www.mankier.com/1/ostree-admin-unlock#--hotfix
- dezgeg 5y agoOne trick to temporarily 'modify' read-only filesystems is to bind-mount something over it: sudo mount --bind /bin/false /usr/bin/pkexec This will be gone over reboot, however.
- 1vuio0pswjnm7 5y ago"We discovered a Local Privilege Escalation (from any user to root) in polkit`s pkexec, a SUID-root program that is installed by default on every major Linux distribution:" I use Linux but do not use a graphics system (X11, Wayland, etc.). When I install, I always start by downloading a rootfs or a bootable image containing a rootfs. For example, if installing Debian, I might start by downloading boot.img.gz https://deb.debian.org/debian/dists/bullseye/main/installer-amd64/current/images/hd-media/boot.img.gz https://deb.debian.org/debian/dists/bullseye/main/installer-... However I do not see pkexec "installed by default" in initrd or initrdg. gzip -d boot.img.gz mount -o loop boot.img /mnt/img gzip -d /mnt/img/initrd.gz cpio -t < /mnt/img/initrd|grep pkexec gzip -dc /mnt/img/initrdg.gz|cpio -t|grep pkexec It appears that to install pkexec I would have to choose it at a later stage. I guess the authors are referring to some other installation method. Perhaps one that denies the user the chance to skip installing a graphics system.
- kevin_b_er 5y agoThe temporary initial RAM filesystem? You are describing the thing that is loaded and run to load the Debian installation data and install Debian. One could argue the thing you are running is not "Debian", but Debian's installer tool.
- 1vuio0pswjnm7 5y agoThat would be an interesting argument. It is a bootloader (syslinux), the Linux kernel and an extensive userland, including dpkg and full set of root certificates. TBH, that is almost everything I need. I install a handful of additional programs, some static binaries compiled from personal source code archives, some programs from the Debian repositories, and I am good to go. Perhaps it would come down to what exactly in the userland defines Debian as Debian. There are certainly differences in the rootfs as I go from one distribution to another. It would be like arguing that NetBSD install media is not NetBSD. For me, it is absolutely NetBSD, just a smaller version.
- jasonhansel 5y ago> OpenBSD is not exploitable, because its kernel refuses to execve() a program if argc is 0 Sounds like they made the right choice. Why would other kernels allow this?
- angry_octet 5y agoThe argv[0] as program name isn't required? Programs run fine without it. Command line options are a bit archaic for controlling initial state anyway.
- pabs3 5y agoFrom one of the linked mails: NB, this was partially fixed in gnulib in 2009: http://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=b06da86eb05ed57e2861061ae5cacf4c7a3686f1 But glib has its own copy of this code, which hasn't been updated since 2008. Embedded code copies are terrible, people really need to start removing them, or at least learning how to update them.
- octoberfranklin 5y ago... and yet when we object to "everything depends on systemd" (which drags in dbus+polkit) the peanut gallery still screams "conspiracy theorist!" This architecture was a bad idea when Windows adopted it. Then it got transplanted to Linux and got even worse.
- errcorrectcode 5y agoWhat happened to udev also. Looked at nosh? https://jdebp.uk/Softwares/nosh/ https://jdebp.uk/Softwares/nosh/
- pdenton 5y agoOn Debian and derivatives, one can override the setuid bit permanently as follows: dpkg-statoverride --update --add root root 0755 /usr/bin/pkexec
- prima-facie 5y agoFYI this is now patched in Archlinux with polkit 0.120-4
- Beltalowda 5y agoThe fix for this ("if (argc < 1) exit(126)" [1]) is just ... ugh. Some weeks ago I wanted to run a game; it showed an error when starting that it failed to set real-time priority for the audio thread, resulting in actual audio stuttering. ALAudio asks rtkit, rtkit asks polkit, and that somehow fails. Why? Who knows. To even figure this out I had to recompile rtkit with some strategic printf() calls in there, because it just doesn't show at all why it failed. Same for polkit. I never did find out what the problem was. I just gave up after a while. It's stuff like this why I dislike all these tools: it all works when it works, but when it fails it really makes your life hard. Here, too, it just exits with 126, no message, and good luck to you as developer or user if something goes wrong. Call me a radical traditionalist unix greybeard, but I really think tools should tell users what goes wrong, even (or perhaps especially) when they're "internal" tools like this, because this it's just really hard to figure out what the problem is. "fprintf(stderr, "too few arguments\n")" is not very hard, it seems to me shrug. [1]: https://gitlab.freedesktop.org/polkit/polkit/-/commit/a2bf5c9c83b6ae46cbd5c779d3055bff81ded683 https://gitlab.freedesktop.org/polkit/polkit/-/commit/a2bf5c...
- yrro 5y agoIn case helpful for you or anyone else, you can find out whether polkit would allow a request for an action with pkcheck(1), for instance: "pkcheck --action-id org.freedesktop.RealtimeKit1.acquire-real-time --process $$" and check the exit status. What is missing in all these complaint threads (and this isn't aimed at you specifically) is the complainers' proposed alternatives. It's very easy to write a glib comment about "sudo already does this" "groups already do this" which indicates only that the person writing the comment doesn't understand the problem that PolKit is trying to solve.
- Beltalowda 5y agoAs near as I could figure out RTkit asked Polkit "do I have permissions to set this real-time?", and Polkit said "no". But perhaps I'm wrong; I found it all very hard to debug as mentioned before, and I didn't care that much just to play some game. I don't have the game on my laptop any more; I'll have to try your pkcheck command next time (although that still won't fix anything, but might get me closer; thanks!) What I lament is not so much that things have changed, but that things have changed in ways I no longer understand or can debug. Back in the Old Days™ you could more or less understand your entire system from a few very basic principles. If something didn't work, you could go in there and usually figure it out on your own. Not that I have rose-coloured glasses about the Old Days™. I remember having to run that horrible "xfree86 -configure" thing when I was starting out with this whole Linux thing. Clearly, things are better now because the last time I had to look at "configuring X" is so long ago I don't even remember how to do it (or even what that filename was; /etc/x.conf? Or /etc/x11.conf? Not sure). I don't think it has to be like this. Just because "su" and "sudo" aren't sufficient and the concepts in e.g. Polkit are good doesn't mean the implementation of these concepts also is.
- teddyh 5y agoWhy are they parsing argv by hand instead of using, say, argp_parse()¹? It’s even the seventh commandment of The Ten Commandments for C Programmers²: “Thou shalt study thy libraries and strive not to reinvent them without cause, that thy code may be short and readable and thy days pleasant and productive.” Also by Henry Spencer, from How to Steal Code³: “Even widely-available library functions often are not used nearly as much as they should be. A conspicuous example is getopt, for command-line argument parsing. Getopt supplies only quite modest help in parsing the command line, but the standardization and consistency that its use produces is still quite valuable; there are far too many pointless variations in command syntax in the hand-cooked argument parsers in most UNIX programs. Public-domain implementations of getopt have been available for years, and AT&T has published (!) the source for the System V implementation. Yet people continue to write their own argument parsers.” Now, of course, we have argp_parse(), which also comes included in glibc, and is much better than getopt(). 1. https://www.gnu.org/software/libc/manual/html_mono/libc.html#Argp https://www.gnu.org/software/libc/manual/html_mono/libc.html... 2. https://www.lysator.liu.se/c/ten-commandments.html https://www.lysator.liu.se/c/ten-commandments.html 3. https://archive.org/details/inventing-wheel-once https://archive.org/details/inventing-wheel-once
- Arch-TK 5y ago"better" is very subjective. If you just want short options, getopt code is shorter, far more portable and easier to write. Even if you DO want long options, argp is still not portable meaning that unless you only want to support glibc linux, you have to keep a local copy or rewrite or fallback from arpg.
- teddyh 5y agoIf we always limit ourselves to “portable” code, how can we ever progress beyond POSIX?
- Arch-TK 5y agoGenerally it involves writing new code, which can itself be portable and can be reused. I would also note that even POSIX isn't portable in some contexts (such as trying to write code which can run on windows too).