Commit Graph

547 Commits

Author SHA1 Message Date
Stefan Berger
4b1a4e5bfa tpm2: Initialize a whole OBJECT before using it
Initialize a whole OBJECT before using it. This is necessary since
an OBJECT may also be used as a HASH_OBJECT via the ANY_OBJECT
union and that HASH_OBJECT can leave bad size inidicators in TPM2B
buffer in the OBJECT. To get rid of this problem we reset the whole
OBJECT to 0 before using it. This is as if the memory for the
OBJECT was just initialized.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-08-02 07:55:48 -04:00
Stefan Berger
fb908ef3c9 build-sys: Build libtpms v0.7.9
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-08-02 07:55:48 -04:00
Stefan Berger
4893c23e3b rpm/debian: Add 0.7.8 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-24 12:07:38 -04:00
Stefan Berger
15319cc900 CHANGES: Updated CHANGES document for 0.7.8
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-24 12:07:38 -04:00
Stefan Berger
a116d36687 tpm2: Restore original value if unmarshalled value was illegal
Restore the original value of the memory location where data from
a stream was unmarshalled and the unmarshalled value was found to
be illegal. The goal is to not keep illegal values in memory.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-24 12:07:38 -04:00
Stefan Berger
d29d80c8ca tpm2: Add maxSize parameter to TPM2B_Marshal for sanity checks
Add maxSize parameter to TPM2B_Marshal and assert on it checking
the size of the data intended to be marshaled versus the maximum
buffer size.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-24 12:07:38 -04:00
Stefan Berger
52a82f3eb6 tpm2: Reset TPM2B buffer sizes after test fails for valid buffer size
Reset the buffer size indicator in a TPM2B type of buffer after it failed
the test for the maximum buffer size it allows. This prevents having bad
buffer sizes in memory that can come to haunt us when writing the volatile
state for example.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-24 12:07:38 -04:00
Stefan Berger
3d27110964 build-sys: Run autoupdate on configure.ac for autoconf 2.71
Run autoupdate on configure.ac and address the following issues:

