]> git.proxmox.com Git - swtpm.git/log
swtpm.git
21 months agoheaders: Apply #ifndef's for _WIN32 from QEMU project
Stefan Berger [Thu, 1 Sep 2022 14:54:19 +0000 (10:54 -0400)]
headers: Apply #ifndef's for _WIN32 from QEMU project

Apply recent changes to this file from upstream QEMU project using
a few #ifndef _WIN32 to make code compileable on Windows.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agotests: Check for fallocate tool and its support for --posix
Stefan Berger [Fri, 26 Aug 2022 17:22:04 +0000 (13:22 -0400)]
tests: Check for fallocate tool and its support for --posix

Older versions of fallocate do not support the --posix option that the test
needs. If --posix is not supported, skip the test.

Also check for availability of the losetup tool.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoheaders: Synchronize with header in QEMU project
Stefan Berger [Fri, 26 Aug 2022 11:42:56 +0000 (07:42 -0400)]
headers: Synchronize with header in QEMU project

QEMU has made a change to a copy of this header file with the following
reason:

On Solaris and Haiku, the _IO() macros are defined in <sys/ioccom.h>.
Add a proper check for this header to our build system, and make sure
to include the header in tpm_ioctl.h to fix a build failure on Solaris
and Haiku.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Implement stub for fips_mode_enabled (OpenBSD)
Stefan Berger [Thu, 25 Aug 2022 20:00:10 +0000 (16:00 -0400)]
swtpm: Implement stub for fips_mode_enabled (OpenBSD)

On OpenBSD openssl/fips.h is not available and FIPS_mode() is not
available, so implement a stub for fips_mode_enabled().

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Advertise the --chroot option with cmdarg-chroot
Stefan Berger [Thu, 25 Aug 2022 16:06:04 +0000 (12:06 -0400)]
swtpm: Advertise the --chroot option with cmdarg-chroot

Advertise the availability of the chroot option with the cmdarg-chroot
verb. Document it in the man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agotests: If filesystem is mounted with nodev opt skip CUSE chroot test
Stefan Berger [Thu, 25 Aug 2022 15:58:06 +0000 (11:58 -0400)]
tests: If filesystem is mounted with nodev opt skip CUSE chroot test

The CUSE TPM test will not work if the filesystem the test case runs
on is mounted with the 'nodev' option since the CUSE TPM can then
not use /tmp/.../dev/cuse.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Add a chroot option
Jennifer Herbert [Tue, 23 Aug 2022 16:08:10 +0000 (17:08 +0100)]
swtpm: Add a chroot option

Add an option to enter a chroot after starting swtpm. This is useful for
sandboxing purposes. When this option is used, it is expected that swtpm
is started as root and the --runas option is used to subsequently drop
privileges (otherwise the chroot could be escaped).

Signed-off-by: Jennifer Herbert <jennifer.herbert@citrix.com>
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
22 months agoswtpm_setup: Add missing description for --vmid to help screen
Stefan Berger [Wed, 24 Aug 2022 13:17:24 +0000 (09:17 -0400)]
swtpm_setup: Add missing description for --vmid to help screen

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Check for defined __SNR_MOUNT_setattr and __NR_mount_setattr
Stefan Berger [Mon, 22 Aug 2022 18:11:47 +0000 (14:11 -0400)]
swtpm: Check for defined __SNR_MOUNT_setattr and __NR_mount_setattr

Address the following compilation error on Debian:

In file included from /usr/include/seccomp.h:821,
                 from seccomp_profile.c:44:
seccomp_profile.c: In function 'create_seccomp_profile':
seccomp_profile.c:115:9: error: '__NR_mount_setattr' undeclared (first use in this function)
  115 |         SCMP_SYS(mount_setattr),
      |         ^~~~~~~~
seccomp_profile.c:115:9: note: each undeclared identifier is reported only once for each function it appears in
seccomp_profile.c:172:9: error: '__NR_quotactl_fd' undeclared (first use in this function)
  172 |         SCMP_SYS(quotactl_fd),
      |         ^~~~~~~~

We need to do this since they are defined like this:

 #define __SNR_mount_setattr             __NR_mount_setattr
 #define __SNR_quotactl_fd               __NR_quotactl_fd

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Include opensslv.h to get OPENSSL_VERSION_NUMBER
Stefan Berger [Mon, 22 Aug 2022 17:59:34 +0000 (13:59 -0400)]
swtpm: Include opensslv.h to get OPENSSL_VERSION_NUMBER

Include openssl/opensslv.h to avoid the following error on Ubuntu:

fips.c: In function 'fips_mode_enabled':
fips.c:61:16: error: implicit declaration of function 'EVP_default_properties_is_fips_enabled' [-Werror=implicit-function-declaration]
   61 |     int mode = EVP_default_properties_is_fips_enabled(NULL);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Resolves: https://github.com/stefanberger/libtpms/issues/345
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Refactor existing function to use new tpmlib_get_cmd_ordinal()
Stefan Berger [Mon, 30 May 2022 14:47:12 +0000 (10:47 -0400)]
swtpm: Refactor existing function to use new tpmlib_get_cmd_ordinal()

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agotests: Add test case to check that swtpm sends a TPM2_Shutdown
Stefan Berger [Wed, 1 Jun 2022 12:44:00 +0000 (08:44 -0400)]
tests: Add test case to check that swtpm sends a TPM2_Shutdown

Add a test case that checks that swtpm sends a TPM2_Shutdown() to the
TPM 2 upon abrupt re-initialization (CMD_INIT) or graceful shutdown
(control channel, CMD_SHUTDOWN) of the TPM 2 and avoids a potential
dictionary attack (DA) lock-out. A previously sent command failing
authorization with DA implications would otherwise trigger the
TPM_PT_LOCKOUT_COUNTER to increase by '1' if the TPM 2 was not properly
shut down by the client (guest OS) with a TPM2_Shutdown() command.

The test case tests whether a TPM2_Shutdown() is now sent before a reset.
The defined password-protected NVRAM area has the DA flag set and the test
case tries to read from it without providing a password. If we didn't send
the TPM2_Shutdown() before the test cases sends the reset (CMD_INIT), then
the dictionary attack lockout counter would be increased by one. With the
instrumentation in the previous patch the automatically sent
TPM2_Shutdown() keeps the counter at 0.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Introduce disable-auto-shutdown flag for --flags option
Stefan Berger [Wed, 17 Aug 2022 18:19:59 +0000 (14:19 -0400)]
swtpm: Introduce disable-auto-shutdown flag for --flags option

Introduce disable-auto-shutdown flag for the --flags option to disable
the sending of TPM2_Shutdown() if swtpm determines that it needs to send
this command to a TPM 2 before device reset or swtpm program termination.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: If necessary send TPM2_Shutdown() before TPMLIB_Terminate()
Stefan Berger [Mon, 30 May 2022 15:10:14 +0000 (11:10 -0400)]
swtpm: If necessary send TPM2_Shutdown() before TPMLIB_Terminate()

If necessary send a TPM2_Shutdown() command to libtpms before processing
CMD_INIT. However, this is only necessary for a TPM 2 and only if the
TPM2_Shutdown command has not been sent by the client (VM TPM driver) as
the last command as it should do under normal circumstances, for example
upon graceful VM shutdown.

This fixes a bug where abrupt VM resets may trigger the TPM 2's dictionary
attack lockout logic due to the TPM 2 not having received a TPM2_Shutdown
command before it was reset using CMD_INIT for example. An OS driver is
typically supposed to send a TPM2_Shutdown to the TPM 2 but an abrupt VM
reset prevents it.

There are 3 control commands where this needs to be done since they
call TPMLIB_Terminate():

- CMD_STOP:
   This command is typically called before setting the state blobs of the
   TPM or before configuring the buffer size [QEMU, test cases].

- CMD_INIT:
   This command is called for resetting and initializing the TPM 2.

- CMD_SHUTDOWN:
   This command is called for a graceful shutdown of the TPM 2.

There are no negative side effects to be expected if TPM2_Shutdown()
is sent before any of these. Also, since none of these are sent before
the state of the TPM is marshalled (for migration for example) migrated
state will not have a TPM2_Shutdown() applied to it (accidentally).

Edk2 sends a sequence of TPM2_Shutdown(SU_STATE) + TPM2_GetRandom()
before suspend-to-ram. Upon wake up a CMD_INIT is sent to the TPM to
reset it, which in this case now requires a TPM2_Shutdown(SU_STATE)
to be sent to the TPM 2 so that certain TPM 2 state is available
again upon resume. To avoid invaliding the SU_STATE, first send a
TPM2_Shutdown(SU_STATE) in *all cases* and only if this fails send a
TPM2_Shutdown(SU_CLEAR). This way the internal state is preserved and
the VM (or user) are expected to use TPM2_Startup(SU_CLEAR) when
staring up the TPM 2 and no previous state needs to be resumed.

Note: The VM's firmware is trusted to use SU_CLEAR under normal circum-
stances and SU_STATE upon resume. So it wouldn't restore the state if
it wasn't needed.

Note: The TPM 2 spec describes the command as follows:

"This command is used to prepare the TPM for a power cycle. The
shutdownType parameter indicates how the subsequent TPM2_Startup() will be
processed.[...]
This command saves TPM state but does not change the state other than the
internal indication that the context has been saved. The TPM shall
continue to accept commands. If a subsequent command changes TPM state
saved by this command, then the effect of this command is nullified. The
TPM MAY nullify this command for any subsequent command rather than check
whether the command changed state saved by this command. If this command
is nullified and if no TPM2_Shutdown() occurs before the next
TPM2_Startup(), then the next TPM2_Startup() shall be
TPM2_Startup(CLEAR)."

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2087538
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Track last command processed by the TPM
Stefan Berger [Mon, 30 May 2022 14:40:01 +0000 (10:40 -0400)]
swtpm: Track last command processed by the TPM

Track the last command processed by the TPM so we can determine whether
we may need to send a TPM2_Shutdown() before reset of the TPM 2.

Introduce a variable lastCommand to help track the last command that
was sent to the TPM 2.

In relation to deciding whether a TPM2_Shutdown() needs to be sent, the
tracking of the last-sent command is merely an optimization since for
example a VM with EDK2 will send a TPM2_Shutdown() followed by a
TPM2_GetRandom() upon suspend-to-ram, thus indicating that the last
command was TPM2_GetRandom(). However, under most circumstances it helps
to avoid sending an additional TPM2_Shutdown() if the OS TPM driver sent
one already.

When the suspended VM resume swtpm gets a CMD_INIT that requires swtpm
to decide whether a TPM2_Shutdown() needs to be sent and per the last-sent
command it will then send a TPM2_Shutdown(SU_STATE) as in the abrupt
termination case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm_ioctl: Only close file descriptor if >= 0 (Coverity)
Stefan Berger [Tue, 16 Aug 2022 11:51:36 +0000 (07:51 -0400)]
swtpm_ioctl: Only close file descriptor if >= 0 (Coverity)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: seccomp: Check for __SNR_xyz rather than __NR_xyz
Stefan Berger [Mon, 15 Aug 2022 17:49:31 +0000 (13:49 -0400)]
swtpm: seccomp: Check for __SNR_xyz rather than __NR_xyz

If seccomp-syscalls.h lags behind the syscall definition of __NR_xyz then
the __SNR_xyz #define is not available. Therefore, switch to check for
__SNR_xyz #define because they are available if __NR_xyz is available.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Implement fips_mode_enabled()
Stefan Berger [Sat, 23 Jul 2022 06:32:44 +0000 (02:32 -0400)]
swtpm: Implement fips_mode_enabled()

Implement fips_mode_enabeld() to check whether FIPS is enabledand
use the new function to check for FIPS mode enablement before
trying to disable it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Rename disable_fips_mode() and move into tpmlib_start()
Stefan Berger [Wed, 20 Jul 2022 20:58:28 +0000 (16:58 -0400)]
swtpm: Rename disable_fips_mode() and move into tpmlib_start()

Rename disable_fips_mode() to fips_mode_disable() amd move into
tpmlib_start() after TPMLIB_MainInit(). Clean up the duplicate
prototype.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Fixed typo `fs_mount` vs `fsmount` and removed duplicates.
Hans [Mon, 15 Aug 2022 12:06:27 +0000 (14:06 +0200)]
swtpm: Fixed typo `fs_mount` vs `fsmount` and removed duplicates.

The project wouldn't compile on my ubuntu 20.04.1 based system with the error message:
```
  CC       libswtpm_libtpms_la-seccomp_profile.lo
In file included from seccomp_profile.c:44:
seccomp_profile.c: In function ‘create_seccomp_profile’:
seccomp_profile.c:105:9: error: ‘__SNR_fs_mount’ undeclared (first use in this function)
  105 |         SCMP_SYS(fs_mount),
      |         ^~~~~~~~
seccomp_profile.c:105:9: note: each undeclared identifier is reported only once for each function it appears in
```

Additionally, there were some duplicates in the profile.

Signed-off-by: Hans Niklas Jacob <hnj@posteo.de>
22 months agoswtpm: Add some more recent syscalls to seccomp profile
Stefan Berger [Fri, 12 Aug 2022 16:53:27 +0000 (12:53 -0400)]
swtpm: Add some more recent syscalls to seccomp profile

Add some more recent syscalls to the disallowlist in the seccomp
profile.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: cuse: Extend usage of FILE_OPS_LOCK to protect a reading thread
Stefan Berger [Tue, 9 Aug 2022 23:58:33 +0000 (19:58 -0400)]
swtpm: cuse: Extend usage of FILE_OPS_LOCK to protect a reading thread

Extend usage of the FILE_OPS_LOCK to prevent other threads from reading or
writing commands or doing ioctls while the current thread is reading a
response. This prevents a race condition where ptm_read_offset is set to 0
by a thread writing a new command to the device while the current thread
is reading a response from the device and needs this offset.

Resolves: https://github.com/stefanberger/swtpm/issues/725
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agotests: Remove dump of logfile at end of test
Stefan Berger [Thu, 11 Aug 2022 15:58:44 +0000 (11:58 -0400)]
tests: Remove dump of logfile at end of test

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm_setup: Add missing newline to help screen
Stefan Berger [Wed, 10 Aug 2022 17:59:41 +0000 (13:59 -0400)]
swtpm_setup: Add missing newline to help screen

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoman: Replace swtpm_cuse man page with redirect to swtpm man page
Stefan Berger [Wed, 10 Aug 2022 22:43:07 +0000 (18:43 -0400)]
man: Replace swtpm_cuse man page with redirect to swtpm man page

The swtpm man page also covers the CUSE TPM, so do not maintain the
swtpm_cuse man page anymore but replace it with a redirect to the swtpm
mane page instead.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: Travial reformatting of arrays of structs
Stefan Berger [Wed, 10 Aug 2022 22:39:08 +0000 (18:39 -0400)]
swtpm: Travial reformatting of arrays of structs

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agoswtpm: cuse: Restrict opening CUSE device to one openable file descriptor
Stefan Berger [Tue, 9 Aug 2022 18:40:49 +0000 (14:40 -0400)]
swtpm: cuse: Restrict opening CUSE device to one openable file descriptor

Restrict the opening of the CUSE device to one single file descriptor. We
can modify the CUSE TPM in this way since the kernel's /dev/tpm0 cannot be
opened multiple times, either, and the CUSE TPM should behave in the same
way.

Adjust test the partial reads case to only open CUSE device file once by
using a python program. Close the open file descriptor 100 before using
swtpm_ioctl to avoid failures.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
22 months agotests: Move swtpm_open_cmddev into swtpm_cmd_tx
Stefan Berger [Tue, 9 Aug 2022 20:04:43 +0000 (16:04 -0400)]
tests: Move swtpm_open_cmddev into swtpm_cmd_tx

Move swtpm_open_cmddev call into swtpm_cmd_tx since the latter function is
always called in a subshell that previously inherited the file descriptor
opened by the test cases. Remove swtpm_cmd_tx from nearly all test cases
and also remove closing of file descriptor 100 via 'exec 100>&-' from test
cases since this is not necessary anymore.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Ignore error if TPMLIB_ChooseTPMVersion for printing caps fails
Stefan Berger [Tue, 19 Jul 2022 23:27:56 +0000 (19:27 -0400)]
swtpm: Ignore error if TPMLIB_ChooseTPMVersion for printing caps fails

Revert the change from the previous patch that shows an error when
TPMLIB_ChooseTPMVersion fails but rather ignore the error as before.
If a TPM 2 is supported then tpm-2.0 capability verb will be shown
and if a TPM 1.2 is supported then tpm-1.2 will be shown, thus
allowing someone reading the JSON to determine what is supported.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Move TPMLIB_ChooseTPMVersion into capabilities_print_json
Stefan Berger [Mon, 18 Jul 2022 22:24:33 +0000 (18:24 -0400)]
swtpm: Move TPMLIB_ChooseTPMVersion into capabilities_print_json

All callers to capabilities_print_json() call TPMLIB_ChooseTPMVersion
right before. Move it into the function now and check the return
code.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm_setup: Implement get_swtpm_capabilities() and call from two functions
Stefan Berger [Tue, 19 Jul 2022 12:20:45 +0000 (08:20 -0400)]
swtpm_setup: Implement get_swtpm_capabilities() and call from two functions

Implement get_swtpm_capabilities() and call it from two existing functions
that now become a lot simpler.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoswtpm: Also advertise the flags-opt-startup option for the CUSE interface
Stefan Berger [Wed, 13 Jul 2022 20:43:40 +0000 (16:43 -0400)]
swtpm: Also advertise the flags-opt-startup option for the CUSE interface

Commit 6559a902 implemented support for the startup-xyz flags for the CUSE
interface but the capability has not been advertised.

Adjust test cases to reflect the new verb being shown for
--print-capabilities.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
23 months agoconfigure: check for bash
William Roberts [Tue, 12 Jul 2022 17:04:10 +0000 (12:04 -0500)]
configure: check for bash

PCR Bank verification needs bash, so check for bash. While at it use the
autoconf shell construct macros over raw shell syntax which is slightly
more portable.

Examples:
./configure --enable-default-pcr-banks=sha256,sha920
checking which PCR banks to activate by default... configure: error: sha256,sha920 is an invalid list of PCR banks

./configure --enable-default-pcr-banks=sha256,sha512
checking which PCR banks to activate by default... sha256,sha512

./configure
checking which PCR banks to activate by default... sha256

Signed-off-by: William Roberts <william.c.roberts@intel.com>
2 years agogitignore: Ignore created files in man/man5/
Stefan Berger [Mon, 27 Jun 2022 14:19:35 +0000 (10:19 -0400)]
gitignore: Ignore created files in man/man5/

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoselinux: Replace hardcoded install path with @prefix@
Stefan Berger [Mon, 27 Jun 2022 12:42:38 +0000 (08:42 -0400)]
selinux: Replace hardcoded install path with @prefix@

Replace the hardcoded install path in src/selinux/swtpm.fc and
src/selinux/swtpmcuse.fc with @prefix@ and append .in to these files so
that they are generated when running configure.

Add the selinux policy input files with their suffix to the CLEANFILES
variable so they get cleaned up and 'make distcheck' works.

Resolves: https://github.com/stefanberger/swtpm/issues/711
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Disable OpenSSL FIPS mode to avoid libtpms failures
Stefan Berger [Wed, 8 Jun 2022 13:19:07 +0000 (09:19 -0400)]
swtpm: Disable OpenSSL FIPS mode to avoid libtpms failures

While libtpms does not provide any means to disable FIPS-disabled crypto
algorithms from being used, work around the issue by simply disabling the
FIPS mode of OpenSSL if it is enabled. If it cannot be disabled, exit
swtpm with a failure message that it cannot be disabled. If FIPS mode
was successfully disabled, print out a message as well.

Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2090219
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Do not activate SHA-1 PCR bank in test case
Stefan Berger [Mon, 13 Jun 2022 18:05:25 +0000 (14:05 -0400)]
tests: Do not activate SHA-1 PCR bank in test case

For being able to run tests with runtime-deactivated SHA-1 (in libtpms),
do not test with SHA-1 bank anymore.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_bios: Use TPM2_ALG_SHA256 as parameter to TPM2_IncrementalSelfTest
Stefan Berger [Mon, 13 Jun 2022 18:02:48 +0000 (14:02 -0400)]
swtpm_bios: Use TPM2_ALG_SHA256 as parameter to TPM2_IncrementalSelfTest

Do not use TPM2_ALG_SHA1 anymore as parameter to TPM2_IncrementalSelfTest()
so that this also works when SHA1 support in libtpms is runtime-disabled.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Update printed copyright notice
Stefan Berger [Sun, 12 Jun 2022 18:29:52 +0000 (14:29 -0400)]
swtpm: Update printed copyright notice

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Remove stale parameter from function documentation
Stefan Berger [Mon, 30 May 2022 15:19:03 +0000 (11:19 -0400)]
swtpm: Remove stale parameter from function documentation

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Fix a typo in an error message
Stefan Berger [Mon, 30 May 2022 15:13:58 +0000 (11:13 -0400)]
swtpm: Fix a typo in an error message

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Replace malloc + strcpy with strdup and handle OOM case
Stefan Berger [Wed, 25 May 2022 19:55:27 +0000 (15:55 -0400)]
swtpm: Replace malloc + strcpy with strdup and handle OOM case

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Handle case where unknown blobtype is given (Coverity)
Stefan Berger [Wed, 25 May 2022 19:47:04 +0000 (15:47 -0400)]
swtpm: Handle case where unknown blobtype is given (Coverity)

Handle the case where an unknown blobtype is given and therefore
cannot be translated to a filename and blobname is NULL. Previously
this would have lead to an error when trying to read the file, now
we handle the failure case earlier.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Cast '1' to uint64_t before shift and assign to uint64_t variable
Stefan Berger [Wed, 25 May 2022 19:31:05 +0000 (15:31 -0400)]
swtpm: Cast '1' to uint64_t before shift and assign to uint64_t variable

To avoid an overflowing expression cast '1' to uint64_t before shifting
it and assigning it to a uint64_t variable. In practice this kind of
overflow would never happen because there aren't that many available
PCR banks.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Initialize res variable (Coverity)
Stefan Berger [Wed, 25 May 2022 18:28:09 +0000 (14:28 -0400)]
swtpm: Initialize res variable (Coverity)

Initialize the 'res' variable at the beginning of the function
even though this wouldn't be necessary in this case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Remove assignment to unused variable
Stefan Berger [Wed, 25 May 2022 18:19:36 +0000 (14:19 -0400)]
swtpm: Remove assignment to unused variable

Remove the assigment to 'res' since the subsequent code path does not
need it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_localca: Add comment that failure to read optsfile is not an issue
Stefan Berger [Wed, 25 May 2022 20:02:45 +0000 (16:02 -0400)]
swtpm_localca: Add comment that failure to read optsfile is not an issue

Add a comment stating that failure to read the optsfile is not an
issue since the optsfile does not need to exist.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Use g_strdup instead of strdup
Stefan Berger [Wed, 25 May 2022 19:13:09 +0000 (15:13 -0400)]
swtpm_setup: Use g_strdup instead of strdup

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Initialize pubek_len (Coverity)
Stefan Berger [Wed, 25 May 2022 18:23:41 +0000 (14:23 -0400)]
swtpm_setup: Initialize pubek_len (Coverity)

Initialize pubek_len even though it isn't necessary to do so since
it will be initialized in the first function to which it is passed.
However, Coverity complains about pubek_len passed to print_as_hex()
not being initialized, even though this is not possible.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_ioctl: Free variable before parsing it to avoid memory leak (Coverity)
Stefan Berger [Wed, 25 May 2022 19:19:19 +0000 (15:19 -0400)]
swtpm_ioctl: Free variable before parsing it to avoid memory leak (Coverity)

Avoid a memory leaks if --tcp is provided multiple times by freeing
the previously allocated memory in the tcp_hostname variable.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_ioctl: Close file descriptor at end of main (Coverity)
Stefan Berger [Wed, 25 May 2022 18:32:53 +0000 (14:32 -0400)]
swtpm_ioctl: Close file descriptor at end of main (Coverity)

Close the file descriptor at the end of the main function.
To avoid closing random file descriptors initialize it with -1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_cert: Test for NULL pointer returned by malloc
Stefan Berger [Wed, 25 May 2022 19:34:57 +0000 (15:34 -0400)]
swtpm_cert: Test for NULL pointer returned by malloc

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_cert: Free variable before parsing it to avoid memory leak (Coverity)
Stefan Berger [Wed, 25 May 2022 19:26:52 +0000 (15:26 -0400)]
swtpm_cert: Free variable before parsing it to avoid memory leak (Coverity)

Avoid memory leaks if one of the parameters --tcp, --tpm-device,
or --unix was passed multiple times by freeing the previously
parsed value.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_cert: Free variable before parsing it to avoid memory leak (Coverity)
Stefan Berger [Wed, 25 May 2022 19:09:47 +0000 (15:09 -0400)]
swtpm_cert: Free variable before parsing it to avoid memory leak (Coverity)

Avoid memory leaks if one of the parameters --modulus, --ecc-x,
or --ecc-y was passed multiple times by freeing the previously
parsed value.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_bios: Do not assigned -1 to closed file descriptor at end of function
Stefan Berger [Wed, 25 May 2022 18:15:32 +0000 (14:15 -0400)]
swtpm_bios: Do not assigned -1 to closed file descriptor at end of function

There's no need to assigned -1 to a closed file descriptor at the
end of a function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Avoid locking directory multiple times
Stefan Berger [Wed, 11 May 2022 02:28:30 +0000 (22:28 -0400)]
swtpm: Avoid locking directory multiple times

Commit 2d3deaef29 forgot to move the check for whether the lock file has
already been opened into the new function opening the lock file and there-
fore the lock file is now opened whenever swtpm gets a PTM_INIT. This fix
prevents the reopening of the lockfile if it has already been opened.
Otherwise many PTM_INIT's will lead to failure since no more files can
be opened.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Remove support for pre-v0.1 state files without header
Stefan Berger [Fri, 6 May 2022 22:41:17 +0000 (18:41 -0400)]
swtpm: Remove support for pre-v0.1 state files without header

Remove support for TPM state files that didn't have the header
because they were created some time before v0.1.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotest: Recreate TPM 2 state files with header
Stefan Berger [Sat, 7 May 2022 18:18:35 +0000 (14:18 -0400)]
test: Recreate TPM 2 state files with header

Use libtpms v0.6.6 and recreate the TPM 2 state file with header.
Start swtpm with the existing state files and have it rewrite the
volatiles state (swtpm_ioctl -v) and permanent state (tssnvdefine
+ tssnvundefine) files so that the header is on the files.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotest: Recreate TPM 2 state files with header
Stefan Berger [Fri, 6 May 2022 21:28:50 +0000 (17:28 -0400)]
test: Recreate TPM 2 state files with header

Use libtpms v0.6.2 and recreate the TPM 2 state file with header.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotest: Recreate TPM 2 state files with header
Stefan Berger [Fri, 6 May 2022 22:31:13 +0000 (18:31 -0400)]
test: Recreate TPM 2 state files with header

Recreate TPM 2 state files that didn't have a header. Use latest
version of libtpms from the stable-0.6.0 branch to create the
state that more recent version have to be able to read.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotest: Recreate TPM 1.2 state files with header
Stefan Berger [Fri, 6 May 2022 22:08:17 +0000 (18:08 -0400)]
test: Recreate TPM 1.2 state files with header

Recreate a TPM 1.2 state file with header.

The state of the TPM 1.2 must be initialized with Startup(ST_CLEAR)
and then saved so that the proper error code appears as a result
when running this test.

The PCR values was originally created by extending PCR 10 with
sha1("test"). This was recreated using this sequence:

s=$(echo -en test | sha1sum | cut -d " " -f1 | sed -n 's/\([a-f0-9]\{2\}\)/\\x\1/pg')
echo -en $s > input
tss1extend  -ha 10 -if input

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotest: Recreate TPM 1.2 state files with header
Stefan Berger [Fri, 6 May 2022 20:47:42 +0000 (16:47 -0400)]
test: Recreate TPM 1.2 state files with header

Recreate TPM 1.2 state files with similar content but with the state
file header. The older versions of the state files were created before
the header was introduced in v0.1. The goal is to be able to get rid
of code supporting pre-v0.1 files that had no header.

The PCR values was originally created by extending PCR 10 with
sha1("test"). This was recreated using this sequence:

s=$(echo -en test | sha1sum | cut -d " " -f1 | sed -n 's/\([a-f0-9]\{2\}\)/\\x\1/pg')
echo -en $s > input
tss1extend  -ha 10 -if input

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agodebian: Add swtpm apparmor profile
Lena Voytek [Thu, 5 May 2022 20:07:23 +0000 (13:07 -0700)]
debian: Add swtpm apparmor profile

An apparmor profile was added for Debian-based distributions in order to
increase security. This blocks swtpm from accessing restricted and unnecessary
files, folders, and network interfaces. swtpm works as normal alongside libvirt
and its configurations, however users may run into issues when using swtpm on
its own when providing it with a restricted directory. The apparmor profile can
be modified to include additional permissions by creating and adding to the
file /etc/apparmor.d/local/usr.bin.swtpm.

Signed-off-by: Lena Voytek <lena.voytek@canonical.com>
2 years agotests: Patch IBM TSS2 test suite for OpenSSL 3.x
Stefan Berger [Tue, 3 May 2022 00:46:50 +0000 (20:46 -0400)]
tests: Patch IBM TSS2 test suite for OpenSSL 3.x

Apply a patch to the IBM TSS2 v1.6 test suite when OpenSSL 3.x is de-
tected.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Repeat TSS command if it fails
Stefan Berger [Tue, 3 May 2022 14:48:07 +0000 (10:48 -0400)]
tests: Repeat TSS command if it fails

Repeat tss command since it may fail if the test case is run alone (-29).
The reason for this is that the command may fail because of this here:

https://github.com/stefanberger/libtpms/blob/stable-0.9/src/tpm2/SessionProcess.c#L1204

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Fix configure script to support _FORTIFY_SOURCE=3
Stefan Berger [Mon, 4 Apr 2022 12:49:37 +0000 (08:49 -0400)]
build-sys: Fix configure script to support _FORTIFY_SOURCE=3

gcc 12.1 supports _FORTIFY_SOURCE=3. Modify the existing check for whether
_FORTIFY_SOURCE=2 can be used to test compile with the user provided
CFLAGS and only add _D_FORTIFY_SOURCE=2 to the HARDENING_CFLAGS if the
user doesn't provide anything that's not compatible.

Following an online article _FORTIFY_SOURCE=3 may add more overhead, so
we only go up to level 2 for now and let build servers or user provide
the higher level via the CFLAGS.

https://developers.redhat.com/blog/2021/04/16/broadening-compiler-checks-for-buffer-overflows-in-_fortify_source#what_s_next_for__fortify_source

Resolves: https://github.com/stefanberger/swtpm/issues/688
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Define __USE_LINUX_IOCTL_DEFS in header file (Cygwin)
Stefan Berger [Mon, 4 Apr 2022 14:30:47 +0000 (10:30 -0400)]
build-sys: Define __USE_LINUX_IOCTL_DEFS in header file (Cygwin)

To be able to test-compile with include/swtpm/tpm_ioctl.h in configure.ac
move the definition of __USE_LINUX_IOCTL_DEFS out of the configure script
into the header file so that the #define is there when needed. In the
configure.ac script the CFLAGS were extended only after the test-compiling
to determine the HARDENING_CFLAGS and the test-compilation failed on Cygwin
(only) since the tpm_ioctl.h didn't compile because of this missing
 #define.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Use uint64_t in tlv_data_append() to avoid integer overflows
Stefan Berger [Mon, 28 Mar 2022 15:23:11 +0000 (11:23 -0400)]
swtpm: Use uint64_t in tlv_data_append() to avoid integer overflows

Instead of uint32_t use uint64_t's for accumulating needed buffer sizes
that are calculated by adding uint32_t length indicators. Use the uint64_t
to check for excessively large buffer sizes that could cause an integer
overflow if uint32_t was used.

This patch addresses the case where a user passes an old version of TPM
state file to swtpm for reading and the file is 4GB in size and thus can
cause an integer overflow in this particular function.

Otherwise, the previous fix to tlv_data_find_tag() protects swtpm from
integer overflows and later out-of-bound accesses when the TPM state is
initially read from a file (assuming the state file has a header, which
is the case since swtpm 0.1). If an excessively large buffer was passed
to libtpms, it would reject it since it would never be able to take in
that much data.

Data written to the file are coming from libtpms that we can trust in
terms of length indicators.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Use uint64_t to avoid integer wrap-around when adding a uint32_t
Stefan Berger [Sat, 26 Mar 2022 03:28:21 +0000 (23:28 -0400)]
swtpm: Use uint64_t to avoid integer wrap-around when adding a uint32_t

To avoid an integer wrap-around use uint64_t for 'offset' so that adding
an untrusted 32-bit number will allow for comparison against the trusted
'buffer_len' 32-bit number:

        if (offset + td->tlv.length > buffer_len)
            return NULL;

This avoids possible out-of-bound accesses and crashes when reading
specially crafted TPM state input data that have a tlv.length that is so
large that is causes an integer overflow.

Resolves: https://github.com/stefanberger/swtpm/issues/678
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_bios: Use unsigned int tcp_port to filter out negative port numbers
Stefan Berger [Sat, 26 Mar 2022 02:54:21 +0000 (22:54 -0400)]
swtpm_bios: Use unsigned int tcp_port to filter out negative port numbers

The port being parsed must be given as unsigned int so that the comparison
of *tcp_port >= 65536 also filters out negative numbers passed via the
command line. Previously one could pass -1 and swtpm_bios would try to
connect.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_ioctl: Use unsigned int tcp_port to filter out negative port numbers
Stefan Berger [Sat, 26 Mar 2022 02:41:00 +0000 (22:41 -0400)]
swtpm_ioctl: Use unsigned int tcp_port to filter out negative port numbers

The port being parsed must be given as unsigned int so that the comparison
of *tcp_port >= 65536 also filters out negative numbers passed via the
command line. Previously one could pass -1 and swtpm_ioctl would try to
connect to port 65535.

Resolves: https://github.com/stefanberger/swtpm/issues/679
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Move block with CUSE-related tests after initial CUSE tests
Stefan Berger [Mon, 21 Mar 2022 19:55:29 +0000 (15:55 -0400)]
build-sys: Move block with CUSE-related tests after initial CUSE tests

Mof the block with the CUSE-related tests further up to be following the
first set of CUSE-related tests.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Show the value of with_chardev after test for chardev
Stefan Berger [Mon, 21 Mar 2022 19:55:11 +0000 (15:55 -0400)]
build-sys: Show the value of with_chardev after test for chardev

Show the value of with_chardev after the test for whether to build
with chadev rather than with_cuse.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Determine GNUTLS_LIBS using pkg-config [OS X]
Stefan Berger [Mon, 21 Mar 2022 19:55:09 +0000 (15:55 -0400)]
build-sys: Determine GNUTLS_LIBS using pkg-config [OS X]

Determine GNUTLS_LIBS using pkg-config rather than hard-coding
it. On OS X it may return a -L<path> to succeed the linking.

Resolves: https://github.com/stefanberger/swtpm/issues/676
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Do not chdir(/) when using --daemon
Stefan Berger [Thu, 3 Mar 2022 14:13:26 +0000 (09:13 -0500)]
swtpm: Do not chdir(/) when using --daemon

With relative paths being used the chdir("/") in daemonize_finish() will
cause file access errors.

Fixes: 98d1d12 ("swtpm: Make --daemon not racy")
Resolves: https://github.com/stefanberger/swtpm/issues/671
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Add probing for -fstack-protector
Stefan Berger [Wed, 2 Mar 2022 18:52:53 +0000 (13:52 -0500)]
build-sys: Add probing for -fstack-protector

Add probing for -fstack-protector to the existing
-fstack-protector-strong since not all platforms support either one
of them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoman: Add missing .config directory to path description when using ${HOME}
Stefan Berger [Mon, 21 Feb 2022 23:58:26 +0000 (18:58 -0500)]
man: Add missing .config directory to path description when using ${HOME}

When the ${HOME} directory is used for finding swtpm_setup.conf it is
to be found in ${HOME}/.config/swtpm_setup.conf.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolves: https://github.com/stefanberger/swtpm/issues/664

2 years agotests: Use ${WORKDIR} in config files to test env. var replacement
Stefan Berger [Tue, 22 Feb 2022 12:46:26 +0000 (07:46 -0500)]
tests: Use ${WORKDIR} in config files to test env. var replacement

To test the replacement of environment variables with their values
use ${WORKDIR} in the test case config files.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm-localca: Re-implement variable resolution for swtpm-localca.conf
Stefan Berger [Mon, 21 Feb 2022 23:37:34 +0000 (18:37 -0500)]
swtpm-localca: Re-implement variable resolution for swtpm-localca.conf

swtpm_localca v0.5 supported resolution of environment variables for
the swtpm-localca.conf configuration file. This functionality was lost
during the port to 'C' in v0.6. This patch now re-implements it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolves: https://github.com/stefanberger/swtpm/issues/663

2 years agoswtpm_localca: Test for available issuercert before creating CA
Stefan Berger [Tue, 1 Feb 2022 17:40:06 +0000 (12:40 -0500)]
swtpm_localca: Test for available issuercert before creating CA

Avoid trying to create TPM certificates while the issuer certificate has
not been created, yet (in a 2nd step).

To resolve this do not just test for availability of the signing key, which
is created first, but also test for the issuer certifcate, which is created
in a 2nd step when the local CA is created. If either one is missing,
attempt to create the CA.

Resolves: https://github.com/stefanberger/swtpm/issues/644
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Check header size indicator against expected size (CID 375869)
Stefan Berger [Wed, 16 Feb 2022 16:17:47 +0000 (11:17 -0500)]
swtpm: Check header size indicator against expected size (CID 375869)

This fix addresses Coverity issue CID 375869.

Check the header size indicated in the header of the state against the
expected size and return an error code in case the header size indicator
is different. There was only one header size so far since blobheader was
introduced, so we don't need to deal with different sizes.

Without this fix a specially craft header could have cause out-of-bounds
accesses on the byte array containing the swtpm's state.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Check for unreasonable number of PCR banks (CID 370783)
Stefan Berger [Wed, 16 Feb 2022 15:21:15 +0000 (10:21 -0500)]
swtpm_setup: Check for unreasonable number of PCR banks (CID 370783)

This fix addresses Coverity issue CID 370783.

Check for an unreasonable number of PCR banks returned from command sent
to swtpm. Limit the number of PCR banks that can be returned to '20',
which is more than enough.

Previously we may not have sanitized the variable correctly but safeguards
were in place:

Even if the 16 bit variable count was the maximum possible (0xffff) we
should be able to allocate the all_pcr_banks array of string pointers.

Safeguards to not overstep the parsed array are in place in the loop
that's entered afterwards where the count variable serves as a limit
for the loop.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Free string array in case of failure
Stefan Berger [Wed, 16 Feb 2022 15:35:14 +0000 (10:35 -0500)]
swtpm_setup: Free string array in case of failure

Free the allocated string array in case of failure.

