Commit Graph

918 Commits

Author SHA1 Message Date
Stefan Berger
24cf223e79 spec: Add missing empty line to spec file
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-04 15:19:36 -04:00
Stefan Berger
925b06ee47 rpm/debian: Add 0.9.7 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-06-10 11:32:28 -04:00
Stefan Berger
676e481180 CHANGES: Updated CHANGES document for 0.9.7
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-06-10 11:32:28 -04:00
Stefan Berger
9f9baccdba 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.ibm.com>
2025-06-10 11:32:28 -04:00
Stefan Berger
7c9a2dc8d1 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:36:56 -04:00
Stefan Berger
9f6fe6c094 tpm2: Remove assigned-to value to offset because it is unused (Coverity)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 12:39:59 -04:00
Stefan Berger
761358fc82 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-15 11:56:40 -04:00
Stefan Berger
baea3de33e 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-15 11:56:40 -04:00
Stefan Berger
5af7abe1f6 tpm2: Filter bad input values to avoid underflow in FindNthSetBit (Coverity)
Address the following Coverity complaint (1550494) by filtering out bad
input values:

  "Expression i--, which is equal to 65535, where i is known to be equal
   to 0, underflows the type that receives it, an unsigned integer 16 bits
   wide."

aSize is typcially 2048 and n is always >= 1 per the input parameter.
Therefore no side-effects are expected from this filter.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 11:56:40 -04:00
Stefan Berger
d7f5fc3644 tpm2: Address a possible unsigned integer underflow (Coverity)
Resolve the following Coverity complaint:

  "Expression command->sessionNum - 1U, which is equal to 4294967295,
   where command->sessionNum is known to be equal to 0, underflows the
   type that receives it, an unsigned integer 32 bits wide."

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 11:56:40 -04:00
Stefan Berger
b5f8f313b7 tpm2: Remove assigned to value to offset because it is unused (Coverity)
Resolve the following Coverity complaint by removing assignment to offset:

  "Assigning value from offset + 148UL to offset here, but that stored
   value is overwritten before it can be used."

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 11:56:40 -04:00
Stefan Berger
444599e77a tpm2: Initialize eccPublic before passing to TPMS_ECC_POINT_Unmarshal (Coverity)
Resolve the following Coverity complaint:

  "Using uninitialized value eccPublic when calling TPMS_ECC_POINT_Unmarshal."

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 11:56:40 -04:00
Stefan Berger
caf9b95f8c tpm2: Preserve more *target and restore them if neede (Coverity)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 11:56:40 -04:00
Stefan Berger
1b0b41293a 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:46:57 -04:00
Stefan Berger
4fcbaaab30 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:59:32 -04:00
Stefan Berger
ed6687523b 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 17:05:15 -04:00
Stefan Berger
50973f8c8f rpm/debian: Remove entry describing reverted patch
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-06-04 13:52:00 -04:00
Stefan Berger
1034c0e2d7 CHANGES: Update CHANGES document for 0.9.7 after revert
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-21 19:15:08 -04:00
Stefan Berger
f73ee6c3bf Revert "Object: clear out sensitive area if on load if not provided"
This reverts commit e82727e546.

The issue has previously been resolved in commit 17255da54c.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-21 19:15:08 -04:00
Stefan Berger
87683f9ec4 rpm/debian: Add 0.9.7 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-14 10:53:27 -04:00
Stefan Berger
c9385bbec0 CHANGES: Updated CHANGES document for 0.9.7
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-14 10:53:27 -04:00
Rob Shearman
e2b5c4f5a8 Object: clear out sensitive area if on load if not provided
When an object is later marshalled in TPM2_ContextSave, the publicOnly
attribute isn't taken into account and therefore potentially stale
sensitive information can be marshalled, which is a problem if the
buffer sizes it contains have values that are too large - this
triggers assertion failures.

Avoid this by clearing out the sensitive area upon ObjectLoad if not
provided, making the behaviour consistent with when a fresh, unused,
object entry is used.

Signed-off-by: Rob Shearman <rob@graphiant.com>
2023-08-14 10:53:27 -04:00
Stefan Berger
0293264228 tpm2: Fix issue in CryptParameterEncryption() (TPM 2 errata v1.4)
Sync with upstream to fix issue in CryptParameterEncryption() from TPM 2
errate v1.4 2.6.1:

"The functions CryptParameterEncryption() and CryptParameterDecryption() in
the reference code in Part 4, 10.2.6.6.5 and 10.2.6.6.6 do not correctly
check the size of the parameter buffer to be encrypted or decrypted. To fix
the issue, the functions should be corrected to check that the parameter
buffer (a TPM2B type field) is at least 2 bytes in length and should use
the function UINT16_Unmarshal() to read the size of the buffer instead of"
BYTE_ARRAY_TO_UINT16().

[...]

The fixed CryptParameterEncryption() function will enter failure mode and
return TPM_RC_FAILURE if the internal response buffer does not contain
enough data for the UINT16 size field."

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-14 10:53:27 -04:00
Stefan Berger
68fedaf618 tpm2: Sync fix in TPM2_PolicyAuthorize() with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-14 10:53:27 -04:00
Stefan Berger
14a0d4d674 tpm2: Sync CryptParameterDecrypt implementation with upstream
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-14 10:53:27 -04:00
Stefan Berger
6a7d19ce0c tpm2: Fix issue related to CryptGenerateKeyDes (TPM 2 errata v1.4)
Fix the following issue from TPM 2 errata v1.4 2.6.3:

