Commit Graph

1661 Commits

Author SHA1 Message Date
Marc-André Lureau
90bd13750d tests: add installed-runner.sh
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2024-07-15 10:38:38 -04:00
Marc-André Lureau
bb59dc7f81 tests: use swtpm_setup.conf from tests
Replace usage of samples/swtpm_setup.conf, use the one from tests/
instead. This allows installed-tests to refer to it.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2024-07-15 10:38:38 -04:00
Marc-André Lureau
6ee1dac22d tests: install tests on the system
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2024-07-15 10:38:38 -04:00
Marc-André Lureau
457b28cc49 tests: lookup system binaries if INSTALLED is set
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2024-07-15 10:38:38 -04:00
Marc-André Lureau
aa5c7191ac selinux: add missing rules for libvirt system
Reported & tested:
https://issues.redhat.com/browse/RHEL-47273

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2024-07-15 09:47:38 -04:00
Lena Voytek
84042ab8b2 debian: Allow non-owner file write access in /var/lib/libvirt/swtpm/
swtpm sometimes needs to create lock files in subdirectories of
/var/lib/libvirt/swtpm/. Since libvirt sets the owner of these
subdirectories to root, apparmor blocks swtpm's access to this when set to
owner. Add write permissions for lock files without the owner restriction
tothe folder to fix wc denials.

Signed-off-by: Lena Voytek <lena.voytek@canonical.com>
2024-06-28 15:12:10 -04:00
Lena Voytek
4f6163ba45 debian: Add sys_admin capability to apparmor profile
Some features of swtpm require kernel modules, such as --vtpm-proxy. Fix
apparmor denials related to this by adding capability sys_admin to the apparmor
profile.

Signed-off-by: Lena Voytek <lena.voytek@canonical.com>
2024-06-28 15:12:10 -04:00
Stefan Berger
81da4d3289 tests: Update to ibmtpm20tss v2.2.0
With patches applied to the test suite this now works with
libtpms v0.7 .. v0.10-dev.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2024-06-27 09:37:21 -04:00
Stefan Berger
1f857cf529 build-sys: Bump up version to 0.10.0 at beginning of dev cycle
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2024-06-27 09:37:21 -04:00
Stefan Berger
f756ee8a28 tests: Use regex to compare --print-states sizes output
Older versions of libtpms produced smaller initial state files.
Therefore, use a regular expression to compare the sizes.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-06-17 12:49:14 -04:00
Stefan Berger
76b58d7e09 debian/rpm: Adjust changelog for 0.9.0 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-06-17 09:03:06 -04:00
Stefan Berger
e327269b1f CHANGES: Add documentation for changes in 0.9.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-06-17 09:03:06 -04:00
Stefan Berger
303d9cfdb5 swtpm: Use umask() to create/truncated state file rather than fchmod()
Since swtpm does not use concurrency while writing state files, set
the process umask to 0 when the state file is created or truncated for
writing and the user requested specific mode bits. This avoids an
additional syscall in the possibly timing critical path when processing
a TPM command and having to write the state.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-06-13 13:53:36 -04:00
Stefan Berger
c2e524dbc7 swtpm: Use fchmod to set mode bits provided by user
The mode bits that the user provided were only applied with open() and were
subject to masking with the value of current umask. When umask was set to
0027 the test case test_commandline was failing because the mode bits on
the create TPM state file were not the expected ones (masked by umask).
Therefore, set the mode bits using fchmod if the user provided them,
otherwise do not set them. This way the mode bits will be set to the values
the user requested.

Currently the directory storage backend was setting the mode bits to the
default value (0640) *after* opening the TPM state file. Now, if the user
did not provide any mode bits then the mode bits will be set so that the
file can be written to as owner. This ensures that at least mode bits 0600
are set by default. However, if the user provided mode bit flags then these
will be used without modification.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-06-12 14:23:54 -04:00
Stefan Berger
85a3a14a41 swtpm: Replace mkstemp with g_mkstemp_full (Coverity)
Replace mkstemp with g_mkstemp_full and pass parameters that lead to
the same mode bits and file opening flags and mkstemp had. This addresses
a Coverity complaint regarding missing application of umask before
mkstemp.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-06-11 12:02:28 -04:00
Stefan Berger
3d620d0dd5 debian: Sync AppArmor profile with what is used by Ubuntu
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-06-11 11:03:03 -04:00
Stefan Berger
b1b9a6a4ab tests: Add test cases for using swtpm --print-states while swtpm is running
swtpm <0.8 tried to lock the .lock file when executing --print-states,
which then failed when another swtpm was holding the lock. This adds
a test case for this scenario.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-06-11 08:43:01 -04:00
Stefan Berger
f7bfb5d8dc tests: Fix 3 occurrences of stray '\' before '-'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-06-10 19:40:31 -04:00
Stefan Berger
0c9a6c4a12 selinux: Re-add rule for svirt_tcg_t and user_tmp_t:sock_file (virt-install)
Re-add a missing rule to the swtpm_svirt policy that is needed for a
virt-install.

