Commit Graph

1306 Commits

Author SHA1 Message Date
Stefan Berger
bd282cce6a tpm2: Fix definition of SequenceUpdate error codes
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
f8ddf879af tpm2: Replace occurrences of xorr with xor
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
4c7dcf2db3 tpm2: Rebase on TPM v1.83: Reduce diffs
- Rename files so the filenames match
- Reduce whitespace diffs
- Other trivial changes

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
5de6c7fe40 scripts: Implement scripts to be able to use meld on upstream codebase
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-31 18:57:14 -04:00
Stefan Berger
4c374f9994 tpm2: Have TPM2_NV_DefineSpace call NvDefineSpace
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-22 15:45:42 -04:00
Stefan Berger
7dfe310f06 configure.ac: Remove old debug enablement and commented statements
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-07 17:44:55 -04:00
Stefan Berger
826771bb4f configure.ac: Use m4sh for if statement
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-07 17:44:55 -04:00
Stefan Berger
1a7aa5a146 configure.ac: Use m4sh for hardending
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-07 17:44:55 -04:00
Stefan Berger
923ecc0994 configure.ac: Use m4sh for test-coverage
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-07 17:44:55 -04:00
Stefan Berger
aebb81b74e configure.ac: Use m4sh for OpenSSL functions-checking block
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-07 17:44:55 -04:00
Stefan Berger
05318a30c8 configure.ac: Reformat to 4 spaces indentation
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-07 17:44:55 -04:00
Stefan Berger
f1b7e02fb5 configure.ac: Use m4sh for case statments
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-07-07 17:44:55 -04:00
Stefan Berger
0453e7b7df tpm2: Helpers: Have ObjectGetPublicParameters return TPM_RC
Convert ObjectGetPublicParameters to return TPM_RC and have it return
TPM_RC_MEMORY in case of a NULL pointer returned from BN_new() and
TPM_RC_FAILURE for any other error. Adjust the 2 callers.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-06-13 17:08:18 -04:00
Stefan Berger
e369684b99 tpm2: Helpers,OpenSSL: Convert some TPM_RC_FAILURE to TPM_RC_MEMORY
Convert those TPM_RC_FAILURE return codes to TPM_RC_MEMORY where
it is certain that it is only an issue related to no memory being available
rather than anything else. The following OpenSSL functions qualify for
this:

- BN_CTX_new & BN_CTX_new_ex
- BN_new

The following ones do not qualify:

- RSA_new: could have failure with ENGINE_init() and ENGINE_get_RSA()
- EC_KEY_new: could have failure with ENGINE_init() and ENGINE_get_EC()
- BigInitialized: initializer could be NULL
- BN_bin2bn: length could be 0

Some functions now test for NULL pointers early on to return TPM_RC_MEMORY.
They would previously have failed in BigInitialized() if the BIGNUM had
been a NULL pointer.

Since TPM_RC_FAILURES should never occur, the new TPM_RC_MEMORYs should
never occur, either. So, this is primarily a clean-up.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-06-13 17:08:18 -04:00
Stefan Berger
22bb8db8e6 tpm2: Helpers: Fix a possible memory leak
Fix a possible memory leak that may occur in case of a failure in
ObjectGetPublicParameters. The already allocated dP, dQ, and qInv
need to be freed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-06-13 17:08:18 -04:00
Stefan Berger
daa2dbdc4d tpm2: Avoid NULL pointer access in case allocation fails
EC_POINT_set_affine_coordinates_GFp would dereference the EC_POINT if it
was NULL. Check P != NULL before calling this function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-06-13 17:08:18 -04:00
Stefan Berger
04b2d8e9af tpm2: Fix potential out-of-bound access & abort due to HMAC signing issue
Some checks failed
Coverity Scan / coverity (push) Has been cancelled
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 12:27:45 -04:00
Stefan Berger
95d144c510 man: Fix typo in man page
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-06-02 17:23:32 -04:00
orbea
95fff22c9b tpm2: fix build for LibreSSL 4.1.0
With LibreSSL 4.1.0 the EC_POINTs_mul function was removed, but the
newer OpenSSL 3 code path works instead.

Signed-off-by: orbea <orbea@riseup.net>
2025-05-26 14:03:38 -04:00
Stefan Berger
e79d68e2d9 ci: Run 'apt update' before 'apt install'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-26 12:56:28 -04:00
Stefan Berger
5da0738636 tpm2: In CheckLockedOut replace TPM_RC_RETRY with TPM_RC_SUCCESS
Some checks failed
Coverity Scan / coverity (push) Has been cancelled
In CheckLockedOut replace the return code of TPM_RC_RETRY with
TPM_RC_SUCCESS since it does not seem to be necessary to run the TPM2
command again but the TPM2 can continue executing the current command.
If NVRAM wasn't available then the code in CheckLockedOut would return
with an error already.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-17 09:25:54 -04:00
Stefan Berger
4dd12eb253 tpm2: Set SFL of default-v2 profile to STATE_FORMAT_LEVEL_CURRENT
To enable RSA-4096 in the default-v2 profile, set the stateFormatLevel
to STATE_FORMAT_LEVEL_CURRENT (8).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-08 20:48:06 -04:00
Stefan Berger
dca9540bc2 tpm2: Fix bugs in RuntimeProfileDedupStrItems
Fix the following bugs in RuntimeProfileDedupStrItems:
- RuntimeProfileDedupStrItems did not memmove the correct number of bytes,
  leading to potential crashes.
