Commit Graph

577 Commits

Author SHA1 Message Date
Stefan Berger
1feea251e7 rpm/debian: Add 0.7.12 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-06-10 14:10:02 -04:00
Stefan Berger
c72ff77ea4 CHANGES: Updated CHANGES document for 0.7.12
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-06-10 14:10:02 -04:00
Stefan Berger
4630edaeb4 tpm2: Fix potential out-of-bound access & abort due to HMAC signing issue
Fix an HMAC signing issue that may causes an out-of-bounds access in a
TPM2B that in turn was running into an assert() in libtpms causing an
abort. The signing issue was due to an inconsistent pairing of the signKey
and signScheme parameters, where the signKey is ALG_KEYEDHASH key and
inScheme is an ECC or RSA scheme.

This fixes CVE-2025-49133.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2025-06-10 14:10:02 -04:00
Stefan Berger
241a42671c ci: Add github actions script
Backport the github actions script from the master branch. In the
coveralls build, use the stable-0.9 branch of swtpm since later versions
of swtpm need later versions of libtpms.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-06-10 14:10:02 -04:00
Stefan Berger
9d6d76cc68 tpm2: Check size of buffer before accessing it (CVE-2023-1017 & -1018)
Check that there are sufficient bytes in the buffer before reading the
cipherSize from it. Also, reduce the bufferSize variable by the number
of bytes that make up the cipherSize to avoid reading and writing bytes
beyond the buffer in subsequent steps that do in-place decryption.

This fixes CVE-2023-1017 & CVE-2023-1018.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-20 09:42:52 -04:00
Juergen Repp
1941dea0e8 tpm2: Do not call EVP_PKEY_CTX_set0_rsa_oaep_label() for label of size 0 (OSSL 3)
Openssl 3.0 did return an error if EVP_PKEY_CTX_set0_rsa_oaep_label was called
with label size 0. The function should only be called if the size of the label
is greater 0.
With this fix TPM2_RSA_Encrypt/Decrypt did work with OpenSSL 1.1 and 3.0
for encryption without label.

Signed-off-by: Juergen Repp <juergen.repp@sit.fraunhofer.de>
2025-05-16 09:31:33 -04:00
Stefan Berger
40c909ec77 tpm2: Return TPM_RC_VALUE upon decryption failure
When decryption fails then return TPM_RC_VALUE rather than TPM_RC_FAILURE.
The old error code could indicate to an application or driver that
something is wrong with the TPM (has possibly gone into failure mode) even
though only the decryption failed, possibly due to a wrong key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-16 09:31:33 -04:00
Stefan Berger
e4c35830ab tpm2: Fix the returned number in the JSON
The JSON returned by TPM2_GetInfo contains a leading zero in the level.

$> swtpm_ioctl --tcp :10000 --info 1
{"TPMSpecification":{"family":"2.0","level":00,"revision":162+0}}

This patch fixes this to:

$> swtpm_ioctl --tcp :10000 --info 1
{"TPMSpecification":{"family":"2.0","level":0,"revision":162+0}}

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-15 10:51:01 -04:00
Stefan Berger
787498e317 Travis: Use swtpm's stable-0.9 branch for testing
Since swtpm now depends on libtpms >= 0.10 use swtpm's stable-0.9
branch for testing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-22 13:58:46 -04:00
Stefan Berger
816797caea tpm12: Replace include of engine.h with err.h
Fedora Rawhide and CentOS 10 do not support OpenSSL engine anymore.
Therefore, replace include of engine.h with err.h since the engine is not
needed anyway but we only need the prototype of ERR_get_error_line_data.
Add missing includes for evp.h and rsa.h.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-09 10:29:23 -04:00
Stefan Berger
8c6a05d228 Travis: Install libgmp-dev for newer swtpm
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-07-09 10:29:23 -04:00
Stefan Berger
c210455e7b rpm/debian: Add 0.7.11 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-11-10 15:03:23 -05:00
Stefan Berger
679072d548 CHANGES: Updated CHANGES document for 0.7.11
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-11-10 15:03:23 -05:00
Stefan Berger
680c9615c9 tpm2: Do not set RSA_FLAG_NO_BLINDING on RSA keys anymore
Do not set the RSA_FLAG_NO_BLINDING on RSA keys anymore. The BoringSSL
documentation states the following:

"RSA_FLAG_NO_BLINDING disables blinding of private operations, which is
a dangerous thing to do. It is deprecated and should not be used. It will
be ignored whenever possible."

So, follow this documentation. OpenSSL does not seem to say much about it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-06-11 23:09:38 -04:00
Stefan Berger
f9007df9cb tpm2: Fix a potential overflow expression (coverity)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-05-29 15:09:05 -04:00
Ross Lagerwall
111f55eb1b tpm2: Fix size check in CryptSecretDecrypt
Check the secret size against the size of the buffer, not the size
member that has not been set yet.

