Commit Graph

1774 Commits

Author SHA1 Message Date
Arthur Gautier
d41849c30e swtpm: fixup typo in error message when pathlen is too long
Signed-off-by: Arthur Gautier <arthur.gautier@arista.com>
2025-11-30 10:34:46 -05:00
Luca Boccassi
e9dfe88740 apparmor: add support for mkosi integration working directory
mkosi integrates with swtpm to automatically set up and build
VMs with vTPM support. The working directory is in an ephemeral
namespace that appears as /work/tmp/, and apparmor stops swtpm
from creating the local state files (lockfile, etc).
Add a policy entry to allow this to work.

Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
2025-11-30 10:28:09 -05:00
Stefan Berger
8084873972 tests: Fix a spelling error in a variable
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-10-01 11:47:22 -04:00
Stefan Berger
3bbeedf119 swtpm_setup: Propagate --allow-signing option for certificate creation
Propagate the --allow-signing option from swtpm_setup into swtpm_localca
so that a certificate will finally be created that reflects the 'Digital
Signature' key usage.

Extend a test case to check for the 'Digitial signature' flag under
'key usage' when --allow-signing is passed.

Resolves: https://github.com/stefanberger/swtpm/issues/1061
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-10-01 11:47:22 -04:00
Stefan Berger
72c5dab0b9 swtpm: Fix comparison of integers with different signedness
Fix the following issue reported when compiling on m68k:

ctrlchannel.c: In function 'ctrlchannel_process_fd':
ctrlchannel.c:710:20: error: comparison of integer expressions of
   different signedness: 'uint32_t' {aka 'unsigned int'} and 'ssize_t'
   {aka 'int'} [-Werror=sign-compar ]
  710 |         if (remain < n)
      |                    ^

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-09-23 10:58:12 -04:00
Luca Boccassi
5c21ea0f3f debian: drop postinst, no longer needed
Use sysusers and tmpfiles

Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
2025-09-23 09:32:29 -04:00
Luca Boccassi
d318d40469 swtpm: install sysusers.d and tmpfiles.d configs
These configuration files will create the required user, group and
data directory on first boot/factory reset/package installation,
without requiring manual scripts or actions. This is very important
for image-based OSes, but it is useful in other cases to, to allow
using declarative configuration instead of scripts.

RPM now has built-in support for sysusers.d too.

https://www.freedesktop.org/software/systemd/man/latest/tmpfiles.d.html
https://www.freedesktop.org/software/systemd/man/latest/sysusers.d.html

Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
2025-09-23 09:32:29 -04:00
Luca Boccassi
9be16ffe0a automake: remove more generated files on distclean
Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
2025-09-23 08:47:26 -04:00
Luca Boccassi
645b116787 automake: do not remove checked in selinux source files on distclean
Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
2025-09-23 08:47:26 -04:00
Bastian Germann
4f963a9330 swtpm_ioctl: double default poll timeout
On very slow architectures the 10s timeout is too slow and can fail
tests. For example on MIPS:

https://buildd.debian.org/status/fetch.php?pkg=swtpm&arch=mipsel&ver=0.7.1-1.1&stamp=1684146306&raw=0
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1036101

Double it to 20s, which has been used for ~2 years in Debian and
has proven to be sufficient to avoid spurious failures.

Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
2025-09-23 08:40:51 -04:00
Luca Boccassi
bba72fb92d man: fix various typos found by Lintian
Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
2025-09-23 08:36:36 -04:00
Stefan Berger
5033ec80c1 tests: cuse: Create /dev/null in chroot environment
Due to the usage of daemonize_prep() by the CUSE swtpm create /dev/null
in the chroot environment.

Suggested-by: Corigne <nathanjodoin@gmail.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-28 10:47:04 -04:00
Stefan Berger
eccaf58ded ci: Check logs for ASAN or UBSAN reports
Exit the build with an error code if ASAN and/or UBSAN issues
are reported.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-28 10:16:32 -04:00
Stefan Berger
a7761d168c tests: Extend test case to test for concurrent access to locked storage
Extend an existing test case to ensure that a 2nd swtpm process terminates
with an error related to not being able to get a lock on the storage's
lockfile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-21 12:13:05 -04:00
Stefan Berger
bdf7e3d6df swtpm: Daemonize before starting TPM to hold locks
Since the CUSE TPM starts TPM in one process but then daemonizes and
effectively runs in a child process, the lock records on the storage
that the parent may have set up are lost due to them not being inherited
by the child. Fix the issue by daemonizing before the TPM is started so
that the child grabs the lock on the storage. Prevent CUSE from forking
so that not another child is created.

As a side-effect, this now moves any error reporting, that may previously
have occurred in the main process and where messages were show on stderr,
into the child process. A log is now required for these messages to become
visible.

Resolves: https://github.com/stefanberger/swtpm/issues/1050
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-21 12:13:05 -04:00
Stefan Berger
3d5d0f2fcb swtpm: Suppress the logging when displaying info flags' JSON result
When printing the output of the info flags, the resuling JSON printed to
stdout should be the only printout. Therefore, suppress all informative
output to stdout so that either the JSON is the only output or only error
messages are printed.

Fixes: 3f551e1dc ("swtpm: Implement --print-info to run TPMLIB_GetInfo with flags")
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-18 14:27:15 -04:00
Stefan Berger
2f46832dab swtpm: Print some warnings to stdout rather than stderr
Have warnings print to stdout since they do not lead to swtpm exiting with
an error code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-18 14:27:15 -04:00
Stefan Berger
bf15af46d1 swtpm: Only disable informative message when using SUPPRESS_INFO_LOGGING
When the special logging file descriptor SUPPRESS_INFO_LOGGING is chosen,
then only suppress informative and warning messages while still allowing
error messages to be printed to stderr.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-18 14:27:15 -04:00
Stefan Berger
a9f680df00 cuse: Move duplicate code into tpm_end()
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-15 16:16:30 -04:00
Stefan Berger
665486b817 tests: Extend test cases with RSA-4096 and default-v2 testing
RSA-4096 is enabled in libtpms v0.11 and requires that default-v2
profile be used. Extend existing test case with test for RSA-4096
and default-v2 profile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-08-05 18:05:08 -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