- Also, it did not handle deduplicating the last item in the comma-
  separated list correctly.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-08 09:13:06 -04:00
Dan Streetman
e814a1c731 tpm2: Enable support for 4096 bit RSA keys (with fixes)
- Enable RSA_4096
- Add RSA_4096 to s_KeySizesRSA at stateFormatLevel 8
- Increase STATE_FORMAT_LEVEL_CURRENT to 8
- Update tests for larger object size and increased StateFormatLevel
- In NVMarshal.c replace MAX_RSA_KEY_BITS with old value 3072
  so that the state is acceptable to older versions of libtpms;
  if we wrote 4096, then older versions of libtpms would reject the
  state.
- In NVMarshal.c replace RSA_4096 with '0' so it is acceptable to older
  versions; if we wrote '1', then older versions of libtpms would reject
  the state.

Fixes: #491

Signed-off-by: Dan Streetman <ddstreet@ieee.org>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-07 12:23:44 -04:00
Stefan Berger
f756952283 Revert "tpm2: Enable support for 4096 bit RSA keys"
This reverts commit 63627b335e.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-07 11:45:36 -04:00
Dan Streetman
63d0d49a7f tpm2: Add 'default-v2' profile
The 'default-v2' profile is currently just a copy of the 'default-v1'
profile, other than the change in the .description text to change
'v0.10' to 'v0.11'.

Signed-off-by: Dan Streetman <ddstreet@ieee.org>
2025-05-07 10:38:22 -04:00
Dan Streetman
63627b335e tpm2: Enable support for 4096 bit RSA keys
- Enable RSA_4096
- Add RSA_4096 to s_KeySizesRSA at stateFormatLevel 8
- Increase STATE_FORMAT_LEVEL_CURRENT to 8
- Update tests for larger object size and increased StateFormatLevel

Fixes: #491

Signed-off-by: Dan Streetman <ddstreet@ieee.org>
2025-05-07 10:38:22 -04:00
Stefan Berger
5695736b4f tpm2 + test: Make it compilable on Debian GNU Hurd
The simple changes make it compilable on GNU Hurd where it is currently
failing to build.

Link: https://buildd.debian.org/status/package.php?p=libtpms&suite=sid
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-28 12:16:21 -04:00
Stefan Berger
3a63c3f3df ci: Update from ubuntu-20.04 to ubuntu-22.04 due to EOL
Ubuntu 20.04 is EOL. Therefore, upgrade it to 22.04.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-28 12:01:31 -04:00
Stefan Berger
567983d859 tpm2: Restrict NV index datasize to MAX_NV_INDEX_SIZE (CID 1608875)
Resolve an issue reported by Coverity caused by the maximum value of
datasize (max. size of an NV index) that was allowed to be 0x10100
(17 bits) even though later on it tried to read an array of maximum size
expressed by 16 bits (Coverity complaint). However, the maximum value of
datasize could only ever have been MAX_NV_INDEX_SIZE, which is gated by
restrictions on the size of an NV index. Therefore, restrict the maximum
datasize of an NV index to MAX_NV_INDEX_SIZE (2048 bytes) since this is
the maximum size that an NV index can be defined for.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-09 10:30:16 -04:00
Stefan Berger
796352fe5c ci: Add a coverity workflow
Trigger the coverity scan workflow when pushing to coverity_scan branch.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-08 22:55:09 -04:00
Stefan Berger
ecb769cdb8 ci: Add github actions script for test builds
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-16 11:32:48 -05:00
Stefan Berger
850c5db370 tpm2: Fix a compilation error in frozen profile
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-13 16:21:16 -05:00
Stefan Berger
5d1014abf2 tpm2: Freeze default-v1 profile
For any new commands, algorithms, and attributes a new profile 'default-v2'
has to be started.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-13 13:48:30 -05:00
Stefan Berger
c56f8f779c tpm2: Add asserts to silence compiler warning due to -Wstringop-overflow=
The following error occurrs on Fedora build servers. To silence the
compiler warning add runtime asserts:

tpm2/crypto/openssl/CryptCmac.c: In function 'CryptCmacEnd':
tpm2/crypto/openssl/CryptCmac.c:194:48: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
  194 |             subkey.t.buffer[subkey.t.size - 1] ^= xorVal;
      |                                                ^
tpm2/TpmTypes.h:1477:33: note: at offset -1 into destination object 'buffer' of size 16
 1477 |         BYTE                    buffer[MAX_SYM_BLOCK_SIZE];
      |                                 ^
lto1: all warnings being treated as errors

In CryptCmacStart the following initialization is done:

cState->iv.t.size = CryptGetSymmetricBlockSize(def->algorithm, def->keyBits.sym);

