Commit Graph

852 Commits

Author SHA1 Message Date
Stefan Berger
e65bedd5e8 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 09:37:38 -04:00
Stefan Berger
06a717f7cf tpm2: Remove assigned-to value to offset because it is unused (Coverity)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-16 14:49:25 -04:00
Stefan Berger
cf625bd27f Insert assert ensuring *buflen != BUFLEN_EMPTY_BUFFER (Coverity)
Address a false positive issue detect by Coverity (CID 1517797)
about *buflen.

Per this assignment of buflen

cached_blobs[st].buflen = buffer ? buflen : BUFLEN_EMPTY_BUFFER;

the following is true:

If cached_blobs[].buffer is     NULL then *buflen  = BUFLEN_EMPTY_BUFFER
If cached_blobs[].buffer is not NULL then *buflen != BUFLEN_EMPTY_BUFFER

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-16 14:49:25 -04:00
Stefan Berger
39f330c041 tpm2: Address Coverity Issue by casting '1' before shift (CID 1470813)
Cast the '1' to UINT64 before shifting it.

Since the shift value is always below 32 it would have never exceeded
the 32bit value it was using before the cast.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-16 14:49:25 -04:00
Stefan Berger
7c6e9dc5c0 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>
2024-08-20 10:35:42 -04:00
Stefan Berger
883a9e071b build-sys: Build libtpms v0.8.10
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-08-20 10:34:37 -04:00
Stefan Berger
779e859211 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 12:44:53 -04:00
Stefan Berger
c6ee56a75b 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-08 19:33:31 -04:00
Stefan Berger
005d1ca04c CHANGES: Updated CHANGES document for 0.8.9
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 15:58:38 -05:00
Stefan Berger
aae8303535 rpm/debian: Add 0.8.9 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 15:58:38 -05:00
Stefan Berger
4625ed3956 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>
2023-02-28 15:58:38 -05:00
Stefan Berger
6e2d51454e build-sys: Build libtpms v0.8.9
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 15:58:38 -05:00
Stefan Berger
10e7b283af CHANGES: Updated CHANGES document for 0.8.8
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-08 09:09:03 -04:00
Stefan Berger
8ba1f372be rpm/debian: Add 0.8.8 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-08 09:09:03 -04:00
Stefan Berger
44596c4c6a 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:29 -04:00
Stefan Berger
45b1524956 tpm2: Fix a potential overflow expression (coverity)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-05-29 14:01:12 -04:00
Ross Lagerwall
d60d80f356 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:37:24 -04:00
Stefan Berger
84aca17354 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:45 -04:00
Stefan Berger
0e050f6d37 build-sys: Add probing for -fstack-protector
Add probing for -fstack-protector to the existing
-fstack-protector-strong since not all platforms support either one
of them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-03-02 15:17:28 -05:00
Juergen Repp
f7f89e33da 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>
2022-03-02 09:15:18 -05:00
Stefan Berger
a8622792c0 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:03 -04:00
Stefan Berger
777abd2dd1 build-sys: Build libtpms v0.8.8
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-15 15:19:03 -04:00
Stefan Berger
f6dd8f55ea CHANGES: Updated CHANGES document for 0.8.7
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 17:11:03 -04:00
Stefan Berger
0dddb6e438 rpm/debian: Add 0.8.7 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 16:51:29 -04:00
Stefan Berger
fb9f0a61e8 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-16 12:24:17 -04:00
Stefan Berger
ad36779ef7 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-16 12:24:17 -04:00
Stefan Berger
de8a3cc6f6 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-16 12:24:17 -04:00
Stefan Berger
6b498a20fa 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-16 12:24:17 -04:00
Stefan Berger
05d2b96c31 build-sys: Build libtpms v0.8.7
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-16 12:24:17 -04:00
Stefan Berger
7a4d46a119 rpm/debian: Add 0.8.6 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-09 16:26:33 -04:00
Stefan Berger
8ae3d744bc 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-09 16:26:33 -04:00
Stefan Berger
7cdd87813c CHANGES: Updated CHANGES document for 0.8.6
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-09 16:26:33 -04:00
Stefan Berger
77702d8f58 build-sys: Build libtpms v0.8.6
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-09 16:26:33 -04:00
Stefan Berger
18ba4c0206 rpm/debian: Add 0.8.5 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-01 13:25:31 +02:00
Stefan Berger
e3e37532d5 CHANGES: Updated CHANGES document for 0.8.5
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-01 13:25:31 +02:00
Stefan Berger
855c4e439a git: Fix erroneous gitignore entries; add missing ones
Fix erroneous gitignore entries that previously showed with the
following command line:

