archive / 2024

xz, or: who actually maintains the foundations?

On Friday it turned out that xz-utils 5.6.0 and 5.6.1 contained a backdoor that, on some distributions, reached sshd. What happened, what I checked on my own machines, and what it says about how we treat open source.

It’s Easter, I should be eating chocolate, and instead I’m reading analyses of a piece of obfuscated shellcode for the third day in a row. Allez.

For anyone who missed it: on Friday, March 29th, a developer reported on the oss-security mailing list that releases 5.6.0 and 5.6.1 of xz-utils contained a backdoor. It now has a CVE number (CVE-2024-3094) and the maximum score of 10. The discovery was, as far as we know right now, almost accidental.

What happened#

A short summary, with the caveat that the analysis is still very much ongoing and details may change:

  • xz-utils is the compression tool and library (liblzma) behind the .xz format. It’s on pretty much every Linux system, because packages, kernels and tarballs get compressed with it.
  • The release tarballs of 5.6.0 (late February) and 5.6.1 (early March) contained a modified build script. During the build, it extracted malicious code from two “test files” (binary blobs that were supposedly broken and valid xz archives) and compiled it into liblzma. That build script wasn’t in the git repository. If you only read the code in git, you saw nothing.
  • The backdoor only activated under specific conditions: x86-64, Linux, glibc, and a build through the Debian or RPM packaging tooling.
  • The target was sshd. OpenSSH itself doesn’t use liblzma. But several distributions patch sshd to use libsystemd (for sd_notify), and libsystemd in turn loads liblzma. Through that detour the malicious code could nest itself in the sshd process and intercept RSA key verification. According to early analyses, whoever held the right private key could execute code on the server before any authentication took place.

Mostly rolling releases and testing versions were affected: Debian testing and unstable, Fedora Rawhide and the Fedora 40 beta, openSUSE Tumbleweed, Kali. Stable releases of Debian, Ubuntu and RHEL hadn’t picked up the new version yet. That was luck, not design. A few more weeks and this would have ended up in releases running on millions of servers.

How it was found#

A developer at Microsoft, doing performance work on PostgreSQL, noticed that SSH logins on his Debian test machine used a suspicious amount of CPU and were about half a second slower than expected. Valgrind was also throwing odd errors. Instead of shrugging it off, he started digging.

Half a second. I don’t know about you, but I’ve thought “hm, that’s weirdly slow” hundreds of times in my career and then got on with my day. The entire internet was saved this week by someone who didn’t.

What I checked myself#

My homelab runs Debian 12 stable, which was still on 5.4.1. Nothing to worry about. My laptop runs Debian testing, and that one did have an affected version:

$ xz --version
xz (XZ Utils) 5.6.0
liblzma 5.6.0

Luckily there’s no sshd on my laptop listening to the outside world. I updated immediately anyway. Debian shipped a package that is actually 5.4.5, with a version number higher than 5.6.1 so apt sees it as an upgrade:

$ sudo apt update && sudo apt install --only-upgrade xz-utils liblzma5
$ apt policy liblzma5 | head -3
liblzma5:
  Installed: 5.6.1+really5.4.5-1
  Candidate: 5.6.1+really5.4.5-1

+really5.4.5. There’s a certain desperation in that version string that I can appreciate.

I also asked my clients whether they use testing or rolling images anywhere in their build pipelines or containers. One of them did, in a CI image based on debian:testing. No sshd in it, so no direct risk, but a good moment to ask why a CI image runs on testing. (The answer was “someone set it up that way once”. The answer is always “someone set it up that way once”.)

The real story: the maintainer#

The technical part is fascinating, but the part that really stays with me is the human one.

For years, xz was maintained by essentially one person, in his spare time. From around 2021 a contributor under the name “Jia Tan” started contributing: small, useful patches at first, then more. At the same time, accounts showed up on the mailing list putting pressure on the original maintainer: why is this so slow, why aren’t patches merged, you should really bring someone else on board. The maintainer had said himself that he had limited time and energy. Eventually Jia Tan got more permissions, and eventually the ability to cut releases.

That’s not a hack in the classic sense. That’s an operation spanning years, with patience and social engineering, aimed at an exhausted volunteer. We don’t know who’s behind it. The patience and the technical sophistication make a lot of people suspect it wasn’t a hobbyist.

It reminds me of Heartbleed in 2014, when it turned out that OpenSSL, the basis of pretty much all encryption on the internet, ran on a handful of people and a ridiculously small budget. Ten years later we apparently haven’t come very far.

What I’m taking away from this#

  • Release tarballs are not the same as the git repo. I’ll look differently at projects that ship tarballs with generated build files. Reproducible builds aren’t an academic hobby.
  • Transitive dependencies are dependencies too. OpenSSH doesn’t use xz. And yet.
  • Weird slowness is a signal. I’m going to try to dig a bit more often instead of clicking it away.
  • “Get another maintainer” isn’t always good advice. I’ve written on an issue before that a project “clearly needed an extra maintainer”. I won’t do that again without knowing who that person would be.
  • Pay for your foundations. I’m a freelancer, not a big company. But this year I’m using part of my training budget to sponsor a few projects my work runs on. Small, but it’s something. Companies making millions off this stuff can easily add a zero.

Someone once summed it up in a comic everyone knows: all of modern digital infrastructure, resting on one tiny block that some random person in Nebraska has been thanklessly maintaining since 2003. This week we saw what happens when someone deliberately comes to pull that block out.

    Tip: / opens search, ↑↓ to select, ↵ to open.