Skip to content

Backport a few patches for v0.7.13 - #625

Open
stefanberger wants to merge 7 commits into
stable-0.7.0from
stable-0.7.0.next
Open

stefanberger wants to merge 7 commits into
stable-0.7.0from
stable-0.7.0.next

Conversation

@stefanberger

Copy link
Copy Markdown
Owner

No description provided.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 68715228-103b-4061-863f-692ae16c5732

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Fix a compilation error that newer gcc versions may complain about:

tpm_library.c: In function 'TPMLIB_GetPlaintext':
tpm_library.c:441:11: error: assignment discards 'const' qualifier from pointer target type [-Werror=discarded-qualifiers]
  441 |     start = strstr(stream, starttag);
      |           ^
At top level:
cc1: note: unrecognized command-line option '-Wno-self-assign' may have been intended to silence earlier diagnostics
cc1: all warnings being treated as errors

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This patch applies a fix for CVE-2026-6726 by clearing the OBJECT on
ObjectFlush.

libtpms does NOT seem to be affected by the vulnerability since a previous
commit already resolved this issue:

33a0398

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This patch fixes CVE-2026-6727. Libtpms is typically not affected unless
it was configured with --disable-use-openssl-functions or if it was built
with '-DUSE_OPENSSL_FUNCTIONS_RSA=0'. Neither would be the 'typical' case.

OaepDecode exposes a potential timing side-channel. Fix the timing
side-channel of this function by accumulating a bad result in a variable
while still executing most of the code. This at least causes the test
case to not report the issue anymore.

Note: This issue only appears when using libtpms with
--disable-use-openssl-functions, which circumvents many OpenSSL functions
for RSA, ECDSA, and others, that likely handle constant-time issues better
than the TPM 2 reference code does.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
@stefanberger stefanberger changed the title Backport a few patch for v0.7.13 Backport a few patches for v0.7.13 Sep 11, 2026
…rypt

TPM_SymmetricKeyData_Decrypt (AES path in src/tpm12/tpm_crypto.c,
OpenSSL backend; and the NSS/FreeBL backend in
src/tpm12/tpm_crypto_freebl.c) only checked
encrypt_length < TPM_AES_BLOCK_SIZE before calling
AES_cbc_encrypt(..., AES_DECRYPT) on a buffer allocated to exactly
encrypt_length bytes. CBC decryption always consumes a whole final
block, so a length that is not a multiple of 16 makes OpenSSL read up
to 15 bytes past the end of the input buffer.

That length is TPM_CONTEXT_BLOB.sensitiveData.size from the command
stream. TPM_Process_LoadKeyContext and TPM_Process_LoadAuthContext run
under TPM_CHECK_ALLOW_NO_OWNER and decrypt the blob with the permanent
contextKey before the integrity HMAC is checked, so the over-read is
reachable with a single unauthenticated command.

Reproduced with a TPM_LoadKeyContext command whose sensitiveData.size
is 17; AddressSanitizer reports a heap over-read:

    READ of size 4 ...
        #0 AES_decrypt aes_core.c
        #1 CRYPTO_cbc128_decrypt cbc128.c
        #2 TPM_SymmetricKeyData_Decrypt tpm_crypto.c
        #3 TPM_Process_LoadKeyContext tpm_session.c

The fix rejects a length that is not a whole number of blocks, the same
requirement the DES backend already enforces. The command then returns
TPM_DECRYPT_ERROR. A zero length is still rejected by TPM_Malloc().

Signed-off-by: sameera <sameera@research.itecz.au>
TPM_Sha1Context_Load() (OpenSSL backend, src/tpm12/tpm_crypto.c)
deserializes the OpenSSL SHA_CTX from a TPMLIB_SetState(VOLATILE) blob
and restores sha_ctx->num with TPM_Load32() without any range check.
num is the number of bytes buffered in sha_ctx->data and OpenSSL uses
it as the write offset in SHA1_Update()/SHA1_Final(): the update path
runs memcpy(p + num, data, SHA_CBLOCK - num). A restored num >=
SHA_CBLOCK makes SHA_CBLOCK - num wrap to a huge size_t, so the next
update writes far past the heap-allocated context, and SHA1_Final()
writes the 0x80 pad byte at p[num] well outside it.

The restored sha1_context / sha1_context_tis are later driven by the
TPM_SHA1Update command and by the host-side TPM_IO_Hash_Data(), both of
which reach TPM_SHA1UpdateCmd() -> SHA1_Update(). The volatile-state
blob is only protected by an unkeyed SHA1 integrity digest computed
after parsing, so num is attacker-controlled across a state restore.

Reproduced by loading a SHA1 context with num = 256 and then issuing
one update; AddressSanitizer reports a wrapped copy:

    ERROR: AddressSanitizer: negative-size-param: (size=-192)
        #0 memcpy
        #1 SHA1_Update
        #2 TPM_SHA1UpdateCmd tpm_crypto.c:2028

Reject num >= SHA_CBLOCK with TPM_BAD_PARAMETER and free the
partially loaded context, the same num bound the TPM 2.0 hash-state
unmarshalers already enforce. The FreeBL backend loads into a
fixed-layout struct guarded by a flatten-size check and does not
restore a write offset, so only the OpenSSL path is affected.

Signed-off-by: sameera <sameera@research.itecz.au>
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