Commit Graph

1755 Commits

Author SHA1 Message Date
Stefan Berger
8d887f195d cuse: Move duplicate code into tpm_end()
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-15 15:18:44 -04:00
Christopher Byrne
83361e74d7 configure.ac: Use m4sh in autoconf variable checks
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-30 16:10:50 -04:00
Christopher Byrne
2190513dbf configure.ac: Remove debug option
The user can set it themselves in CFLAGS. Autoconf defaults to -O2 -g
if CFLAGS is not set.

Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-30 16:10:50 -04:00
Christopher Byrne
079d7e3b46 configure.ac: Use m4sh and pkgconf macros for openssl
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-30 08:39:36 -04:00
Christopher Byrne
7c8aa19ed8 configure.ac: Simplify SELinux checks
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-30 08:39:36 -04:00
Christopher Byrne
cf46ff2cc0 configure.ac: Use m4sh and pkgconf macros for gnutls
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-30 08:39:36 -04:00
Christopher Byrne
ccb7e1c2f4 configure.ac: Use pkgconf for gmp
pkgconf supports setting GMP_CFLAGS and GMP_LIBS if the pkgconf file
does not exist, for older (pre-2019) distributions.

Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-30 01:12:42 -04:00
Christopher Byrne
0d1bb323e3 configure.ac: Use m4sh and pkgconf for CUSE support
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-30 01:12:42 -04:00
Christopher Byrne
754e23e416 configure.ac: Use pkgconf and m4sh for libseccomp
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-30 01:12:42 -04:00
Christopher Byrne
21f697a788 configure.ac: Use pkgconf and m4sh for libtpms crypto
PKG_CHECK_VAR was been available since 2014

Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-30 01:12:42 -04:00
Christopher Byrne
f37ee0e843 configure.ac: Use m4sh for sanitizers
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-29 22:44:15 -04:00
Christopher Byrne
a371f75890 configure.ac: Use m4sh for test coverage
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-29 22:44:15 -04:00
Christopher Byrne
ab4ef15ef3 configure.ac: Use m4sh in hardening
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-29 22:44:15 -04:00
Christopher Byrne
03dd21b25d configure.ac: Use m4sh for tests
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-29 22:44:15 -04:00
Christopher Byrne
f8910312df configure.ac: Use m4sh for chardev
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-29 22:44:15 -04:00
Christopher Byrne
ae580c90c4 configure.ac: Use pkgconf for glib
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-29 22:44:15 -04:00
Christopher Byrne
b1a6b5fa61 configure.ac: Use pkgconf of json-glib
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-29 22:44:15 -04:00
Christopher Byrne
af6b2ce0cd configure.ac: Clean up libtpms checks
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-29 22:44:15 -04:00
Christopher Byrne
6c7f9cd07a configure.ac: Use pkgconf macros for libtasn1
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-29 22:44:15 -04:00
Christopher Byrne
a59486aee4 configure.ac: Use correct m4 comments
Signed-off-by: Christopher Byrne <salah.coronya@gmail.com>
2025-06-29 22:44:15 -04:00
Stefan Berger
4a0e632f37 swtpm: Prevent an integer overflow (false positive; CID 440360)
Prevent an integer overflow with the recvd variable. However, the
buffer_len variable serves as an upper bound for how many bytes will ever
be received, so that this integer overflow will never occur. Therefore,
this is a false positive reported by Coverity. Fix it anyway.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-29 10:31:44 -04:00
Stefan Berger
2562694adc swtpm: Prevent an integer overflow (false positive; CID 440361)
Prevent an integer overflow that could result from adding the return value
of 'n' to an existing value. However, for this to occurr in this function,
one would have to write() more than 4G of data on a 32bit system for
example. So, this is a false positive reported by Covertity, but fix it
anyway.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-29 10:03:32 -04:00
Stefan Berger
6a25e170a9 swtpm: Adjust code to avoid integer overflows (false positive; CID 440362)
Change the type of buffersize parameter of SWTPM_IO_Read from size_t to
uint32_t to match that of the caller and to avoid Coverity complaints
about possible integer overflows. Also change the offset to uint32_t.