Also ensure that CryptGetSymmetricBlockSize in this case also always returns
a valid size to the TPM2B_IV that it is initializing, which would be the root
cause of any error.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-06 12:56:21 -05:00
Stefan Berger
3209d3b57d Travis: Downgrade to setuptools 59.6.0 to avoid error in 71.x
There seems to be a well known error in setuptools 71.x that prevents
installation of cpp-coveralls on Travis now:

File "/usr/local/lib/python3.10/dist-packages/setuptools/_core_metadata.py", line 285, in _distribution_fullname

    canonicalize_version(version, strip_trailing_zero=False),

TypeError: canonicalize_version() got an unexpected keyword argument 'strip_trailing_zero'

Fall back to the default version that is used in Ubuntu Jammy (59.6.0)
since later versions also lead to the same error.

Link: https://github.com/pypa/setuptools/issues/4483
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-12-06 12:56:21 -05:00
Stefan Berger
f22745c729 debian: Use --disable-hardening to avoid multiple usages of -D_FORTIFY_SOURCE=.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-15 10:52:20 -05:00
Stefan Berger
8061411962 tpm2: Add padding to OBJECT for 32bit targets
The nvram_offsets test fails on 32bit targets due to an unexpected size
of an OBJECT. This was due to missing padding.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-15 10:52:20 -05:00
Stefan Berger
bdd9a771f7 build-sys: Build libtpms v0.11.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-15 10:52:20 -05:00
Stefan Berger
17f253a767 rpm/debian: Add 0.10.0 entry to changelog
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-14 07:51:51 -05:00
Stefan Berger
80aa61bae1 CHANGES: Updated CHANGES document for 0.10.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-14 07:51:51 -05:00
Stefan Berger
ad6e794d11 man: Fix spelling mistakes and mentioned Attributes for profiles
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-13 12:05:59 -05:00
Stefan Berger
7e2526a265 tests: Initialize len_cmp to 0 so it has an assigned value
Avoid the following error message due to potentially
uninitialized variable:

base64decode.c:64:20: warning: The right operand of '!=' is a garbage \
  value [core.UndefinedBinaryOperatorResult] <--[clang]

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-11 17:11:19 -05:00
Stefan Berger
64d263aff0 build-sys: Do not build statically linked tests when --disable-static used
When --disable-static is used statically linked tests cannot be run.
Therefore, put the evaluation of --enable-static-tests after
--disable-static has been tested for and only set ENABLE_STATIC_TESTS
if both are 'yes'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-11 17:11:19 -05:00
Stefan Berger
fa4f9ab561 tests: Ignore gcc -Wmissing-braces on OBJECT initialization
Have gcc ignore -Wmissing-braces to suppress 15 of these types of
warnings:

/home/stefanb/dev/libtpms/tests/object_size.c:13:21: warning: missing braces around initializer [-Wmissing-braces] <--[gcc]
   13 |     OBJECT object = {
      |                     ^
/home/stefanb/dev/libtpms/tests/object_size.c:13:21: warning: missing braces around initializer [-Wmissing-braces] <--[gcc]
[...]

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-11 17:11:19 -05:00
Stefan Berger
48d52b5e40 tests: Initialize cmd with NULL at top of function
Fix the following gcc warning on Fedora rawhide:

tpm2_cve-2023-1017.c: In function ‘main’:
tpm2_cve-2023-1017.c:169:5: warning: ‘cmd’ may be used uninitialized [-Wmaybe-uninitialized]
  169 |     free(cmd);
      |     ^~~~~~~~~
tpm2_cve-2023-1017.c:125:20: note: ‘cmd’ was declared here
  125 |     unsigned char *cmd = malloc(maxcmdsize);
      |                    ^~~

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-11-11 17:11:19 -05:00
Stefan Berger
b8c9153a3f tpm2: Only copy Attributes when non-modifyable profile is chosen
If the user provides no Attributes field in the profile then do not copy
the attributes from the internal profile if that profile may be modified.
In this case assume that the the user wanted no attributes. It now is
also unnecessary that any Attributes be set in a modifyable profile ever,
since they will not be copied.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-17 16:30:30 -04:00
Stefan Berger
a5248a9859 test: Allow setting Attributes in JSON profile with an empty string
Adjust the regex checking the JSON input to allow for empty string values,
which will be only used by 'Attributes' since they are all optional.
Then, allow the user to provide an empty string with the Attributes in the
JSON like this: {...,"Attributes":"", ...}

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-17 16:30:30 -04:00
Stefan Berger
aef0ecbeb4 tpm2: Add missing attributes to code documentation and man pages
Add attributes documentation where found missing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-17 16:30:30 -04:00
Stefan Berger
ecff064e8d tpm2: Implement check to disable ECC key derivation: no-ecc-key-derivation
Per "TCG FIPS 140-3 guidance for TPM 2.0" document the following functions
must prevent an asymmetric ECC key derivation:
- Table 14: TPM2_CreateLoaded
- Table 18: TPM2_ZGen_2Phase
- Table 26: TPM2_Commit
- Table 26: TPM2_EC_Ephemeral

Return TPM_RC_TYPE as a return code to indicate failure of deriving a key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-10-15 11:56:24 -04:00