Commit Graph

902 Commits

Author SHA1 Message Date
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
Stefan Berger
0a11a6726d build-sys: Build libtpms v0.9.3
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-03-02 09:15:37 -05:00
Stefan Berger
e81d634c27 rpm/debian: Add 0.9.2 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-01-05 15:59:06 -05:00
Stefan Berger
259c1310ff CHANGES: Updated CHANGES document for 0.9.1
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-01-05 08:07:18 -05:00
Stefan Berger
b662e6fd71 tpm2: When writing state initialize s_ContextSlotMask if not set
If s_ContextSlotMask was not set since the TPM 2 was not initialized
by a call to TPM_Manufacture() or the state was not resumed, then
initialize the s_ContextSlotMask to 0xffff.

This situation can occur if a VM with an attached swtpm was started
and the VM's firmware either doesn't support TPM or didn't get to
initialize the vTPM.

The following commands recreated the issue with a SeaBIOS-only VM that
had no attached hard disk but an attached TPM 2:

virsh start BIOS-only-VM ; virsh save BIOS-only-VM save.bin ; \
 virsh restore save.bin

Error: Failed to restore domain from save.bin
error: internal error: qemu unexpectedly closed the monitor: \
2022-01-04T19:26:18.835851Z qemu-system-x86_64: tpm-emulator: Setting the stateblob (type 2) failed with a TPM error 0x3 a parameter is bad
2022-01-04T19:26:18.835899Z qemu-system-x86_64: error while loading state for instance 0x0 of device 'tpm-emulator'
2022-01-04T19:26:18.835929Z qemu-system-x86_64: load of migration failed: Input/output error

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2035731
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-01-05 08:07:18 -05:00
Stefan Berger
52cd3bcdfd build-sys: Build libtpms v0.9.2
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-01-05 08:07:18 -05:00
Stefan Berger
1ff6fe1f43 CHANGES: Updated CHANGES document for 0.9.1
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-24 09:54:47 -05:00
Stefan Berger
826754c525 rpm/debian: Add 0.9.1 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-24 09:54:47 -05:00
kpcyrd
d39256e2e8 Fix "maybe-uninitialized" warning
exp_array_size is always initialized if `rc == TPM_RC_SUCCESS` and never used
if `rc != TPM_RC_SUCCESS` but some compilers have trouble noticing this.

Signed-off-by: kpcyrd <git@rxv.cc>
2021-10-29 10:19:42 -04:00
Stefan Berger
bf1f9c8d4e 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 17:10:21 -04:00
Stefan Berger
dbfc15279a build-sys: Build libtpms v0.9.1
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-15 17:10:21 -04:00
Stefan Berger
dc4e3f6313 rpm/debian: Add 0.9.0 entry in changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-28 16:55:28 -04:00
Stefan Berger
ab25f924d1 CHANGES: Updated CHANGES document for 0.9.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-28 16:55:28 -04:00
Stefan Berger
4bc846f869 build-sys: Use -DOPENSSL_SUPPRESS_DEPRECATED to suppress warning (OSSL 3)
Instead of using -Wno-deprecated-declarations use
-DOPENSSL_SUPPRESS_DEPRECATED to only suppress OpenSSL deprecated
declarations warnings.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-09-21 16:52:22 -04:00
Stefan Berger
f45bafa9bd 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-15 13:28:08 -04:00
Stefan Berger
3091ef1184 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-15 13:28:08 -04:00
Stefan Berger
ed94c7fd14 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-15 13:28:08 -04:00