An integer overflow would never have occurred since buffersize always
served as an upper bound of the number of bytes received.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-29 10:03:32 -04:00
Stefan Berger
7622a6e51d swtpm: Check for sysconf returning bad size for _SC_PAGESIZE (CID 440365)
Catch the unlikely case that sysconf returns 0 for _SC_PAGESIZE and avoid
integer overflow with the pagesize calculation, that should never occur if
pagesize is within normal limits. Also ensure that no overflow happens
with the msync_count variable.

On 64bit machines, casting count to size_t could work but would not work on
32bit platforms where size_t is the same as uint32_t, so the overflow
complain would not go away there.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-29 10:03:32 -04:00
Stefan Berger
0727e87445 swtpm: Report error on rename's in error path (CID 466753)
If the revert of the renaming of files fails report an error there as well.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-29 10:03:32 -04:00
Stefan Berger
eb79f144dd swtpm: Return ssize_t rather than int from logging functions (CID 440364)
Return ssize_t rather than int from logging function to resolve Coverity
complaints about possible integer overflows. Since no caller looks at the
return value from the logging functions, no other changes are necessary.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-29 10:03:32 -04:00
Stefan Berger
f0c91b3947 swtpm: Mark do_fsync in linear backend as unused parameter
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-29 10:03:32 -04:00
Stefan Berger
24fdb845b4 swtpm: Display error for fsync option on linear storage backend
Display an error if the user set the fsync option when using the
linear storage backend.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-28 07:29:44 -04:00
Stefan Berger
9578dc45f2 swtpm: Display error for backup option on linear storage backend
Display an error if the user set the backup option when using the
linear storage backend. Update the documentation about the rejection.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-28 07:29:44 -04:00
Stefan Berger
bd77a3440a tests: Extend existing test case to use the new fsync option
Extend an existing test case to use the new fsync option to at least test
the option parser. That fsync() is actually being called is not easy to
observe.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-27 16:28:39 -04:00
Stefan Berger
093248eb4d swtpm: Add option for storage backend to use fsync
Add an option to have the storage backend use fsync whenever state is
written to disk. Advertise this capability with
'tpmstate-dir-backend-opt-fsync' and adjust a test case.

Only support for the directory-backend is implemented.

