Skip to content

fix loading of parent handles in TPM TSS2 keys#175

Merged
gotthardp merged 1 commit into
masterfrom
tssfix
Apr 26, 2026
Merged

fix loading of parent handles in TPM TSS2 keys#175
gotthardp merged 1 commit into
masterfrom
tssfix

Conversation

@gotthardp

Copy link
Copy Markdown
Contributor

Fixes: #152

@gotthardp

Copy link
Copy Markdown
Contributor Author

This supersedes the #153.

@gotthardp gotthardp force-pushed the tssfix branch 3 times, most recently from 58ad012 to 2615cd1 Compare April 26, 2026 17:27
@gotthardp gotthardp merged commit ec1d2d1 into master Apr 26, 2026
12 of 13 checks passed
@gotthardp gotthardp deleted the tssfix branch April 26, 2026 20:18
Comment thread src/tpm2-provider-pkey.c

if (parent == 0)
keydata->parent = TPM2_RH_OWNER;
else if (parent <= UINT32_MAX)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By changing parent from type uint64_t to TPM2_HANDLE (which according to tpm2-tss is an uint32_t see: https://github.com/tpm2-software/tpm2-tss/blob/a54a27df0732cde2c47b1d4d0e7bef489dc8a7d5/include/tss2/tss2_tpm2_types.h#L1050 and https://github.com/tpm2-software/tpm2-tss/blob/a54a27df0732cde2c47b1d4d0e7bef489dc8a7d5/include/tss2/tss2_common.h#L24) this line will always be true.

Have a look at line 153:
BN_get_word returns an BN_ULONG, which is 32-bits on 32-bit systems and 64-bits on 64-bit systems.
BN_get_word set's all bits in case of an error.

parent is of type TPM2_HANDLE which is of type uint32_t.

On a 64 bit system, we're performing an implicit conversion from uint64 to uint32. This shouldn't be a problem in case of a valid parent-handle as they're in the range 0x81000000 - 0x81FFFFFF. I think we should handle the case where BN_get_word() returns something bigger than a 32bit value on 64bits systems and on 32bit systems we should treat the return value UINT32_MAX as error.

@thomkopp

Copy link
Copy Markdown

I would have loved to see a comment in the final code, regarding the reason for this change. This is due to compatiblity with older provider/engine versions.

I took quite an effort to analyze and document everything here:
30d57cf#diff-b7d2c2757e9c2e3ca8b0f9c475fa9921fc8b4f569a2cacdc43393fbf37c470dbR148

That might be helpful in the future.

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.

Loading of TPM2-TSS keys created with version earlier than 1.2.0 always fails

2 participants