Repository navigation
fix(tpm2): bound allocations and loops driven by TPM responses - #1481
Merged
Merged
Conversation
kvinwang
force-pushed
the
fix/tpm-count-alloc
branch
from
October 23, 2026 05:19
fced1c4 to
1205352
Compare
Signed-off-by: Kevin Wang <wy721@qq.com>
…nv_read Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang
force-pushed
the
fix/tpm-count-alloc
branch
from
October 23, 2026 05:27
1205352 to
143fe9b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Follow-up to #1477; same input (a host-controlled vTPM), same impact (the guest aborts or stalls during boot):
TpmlPcrSelectionandTpmlDigestunmarshal callVec::with_capacity(count)with the TPM-supplied u32 count, andadd_command_capabilitydoes the same withcount + 1.count = 0xFFFFFFFFin a 4-byte buffer asks for ~100 GB before the first element fails to parse; the pcr_read paths reach this in the guest.get_randomloops until it hasnum_bytes; a TPM that keeps answering with an empty TPM2B makes it spin forever.get_handlesresumes atlast_seen + 1; a TPM that answersmore_datawith a handle below the requestedpropertysends it back to the same range forever.nv_readdoes not truncate to the NV index'sdata_size(its siblingnv_read_with_authdoes), so oversized chunks are returned as-is.Fix
count.min(buf.remaining()),/ 4for u32 attributes). Every entry consumes bytes, so a larger count fails with the existing underflow error.get_randombails on an empty response.get_handlesbails when the TPM's last handle is below the requested start.nv_readtruncates todata_size, asnv_read_with_authalready does.Verification
New test
a_huge_list_count_fails_without_preallocating, run underulimit -v 4000000:with_capacity(count):memory allocation of 103079215080 bytes failed, process aborts.New test
get_handles_stops_when_the_tpm_goes_backwards(stream-backed fake TPM answeringmore_datawith a handle below the range): the fixed code errors after 1 request; without the check it keeps asking and only stops when the fake TPM hangs up after 4.cargo test -p tpm2passes;cargo clippy -p tpm2 -- -D warnings -D clippy::unwrap_used -D clippy::expect_usedclean.