Reference: https://bugzilla.redhat.com/show_bug.cgi?id=2283878
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-05-31 14:55:23 -04:00
jeremie leska
857ec3ed93 swtpm: fix typo in help message
capabilites -> capabilities

Signed-off-by: jeremie leska <jeremie.leska@gmail.com>
2024-05-29 20:01:50 -04:00
Stefan Berger
3fe7895f9b selinux: Redevelop SELinux policy for Fedora 40 (ditch old rules)
Due to a significant change in the targeted SELinux policy re-develop
the SELinux policy for swtpm. New rules in swtpm_libvirt.te are needed
when libvirt causes new interactions between swtpm and other types.
Also consider extensions to the SELinux policy previously added due to
domain XML and command lines described in the following patches:

- 63825b296c
- 7dac1dbf6f

Also:
- add rules related to user_tmp_t are due to the following paths being used
  in session mode: /run/user/*/libvirt/qemu/run/swtpm
- add rules for swtpm_t accessing qemu_var_run_t file/dir/sockfile
- add rules for swtpm_localca (newly installed F40 system) needed once when
  /var/lib/swtpm-localca is empty and files there are created

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-05-27 20:06:17 -04:00
Stefan Berger
bfd6b8270a swtpm: cuse: Lock thread_busy_lock reading thread_busy (Coverity)
Coverity is complaining that thread_busy needs to be locked before
reading. For consistency reasons now also lock thread_busy before reading
it. However, in this case it does not make a difference whether this lock
is held when reading thread_busy since file_ops_lock is held when the
thread_busy flag is set and when it is read with a call to this function
(worker_thread_is_busy). Also while the thread is busy no further commands
can be submitted and it can then reset the thread_busy flag without holding
the file_ops_lock.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-04-22 08:48:48 -04:00
Stefan Berger
89b6991cee swtpm: cuse: Add lock comments to thread and variables (Coverity)
Coverity is complaining that ptm_response in the worker_thread needs to
be locked via the file_ops_lock since it is always locked when
ptm_response is accessed. However, once the thread has been started any
concurrent modification of the ptm_response is prevented with the
thread_busy flag. Therefore, add comments to the thread and ptm_reponse
variable about the locking.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-04-22 08:48:48 -04:00
Stefan Berger
249ead4572 swtpm: cuse: Lock file_ops_lock before sending startup (Coverity)
Even though concurrency is not possible before ptm_cuse_lowlevel_main
is called lock the file_ops_lock since Coverity is complaining that

- g_lastCommand in ptm_send_startup
- ptm_repsonse in ptm_send_startup
- tpm_running in main

are not locked. For consistency reasons now also lock these variables
even before activation of concurrency.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-04-22 08:48:48 -04:00
Stefan Berger
a18714f29a swtpm: cuse: Lock file_ops_lock before reading tpm_running
Lock the file_ops_lock before reading the tpm_running variable so that
access to access to it is serialized among all possible threads.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-22 16:03:03 -04:00
Stefan Berger
d258668d51 build-sys: Add support for --disable-tests to disable tests
Add support for --disable-tests to disable the tests and the checking
for tools that only need to be installed for the tests. Keep the tests
enabled as default as it was before.

Resolves: https://github.com/stefanberger/swtpm/issues/843
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-22 11:18:05 -04:00
Stefan Berger
e52406a768 swtpm_ioctl: Separate return code from flags
Separate the return code returned from change_fd_flags from the current/
original flags of the file descriptor. Return the flags in an optional
integer.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-19 15:22:33 -04:00
Stefan Berger
2534112322 tests: Rearrange order of test cases to run some also as 'root'
Some test cases can be run as root, so rearrange the order of the
test cases so that not all of them are skipped if the test case
runs as 'root'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-19 14:28:01 -04:00
Stefan Berger
529988f1e4 tests: Add tests for command line options and combinations of options
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-14 12:09:20 -04:00
Stefan Berger
f4fcd75685 swtpm_setup: Fail --pcr-banks without --tpm2
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-14 12:09:20 -04:00
Stefan Berger
e02626d038 swtpm_setup: Fail --decryption or --allow-signing without --tpm2
The help screen states that --decryption and --allow-signing require
--tpm2. Enforce this now also when checking flag combination since
neither flags would have any effect for a TPM 1.2.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-14 12:09:20 -04:00
Ross Lagerwall
f237f9f0b4 swtpm: Fix double free in error path
On error, the caller will call options_value_free() so don't free
ovs->options to avoid a double free.

Fixes: c94a1c4cbd ("swtpm: Fix memory leak in case realloc fails")
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
2024-03-14 08:45:35 -04:00
Ross Lagerwall
8655c6f8ec swtpm: Close fd after main loop
If we've accepted a connection fd during the main loop, close it once
the main loop terminates.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
2024-03-14 08:45:35 -04:00
Stefan Berger
a672b2dc03 headers: Exclude TPM ioctls definitions for the GNU/Hurd
Follow changes in the QEMU codebase supporting GNU/Hurd.

Reference: https://lists.nongnu.org/archive/html/qemu-devel/2024-01/msg03702.html

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-02-15 10:07:19 -05:00
Stefan Berger
a4347aff21 tests: Remove unnecessary '\' before '/'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-01-08 15:04:38 -05:00
Stefan Berger
06b1b1f9ff tests: Add softhsm_setup to shellcheck'ed files and fix issues
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-11-22 07:16:44 -05:00
Stefan Berger
4b008b9067 Revert "utils: Implement find_program() to try BINDIR path before PATH"
Test cases using swtpm_localca were failing because swtpm_localca
now picked up the swtpm_cert installed in /usr/bin/swtpm_cert rather
than the one in the PATH. This revert fixes the issue and users will
have to adjust their PATH for out-of-PATH installations.

Resolves: https://github.com/stefanberger/swtpm/issues/829
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-09-01 22:48:45 -04:00
Stefan Berger
63aae4d2a4 build-sys: Display GMP_LIBS and GMP_CFLAGS
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-29 18:59:13 -04:00
Stefan Berger
a61c08a4c7 build-sys: Only display warning if pkg-config for gmp fails
Since many older gmp development packages do not provide the pkg-config
file for gmp, just display a warning and fall back to default values.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-28 12:19:42 -04:00
Stefan Berger
3068b48d18 tests: Add missing 'exit 1' on unexpected file size on --reconfigure
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 17:19:29 -04:00
Stefan Berger
116953fb1d tests: Add test cases for swtpm_cert with max serial number
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-26 17:19:29 -04:00
Stefan Berger
1950b1765d swtpm_localca: Add support for up to 20 bytes serial numbers
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-22 21:21:03 -04:00
Stefan Berger
c877bec553 swtpm_cert: Add support for serial numbers up to 20 bytes long
x509 certificate serial numbers can be up to 20 bytes long.
Support this via gmp library.

A serial number must not have its most significant bit set, which
would indicate a negative number. If this is the case, insert '0'
as the first byte.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-22 21:21:03 -04:00
Stefan Berger
605e0ce880 build-sys/rpm/debian: Add gmp library and devel package as dependency
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-22 21:21:03 -04:00
Stefan Berger
6a2c342798 utils: Add 'const' to input parameter of type 'unsigned char *'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-21 19:01:38 -04:00
Stefan Berger
a96509723f swtpm_setup: Flush spk after persisting to create room for another key
Future extensions will need room for another key, so flush the spk after
persisting it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 11:36:21 -04:00
Stefan Berger
3e93c9b324 swtpm_localca: Introduce --key as more generic alias for --ek
swtpm_localca may also receive the key parameters of other keys than
the ek, therefore introduce the --key alias for --ek and rename the
variable ekparmas to key_params throughout the code.

Extend the man page to describe the --key option as an alias that
is to be used for other public key parameters than specifically those
of an ek.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 11:36:21 -04:00
Stefan Berger
f29b46f961 swtpm_setup: Refactor duplicate code into swtpm_tpm2_write_cert_nvram
Also rename the variable purpose to certtype since this better describes
what it is.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00
Stefan Berger
2c96242d13 swtpm_setup: Move persisting of certificate into tpm2_persist_certificate
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00
Stefan Berger
b3683ba107 swtpm_setup: Pass key_type to function creating filename for key
To make the function creating filenames for keys less ek-specific,
pass the key_type, such as "ek", into this function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-19 09:18:09 -04:00