"The function CryptGenerateKeyDes() in the reference code in Part 4,
0.2.9.2.3 does not correctly check the symmetric key size provided in the
sensitive parameter. To fix the issue, the function will check that the
size of the requested TDES key is a multiple of 8 bytes or otherwise the
TPM will return TPM_RC_SYMMETRIC."

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-14 10:53:27 -04:00
Stefan Berger
6e41f8f48a tpm2: Check size of TPM2B_NAME buffer before reading 2 bytes from it
Fix the missing buffer size check that the TPM 2 errata v1.4 mentions in
2.6.2 by adding a buffer size check before reading 2 bytes from a
TPM2B_NAME buffer. There's no known CVE for this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-14 10:53:27 -04:00
Stefan Berger
70040a58ee build-sys: Build libtpms v0.9.7
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-14 10:53:27 -04:00
Stefan Berger
f8c2dc7e12 rpm/debian: Add 0.9.6 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 15:57:55 -05:00
Stefan Berger
c4d875e74d CHANGES: Updated CHANGES document for 0.9.6
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 15:57:55 -05:00
Stefan Berger
6a6d40d8e2 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:57:55 -05:00
Stefan Berger
45134aef3e build-sys: Build libtpms v0.9.6
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-02-28 15:57:55 -05:00
Stefan Berger
df1c3e98d6 rpm/debian: Add 0.9.5 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-07-01 11:36:16 -04:00
Stefan Berger
e93c0082be CHANGES: Updated CHANGES document for 0.9.5
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-07-01 11:36:16 -04:00
Stefan Berger
a4b8797259 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-06 08:47:05 -04:00
Stefan Berger
b1b2cf5e15 tpm2: Fix a potential overflow expression (coverity)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-05-29 13:23:21 -04:00
Ross Lagerwall
78a27cf0c3 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:40:22 -04:00
Stefan Berger
6728aada47 build-sys: Build libtpms v0.9.4
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-05-24 23:40:22 -04:00
Stefan Berger
e4d68670e1 rpm/debian: Add 0.9.4 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-04-25 14:17:25 -04:00
Stefan Berger
b6dc4fa924 CHANGES: Updated CHANGES document for 0.9.4
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-04-25 14:17:25 -04:00
Stefan Berger
64887bc651 tpm: #undef printf in case it is #define'd (OSS-Fuzz)
The build environment used by OSS-Fuzz reports this error.

 In file included from /src/libtpms/src/tpm_debug.c:42:
 /src/libtpms/src/tpm_debug.h:69:9: error: 'printf' macro redefined [-Werror,-Wmacro-redefined]
 #define printf(...) TPMLIB_LogPrintf(__VA_ARGS__);
 :         ^
 /usr/include/x86_64-linux-gnu/bits/stdio2.h:110:11: note: previous definition is here
 # define printf(...) \
           ^
 1 error generated.

The simple fix is to #undef printf in case it is #define'd.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-04-21 09:50:50 -04:00
Steve Langasek
26e65226c5 tpm2: Initialize variables due to gcc complaint (s390x, false positive)
Detected by gcc on Ubuntu/s390x

Origin: https://git.launchpad.net/ubuntu/+source/libtpms/tree/debian/patches/uninitialized-variable.patch

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2022-04-04 16:49:38 -04:00
Steve Langasek
e856a73933 tpm12: Initialize variables due to gcc complaint (s390x, false positive)
Detected by gcc on Ubuntu/s390x

Origin: https://git.launchpad.net/ubuntu/+source/libtpms/tree/debian/patches/uninitialized-variable.patch

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2022-04-04 16:49:38 -04:00
Stefan Berger
f0fda0646a Fix configure script to support _FORTIFY_SOURCE=3
gcc 12.1 supports _FORTIFY_SOURCE=3. Modify the existing check for whether
_FORTIFY_SOURCE=2 can be used to test compile with the user provided
CFLAGS and only add _D_FORTIFY_SOURCE=2 to the HARDENING_CFLAGS if the
user doesn't provide anything that's not compatible.

Following an online article _FORTIFY_SOURCE=3 may add more overhead, so
we only go up to level 2 for now and let build servers or user provide
the higher level via the CFLAGS.

https://developers.redhat.com/blog/2021/04/16/broadening-compiler-checks-for-buffer-overflows-in-_fortify_source#what_s_next_for__fortify_source

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-04-04 16:08:49 -04:00
Stefan Berger
897c8f8697 tpm2: Check return code of BN_div()
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:34:48 -04:00
Stefan Berger
c2e840b88b build-sys: Build libtpms v0.9.4
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-03-30 13:34:48 -04:00
Stefan Berger
a63c51805e rpm/debian: Add 0.9.3 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-03-07 12:07:25 -05:00
Stefan Berger
472bc355ef CHANGES: Updated CHANGES document for 0.9.3
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-03-07 12:07:25 -05:00
Stefan Berger
3f8fbc831b 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:03:08 -05:00
Juergen Repp
1de757972e 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:37 -05:00