** Description changed: [ Impact ] - Resolute ships apt (3.2.0 in the release pocket, 3.2.1ubuntu0.1 in - resolute-updates) which uses OpenSSL for both hashing and TLS. There are - defects in how apt uses OpenSSL for hashing: + Resolute (3.2.0 in the release pocket, 3.2.1ubuntu0.1 in resolute- + updates) and Stonking (3.3.3ubuntu0.1 in stonking-updates) ship apt + which uses OpenSSL for both hashing and TLS. There are defects in how + apt uses OpenSSL for hashing: 1. apt ignores the return values of the OpenSSL calls it makes for hashing so a failed call goes unnoticed and data is reported as hashed when it is not. For the user this shows up as a "Hash Sum mismatch" which says nothing about hashing failures. OpenSSL's own software implementation does not fail these calls, but another provider can. Additionally, a failed call leaves an error on OpenSSL's error stack, and a single stack is shared between libcrypto and libssl per thread. apt does not remove it, so the next TLS read that only has to wait for data is taken for a failure. A working HTTPS download is then aborted and retried, with the hashing error reported as a TLS read error. Fix: https://salsa.debian.org/apt-team/apt/-/commit/7d5a2b59b6f0f3472b79ae017fdb820ea7215de9 2. When OpenSSL cannot provide any of the hash algorithms a repository publishes, apt compares the download on file size alone and accepts it as verified. This needs an OpenSSL configuration in which those algorithms are unavailable, so an attacker cannot cause it directly. Fix: https://salsa.debian.org/apt-team/apt/-/commit/2692004ad93997b4a06a2c40675d7b9737e29a38 With these fixes, a failed call is correctly reported through apt's error system, the errors it pushed on the error stack are removed so they cannot resurface later on, digests that were not computed are not handed out, and a download with no usable hash is rejected. [ Test Plan ] Steps 2 to 4 need an OpenSSL digest call to fail, and OpenSSL's own provider never fails one. faildigest.c, attached to this bug, is an LD_PRELOAD library written for it. It makes one EVP call (EVP_DigestUpdate, EVP_MD_CTX_copy or EVP_DigestFinal_ex) fail for SHA256 and leaves a record on the OpenSSL error stack as a failing provider would. By default only the first such call fails; APT_FAIL_NTH=0 makes every one fail. Step 5 instead makes every hash algorithm unavailable, using OpenSSL's null provider. Commands inside the container run as root. - Reproduce the bug: 1. Set up a resolute container with the apt version in resolute-updates: a) On the host, from the directory holding faildigest.c: lxc launch ubuntu:26.04 apt-sru lxc file push faildigest.c apt-sru/root/ lxc exec apt-sru -- bash Every command from here on runs inside the container: cd /root b) Install the build tools, the test package and the current apt, and build the library: apt update apt install -y build-essential libssl-dev openssl ca-certificates apt apt-utils hello gcc -shared -fPIC -O2 -o /usr/local/lib/faildigest.so faildigest.c -ldl c) Check that the installed apt is the version in resolute-updates, 3.2.1ubuntu0.1 at the time of writing: apt-cache policy apt d) Write an OpenSSL config that activates only the null provider, so no digest is available at all: printf '%s\n' 'openssl_conf = openssl_init' '[openssl_init]' 'providers = provider_sect' '[provider_sect]' 'null = null_sect' '[null_sect]' 'activate = 1' > /etc/ssl/null.cnf e) Create a test input: printf abc > /tmp/abc 2. Observe that apt prints a wrong hash for a local file, with no error, when a hashing call fails. "apt-helper hash-file" is a small tool shipped with apt. It reads a file and prints its MD5, SHA1, SHA256 and SHA512 hash values using the same libapt-pkg code that uses OpenSSL to verify downloads. For each hash, there are three OpenSSL calls that can be made: - update (EVP_DigestUpdate) adds a block of the file's data to the hash being computed. - copy (EVP_MD_CTX_copy) duplicates the hash state, so the result can be read without ending the hash in progress. - final (EVP_DigestFinal_ex) turns that copy into the digest. In a) view these calls working, then in b) force the hash to fail with the preload library, and notice that the return value is not checked - an incorrect hash is given with no warnings or errors. a) Hash /tmp/abc with nothing failing: /usr/lib/apt/apt-helper hash-file /tmp/abc; echo rc=$? Assert rc=0 and the correct SHA256 line for "abc": SHA256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad b) Now force the hashing to fail for SHA256 using the preload library. The loop below hashes /tmp/abc three times, once per OpenSSL call. Each time the preload library makes a different call fail for SHA256 and prints "faildigest: failing EVP ... for SHA256" when it does. On apt 3.2.1ubuntu0.1 the return value is not checked and the error is not handled, so a full list of hashes is still printed. For update, the hash of empty input is printed, as the data was never added to the hash. For final and copy the SHA256 value changes between runs as the digest was never written, so apt prints whatever was in memory. for m in update final copy; do LD_PRELOAD=/usr/local/lib/faildigest.so APT_FAIL_DIGEST=$m /usr/lib/apt/apt-helper hash-file /tmp/abc; echo rc=$? done Assert for each of the three runs: - rc=0. - The MD5Sum, SHA1, SHA512 and Checksum-FileSize lines are the same as in a). - The SHA256 line is wrong. With update failing it is the hash of the empty string: SHA256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 With final or copy failing it is some other value, which changes if the run is repeated. 3. Observe that apt reports a failed hashing call as a TLS error during an HTTPS download. When apt downloads over HTTPS, a single process uses OpenSSL for both TLS and hashing the data as it arrives, with OpenSSL recording errors on a single error stack per thread. apt 3.2.1ubuntu0.1 does not check a hash call's return value, so it does not report errors or handle the error stack. A subsequent TLS read finds the error still there and reports it as its own failure. apt treats a TLS read error as temporary and retries the download. In a) observe a correct download, then contrast to the failure in b). a) Switch the sources to https and download a package with nothing failing: sed -i 's#http://#https://#' /etc/apt/sources.list.d/ubuntu.sources apt update; cd /tmp; rm -f hello_*.deb apt download hello; echo rc=$? Assert a "Get:1 https://... hello" line, rc=0 and the file hello_*.deb in /tmp. b) Now force the hashing to fail for SHA256 using the preload library. The download itself still works, as TLS is not affected. Only the SHA256 hashing fails. The preload library prints a "faildigest: failing EVP update for SHA256" line each time it makes a call fail - these lines are not apt output. However apt 3.2.1ubuntu0.1 reports "Error reading from server" as the unchecked hashing error is left on OpenSSL's error stack, and the next TLS read picks it up as its own. apt treats a read error as temporary, prints "Ign:1" and retries up to three times, each time continuing from the part of the file it already has. Once the file is complete, apt compares its hashes with the expected ones and reports "Hash Sum mismatch": the SHA256 is the hash of the empty string, as no data was ever added to it. rm -f hello_*.deb LD_PRELOAD=/usr/local/lib/faildigest.so APT_FAIL_DIGEST=update APT_FAIL_NTH=0 apt download hello; echo rc=$? Assert: - rc=100. - One or more "Ign:1 https://... hello" lines, usually two or three, one per retry. The number of lines depends on how much of the file arrives in each attempt. - An "Err:1" line followed by "OpenSSL error: error:030C0103:digital envelope routines::internal error Error reading from server - read (5: Input/output error)". This is the hashing error reported as a TLS read error. - "Hash Sum mismatch". Observe that under "Hashes of received file" the SHA512, SHA1, MD5Sum and Filesize match the expected ones, and the SHA256 is the hash of the empty string: SHA256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 - A last line "Error: Failed to fetch https://... Hash Sum mismatch". 4. Observe that apt-ftparchive writes a wrong hash into a Packages file, with no error, when a hashing call fails. apt-ftparchive builds an apt repository and runs on the server side, not on clients. For each package it writes an entry into the repository's Packages file, with the package's size and hashes. Clients download the Packages file and use those hashes to verify every package they fetch. A wrong hash written by the server is published to every client, and each of them will reject a good package with "Hash Sum mismatch". a) Put a package into a new repository directory and generate its entry with nothing failing. The grep keeps only the SHA256 and SHA512 lines of the entry: mkdir -p /tmp/repo/pool; cd /tmp; rm -f hello_*.deb; apt download hello mv hello_*.deb /tmp/repo/pool/; cd /tmp/repo sha256sum pool/hello_*.deb apt-ftparchive packages pool | grep -E '^(SHA256|SHA512):' Assert that the SHA256 line has the same value as sha256sum printed. For hello 2.10-5build1 the two lines are: SHA256: b6e9bef3c865aa17757cd9ffa820c05a37833f8a6b58287afc9f32dedb345965 SHA512: ffd586fe981aec819ebd848f11640c1a9b9740a1b57231509bbef25b28a65a813d4e6a066df91b393d3cb911766084349729588ca247728f997468a931161548 b) Force the hashing to fail for SHA256 using the preload library. Generate the entry again with every SHA256 final call failing. Recall that the preload library prints a "faildigest: failing EVP final for SHA256" line when it makes the call fail, this line is not apt- ftparchive output. apt-ftparchive 3.2.1ubuntu0.1 does not check the return value, so it writes a SHA256 line anyway and reports no error. cd /tmp/repo LD_PRELOAD=/usr/local/lib/faildigest.so APT_FAIL_DIGEST=final APT_FAIL_NTH=0 apt-ftparchive packages pool | grep -E '^(SHA256|SHA512):' Assert: - The SHA512 line is the same as in a). Only SHA256 was made to fail. - The SHA256 line is not the one from a). It is not the hash of anything, the digest was never written, so apt-ftparchive prints whatever was in memory, and the value changes between runs. - apt-ftparchive prints no error. Nothing tells the repository's publisher that the SHA256 it is about to publish is wrong. 5. Observe that apt accepts a download on its file size alone when no hash can be computed. If all of OpenSSL's hash algorithms are unavailable, apt 3.2.1ubuntu0.1 compares only the file size and accepts a match as verified. This needs the machine's own OpenSSL to refuse the algorithms, for example a provider configuration without the default provider, as used here. An attacker cannot cause that directly. It is still wrong, a size-only match must never count as a verified download. Use http for this step, as HTTPS needs the same algorithms. sed -i 's#https://#http://#' /etc/apt/sources.list.d/ubuntu.sources apt update apt clean; cd /tmp; rm -f hello_*.deb OPENSSL_CONF=/etc/ssl/null.cnf apt download hello; echo rc=$? Assert a "Get:1 http://... hello" line, no error and rc=0. The file was accepted with no hash computed for it. - Test the fix: 1. In the same container, enable resolute-proposed and install the fixed version: printf '%s\n' 'Types: deb' 'URIs: http://archive.ubuntu.com/ubuntu' 'Suites: resolute-proposed' 'Components: main universe' 'Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg' > /etc/apt/sources.list.d/proposed.sources apt update apt install -y -t resolute-proposed apt libapt-pkg7.0 apt-utils apt-cache policy apt Assert the installed version is the one from resolute-proposed, expected to be 3.2.2. 2. Repeat step 2 of "Reproduce the bug". Assert that a) prints the same correct output as before. Assert that in b) all three runs print "E: Computing the SHA256 hash failed: internal error" and rc=100. For update nothing else is printed. For final and copy the other hashes are printed and the SHA256 line is omitted. 3. Repeat step 3 of "Reproduce the bug". Assert that a) downloads the package as before. Assert that b) prints "Err:1" followed by "Computing the SHA256 hash failed: internal error". This will be repeated once per failed call, with no "OpenSSL error" line, no "Ign:" retries, and rc=100. 4. Repeat step 4 of "Reproduce the bug". Assert that a) prints the same two lines as before. Assert that b) prints the same SHA512 line, no SHA256 line, and the errors "E: Computing the SHA256 hash failed: internal error" and "E: Errors apply to file 'pool/hello_...deb'". 5. Repeat step 5 of "Reproduce the bug". Assert "Err:1" followed by "Insufficient information available to perform this download securely", a last line "Error: Failed to fetch ...", and rc=100. 6. Check that normal use still works with the fix, with nothing made to fail. Every download apt makes goes through the changed hashing code, so update the package lists and reinstall a package, first over http and then over HTTPS: apt update && apt install -y --reinstall hello sed -i 's#http://#https://#' /etc/apt/sources.list.d/ubuntu.sources apt update && apt install -y --reinstall hello sed -i 's#https://#http://#' /etc/apt/sources.list.d/ubuntu.sources Assert that both updates and both installs finish with no error. Verified on 2026-11-05 in a fresh LXD resolute container: apt 3.2.1ubuntu0.1 shows every result under "Reproduce the bug", and a build of the merge request against 3.2.y shows every result under "Test the fix": https://salsa.debian.org/apt-team/apt/-/merge_requests/647 + For stonking, repeat both parts in a stonking container (lxc launch + ubuntu:26.10 apt-sru-stonking), using stonking-proposed in "Test the + fix". One step differs: the stonking archive publishes only SHA512 for + packages, so in step 3b add APT_FAIL_ALGO=SHA512 to the command. apt + 3.3.3ubuntu0.1 then reports "Hash Sum mismatch" with no "Ign:1" or + "OpenSSL error" lines, and the fixed version reports "Computing the + SHA512 hash failed: internal error". + + Verified on 2026-11-09 in a fresh LXD stonking container. Merge request: + https://salsa.debian.org/apt-team/apt/-/merge_requests/649 + [ Where problems could occur ] These fixes change how libapt-pkg computes hashes and when apt accepts a download as verified. apt computes hashes for every file it downloads or verifies, so a mistake here would affect normal use and not only the failure cases: - With OpenSSL's default provider, apt could wrongly treat a hash as failed to compute. apt update and apt install would then fail with "Computing the ... hash failed", "Hash Sum mismatch" or "Insufficient information available to perform this download securely". This should not happen: the unit and integration tests that come with the fixes guard against it, and the Test Plan above checks that hashing and downloads work when nothing is made to fail. - OpenSSL has a single error stack, shared between TLS and hashing. Hashing now removes the errors it puts there, but an untested code path could still leave one behind. The worst case is what step 3 of "Reproduce the bug" shows on apt 3.2.1ubuntu0.1: an HTTPS download that reports a misleading OpenSSL error and is retried or fails. Some intended changes will look like regressions on systems whose OpenSSL provider can fail or refuse a hash algorithm, such as FIPS configurations and hardware-backed or third-party providers: - A client that cannot compute any of the strong hashes a repository publishes could install from it before, unverified. It is now refused with "Insufficient information available to perform this download securely" until its OpenSSL configuration is fixed. - "apt-helper hash-file" now reports an error and exits non-zero, where it printed a wrong hash before. apt-ftparchive now reports an error and leaves out the affected hash, or the whole package entry if its data could not be hashed. Its exit status is still 0, so a script that builds a repository only notices if it checks the error output. [ Other Info ] - The merge request (https://salsa.debian.org/apt- - team/apt/-/merge_requests/647) against apt's 3.2.y branch carries five - commits, each cherry-picked from apt main: + Two merge requests, one for resolute branch and one for stonking: + + The resolute one carries both sets of fixes below. The stonking one + carries only the second, as stonking already has the first. + + https://salsa.debian.org/apt-team/apt/-/merge_requests/647 + https://salsa.debian.org/apt-team/apt/-/merge_requests/649 - The two fixes named in LP: #2171346 (d714c12f4, dfeecf7f5) and a related integration test (489e6ba73). - The two fixes for this bug, "Reject downloads whose hash cannot be computed" (2692004ad) and "Report OpenSSL failures while hashing" (7d5a2b59b).
-- You received this bug notification because you are a member of Ubuntu Bugs, which is subscribed to Ubuntu. https://bugs.launchpad.net/bugs/2172252 Title: [SRU] apt mishandles OpenSSL hashing failures: downloads verified on size alone, silent partial hashes, stale OpenSSL errors To manage notifications about this bug go to: https://bugs.launchpad.net/ubuntu/+source/apt/+bug/2172252/+subscriptions -- ubuntu-bugs mailing list [email protected] https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs
