Commit Graph

1439 Commits

Author SHA1 Message Date
Stefan Berger
0e0d346651 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-13 08:52:56 -04:00
Stefan Berger
e813c5a985 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-13 08:52:56 -04:00
Stefan Berger
95acda912f ci: Update from ubuntu-20.04 to ubuntu-24.04 due to EOL
Github actions does not run ubuntu-20.04 anymore due to EOL. Update the
20.04 entries to use 24.04.

cpp-coveralls needs an older version of python3 due to pkgutil.ImpImporter
having disappeared in more recent python versions. Therefore, leave
test-coveralls at 22.04.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-13 08:52:56 -04:00
Stefan Berger
746834fc6d ci: Run apt-get update
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-13 08:52:56 -04:00
Stefan Berger
e6de90740f ci: Add github actions to replace Travis
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-13 08:52:56 -04:00
Stefan Berger
1c27ab887c CHANGES: Add a note about OPENSSL_ENABLE_SHA1_SIGNATURES=1 for swtpm
Users should use swtpm >= 0.10.0, since it handles SHA1 signatures
better. This version needs users to set OPENSSL_ENABLE_SHA1_SIGNATURES=1
for swtpm to be able to sign a SHA1.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2025-05-13 08:52:56 -04:00
Stefan Berger
1977a14205 tests: Set OPENSSL_ENABLE_SHA1_SIGNATURES=1 on swtpm in IBMTSS2 test
To keep the IBMTSS2 test running, set OPENSSL_ENABLE_SHA1_SIGNATURES=1
on swtpm so that it is allowed to sign a SHA1 and does not create
and error.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2025-05-13 08:52:56 -04:00
Stefan Berger
67cae50686 tests: Set OPENSSL_ENABLE_SHA1_SIGNATURES=1 for IBMTSS2 test
The IBMTSS2 tests suite creates signatures over SHA1 that may now fail on
RHEL 9.x and CentOS 9. To have these tests succeed set
OPENSSL_ENABLE_SHA1_SIGNATURES=1 so the tests do not need to be modified
and also check that the TPM 2 can handle SHA1 signatures as before.
'swtpm socket --tpm2' should set this environment variable automatically
if needed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-13 08:52:56 -04:00
Stefan Berger
1544c99ca5 tests: Remove unnecessary include of openssl/engine.h
To keep the older version of the IBM TSS2 test suite working, remove the
unnecessary include of openssl/engine.h to allow it to compile with more
recent versions of OpenSSL where this header file is missing.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2025-05-06 16:01:12 -04:00
Stefan Berger
a5d7c9511b swtpm: Return TPM_FAIL from invalid header version case
Return TPM_FAIL in case of an invalid header version number to avoid a
potential segmentation fault when accessing an unavailable buffer due to
the header parser not returning an error code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 20:31:41 -04:00
Stefan Berger
a6e9711ce2 swtpm_setup: Initialize key_description with a default string
Initialize key_description with a default string rather than using it
possibly uninitialized. In practice it would never be used uninitialized
since if a platform certificate is to be created, then the ek certificate
would have also been created and therefore swtpm2->ops->create_ek()
would have been called and set key_description.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 20:31:41 -04:00
Stefan Berger
3ce5bfd73b build-sys: Build swtpm-0.8.3
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-09-24 20:31:41 -04:00
Stefan Berger
507d14219d debian/rpm: Adjust changelog for 0.8.2 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-22 16:52:59 -04:00
Stefan Berger
c2ca126471 CHANGES: Add documentation for changes in 0.8.2
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-22 16:52:59 -04:00
Stefan Berger
77c5bf101b 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:52:59 -04:00
Stefan Berger
08ac269ba4 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 16:52:59 -04:00
Stefan Berger
fea5006e18 build-sys: Build swtpm-0.8.2
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2024-03-22 16:52:59 -04:00
Stefan Berger
d2849a9f5c debian/rpm: Adjust changelog for 0.8.1 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-15 13:23:18 -04:00
Stefan Berger
abb8693aba CHANGES: Add documentation for changes in 0.8.1
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-15 13:23:18 -04:00
Stefan Berger
057606875f SELinux: Add rules for user_tpm_t:sockfile to allow unlink
With a memoryBacking node added to the libvirt domain XML, the unlink
permission on user_tmp_t:sockfile becomes necessary to avoid an avc
denial.

  <currentMemory unit='KiB'>2097152</currentMemory>
  <memoryBacking>
    <hugepages>
      <page size='2048' unit='KiB'/>
    </hugepages>
  </memoryBacking>

Also add the unlink permission to the other occurrences of sock_file.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2165142
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-15 13:23:18 -04:00
Stefan Berger
0b210b688e SELinux: Add rules for sock_file on user_tmp_t
The following command line did not function on an x86_64 host due to missing
SELinux rules:

virt-install -v \
 --name fedora-38-aarch64 \
 --ram 4096 \
 --disk path=fedora-38.img,cache=none \
 --nographics \
 --os-variant fedora38 \
 --import \
 --virt-type=qemu \
 --arch aarch64 \
 --check all=off

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2228423
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-15 13:23:18 -04:00
Lena Voytek
a771ecf4c4 debian: Allow apparmor access to qemu session bus swtpm files
When running a VM connected to qemu:///session, swtpm needs access to its own
process id and socket files in /run/user/<UID>/libvirt/qemu/run/swtpm/. Add
permissions to access them in the apparmor profile.

Signed-off-by: Lena Voytek <lena.voytek@canonical.com>
2023-08-15 13:23:18 -04:00
Stefan Berger
9fe87d98b1 swtpm_setup: Exit with '0' upon --version rather than '1'.
The --version option was using the wrong goto label error rather than
out to now also exit with exitcode 0.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-15 13:23:18 -04:00
Stefan Berger
cc5750e6ce swtpm_localca: Add missing NULL option to end of array
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-15 13:23:18 -04:00
Michal Privoznik
663a66c14e swtpm_setup: Initialized @argv in get_swtpm_capabilities()
The compiler (though wrongly) identifies that the @argv variable
inside of get_swtpm_capabilities() function cam be used
uninitialized. While this is a spurious warning, it's common
practice to initialize g_autofree variables to NULL.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2023-08-15 13:23:18 -04:00
Michal Privoznik
fd06ee932e swtpm: Restore logging to stderr on log open failure
When opening a log file fails (--log file=/some/path) for
whatever reason the @logfd variable is left set to -1 (the retval
of open()). And due to how _logprintf() is written, the
subsequent attempt to log this failure (logprintf()) returns too
early not printing the useful error.

Therefore, restore the original (CONSOLE_LOGGING) value.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2023-08-15 13:23:18 -04:00
Stefan Berger
786ba0440a build-sys: Build swtpm-0.8.1
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2023-08-15 13:23:18 -04:00
Stefan Berger
2ae7b01937 debian/rpm: Adjust changelog for 0.8.0 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-11-10 12:24:08 -05:00
Stefan Berger
441d8839d2 CHANGES: Add more documentation for changes in 0.8.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-11-10 12:24:08 -05:00
Stefan Berger
22e975dc05 tests: Pass --verify-profile=medium to certtool if supported
certtool emits the following message if --verify-profile is not
passed:

Note that no verification profile was selected. In the future the medium profile will be enabled by default.
Use --verify-profile low to apply the default verification of NORMAL priority string.

Pass the --verify-profile option if certtool supports it (since ~3.6.12).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-11-02 11:14:19 -04:00
Ross Lagerwall
a2abd3b67d swtpm_setup: Configure swtpm to log to stdout/err if needed
If swtpm_setup is configured with a log file, it launches swtpm
configured with the same log file. If not, swtpm_setup logs will go to
stdout/stderr and it should configure swtpm to do the same.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
2022-11-01 18:01:47 -04:00
Stefan Berger
66117eefa8
Update bug_report.md
Make exact steps to recreate the issue a requirement for the bug report.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-10-10 07:53:26 -04:00
Stefan Berger
87ce53ffc4 swtpm: Add another exit label to avoid gcc -fanalyzer false positive
Move existing exit label before the return statement and add another
label that includes the free(filebuffer). This avoids a false positive
by 'gcc -fanalyzer' that seems to think that free(filebuffer)
would double-free filebuffer after filebuffer = realloc(tmp, ..)
failure.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-10-05 07:37:14 -04:00
Stefan Berger
7d79ecd694 swtpm: Return TPM_FAIL if SWTPM_NVRAM_DecrytpData is called without key
Return TPM_FAIL if SWTPM_NVRAM_DecryptData() is called without a key or
if an unhandle type of encryption mode is encountered. Previously this
function would return no error but also would not do any decryption if
no key was provided. Consequently, it would then also not return a byte
array with decrypted data which in turn could led to potential NULL
pointer accesses in subsequent calls. However, all current callers check
whether they have a valid key before they call this function. So the
change is primarily done for static analyzers, such as gcc -fanalyzer,
to ease code analysis.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-30 13:12:06 -04:00
Stefan Berger
c94a1c4cbd swtpm: Fix memory leak in case realloc fails
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-30 11:06:13 -04:00
Stefan Berger
8cbb6dae18 CHANGES: Add documentation for changes in 0.8.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-29 07:36:32 -04:00
Stefan Berger
aa92bbf615 tests: Replicate test_ctrlchannel3 for TPM 2 to test_tpm2_ctrlchannel3
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-22 13:27:38 -04:00
Stefan Berger
9c5bb4ac73 tests: Test automatic termination upon loss of ctrl channel connection
Extend the test_ctrlchannel3 to test for automatic termination of swtpm
upon loss of control channel connection.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-22 13:27:38 -04:00
Stefan Berger
1f36b7fec4 tests: Use SOCK_STREAM for CMD_SET_DATAFD socketpair
Switch to SOCK_STREAM for the CMD_SET_DATAFD socketpair where the one
end is passed to swtpm to test that this type of socket will cause
automatic termination of swtpm when the connection is lost. This is also
the socket type that QEMU uses.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-22 13:27:38 -04:00
Stefan Berger
d5296e19e7 swtpm: Extend capabilities JSON and show ctrl-opt-terminate
Extend the capabilities JSON and show the support for the terminate
parameter of the --ctrl option.

Adjust test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-22 13:27:38 -04:00
Stefan Berger
6ecf5880ed swtpm: Implement terminate parameter for ctrl channel loss
Implement support for the terminate parameter for the control channel
option so that swtpm terminates once the control channel connection is
lost. The primary use case is QEMU that holds the control channel
permanently.

Resolves: https://github.com/stefanberger/swtpm/issues/753
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-22 13:27:38 -04:00
Stefan Berger
185832c8d4 swtpm: Set tpm_running = false after TPMLIB_Terminate() on CMD_SHUTDOWN
Set tpm_running = false after TPMLIB_Terminate() call on CMD_SHUTDOWN
to prevent a call to tpmlib_maybe_send_tpm2_shutdown() at the exit
of the mainloop.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-22 09:52:10 -04:00
Stefan Berger
aa2ed3e460 swtpm: Also send TPM2_Shutdown when swtpm terminates by signal
Also send TPM2_Shutdown when swtpm is terminated by a signal or due to
lost connection (--terminate option). Previously supported reasons for
sending the TPM2_Shutdown were primarily related to commands sent via
the command channel.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-22 09:52:10 -04:00
Stefan Berger
fd5bad56d5 swtpm: Add missing '%' to %08x
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-22 09:52:10 -04:00
Stefan Berger
448f6326d7 swtpm,man: Clarify that --terminate works only for TCP data channel
The --terminate option is only for the TCP data channel.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-21 17:20:18 -04:00
Stefan Berger
4e4e6e82cb swtpm: Do 300 locking retries instead of only 100
Increase the number of locking retries to 300 over 3 seconds
instead of 100 over 1 second. This gives the failing side more
time to release the lock.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-20 13:00:34 -04:00
Stefan Berger
34886d2841 debian: Do not remove swtpm_cuse.8 via clean file
swtpm_cuse.8 is not generated anymore but its a static file now
that must not be removed anymore via the debian/clean file.

Resolves: https://github.com/stefanberger/swtpm/issues/751
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-19 10:00:46 -04:00
Stefan Berger
e5fdd1c181 tests: Add test case for state migration and storage locking
Add a test case that monitors the locking of the storage by swtpm using the
directory storage backend to ensure that the lock is taken at the right
time and released when required.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-06 14:08:45 -04:00
Stefan Berger
6fbb219db9 swtpm: Implement CMD_LOCK_STORAGE to lock storage
Implement CMD_LOCK_STORAGE / PTM_LOCK_STORAGE for a user to be able to
lock the storage of the storage backend (if supported) after its lock
has been released for example when the 'savestate' blob was received
while the TPM state was migrated.

Also adjust test case and extend man pages.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-06 14:08:45 -04:00
Stefan Berger
e821754bb6 swtpm: Advertise --migration option in capabilities JSON
Advertise the capability of supporting the --migration option
in the capabilies JSON that now has the cmdarg-migration verb:

$ swtpm socket --print-capabilities | jq
{
  "type": "swtpm",
  "features": [
    "tpm-1.2",
    "tpm-2.0",
    "tpm-send-command-header",
    "flags-opt-startup",
    "flags-opt-disable-auto-shutdown",
    "cmdarg-seccomp",
    "cmdarg-key-fd",
    "cmdarg-pwd-fd",
    "cmdarg-print-states",
    "cmdarg-migration",
    "nvram-backend-dir",
    "nvram-backend-file"
  ],
  "version": "0.8.0"
}

Adjust test cases and extend man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2022-09-06 14:08:45 -04:00