-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tpm2: fix SignedCompareB #367
tpm2: fix SignedCompareB #367
Conversation
src/tpm2/MathOnByteBuffers.c
Outdated
const BYTE *a, /* IN: a buffer */ | ||
const UINT32 bSize, /* IN: size of b */ | ||
const BYTE *b /* IN: b buffer */ | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you leave this part here untouched so it remains as close to the specs as possible.
Thanks for the PR. I would not have found this bug. Luckily no release has been made that includes the recent change to this code. You are basically reverting this patch here: 6ac04e4 Basically you are saying that the code in rev164 is wrong [pdf page 572 ]? : https://trustedcomputinggroup.org/wp-content/uploads/TCG_TPM2_r1p64_Part4_SupportingRoutines_code_15may2021.pdf |
SigedCompare returns -1 for the following call: BYTE a = 0x81; BYTE b = 0x82; SignedCompareB(1, &a, 1, &b); But should return 1, because signed 0x81 > 0x82 Signed-off-by: Juergen Repp <[email protected]>
f140d60
to
04a01b7
Compare
I downloaded the spec and found the code for SignedCompare at page 543. This code seems to be ok but is different from: libtpms/src/tpm2/MathOnByteBuffers.c Line 105 in 0c32f39
|
With two's complement (are these number's in two's complement): a = 0x81 = -127 and b = 0x82 = -126 a < b, therefore it should be '-1'.
For the current algorithm this results in (values I would expected in 2nd column):
For the old and your proposed algorithm (basically a revert to the old one):
The REAL issue here is, what all did this change break? |
With the new libtpms the test policynv in the tpm2-tools ci which always worked failed. Here a short example for this test in the ci:
This test, which also works with a AMD firmware TPM, now did return 0x126 if the new libtpms was used. |
Seems to be in the TPM Errata: https://trustedcomputinggroup.org/wp-content/uploads/TPM-2.0-Library-Spec-v1.59-Errata-v1.4_pub.pdf |
@stefanberger thank you for explaining the signed comparisons in such detail. I will adapt the tpm tool tests in the CI to the libtpms with the fix for SignedCompareB. And I think the PR can be closed. |
It looks like we may run into backwards compatibility problems at some point where some policies created on older TPMs/libtpms won't work on newer TPM versions / libtpms. |
The values for signed compare will be compatible with the new libtpms. We will check the return codes for signed compares and skip these tests if 0x126 is returned to finally allow prs with successful tests into the ci again. |
Tests are not so much my concern, user's policies are more of a concern. |
yes that's really an unpleasant thing but not avoidable? |
By leaving it broken it could be avoided. It can cause major headaches on any number of machines. |
IMHO, the TCG TPM reference code will include this fix for the next "actual release" and also actual TPMs start implementing the correct(ed) behavior. |
See Part 2. There is at least a NOTE: 6.8 TPM_EO (EA Arithmetic Operands) |
Changelog: version 0.10.0: - tpm2: Support for profiles: default-v1 & custom - tpm2: Add new API call TPMLIB_SetProfile to enable user to set a profile - tpm2: Extende TPMLIB_GetInfo to return profiles-related info - tpm2: Implemented crypto tests and restrictions on crypto related to FIPS-140-3; can be enabled with profiles - tpm2: Enable Camellia-192 and AES-192 - tpm2: Implement TPMLIB_WasManufactured API call - tpm2: Fixes for issues detected by static analyzers - tpm2: Use OpenSSL-based KDFe implementation if possible - tpm2: Update to TPM 2 spec rev 183 (many changes) - tpm2: Better support for OpenSSL 3.x - tpm2: Use Carmichael function for RSA priv. exponent D (>= 2048 bits) - tpm2: Fixes for CVE-2023-1017 and CVE-2023-1018 - tpm2: Fix of SignedCompareB(). NOTE: This fix *may* result in backwards compatibility issues with PCR policies used by TPM2_PolicyCounterTimer and TPM2_PolicyNV when upgrading from v0.9 to v0.10. stefanberger/libtpms#367 (comment)
SigedCompare returns -1 for the following call:
BYTE a = 0x81;
BYTE b = 0x82;
SignedCompareB(1, &a, 1, &b);
But should return 1, because signed 0x81 > 0x82
Signed-off-by: Juergen Repp [email protected]