Extend the swtpm man page with a description of this new option.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-27 16:28:39 -04:00
Stefan Berger
795c1973c9 swtpm: Implement support for fsync on a file and directory
Implement support for fsync on a file and directory when using the
directory-backend. Pass the user's choice for whether to call fsync and
pass the boolean into the storage backend. Only the directory-backend is
supporting this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-27 16:28:39 -04:00
Stefan Berger
ec7730c70d swtpm_setup: Also check respbuffer_len for possible NULL pointer (CID 466756)
Some checks failed
Coverity Scan / coverity (push) Has been cancelled
respbuffer_len is a pointer that may be NULL but will not be NULL when
respbuffer is not NULL. Nevertheless, also check it for NULL pointer before
accessing it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-22 17:21:53 -04:00
Leo
17fc25d48a cuse: add libfuse3 support
libfuse2 contains unaddressed security issue. (libfuse/libfuse#15)

libfuse3 is preferred over libfuse2, while libfuse2 support is kept as
fallback.

	- src/swtpm/cuse_tpm.c: fuse3 as default, add a macro `WITH_FUSE2` when fallback fuse library is linked against
	- configure.ac: check fuse3, if not found, check fuse2, if still not found, fail out; show LIBFUSE_CFLAGS and LIBFUSE_LIBS in `./configure` output

Signed-off-by: Leo <i@hardrain980.com>
2025-05-22 10:47:23 -04:00
Stefan Berger
1db1037525 swtpm: Return error if more bytes received than user wanted to send
Some checks are pending
Coverity Scan / coverity (push) Waiting to run
Return an error code if HASH_DATA received more bytes from the user than
what the user indicated in the length field that he wanted to send. This
avoids an integer underrun of the 'remain' variable in the loop that would
then cause the loop to wanting to receive around 4GB of data.

Also fix some indentation issues.
Use be32toh instead of (the equivalent) htobe32 when reading from the
packet.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-20 20:28:25 -04:00
Stefan Berger
4da66c66f9 tests: Retry NVWrite command after 0x922 return code and inc lockout counter
When returncode 0x922 is received from NVWrite then retry the command so
that it gets the expected error code from failing to provide a password.
When checking the lockout counter, increase the numbers now.

Patched versions of libtpms may not return 0x922 anymore, so write the code
that it can test both cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-12 18:46:28 -04:00
Stefan Berger
8f9166787c tests: Do not patch for OpenSSL 3.x anymore since bug seems fixed
A patch was applied to the IBMTSS2 test cases due to a bug in OpenSSL. At
least with OpenSSL 3.2.4 (and possibly much earlier), this bug has been
found to have been fixed, so disable the patching for now and leave a FIXME
in there directing that the code block can be removed entriely at some
point.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-09 13:17:39 -04:00
Stefan Berger
a4a9f336f5 tests: Use IBMTSS2 test v2.4.1
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-09 13:17:39 -04:00
Stefan Berger
95476e31ff swtpm_setup: Hint at profile default-v2 when CreatePrimary() fails with 0x2c4
If TPM2_CreatePrimary(RSA) fails with 0x2c4 error code, display an error
message hinting the user at using the 'default-v2' profile since most likely
the RSA key size is too large for the default or given profile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-09 10:56:13 -04:00
Stefan Berger
732bbd6ad3 test: Extend existing test case with backup option
Extend an existing test case with the backup option for the directory
backend. Check correct behavior by trying to start swtpm with missing
state decryption key and ensure that file renamings are handled as
expected.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-09 08:44:42 -04:00
Stefan Berger
9b7021bb01 swtpm: Implement storage functions to restore a state backup file
When the users specifies that a backup file is to be made and the permanent
state file is missing when the NVRAM is initialized (SWPTM_NVRAM_Init), but
the backup state file exists, then swtpm will permanently rename the backup
file to permanent state file and attempt to start with it. Otherwise, it
will try to start with the 'normal' permanent state file first and if this
fails, it will rename the backup file to the permanent state file and
attempt to start with it. If both cases fail, it will revert any renaming.

Only support for the directory-backend is implemented.

Extend the swtpm man page with a description of this behavior.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-09 08:44:42 -04:00
Stefan Berger
e3694b7b15 swtpm: Add option for storage backend to make a backup file
Add an option to have the storage backend make a backup file of
the permanent state file. Advertise this capability with
'tpmstate-dir-backend-opt-backup' and adjust a test case.

Extend the documentation.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-09 08:44:42 -04:00
Stefan Berger
186f72a3a9 swtpm: Make a backup of the permanent state file in dir-backend
Query for tpmstate_get_make_backup() to decide whether to make a backup of
the permanent state file. If a backup is requested, then rename the current
state file in the directory backend to the backup file (suffix .bak).

Only the directory backend supports backing up of the permanent state file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-09 08:44:42 -04:00
Stefan Berger
8522c9dfad man: Add rsa-keysize-4096 to possible capabilties output of swtpm
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-08 20:49:36 -04:00
Stefan Berger
e3668c9f26 swtpm_setup: Add support for RSA-4096 keys for EKs
Add support for RSA-4096 kyes for EKs. This requires users to choose the
default-v2 profile because this is the only profile that currently enables
this type of a key.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-08 20:49:36 -04:00
Stefan Berger
8a3592fb02 tests: Extend regex to allow for optional RSA-4096 keys
libtpms v0.11 will support RSA-4096 keys. Adjust the test case
regex for optional output of 'tpm2-rsa-keysize-4096'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2025-05-07 10:28:58 -04:00
Stefan Berger
fdb2b546d4 samples: Have 2 more files shellcheck'ed
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2025-05-02 09:50:19 -04:00
Stefan Berger
6d951a7a35 debian: Do not user parallel testing to avoid timeouts
The build for RISC-V causes timeouts when running tests in parallel due
to the CPU being emulated. Avoid the timeouts by not running parallel
tests.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-29 21:32:07 -04:00
Stefan Berger
4d2e967423 tests: Use proper command line options on GNU/Hurd systems
GNU/Hurd systems use the same sed/sha1sum/state command lines as Linux
and Cygwin.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-28 20:38:14 -04:00
Stefan Berger
6df68dcde5 swtpm: Make swtpm compilable on GNU/Hurd systems
Fix issues related to headers to make swtpm compilable on GNU/Hurd systems.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-04-28 20:38:14 -04:00