Skip to content

tpm2_identity_util!: add buffer size check in hmac_outer_integrity to prevent potential oob#3571

Merged
JuergenReppSIT merged 1 commit into
tpm2-software:masterfrom
hyperfinitism:fix/potential-oob
Mar 27, 2026
Merged

tpm2_identity_util!: add buffer size check in hmac_outer_integrity to prevent potential oob#3571
JuergenReppSIT merged 1 commit into
tpm2-software:masterfrom
hyperfinitism:fix/potential-oob

Conversation

@hyperfinitism
Copy link
Copy Markdown
Contributor

Summary

hmac_outer_integrity() concatenates two caller-supplied buffers into a fixed-size stack buffer of TPM2_MAX_DIGEST_BUFFER (1024) bytes using memcpy without checking their combined size.

This PR adds a buffer size check before the memcpy calls to prevent a potential oob. To propagate the error to callers, the return type of hmac_outer_integrity() and its public wrapper tpm2_identity_util_calculate_outer_integrity() is changed from void to bool.

Changes

  • Add a size check in hmac_outer_integrity(): emit an error log message and return false if buffer1_size + buffer2_size > TPM2_MAX_DIGEST_BUFFER
  • Change the return type of hmac_outer_integrity() from void to bool
  • Breaking change: change the return type of the public API function tpm2_identity_util_calculate_outer_integrity() from void to bool and update the declaration in tpm2_identity_util.h
  • Update all three call sites to check the return value:
    • tools/tpm2_duplicate.c
    • tools/tpm2_import.c
    • tools/tpm2_makecredential

hmac_outer_integrity() concatenates two caller-supplied buffers into a
fixed-size stack buffer of TPM2_MAX_DIGEST_BUFFER (1024) bytes using
memcpy without checking their combined size.

This commit adds a buffer size check before memcpy to prevent potential
oob.

To propagate errors to the caller, the return type of hmac_outer_integrity()
and tpm2_identity_util_calculate_outer_integrity() from void to bool.

The latter change breaks compatibility with the public API.

Signed-off-by: Takuma IMAMURA <209989118+hyperfinitism@users.noreply.github.com>
@JuergenReppSIT
Copy link
Copy Markdown
Member

@hyperfinitism Thank you for the PR.

@JuergenReppSIT JuergenReppSIT merged commit c9a5dff into tpm2-software:master Mar 27, 2026
23 checks passed
@hyperfinitism hyperfinitism deleted the fix/potential-oob branch April 14, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants