blog.rust.gay

GPGME's double free waited for another bug's deadline

GPGME 2.3.1 was released on November 19 and announced the next day. It fixes CVE-2026-129975, a double free that a crafted OpenPGP key can trigger with a user ID of unusual length. The advisory is short, the patch is small, and the interesting part is everything around it: why the bug survived, who ships the library, and why the disclosure date moved because of a different project's bug.

The timing is not a detail. GnuPG had set November 25 for coordinated disclosure. GitLab, which reported the issue, moved its own disclosure earlier because of Ruby2Shell, so GnuPG published on November 20. A bug in Ruby changed the calendar for a bug in GnuPG. That is how coordinated disclosure actually works: it is a schedule negotiated across projects, not a property of the vulnerability.

The 1,024-byte buffer and the early return

The root cause sits in two internal functions that read status lines and key listings from gpg. Both allocate a 1,024-byte buffer and reallocate it when more space is needed. The function uses the pointer to the new buffer, but assigns it back to the context object only at the end.

That ordering is the bug. If the function returns early because of a read error or another event, the context still holds the old pointer. The old buffer has already been freed by the reallocation, so the context is pointing at freed memory. When the context is released, the library frees that memory a second time.

A double free is not automatically exploitable. The useful question is what happens between the two frees. If the allocator reuses the freed block for attacker-influenced data, the second free can corrupt allocator metadata or produce a write primitive. The advisory says the double free can be used to exfiltrate data from applications, for example by sending signed data, and that remote code execution cannot be ruled out. It does not claim a reliable exploit chain, and it does not need to. The fix is cheap enough that the uncertainty should not be carried.

The trigger is a crafted OpenPGP key with a very long user ID. That is a useful reminder that parsers for attacker-supplied keys are part of the attack surface even when the cryptographic math is sound. The bug is not in the signature verification. It is in the code that reads the text gpg produces about a key.

Why the allocator may not catch it

Textbook double-free detection assumes the two frees happen close together. Allocators often keep a flag or a free-list check that notices a block being freed twice. If another allocation claims the block in between, the second free looks like a legitimate free of a different object. The check can pass while the state is already wrong.

The advisory says exactly this: allocations between the two frees can prevent the common double-free checks from firing. That makes the bug harder to catch in testing and harder to classify from a crash report. A test that frees a context immediately after a failed read may reproduce a clean abort. A real application that does other work in between may corrupt memory quietly.

This is also why the fix is about ownership rather than about adding a null check. The function needs to update the context's pointer as soon as the reallocation succeeds, so an early return cannot leave a stale reference behind. The advisory attaches a patch for older versions, which suggests the change is small enough to backport.

The blast radius is an inventory problem

All software using GPGME before 2.3.0 is affected, whether the library is shared, a DLL, or statically linked. Version 2.3.0 was never publicly released, so the practical boundary is 2.2.0 and earlier.

The list of affected software is the point. GPGME is the glue between applications and gpg, so it shows up in places that do not advertise a cryptography dependency: Gpg4win, GnuPG Desktop, GnuPG VS-Desktop, most mail clients, many XMPP clients, Samba, and Flatpak. The advisory does not enumerate versions for each. It does not need to. If the application links GPGME, it inherited the bug.

Shared-library updates are the easy case. A distribution ships a new package, the dynamic linker picks it up, and the application is fixed after a restart. DLLs on Windows are a separate distribution channel. Statically linked binaries are the hard case: the vulnerable code is inside the executable, so updating the system library does nothing. Those binaries must be rebuilt against 2.3.1. A container image built from an older base image has the same problem, even if the host is patched.

That is why the advisory calls for an immediate update rather than a workaround. There is no configuration flag that turns off the affected path for every application. The only reliable fix is to replace the library or rebuild the binary.

The static-linking gap

Static linking turns a library bug into a build artifact. A package manager can replace a shared libgpgme.so, but it cannot reach into an executable that copied the vulnerable functions at link time. The same is true of a container image that was built months ago and then promoted by digest, or a Windows installer that bundles its own DLL.