Reported by Coverity.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
2022-05-24 23:36:56 -04:00
Stefan Berger
7c0e0c3948 tpm2: Check return code of BN_div()
Backport of 8590849b65.

Check the return code of BN_div() when calculating Q and Qr of
a private key.

Resolves: https://github.com/stefanberger/libtpms/issues/304
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-03-30 13:16:21 -04:00
Stefan Berger
8651aff8a3 tpm2: Do not write permanent state if only clock changed
To avoid timeouts on short-running commands, such as TPM2_PCR_Extend,
avoid triggering the writing of the permanent state of the TPM 2
if only the clock was updated. So the clock by itself will not cause
the permanent state to be written out anymore but there have to be
other reasons as well.

The state will still be written out upon a TPM2_Shutdown, which is
supposed to be the last command to be sent to the TPM when shutting
down the VM/vTPM. Also, the permanent state will still carry the
latest clock value if it is retrieved via control channel for
VM/VTPM suspend.

The case that may be affected, but is of lesser importance, is the one
where swtpm's volatile state is written to storage using 'swtpm_ioctl -v'
and then swtpm is terminated and restarted (similar to suspend/resume)
and the permanent state file is read from storage but does not contain
the latest clock value. In this case the go.clock will be updated when
the first command after resume is executed.

This fixes the swtpm issue https://github.com/stefanberger/swtpm/issues/597.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-15 15:19:21 -04:00
Stefan Berger
48b8f35b3e build-sys: Build libtpms v0.7.11
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-15 15:19:21 -04:00
Stefan Berger
2c66b28bb8 rpm/debian: Add 0.7.10 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 16:51:59 -04:00
Stefan Berger
90746500a7 CHANGES: Updated CHANGES document for 0.7.10
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 16:51:59 -04:00
Stefan Berger
a1ff5b1cb9 build-sys: Add -Wno-deprecated-declarations to default CFLAGS (OSSL 3)
To be able to build with OpenSSL 3.0 we need to added
-Wno-deprecated-declarations to the default CFLAGS.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 16:51:59 -04:00
Stefan Berger
be7e9f6585 build-sys: Test for functions if #defines are not found (OSSL 3)
OpenSSL 3.0 has converted several RSA-related #defines to functions, so
that AX_CHECK_DEFINE only works for OpenSSL 1.1.0 but for OpenSSL 3.0.0
we have to also use AC_CHECK_LIB to determine whether the function is
available.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 16:51:59 -04:00
Stefan Berger
c9304967e6 tpm2: Only call EVP_PKEY_CTX_set0_rsa_oaep_label when label != NULL (OSSL 3)
EVP_PKEY_CTX_set0_rsa_oaep_label must only be called with label != NULL.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 16:51:59 -04:00
Stefan Berger
49af9285ea tpm2: Use EVP_PKEY_get1_RSA() rather than EVP_PKEY_get0_RSA (OSSL 3)
OpenSSL 3.0 has changed the signature of EVP_PKEY_get0_RSA() from

struct rsa_st *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);

to

const struct rsa_st *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey);

We now have to use EVP_PKEY_get1_RSA with this signature so that we can
access the RSA key. The signature of that function hasn't changed between
OpenSSL 1.1.0 and 3.0.0.

struct rsa_st *EVP_PKEY_get1_RSA(EVP_PKEY *pkey);

Free the additional reference held on the RSA key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 16:51:59 -04:00
Stefan Berger
3017a5b14c tpm2: Marshal event sequence objects' hash state
Event sequence objects were never properly marshalled and when their state
was saved and later restored their state may have been corrupted. Fix this
now by also marshalling the state of event sequence objects.

Bump up the version of the HASH_OBJECT's header to '3' so that previously
written state can be resumed if an event sequence object is encountered
and we only unmarshal an event sequence object when the version is at least
'3'.

Fixes issue #259.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 16:51:59 -04:00
Stefan Berger
9c46c6fe76 build-sys: Build libtpms v0.7.10
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 16:51:59 -04:00
Stefan Berger
3461a606f4 rpm/debian: Add 0.7.9 entry in changelog
Also address an rpmlint issue.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-01 13:26:20 +02:00
Stefan Berger
58cc3e17b3 CHANGES: Updated CHANGES document for 0.7.9
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-01 13:26:20 +02:00
Stefan Berger
6f3ad179c9 tpm2: NVMarshal: Handle index orderly RAM without 0-sized terminating node
The NVRAM entries in s_indexOrderlyRam array do not need to contain a
0-sized terminating node. Instead, the entries may fill up this 512
byte array so that no NV_RAM_HEADER structure fits anymore. The fact
that no more NV_RAM_HEADER structure fits is also an indicator for the
last entry. We need to account for this in the code marshalling and
unmarshalling the entries so that we stop marshalling the entries
then and similarly stop unmarshalling.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-08-02 07:55:48 -04:00
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