Existing callers auto-free the array already, so there's no memory leak,
but it is better to free it in the function where it is allocated.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Cast constant to uint64_t before shifting (CID 375870)
Stefan Berger [Wed, 16 Feb 2022 15:05:30 +0000 (10:05 -0500)]
swtpm: Cast constant to uint64_t before shifting (CID 375870)

Cast the '1' to uint64_t as suggested by Coverity (CID 375870).
Since 'j' is always less than '32', the previous code was correct as
well.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: fix newline before full stop in swtpm-not-found error
наб [Thu, 25 Nov 2021 22:28:11 +0000 (23:28 +0100)]
swtpm_setup: fix newline before full stop in swtpm-not-found error

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
2 years agoMove *.conf and *.options to man5
Seunghun Han [Thu, 11 Nov 2021 02:38:22 +0000 (11:38 +0900)]
Move *.conf and *.options to man5

According to the man page sections guideline, man8 should be used
for system administration commands. So this commit moves *.conf and
*.options files to man5.

Signed-off-by: Seunghun Han <kkamagui@gmail.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Implement function reporting error when choosing unsupported TPM
Stefan Berger [Fri, 19 Nov 2021 22:35:33 +0000 (17:35 -0500)]
swtpm: Implement function reporting error when choosing unsupported TPM

Implement tpmlib_choose_tpm_version() that reports an error when an un-
supported version is chosen. Have it used by existing code where possible.

If TPM 1.2 is not supported by libtpms, the following message is now
displayed:

swtpm: Error: TPM 1.2 is not supported by libtpms.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2024583
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Bump up version to 0.8.0 at beginning of dev cycle
Stefan Berger [Sat, 20 Nov 2021 16:14:44 +0000 (11:14 -0500)]
build-sys: Bump up version to 0.8.0 at beginning of dev cycle

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agodebian/rpm: Adjust changelog for 0.7.0 release
Stefan Berger [Mon, 18 Oct 2021 19:23:42 +0000 (15:23 -0400)]
debian/rpm: Adjust changelog for 0.7.0 release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoCHANGES: Add more documentation for changes in 0.7.0
Stefan Berger [Mon, 18 Oct 2021 19:19:57 +0000 (15:19 -0400)]
CHANGES: Add more documentation for changes in 0.7.0

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Move regex to test PCR banks into configure script
Stefan Berger [Mon, 8 Nov 2021 12:24:06 +0000 (07:24 -0500)]
build-sys: Move regex to test PCR banks into configure script

Move the regex test for the PCR banks into the configure script.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_localca: Do not assign pointer to g_strchomp result (Coverity)
Stefan Berger [Fri, 5 Nov 2021 22:05:18 +0000 (18:05 -0400)]
swtpm_localca: Do not assign pointer to g_strchomp result (Coverity)

Get rid of a Coverity complaint by not assigning the same pointer
to the result of g_strchomp() as the parameter to the function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Do not assign pointer to g_strchomp result (Coverity)
Stefan Berger [Fri, 5 Nov 2021 22:03:39 +0000 (18:03 -0400)]
swtpm_setup: Do not assign pointer to g_strchomp result (Coverity)

Get rid of a Coverity complaint by not assigning the same pointer
to the result of g_strchomp() as the parameter to the function.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Fix expiration date check for 32 bit machines
Stefan Berger [Fri, 5 Nov 2021 19:16:43 +0000 (15:16 -0400)]
tests: Fix expiration date check for 32 bit machines

certtool on 32 bit machines seems to expire a never expiring certificate
in 2037 rather than 9999.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Fix compilation error on 32bit machines
Stefan Berger [Fri, 5 Nov 2021 19:02:05 +0000 (15:02 -0400)]
swtpm: Fix compilation error on 32bit machines

Fix the following compilation error occurring on 32bit machines:

swtpm_nvstore_linear_file.c: In function 'SWTPM_NVRAM_LinearFile_Mmap':
swtpm_nvstore_linear_file.c:58:20: error: comparison of integer expressions of different signedness: '__off_t' {aka 'long int'} and 'unsigned int' [-Werror=sign-compare]
   58 |     if (st.st_size >= (uint32_t)sizeof(struct nvram_linear_hdr)) {
      |                    ^~

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: OSSL 3: Make TPM 1.2 test compile; skip IBM TSS 2 test
Stefan Berger [Fri, 5 Nov 2021 12:23:04 +0000 (08:23 -0400)]
tests: OSSL 3: Make TPM 1.2 test compile; skip IBM TSS 2 test

Add CFLAGS="-DOPENSSL_SUPPRESS_DEPRECATED=1" to the configure line
to avoid compile-time errors when building the TPM 1.2 test with
OpenSSL 3.0.

IBM TSS2 v1.6 test does not currently work with OpenSSL 3.0, so
skip it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Add support for --reconfigure flag to change active PCR banks
Stefan Berger [Fri, 29 Oct 2021 17:04:07 +0000 (13:04 -0400)]
swtpm_setup: Add support for --reconfigure flag to change active PCR banks

Add support for --reconfigure option for the swtpm_setup to be able to
change the active PCR banks. This option only works with --tpm2 and does
not allow to pass several other options such --create-ek or
--create-ek-cert or --create-platform-cert that would alter the state of
the TPM 2 in other ways.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Support filenames with spaces in some functions
Stefan Berger [Fri, 29 Oct 2021 16:57:40 +0000 (12:57 -0400)]
tests: Support filenames with spaces in some functions

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Create flags by shifting '1'
Stefan Berger [Fri, 29 Oct 2021 15:42:27 +0000 (11:42 -0400)]
swtpm_setup: Create flags by shifting '1'

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: exit with error code if mktemp fails
Stefan Berger [Tue, 2 Nov 2021 01:15:32 +0000 (21:15 -0400)]
tests: exit with error code if mktemp fails

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>