The practical consequence is that two hosts can run the same application version and have different exposure. One links the system library and picks up the fixed package. The other ships a static build and stays vulnerable until the vendor rebuilds it. Version numbers on the application do not distinguish the two.

An SBOM helps with the inventory, but only if it records link mode and not just a package name. A component entry that says "gpgme 2.2.0" is a start; the useful entry says whether that copy is shared or embedded, and which binary contains it. Without that, the rebuild list is a guess.

The same gap applies to language bindings. GPGMEPP and GPGMEQT do not need updates, according to the advisory, which narrows the search. But an application that wraps GPGME through its own FFI layer may still embed the C library. The question to ask is not "do we use GPGME directly" but "which binaries contain the affected functions."

Disclosure is a schedule, not a risk score

The timeline is worth reconstructing because it shows how little control a project has over its own disclosure date. Johan Carlsson discovered the bug. GitLab informed the GnuPG project on November 12. The project set November 25 for coordinated disclosure. Then GitLab moved its own disclosure earlier because of Ruby2Shell, and GnuPG moved with it, publishing on November 20.

Ruby2Shell is a different vulnerability in a different project. It has nothing to do with GPGME's buffer handling. But coordinated disclosure is a system of interlocking embargoes. When one party decides that a bug is being exploited or that a fix can no longer wait, adjacent projects often move too, because the alternative is a fragmentary release where users hear about one bug and not the other.

The cost of moving earlier is that downstream consumers have less time to prepare. The cost of moving later is that the embargo may break anyway. Neither cost is visible in a CVSS score. This is why "severity" and "urgency" are different words. The GPGME bug is serious because of what the library touches, but the date was set by operational coordination, not by a calculated exploit timeline.

There is also a practical asymmetry in coordinated disclosure: the project that discovers the bug controls the technical details, but the project that ships the affected library controls the patch. When those are different organizations, the date is a negotiation. GitLab had its own reason to move. GnuPG could have held the line and disclosed later, but that would have left users hearing about a Ruby bug while a GnuPG fix sat unreleased. Moving with the adjacent disclosure was the lesser evil.

What to do

Update GPGME to 2.3.1. For a shared library, that means the distribution package. For a DLL, take it from Gpg4win 5.1.2, which includes the fixed library. For a statically linked binary, rebuild against 2.3.1. If an application cannot be rebuilt yet, the advisory's patch can be applied to older versions, but that is a stopgap, not a destination.

Then widen the inventory. The advisory says GPGMEPP and GPGMEQT do not need updates, which is useful because it narrows the search. But it also says most mail clients and many XMPP clients use GPGME, and those are exactly the applications that tend to be installed outside a central package manager. Check the applications that bundle their own libraries, the Windows installers, the Flatpak runtimes, and the container images that ship a crypto stack.

The advisory also notes that 2.3.1 adds post-quantum algorithm constants: GPGME_PK_MLKEM, GPGME_PK_MLDSA and GPGME_PK_DLTHM. That is a useful marker. If a build reports 2.3.1, it has the fix and the new constants. If it reports 2.2.0 or earlier, it does not. If it reports 2.3.0, that version was never public, so the report is suspect.

Conclusion

A library double free is usually treated as a packaging problem: ship the new version, tell users to update, move on. The GPGME case shows why that is incomplete. The fix is a small ownership change. The distribution is mail clients, Samba, Flatpak, Windows installers and static builds, each with its own update path.

The other lesson is about disclosure coupling. A bug in Ruby moved the date for a bug in GnuPG. That is not a failure of process. It is the process working under pressure. The practical takeaway for operators is to treat disclosure dates as coordination signals, not as risk assessments, and to keep an inventory of the libraries that never show up in the application's own dependency list.

GPGME is exactly that kind of dependency: quiet, widely linked, and easy to forget. The patch is available. The inventory is the hard part.

Sources


← back to posts