git ls-files -i --exclude-standard -c

Add some missing ones.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-08-31 22:47:53 +02:00
Stefan Berger
aaef222e86 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-07-29 17:54:34 -04:00
Stefan Berger
33a03986e0 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-07-29 17:54:34 -04:00
Stefan Berger
22c9bf90f4 tpm2: Avoid compiler warning by using memcpy instead of MemoryCopy (gcc 10.3)
Fix the following compiler warning from gcc 10.3.0 by using memcpy
instead of MemoryCopy (fixes issue #229).

tpm2/NVDynamic.c: In function 'NvRamGetEnd':
tpm2/NVDynamic.c:378:12: warning: function may return address of local variable [-Wreturn-local-addr]
  378 |     return iter;
      |            ^
tpm2/NVDynamic.c:339:26: note: declared here
  339 |     NV_RAM_HEADER        header;
      |                          ^
tpm2/NVDynamic.c: In function 'NvRamGetIndex':
tpm2/NVDynamic.c:411:12: warning: function may return address of local variable [-Wreturn-local-addr]
  411 |     return currentAddr;
      |            ^
tpm2/NVDynamic.c:339:26: note: declared here
  339 |     NV_RAM_HEADER        header;
      |                          ^

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-09 17:13:16 -04:00
Stefan Berger
a016ae7d29 build-sys: Build libtpms v0.8.5
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-07-09 17:13:16 -04:00
Stefan Berger
a594c4692a rpm/debian: Add 0.8.4 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-24 12:05:54 -04:00
Stefan Berger
dc176a5ff5 CHANGES: Updated CHANGES document for 0.8.4
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-24 12:05:54 -04:00
Stefan Berger
5cc98a62dc 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:05:54 -04:00
Stefan Berger
3ef9b26cb9 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:05:54 -04:00
Stefan Berger
f16250b35a 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:05:54 -04:00
Stefan Berger
2d412c9aeb build-sys: Run autoupdate on configure.ac for autconf 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:05:54 -04:00
Stefan Berger
d67dffcdde build-sys: Build libtpms v0.8.4
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-03 15:00:18 -04:00
Stefan Berger
9e736d5281 rpm/debian: Add 0.8.3 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-01 06:39:46 -04:00
Stefan Berger
043a0d9a66 CHANGES: Updated CHANGES document for 0.8.3
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-01 06:39:46 -04:00
Stefan Berger
2558937efa tpm2: Consume padding bytes in TPM2_ContextLoad() (Win2k19, issue #217)
Windows 2019 Server padds the TPM_ContextLoad() command with additional
bytes up to TPM_PT_MAX_OBJECT_CONTEXT for the TPMS_CONTEXT part. Since
libtpms does not use an OBJECT to serialize the keys (anymore) it now
uses less bytes than the MAXimum of TPM_PT_MAX_OBJECT_CONTEXT bytes and
the padding leaves some unconsumed bytes that end up failing the command
since no left-over bytes are allowed in any command.

When unconsumed bytes are left in TPMS_CONTEXT_Unmarshal() we check that
the original passed in size was that of TPM_PT_MAX_OBJECT_CONTEXT and
only then consume the additional padding bytes. Luckily only one command
calls TPMS_CONTEXT_Unmarshal() so that no unwanted side effects should
occur anywhere else, such as no bytes left for unmarshalling the next
structure.

The wisdom behind the padding is not quite clear but it feels like
ill-fixing the code to work around a Windows 2019 server bug...

This patch fixes issed #217

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-06-01 06:39:46 -04:00