On the afternoon of 4 November a good many administrators added one line to their APT configuration, Acquire::Retries 0;, and then went back to whatever they had been doing. The line came from the security advisory, which suggested it "may mitigate the issue" until the fixed APT arrived. It switches off a feature that had been on by default since APT 2.3.2: when a download fails, try again. Read in the current source, acquire-worker.cc takes the number of attempts from Acquire::Retries and falls back to three.
The advisory, DSA 6607-1, needed only two sentences to explain why trying again had become dangerous. Max Justicz had found that "APT can merge two different package downloads after an HTTP redirect gives them the same URI", and that "Improper file handling when resuming an HTTP download allows a man-in-the-middle attacker to replace a package after verification, resulting in the execution of arbitrary code as root." A malicious mirror or a hostile proxy would do. Every default installation from Debian 12 and Ubuntu 22.04 onwards had the hole open, Ubuntu rated it 7.7, and Debian shipped the fix in APT 3.0.4 for trixie the same day.
A network nobody has to trust
APT's design is older than most of the machines it now runs on, and it was a sound one. Secure APT arrived with APT 0.6 in 2003, Debian moved to it in 2005, and the idea behind it is simple. The archive signs a Release file, the Release file lists the hashes of the package indices, the indices list the hashes of the packages, and so a single signature vouches for everything below it. With that chain in place, the wire itself stops mattering. Debian's own wiki explains, quite openly, why so many addresses in a Debian sources list begin with plain http: "Debian packaging security is designed not to need a secure network."
That is a reasonable bargain. Mirrors are run by volunteers all over the world, and none of them needs to be trusted, because any file a mirror hands over is checked against a hash that only the archive could have signed. The bargain has one condition, which everybody takes as read: the check must be done on the file that is installed, and nothing may come between the two.
The same door, twice
Justicz has been through that door before. In January 2019 he described CVE-2019-3462, and the mechanism is worth a moment. APT does not download files itself. It starts a worker process for each protocol and talks to it over a little text protocol on standard input and output, and when the worker has finished, it reports the file and its hashes back to the parent. The HTTP worker copied the Location header of a redirect into that report without cleaning it, so a server could smuggle a complete, forged "download finished" message into the stream. In his words, "The parent process will trust the hashes returned in the injected 201 URI Done response". He suggested, as a stopgap, running the update with redirects switched off.
Seven years later the details are different and the place is the same. In 2019 the parent trusted hashes it had not computed. In 2026 it computed them correctly and then installed a file that a resumed download had changed afterwards. Both times the signature chain held perfectly well. The attack went round it, through the machinery that moves bytes from the mirror into the cache, which is a bit of a palaver for something whose whole job is to fetch a file.
Where pkg looks
On FreeBSD the package manager is pkg, and its default configuration sits in /etc/pkg/FreeBSD.conf. On FreeBSD 15.1 the first repository reads:
FreeBSD-ports: {
url: "pkg+https://pkg.FreeBSD.org/${ABI}/quarterly",
mirror_type: "srv",
signature_type: "fingerprints",
fingerprints: "/usr/share/keys/pkg",
enabled: yes
}
Two decisions are visible in those lines. The catalogue of the repository is signed, and pkg accepts it only if the signing key matches one of the fingerprints shipped with the base system in /usr/share/keys/pkg; the catalogue carries the SHA-256 sum of every package. And the transport is HTTPS. Baptiste Daroussin switched the default with a commit titled "pkg: use https by default" on 8 June 2023, and it reached the releases with FreeBSD 14.1. FreeBSD 14.0 still fetched over plain HTTP, which is worth knowing if you have an old machine in a cupboard.
The more interesting part is where the hash is checked. In libpkg/repo/binary/fetch.c the package is downloaded into the cache under a name that includes its checksum, and then pkg calls pkg_checksum_validate_file() on that file, reading it from disk and comparing the result with the sum from the signed catalogue. There is no worker reporting a hash on pkg's behalf, and there is no second download merged into the first. If a partial file is resumed, the sum is taken over the whole file afterwards. A stale file in the cache that fails the check is deleted and fetched once more. If a file it has just downloaded does not match, it stops with "failed checksum from repository", and nothing is installed.
None of this is exotic. It is simply the condition from Debian's bargain, written into the code at the one place where it matters, and kept above board by the fact that the file being hashed and the file being installed are the same file.
The limit
APT checks hashes too. The chain of signatures in Debian is sound, and both holes were bugs in the transport, fixed on the day they were announced. The argument here is about where the check sits, and how much code stands between the check and the installation.
pkg has had its own trouble with signatures. In 2014 an erratum noted that only FreeBSD 10.0 had shipped with the official keys and a bootstrap that checked the signature of pkg itself, and in 2015 another found that an unsupported signature_type made the bootstrap behave "as if signature_type is set to "none"". The default configuration was not affected by the second, both were fixed, and in both cases the fault lay in the bootstrap that installs pkg, whilst the check that pkg itself performs was untouched.
TLS is not verification. HTTPS keeps the bytes honest on the way, and it does nothing against a compromised mirror. On pkg, the checksum against the signed catalogue does that work; the TLS default is a second lock on the door.
What a retry costs
Debian chose, sensibly, to make the network irrelevant and the signature everything. The price of that choice is that the code between the signature check and dpkg has to be perfect for every download from every mirror in the world, and twice in seven years it was not. The bill for the second time went to every Debian 12 and Ubuntu 22.04 machine that had kept the default of three attempts, and it was paid on 4 November by administrators typing a zero into a configuration file.
pkg asks for less perfection. It hashes the file it is about to install, and if the file has changed, it refuses.