configure.ac:10: warning: 'AM_CONFIG_HEADER': this macro is obsolete.
configure.ac:10: You should use the 'AC_CONFIG_HEADERS' macro instead.
./lib/autoconf/general.m4:2434: AC_DIAGNOSE is expanded from...
aclocal.m4:1071: AM_CONFIG_HEADER is expanded from...
configure.ac:10: the top level
configure.ac:31: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:31: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:31: the top level
configure.ac:72: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:72: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:72: the top level
configure.ac:90: warning: The macro `AC_HELP_STRING' is obsolete.
configure.ac:90: You should run autoupdate.
./lib/autoconf/general.m4:204: AC_HELP_STRING is expanded from...
configure.ac:90: the top level
configure.ac:253: warning: The macro `AC_PROG_LIBTOOL' is obsolete.
configure.ac:253: You should run autoupdate.
m4/libtool.m4:99: AC_PROG_LIBTOOL is expanded from...
configure.ac:253: the top level
configure.ac:258: warning: The macro `AC_HEADER_STDC' is obsolete.
configure.ac:258: You should run autoupdate.
./lib/autoconf/headers.m4:704: AC_HEADER_STDC is expanded from...
configure.ac:258: the top level

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-24 12:07:38 -04:00
Stefan Berger
c1fce830bf build-sys: Build libtpms v0.7.8
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-24 12:07:38 -04:00
Stefan Berger
3d3f0a6ed2 Travis: Install libjson-glib-dev and drop a few python dependencies
Since swtpm_setup has been rewritten in 'C' now we can drop a few
python dependencies but need libjson-glib-dev as a new dependency
for testing with swtpm's master branch.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-05-30 15:33:16 -04:00
Stefan Berger
0ebbf1e0bb tpm2: Surround all occurrences of BLOCK_SKIP_READ() with tests of 'rc'
Do not call BLOCK_SKIP_READ once rc has been set to any error value.
Therefore, surround all occurrences of BLOCK_SKIP_READ() with tests
of 'rc'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-05-04 14:02:26 -04:00
Stefan Berger
fd5bd3fb1d rpm/debian: Add 0.7.7 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-01 13:17:11 -05:00
Stefan Berger
8c7c974b17 CHANGES: Updated CHANGES document for 0.7.7
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-01 13:17:11 -05:00
Stefan Berger
68aa19dac7 tpm2: CryptSym: fix AES output IV
The TPM is supposed to provide the output IV in the ivInOut parameter in
CryptSymmetricEncrypt. In the case of using the openssl routines, the
output IV is missed, and the resulting output from the TPM is in the
input IV.

OpenSSL unfortunately does not export EVP_CIPHER_CTX_iv() until
tags/OpenSSL_1_1_0, so we have to fall back to the reference code for
previous OpenSSL versions.

Signed-off-by: William Roberts <william.c.roberts@intel.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-01 13:17:11 -05:00
Stefan Berger
f926190b89 build-sys: Build libtpms v0.7.7
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-03-01 13:17:11 -05:00
Stefan Berger
46a0c5fe16 rpm/debian: Add 0.7.6 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-26 21:50:22 -05:00
Stefan Berger
5d4100e16b CHANGES: Updated CHANGES document for 0.7.6
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-26 21:43:46 -05:00
Stefan Berger
8b6b49ed7e build-sys: Build libtpms v0.7.6
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-26 21:43:46 -05:00
Stefan Berger
d78d04f02c tpm2: Fix public key context save due to ANY_OBJECT_Marshal usage
This patch fixes a VM suspend/resume issue when externally loaded public
keys are involved.

This patch addresses the bug reported in issue #195 where the saving of
an externally loaded public key's context doesn't work due to the usage of
ANY_CONTEXT_SAVE for saving key contexts. This patch fixes the issue by
creating local versions of TPM_SENSITIVE_Marshal/_Unmarshal that deals
with the case where sensitiveType is not a type of private key but a
public key instead that basically doesn't have much information in
TPM_SENSITIVE but is all zeros instead.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-26 15:00:17 -05:00
Stefan Berger
accf4437c6 tpm12: Implement TPM_PrintFourLimit to print 4 or less bytes
Implement TPM_PrintFourLimit to print only up to 4 bytes or less.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-26 15:00:17 -05:00
Stefan Berger
ae15c8c76b tpm12: Use TPM_PrintFourLimit where <= 4 bytes may exist
Use TPM_PrintFourLimit in those cases where less than 4 bytes of
valid data may exist. Hashes, nonces, encrypted data, and others
typically have more than 4 bytes but data read from NVRAM or
to be encrypted data may have less.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-26 15:00:17 -05:00
Stefan Berger
1d9abaf99d tpm2: Sanitize values read from TPM state stream (Coverity)
Sanitize some of the values read from the TPM state stream.
All Coverity discoveries seem to be false positives.

Coverity doesn't like to see array_size being used in the loop even
though it was compared against ARRAY_SIZE() before. We solve this by
using ARRAY_SIZE() as the loop limit now rather than array size.

Compare seed.b.size against PRIMARY_SEED_SIZE even though this is
already being done in TPM2B_Unmarshal().

The num_bytes parameter is sanitized via a comparison involving a
sum over a sum of values, but Coverity doesn't seem to detect this.
Then we have to use it as a loop limit. I don't see another way.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-23 07:28:19 -05:00
Stefan Berger
31d4c1dcb6 tpm2: Prevent a potential buffer overrun (Coverity)
Prevent a potential buffer overrun by checking that EVP_DecryptUpdate()
has not overrun the buffer it was passed in, so this overrun should
never occurr unless EVP_DecryptUpdate() was wrong. Also the pAssert above
it should have taken care of it already.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-23 07:28:19 -05:00
Stefan Berger
f19282b243 tpm2: Initialize keyschedule before AES_set_encrypt_key (overity)
Coverity complains that the *output* variable passed to
AES_set_encrypt_key contains uninitialized bytes, so we initialize
the variables now.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-23 07:28:19 -05:00
Stefan Berger
25223a2d0e tpm2: Initialize variable and check rc before accessing nrh.size (Coverity)
Coverity complains that nrh may not be initialize when copying nrh.size
from it into the buffer pointer to by nrhp. So resolve this by clearing
nrh at the beginning of the loop and checking 'rc' after the Unmarshal.

Previously we could have copied an uninitialized nrh.size but would have
propagated the rc error code from UINT32_Unmarshal(), so this fix doesn't
really change anything.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-23 07:28:19 -05:00
Stefan Berger
e271498466 rpm/debian: Add 0.7.5 entries to changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-18 07:49:07 -05:00
Stefan Berger
d13e628f9e CHANGES: Update CHANGES file for 0.7.5
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-18 07:49:07 -05:00
Stefan Berger
153a9579e8 tpm2: Add comment to buggy RSAAdjustPrimeCandidate
This patch adds a description to the buggy RSAAdjustPrimeCandidate
implementation that can only be properly fixed after 0.7.x.

Reported-by: Nicolas Iooss <nicolas.iooss@ledger.fr>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-18 07:49:07 -05:00
Stefan Berger
8001ad0b96 tpm2: Return properly sized array for b parameter for NIST P521 (HLK)
This patch ensures that the leading zeros in the b parameter for NIST P521
are being kept so that HLK accepts the returned parameters from
TPM2_ECC_Parameters. Now 66 bytes are reported for 'b' rather than only 65.
Do the same for the 'a' parameter, though that one was properly reported
already because it didn't have any leading zeros.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-15 19:13:11 -05:00
Stefan Berger
b2e3991057 tpm2: Fix typos and error reporting inconsitencies in NVMarshal.c
This patch addresses issue #177 by fixing some typos and error
reporting inconsistencies (how structures are spelled) in NVMarhsal.c.

Reported-by: Nicolas Iooss <nicolas.iooss@ledger.fr>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-02-15 13:01:10 -05:00
Stefan Berger
f1740791c3 tpm2: Address issues detected by cppcheck (false positives)
cppcheck has detected the following issues in 2 functions. However,
neither one of the out-of-bounds array access can happen with the
existing code (see comments in patch).

src/tpm2/Session.c:399:5: note: After for loop, slotIndex has value 3
    for(slotIndex = 0; slotIndex < MAX_LOADED_SESSIONS; slotIndex++)
    ^
src/tpm2/Session.c:414:15: note: Assuming condition is false
    if(result != TPM_RC_SUCCESS)
              ^
src/tpm2/Session.c:419:15: note: Array index out of bounds
    s_sessions[slotIndex].occupied = TRUE;
              ^
src/tpm2/Session.c:591:27: error: Array 's_sessions[3]' accessed at index 3, which is out of bounds. [arrayIndexOutOfBounds]
    MemoryCopy(&s_sessions[slotIndex].session, session, sizeof(SESSION));
                          ^
src/tpm2/Session.c:571:5: note: After for loop, slotIndex has value 3
    for(slotIndex = 0; slotIndex < MAX_LOADED_SESSIONS; slotIndex++)
    ^
src/tpm2/Session.c:581:8: note: Assuming condition is false
       && contextIndex != s_oldestSavedSession)
       ^
src/tpm2/Session.c:591:27: note: Array index out of bounds
    MemoryCopy(&s_sessions[slotIndex].session, session, sizeof(SESSION));
                          ^

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-01-02 20:38:26 -05:00
Stefan Berger
1df79fddec tpm2: Fix negate overflow error (UBSAN)
Fix a negate overflow error.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-25 12:21:48 -05:00
Stefan Berger
e2b71ca032 tpm2: Fix issue with misaligned address when marshalling NVRAM (UBSAN)
UBSAN detects possibly misaligned address when reading out of the
TPM 2's NVRAM and when writing back into it. The NV_RAM_HEADER may
be unaligned like this:

tests/test_tpm2_save_load_state_3.log:tpm2/Marshal.c:117:29: \
  runtime error: load of misaligned address 0x7ffcb53b3bca for type 'UINT32', which requires 4 byte alignment

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-25 12:21:48 -05:00
Stefan Berger
ff8af1d9e1 build-sys: Build libtpms v0.7.5
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-25 12:21:48 -05:00
Stefan Berger
590ce162a8 debian: Add missing line in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-02 13:54:36 -05:00
Stefan Berger
984ad238de debian: Fix typo in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-11-01 19:32:05 -05:00
Stefan Berger
2452a24dab rpm/debian: Add 0.7.4 entry to changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-30 15:24:40 -04:00
Stefan Berger
87bb1758fc CHANGES: Update CHANGES file for 0.7.4
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-30 15:24:40 -04:00
Stefan Berger
937cdade6d build-sys: Build libtpms v0.7.4
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-30 15:24:40 -04:00
Stefan Berger
6f247f7105 tpm2: Add utilities for debugging of constant time issues
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-30 11:27:32 -04:00
Stefan Berger
92adc76acf tpm2: Add Ec signing related changes to consttime.txt notes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-30 11:27:32 -04:00
Stefan Berger
089485035f tpm2: EcSM2: Enforce that the random bnK has no leading zeros
Make sure that the value of bnK is not short so that the subsequent
BnEccModMult() runs in constant time. We take the same approach as with
the modifications to BnEccGenerateKeyPair() where we request bnK to have
all bytes set (no leading zeros that will be cut away) in case the order
of the curve is as byte boundary. In the other cases we add the order
to bnK, which creates bnK1, which we then use for BnEccModMult's scalar
parameter.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Suggested-by: Charanjit Jutla <csjutla@us.ibm.com>
Reviewed-by: Charanjit Jutla <csjutla@us.ibm.com>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-30 11:27:32 -04:00
Stefan Berger
5c224b8d98 tpm2: EcSchnorr: Enforce that the OpenSSL-generated bnD has no leading zeros
To avoid a potential side channel in the EcSchnorr signing algorithm,
enforce that the OpenSSL-generated bnD does not have leading zeros
that may then cause a timing side channel in the BnEccModMult() operation.

We modified BnEccGenerateKeyPair() so it calls BnEccModMult with a scalar
of constant number of bytes (for a particular curve):

In this version of BnEccGenerateKeyPair we take a dual approach to constant
time requirements: For curves whose order is at the byte boundary, e.g.
NIST P224/P256/P384, we make sure that bnD has all bytes set (no leading zeros)
so that OpenSSL BIGNUM code will not reduce the number of bytes and the
subsequent BnEccModMult() would run faster for a shoter value. For all other
curves whose order is not at the byte boundary, e.g. NIST P521, we simply
always add the order to bnD and call BnEccModMult() with the result bnD1,
which leads to the same result.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Suggested-by: Charanjit Jutla <csjutla@us.ibm.com>
Reviewed-by: Charanjit Jutla <csjutla@us.ibm.com>
Tested-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-30 11:27:32 -04:00
Stefan Berger
8583927139 tpm2: Leave notes in code about Nonces that may have leading zeros
Some parameters in the EC code may have leading zeros without causeing
a timing side channel.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-30 11:27:32 -04:00
Stefan Berger
785ad4d03f tpm12: Add a note to RSA related to EVP conversion for constant-time
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-23 23:06:46 -04:00
Stefan Berger
ecc2e95929 tpm12: Use EVP functions for encryption
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-23 23:06:46 -04:00
Stefan Berger
51d1ca8ce4 tpm12: Use EVP functions for decryption
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-23 23:06:46 -04:00
Stefan Berger
03d13d5f19 tpm12: Set BN_FLG_CONSTTIME to select constant time computations
Set BN_FLG_CONSTTIME on the sensitive parts of the RSA key to
select constant time computations.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-23 23:06:46 -04:00
Stefan Berger
5ea3e6183d Travis: Add python3 dependencies for swtpm test
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-23 23:06:46 -04:00
Stefan Berger
b6f1a15268 Travis: Run additional IBM TSS2 related test; use Bionic
Run some additional IBM TSS2 related tests for better code
coverage. We need to switch to Bionic to get the tss2 package.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2020-10-23 23:06:46 -04:00