Supply Chain as Research: the xz-utils Case
Most of this course looks for mistakes: a missing bounds check, a wrong range, a lenient state machine. Supply-chain attacks are different: the "bug" is deliberate, written by someone who had commit or release rights and who worked to make it look normal. Finding such code is still research, with hypotheses, tools and triage, but the signals are different: not crashes, but inconsistencies between what was reviewed and what was shipped, opaque data where code should be readable, and behaviour that doesn't match expectations. The backdoor in xz-utils, discovered in March 2024, is the case study every researcher should know. This lesson treats it as a detection problem; the full incident and the controls are in Real Incidents: event-stream to xz-utils and the rest of Software Supply Chain Security. How the backdoor worked internally is deliberately left out.
What happened, in detection terms
The public facts, summarised from the supply-chain course: a co-maintainer, active for about two years, released xz-utils 5.6.0 and 5.6.1 in early 2024. Opaque binary files committed as "test files" carried the payload; a build macro (build-to-host.m4) that existed only in the release tarballs, not in the Git repository, extracted it during the build of distribution packages. It targeted sshd on some Linux distributions through liblzma. Andres Freund noticed that SSH logins on Debian unstable (sid) systems used unexpectedly much CPU and that liblzma caused Valgrind errors, investigated, and reported it on 29 March 2024 (CVE-2024-3094). It was caught in unstable and testing distributions before reaching most stable releases.
Each phrase of that summary is a detection signal:
| Signal | What a researcher or a pipeline could check |
|---|---|
| tarball differs from the tag | rebuild the release from the tag and compare; every file outside the known generated set is suspicious |
| opaque "test data" | binary files with no generator, high entropy, unclear purpose, added by a new contributor |
| the build reads test data | build scripts have no business decoding test fixtures |
| performance and sanitizer anomalies | a library update that makes logins slower and makes Valgrind complain deserves a root-cause analysis |
| social pattern | pressure on a lone maintainer to hand over release rights, new accounts arguing for it |
Three checks on a toy release
The example builds a toy project's Git tag and its release tarball (harmless placeholder contents; the shape copies the case). It runs the three mechanical checks: diff the tarball against the tag (allowing only the files autotools generates), measure the entropy of test files, and search build scripts for references to test data. It runs in your browser:
import hashlib, math, random
from collections import Counter
# A toy project "labzip" (not real code). The git tag and the release tarball should match,
# apart from files the release process generates. All contents are harmless placeholders.
rng = random.Random(2024)
noise = bytes(rng.randrange(256) for _ in range(4096)) # stands in for an opaque blob
tag = {
"src/decode.c": b"int decode(const unsigned char *p, int n) { /* ... */ return 0; }\n",
"configure.ac": b"AC_INIT([labzip], [5.6.1])\nm4_include([m4/build-to-host.m4])\n",
"m4/build-to-host.m4": b"dnl helper macros for build paths\nAC_DEFUN([LAB_BUILD_PATHS], [...])\n",
"tests/files/good-1.lz": b"LZ\x01\x00" + b"hello" * 20,
"tests/files/bad-header.lz": b"LZ\xff\x00" + b"x" * 40,
"tests/files/bad-blob.lz": b"LZ\x02\x00" + noise, # committed as a "corrupt test file"
}
tarball = dict(tag)
tarball["configure"] = b"#! /bin/sh\n# generated by autoconf\n" # expected: generated
tarball["Makefile.in"] = b"# generated by automake\n" # expected: generated
tarball["m4/build-to-host.m4"] += b"dnl ...\n gl_extract=`cat tests/files/bad-blob.lz | tr ...`\n"
GENERATED = {"configure", "Makefile.in"} # what autotools makes
def entropy(data):
c = Counter(data)
return -sum(n / len(data) * math.log2(n / len(data)) for n in c.values())
h = lambda b: hashlib.sha256(b).hexdigest()[:12]
print("tarball vs tag:")
for path in sorted(set(tag) | set(tarball)):
if path not in tag:
kind = "generated (expected)" if path in GENERATED else "ONLY IN TARBALL"
print(f" {path:<26} {kind}")
elif h(tag[path]) != h(tarball.get(path, b"")):
print(f" {path:<26} DIFFERS from the tag ({h(tag[path])} vs {h(tarball[path])})")
print("test files:")
for path in sorted(p for p in tarball if p.startswith("tests/")):
e = entropy(tarball[path])
print(f" {path:<26} {len(tarball[path]):5d} bytes, entropy {e:.2f} bits/byte{' <-- opaque' if e > 7.5 else ''}")
print("build scripts that read test data:")
for path, data in sorted(tarball.items()):
if path.endswith((".m4", ".ac", ".am")) and b"tests/" in data:
print(f" {path}: reads {data[data.index(b'tests/'):].split()[0].decode()}")tarball vs tag:
Makefile.in generated (expected)
configure generated (expected)
m4/build-to-host.m4 DIFFERS from the tag (8bb124928f4b vs fc5a06e856cb)
test files:
tests/files/bad-blob.lz 4100 bytes, entropy 7.96 bits/byte <-- opaque
tests/files/bad-header.lz 44 bytes, entropy 0.62 bits/byte
tests/files/good-1.lz 104 bytes, entropy 2.16 bits/byte
build scripts that read test data:
m4/build-to-host.m4: reads tests/files/bad-blob.lz
- The two generated files are expected. The one real difference is a build macro that changed between tag and tarball: reviewing the repository would never show it.
- One test file has an entropy of 7.96 bits per byte, the signature of compressed or encrypted data (entropy profiles), while the other fixtures are small and readable. On its own, a high-entropy test file is normal for a compression library; together with the next line it is not.
- The modified macro reads that test file during the build.
No single check proves malice; together they produce a hypothesis worth a careful human review, which is exactly how the real case unfolded, starting from a performance anomaly.
How such attacks are detected at scale
- Reproducible builds and tarball verification: distributions and rebuilders compare release artefacts with what the tagged source produces (Reproducible Builds); some build directly from the Git tag instead of maintainer tarballs.
- Provenance that records which source commit and which build produced an artefact, so "built from this tag" is checkable (SLSA).
- Review of binary and generated files, with policies that test fixtures come with the script that generated them.
- Behavioural monitoring and profiling: unexplained changes in CPU time, new symbols resolved at load time, sanitizer and Valgrind runs on updates of core libraries.
- Maintainer-level signals: changes in release managers, new signing keys, CI changes that disable checks (fuzzing and sanitizer jobs being turned off is a red flag).
How the risk is reduced
Support maintainers (funding, co-maintainers vetted over time, shared release duties), require two-person review for release-process changes, generate release artefacts in CI from the tag with provenance, and consume dependencies by digest with SBOMs so that "where is liblzma 5.6.1 installed?" takes minutes to answer. When a case like this appears, the response is an emergency advisory, downgrades or rebuilds, and an audit of everything the person touched.
Ethics of supply-chain research
Researching the supply chain must never become an attack on it. Publishing a test package to a public registry "to see if anyone installs it", or submitting deliberately flawed patches to a project to measure its review, affects real people and real maintainers who did not consent; universities and registries have reacted strongly to such experiments. Study your own packages and mirrors, analyse public artefacts offline, and coordinate with registries and projects before any experiment that touches their users.
Pitfalls
- Reviewing the repository and shipping the tarball. The two can differ; check what you build.
- Ignoring "just a performance regression". The xz backdoor was found because someone did not.
- Treating signed releases as reviewed. The xz releases were signed by their release manager; signatures prove who, not what.
- Accusing on statistics. High entropy and a changed macro justify a careful, private investigation and a report to the distribution's security team, not a public accusation.
Practice
1. Add a fourth check: files in the tarball whose timestamps or authorship changed with a new release manager. Why is it weaker than the diff?
Metadata is easy to fake and naturally noisy (many legitimate changes). The tag-tarball diff is mechanical and has almost no false positives once the generated files are listed.
2. A compression library legitimately ships high-entropy test files. How do you keep the entropy check useful?
Require every binary fixture to have a generator script or a documented origin in the repository, regenerate them in CI and compare; flag only fixtures without one. Combine with the build-reads-test-data check, which is unusual in any project.
3. Why did building from the Git tag (instead of the tarball) avoid the backdoor's activation step?
The modified build-to-host.m4 existed only in the tarball; the Git repository did not contain that file at all. A build from the tag regenerates the build system with the standard macro (from gnulib, via autoreconf), which does not extract the payload. (In the toy, the tag has a harmless version of the macro so that the diff has something to compare.)
Test yourself
Which check would have exposed the activation step of the xz-utils backdoor mechanically?
- Scanning for CVEs
- Comparing the release tarball with the tagged Git source
- Checking the signature
- Counting downloads
How was the backdoor actually noticed?
- By an antivirus
- A developer investigated unexpected CPU use in SSH logins and Valgrind errors
- By a CVE scanner
- By the attacker's mistake in a commit message
Why is 'the release was signed' not enough?
- Signatures can be forged easily
- A signature proves who released it, not that the contents are what was reviewed
- Signatures expire
- Distributions ignore signatures