]> git.proxmox.com Git - swtpm.git/log
swtpm.git
2 years agobump version to 0.7.1~bpo11+1 proxmox/stable-0.7
Thomas Lamprecht [Tue, 22 Feb 2022 06:56:26 +0000 (07:56 +0100)]
bump version to 0.7.1~bpo11+1

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agodebian/rpm: Adjust changelog for 0.7.1 release v0.7.1
Stefan Berger [Fri, 18 Feb 2022 12:06:06 +0000 (07:06 -0500)]
debian/rpm: Adjust changelog for 0.7.1 release

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoCHANGES: Add documentation for changes in 0.7.1
Stefan Berger [Fri, 18 Feb 2022 12:01:11 +0000 (07:01 -0500)]
CHANGES: Add documentation for changes in 0.7.1

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
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 crafted header could 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 agobuild-sys: Build swtpm-0.7.1
Stefan Berger [Tue, 1 Feb 2022 17:57:04 +0000 (12:57 -0500)]
build-sys: Build swtpm-0.7.1

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>
2 years agoswtpm_localca: Replace '+' and ',' characters in VMId's
Stefan Berger [Mon, 1 Nov 2021 13:08:22 +0000 (09:08 -0400)]
swtpm_localca: Replace '+' and ',' characters in VMId's

Certain characters are not accepted by gnutls when creating the
subject with the 'CN' from the vmid, so we have to replace those
characters with another one, such as '_'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Write active_pcr_banks into swtpm_setup.conf
Stefan Berger [Thu, 28 Oct 2021 17:04:24 +0000 (13:04 -0400)]
swtpm_setup: Write active_pcr_banks into swtpm_setup.conf

Write the active_pcr_banks into swtpm_setup.conf with the default
PCR banks from the configure script.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Get active PCR banks from swtpm_setup.conf
Stefan Berger [Thu, 28 Oct 2021 16:23:14 +0000 (12:23 -0400)]
swtpm_setup: Get active PCR banks from swtpm_setup.conf

If the user did not provide the PCR banks to activate through the command
line options, try to read it from the config file and if nothing is found
there, fall back to the DEFAULT_PCR_BANKS as set during configure time.

Move the check for the PCR banks after the access check to the
configuration file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Move code to activate PCR banks into own function
Stefan Berger [Thu, 28 Oct 2021 15:54:20 +0000 (11:54 -0400)]
swtpm_setup: Move code to activate PCR banks into own function

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agobuild-sys: Add support for --enable-default-pcr-banks=list of PCR banks
Stefan Berger [Thu, 28 Oct 2021 15:25:31 +0000 (11:25 -0400)]
build-sys: Add support for --enable-default-pcr-banks=list of PCR banks

Add an option that allows for the configuration of the default PCR bank
to use. This was currently hard coded to sha256 and now may be passed
via this option. The fallback is still sha256. Valid PCR bank names are
sha1, sha256, sha384, and sha512. The passed list must be a comma-
separated list of the valid PCR bank names.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoman: Add version when feature was added when missing fix some others
Stefan Berger [Fri, 29 Oct 2021 17:40:12 +0000 (13:40 -0400)]
man: Add version when feature was added when missing fix some others

Add the version to items indicating when the feature was added.
Fix and unify some other ones.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup.conf: Use /usr/bin/swtpm_localca for create_certs_tool
Stefan Berger [Thu, 28 Oct 2021 18:06:29 +0000 (14:06 -0400)]
swtpm_setup.conf: Use /usr/bin/swtpm_localca for create_certs_tool

swtpm_setup.conf has traditionally pointed to
/usr/share/swtpm/swtpm-localca for create_certs_tool but since
/usr/bin/swtpm_localca is now available, have newly created
config files point to this executable instead.

Since there are possibly many swtpm_setup.conf out there pointing
to /usr/share/swtpm/swtpm-localca, we have to still install
swtm_localca there as well and package it.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Add missing sys/wait.h include (BSDs)
Stefan Berger [Wed, 27 Oct 2021 23:24:06 +0000 (19:24 -0400)]
swtpm_setup: Add missing sys/wait.h include (BSDs)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Add missing signal.h include (BSDs)
Stefan Berger [Wed, 27 Oct 2021 23:23:10 +0000 (19:23 -0400)]
swtpm: Add missing signal.h include (BSDs)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Convert 2 test cases to use --daemon option
Stefan Berger [Wed, 27 Oct 2021 01:38:45 +0000 (21:38 -0400)]
tests: Convert 2 test cases to use --daemon option

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Add test case for chardev for swtpm --print-states option
Stefan Berger [Wed, 27 Oct 2021 01:38:00 +0000 (21:38 -0400)]
tests: Add test case for chardev for swtpm --print-states option

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Make --daemon not racy
Nicolas Williams [Tue, 12 Oct 2021 16:58:06 +0000 (11:58 -0500)]
swtpm: Make --daemon not racy

Signed-off-by: Nicolas Williams <nico@cryptonector.com>
2 years agoswtpm_setup: Only activate SHA256 PCR bank, not SHA1 bank anymore
Stefan Berger [Fri, 22 Oct 2021 10:53:36 +0000 (06:53 -0400)]
swtpm_setup: Only activate SHA256 PCR bank, not SHA1 bank anymore

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoman: Improve the documentation of swtpm_setup's --create-config-files
Stefan Berger [Tue, 19 Oct 2021 14:00:24 +0000 (10:00 -0400)]
man: Improve the documentation of swtpm_setup's --create-config-files

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Report stderr as returned by external tool (swtpm-localcal)
Stefan Berger [Tue, 19 Oct 2021 11:10:44 +0000 (07:10 -0400)]
swtpm_setup: Report stderr as returned by external tool (swtpm-localcal)

Report the error printed out via stderr as returned by swtpm-localca for
example.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agorpm: Update spec file to also work on CentOS9-stream
Stefan Berger [Mon, 18 Oct 2021 16:06:22 +0000 (12:06 -0400)]
rpm: Update spec file to also work on CentOS9-stream

CentOS9 has no more trousers, so disable it for rhel >= 9.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotest: Add missing _test_tpm2_file_permissions file to EXTRA_DIST
Stefan Berger [Mon, 18 Oct 2021 13:52:01 +0000 (09:52 -0400)]
test: Add missing _test_tpm2_file_permissions file to EXTRA_DIST

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agorpm/debian: Clean up packaging files
Stefan Berger [Mon, 18 Oct 2021 13:20:33 +0000 (09:20 -0400)]
rpm/debian: Clean up packaging files

- Remove unused python3-twisted and gmp-devel.
- Add back rule to package /man8/swtpm_localca.8*

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agorpm: Remove man8/swtpm_localca.8 from specfile
Stefan Berger [Mon, 18 Oct 2021 11:19:23 +0000 (07:19 -0400)]
rpm: Remove man8/swtpm_localca.8 from specfile

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Disable fsync on file & dir due to TPM timeouts (issue #597)
Stefan Berger [Fri, 15 Oct 2021 03:34:53 +0000 (23:34 -0400)]
swtpm: Disable fsync on file & dir due to TPM timeouts (issue #597)

We cannot currently fsync on the TPM's state file and the dir since this
takes too long and commands in a VM may time out. The reason for this is
that the TPM 2 code occasionally writes the permanent state out even on
commands like TPM2_PCR_Extend that must not take a long time.

See explanation for this in the libtpms PR https://github.com/stefanberger/libtpms/pull/274 .

We will re-enable this feature in 'a while' once the updated libtpms
version has been made more widely available.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Initialize variables to avoid compiler warnings
Stefan Berger [Fri, 15 Oct 2021 11:44:53 +0000 (07:44 -0400)]
swtpm_setup: Initialize variables to avoid compiler warnings

Fix issue #591 by initializing the variables swtpm_has_tpm2 and
swtpm_has_tpm12.

swtpm_setup.c:1178:31: note: 'swtpm_has_tpm2' was declared here
     gboolean swtpm_has_tpm12, swtpm_has_tpm2;
                               ^~~~~~~~~~~~~~
swtpm_setup.c:1019:5: error: 'swtpm_has_tpm12' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     printf("{ \"type\": \"swtpm_setup\", "
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            "\"features\": [ %s%s\"cmdarg-keyfile-fd\", \"cmdarg-pwdfile-fd\", \"tpm12-not-need-root\""

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Fix case when no backend URI has been specified
Stefan Berger [Tue, 12 Oct 2021 10:27:26 +0000 (06:27 -0400)]
swtpm: Fix case when no backend URI has been specified

It is possible to start swtpm with this command line even though
neither storage nor communication channels have been provided.

./src/swtpm/swtpm socket --flags not-need-init,startup-clear

Since sending a startup message to the TPM will cause it to
want to store permanent state, we have to handle the case when
no storage backend was given and therefore the backend_uri
is NULL.

Previously the above command line caused a NULL pointer exception
but now handles this case with the following output:

swtpm: SWTPM_NVRAM_Init: Missing backend URI.
swtpm: Error: Could not initialize libtpms.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Fix a forgotten endianess-conversion
Stefan Berger [Mon, 11 Oct 2021 20:20:46 +0000 (16:20 -0400)]
swtpm: Fix a forgotten endianess-conversion

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_localca: Created certificates for CAs and TPM that do not expire
Stefan Berger [Fri, 8 Oct 2021 15:19:33 +0000 (11:19 -0400)]
swtpm_localca: Created certificates for CAs and TPM that do not expire

Rather than having the CA certificates, that are created on the fly,
expire in 10 years, have them not expire at all.

Also create TPM certificates that don't expire and extend a test
case for this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_cert: Allow passing -1 for days to get a non-expiring certificate
Stefan Berger [Fri, 8 Oct 2021 16:06:50 +0000 (12:06 -0400)]
swtpm_cert: Allow passing -1 for days to get a non-expiring certificate

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Exit with error code 1 on unknown option
Stefan Berger [Fri, 8 Oct 2021 13:35:47 +0000 (09:35 -0400)]
swtpm_setup: Exit with error code 1 on unknown option

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_localca: Exit with error code 1 on unknown option
Stefan Berger [Fri, 8 Oct 2021 13:40:55 +0000 (09:40 -0400)]
swtpm_localca: Exit with error code 1 on unknown option

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_localca: Use g_get_user_config_dir() rather than own code
Stefan Berger [Thu, 7 Oct 2021 20:00:06 +0000 (16:00 -0400)]
swtpm_localca: Use g_get_user_config_dir() rather than own code

Replace own code with g_get_user_config_dir() which makes things
a lot simpler.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Use g_get_user_config_dir() rather than own code
Stefan Berger [Thu, 7 Oct 2021 19:47:39 +0000 (15:47 -0400)]
swtpm_setup: Use g_get_user_config_dir() rather than own code

Replace own code with g_get_user_config_dir() which makes things
a lot simpler.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Add a test case for the new swtpm_setup option
Stefan Berger [Thu, 7 Oct 2021 12:41:47 +0000 (08:41 -0400)]
tests: Add a test case for the new swtpm_setup option

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agosamples: Have swtpm-create-user-config-files run swtpm_setup
Stefan Berger [Thu, 7 Oct 2021 00:18:01 +0000 (20:18 -0400)]
samples: Have swtpm-create-user-config-files run swtpm_setup

Have swtpm-create-user-config-files run swtpm_setup with the new
--create-config-files option and possible parameters.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Implement --create-user-config skip-if-exist
Stefan Berger [Thu, 7 Oct 2021 00:37:59 +0000 (20:37 -0400)]
swtpm_setup: Implement --create-user-config skip-if-exist

Implement support for skipping over creating the files
if any one of the config files already exist.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Implement option --create-config-files to create config files
Stefan Berger [Wed, 6 Oct 2021 20:58:04 +0000 (16:58 -0400)]
swtpm_setup: Implement option --create-config-files to create config files

Implement the option --create-config-files to create config files
for swtpm_setup and swtpm-localca for a user account. The files will
be created under the $XDG_CONFIG_HOME or $HOME/.config directories.

This option supports optional arguments 'overwrite' to allow overwriting
existing config files as well as the optional argument 'root' to create
config files under root's home directory. Both options can be passed
by separating them with a ','.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Move ARRAY_LEN and min #define's to swtpm_utils.h
Stefan Berger [Wed, 6 Oct 2021 17:57:38 +0000 (13:57 -0400)]
swtpm: Move ARRAY_LEN and min #define's to swtpm_utils.h

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agod/swtpm-tools postinst: create the TSS user if it does not exist
Thomas Lamprecht [Thu, 7 Oct 2021 10:14:11 +0000 (12:14 +0200)]
d/swtpm-tools postinst: create the TSS user if it does not exist

Adapted from tpm-udev [0] which handles that, but it is not really a
hard-requirement for swtpm and TSS_USER is configurable after all
(even if that is mostly used for the test system).

So, create that user and group if it does not exists to avoid errors
and failing installation.

[0]: https://salsa.debian.org/debian/tpm-udev/-/blob/master/debian/tpm-udev.postinst

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agod/swtpm-tools postinst: avoid trying to create/chown in non-configure steps
Thomas Lamprecht [Thu, 7 Oct 2021 10:10:43 +0000 (12:10 +0200)]
d/swtpm-tools postinst: avoid trying to create/chown in non-configure steps

configure steps should be limited to get only executed on, well
configuration, so check for that and do nothing in the remaining
commands [0] the postinst can be called with.

[0]: https://www.debian.org/doc/debian-policy/ch-maintainerscripts.html#summary-of-ways-maintainer-scripts-are-called

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agodebian: downgrade trousers package dependency to recommended
Thomas Lamprecht [Thu, 7 Oct 2021 07:09:33 +0000 (09:09 +0200)]
debian: downgrade trousers package dependency to recommended

Currently `trousers` is listed as (hard) Dependency, but it does not
seems to be required for quite a few usecases, e.g., ours where we
mainly using swtpm for providing a tpm to VMs.

With trousers in Debian one gets an additional pain point: it comes
with rather dated and in some cirumstances failing by mistake init
script [0] that can throw errors when setting up during installation
and thus fail the whole installation of swtpm as Debian policy for
`Depends` hits:

> A package will not be configured unless all of the packages listed
> in its Depends field have been correctly configured
-- [1]

Declaring dependencies for things are not a hard requirement means
that a user will be required to install more dependencies than
actually needed.

Just documenting that as fact why I investigated in the
hard-requirement on trousers in the first place, not an actual
justification - it's a packaging bug after all.

So downgrade the dependency to "Suggests", as it seems a reasonable
level when checking its documented meaning:

> This is used to declare that one package may be more useful with
> one or more others. Using this field tells the packaging system and
> the user that the listed packages are related to this one and can
> perhaps enhance its usefulness, but that installing this one without
> them is perfectly reasonable.
-- [1]

[0]: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=895201
[1]: https://www.debian.org/doc/debian-policy/ch-relationships.html

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2 years agoman: Enumerate the nvram-backend-dir separately
Stefan Berger [Wed, 6 Oct 2021 22:16:04 +0000 (18:16 -0400)]
man: Enumerate the nvram-backend-dir separately

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Display the --print-states capability and document it
Stefan Berger [Wed, 6 Oct 2021 22:13:01 +0000 (18:13 -0400)]
swtpm: Display the --print-states capability and document it

Display the --print-states capability in the --print-capabilites
output as cmdarg-print-states.

Document availability in the man page.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Move gmalloc after block that may return NULL on failure v0.7.0-rc1
Stefan Berger [Tue, 5 Oct 2021 20:22:25 +0000 (16:22 -0400)]
swtpm_setup: Move gmalloc after block that may return NULL on failure

To avoid a memory leak, move the gmalloc after a block that may
return NULL on failure.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Introduce label to skip over closing of pidfile
Stefan Berger [Tue, 5 Oct 2021 20:18:25 +0000 (16:18 -0400)]
swtpm_setup: Introduce label to skip over closing of pidfile

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Call msync with length = 0 on Cygwin
Stefan Berger [Tue, 5 Oct 2021 18:29:51 +0000 (14:29 -0400)]
swtpm: Call msync with length = 0 on Cygwin

Cygwin internally uses the Windows API call FlushViewOfFile that
seems to not like to be called with an excessive number of bytes.
Instead, call it with length = 0 so that 'the file is flushed from
the base address to the end of the mapping' and then msync() succeeds.

Source:
https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-flushviewoffile

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Use SWTPM_ATTR_UNUSED on unused parameters (BSDs)
Stefan Berger [Tue, 5 Oct 2021 16:46:40 +0000 (12:46 -0400)]
swtpm_setup: Use SWTPM_ATTR_UNUSED on unused parameters (BSDs)

To silence the BSD gcc compiler on unused function parameters,
use SWTPM_ATTR_UNUSED.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Use pidfile filename rather than fd (Cygwni, BSDs)
Stefan Berger [Tue, 5 Oct 2021 16:39:49 +0000 (12:39 -0400)]
swtpm_setup: Use pidfile filename rather than fd (Cygwni, BSDs)

Use the pidfile filename rather than the fd because Cygwin for example
does not seem to support passed file descriptors and also OpenBSD
does not pass some test cases because of this.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Use /usr/bin/env bash rather than /bin/bash (BSDs)
Stefan Berger [Tue, 5 Oct 2021 16:36:48 +0000 (12:36 -0400)]
tests: Use /usr/bin/env bash rather than /bin/bash (BSDs)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoheaders: Add defines for little endian data conversion (OS X)
Stefan Berger [Tue, 5 Oct 2021 15:37:54 +0000 (11:37 -0400)]
headers: Add defines for little endian data conversion (OS X)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Use compiler and system dependent header files
Stefan Berger [Tue, 5 Oct 2021 15:22:24 +0000 (11:22 -0400)]
swtpm: Use compiler and system dependent header files

The header file endian.h does not exists everywhere, so we have to
use system_dependencies.h to get something similar on all systems.

Some compilers, such as gcc on FreeBSD, are picky about unused
function parameters, so we have to decorate the unused ones
with SWTPM_ATTR_UNUSED.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Use sys/mount.h and support block devs only if BLKGETSIZE64 exists
Stefan Berger [Tue, 5 Oct 2021 15:17:01 +0000 (11:17 -0400)]
swtpm: Use sys/mount.h and support block devs only if BLKGETSIZE64 exists

The header file fs/linux.h only exists on Linux but we can also
use sys/mount.h, which also exists on Cygwin and the BSDs.

Only support  block devices if BLKGETSIZE64 is defined.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: mention dir:// and file:// in man page and usage
Stefan Reiter [Thu, 30 Sep 2021 13:59:40 +0000 (15:59 +0200)]
swtpm_setup: mention dir:// and file:// in man page and usage

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm_setup: add test case to exercise file backend
Stefan Reiter [Thu, 30 Sep 2021 09:27:14 +0000 (11:27 +0200)]
swtpm_setup: add test case to exercise file backend

heavily copy-pas^W inspired by 'test_swtpm_setup_overwrite'

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm_setup: add file backend
Stefan Reiter [Thu, 30 Sep 2021 08:40:01 +0000 (10:40 +0200)]
swtpm_setup: add file backend

Add a second backend for supporting the file:// linear nvram store in
swtpm.

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm_setup: add abstract swtpm_backend_ops with dir:// implementation
Stefan Reiter [Thu, 30 Sep 2021 08:03:05 +0000 (10:03 +0200)]
swtpm_setup: add abstract swtpm_backend_ops with dir:// implementation

Abstract away implementation specific code for handling TPM state in
swtpm_setup. The current code for handling directories is moved to
'swtpm_backend_dir.c'.

Where possible, the input argument is simply passed verbatim as
'backend-uri' to swtpm.

No functional change intended, aside from supporting 'dir://' as
optional prefix. The checks for lock-file accessibility are moved to
check_access(), but that shouldn't affect anything AFAICT.

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm_setup: use mkstemp for pidfile
Stefan Reiter [Thu, 30 Sep 2021 08:17:57 +0000 (10:17 +0200)]
swtpm_setup: use mkstemp for pidfile

This avoids issues with state backends where we don't have a convenient
directory for a pidfile available.

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm_setup: remove redundant delete_state function
Stefan Reiter [Thu, 30 Sep 2021 07:30:45 +0000 (09:30 +0200)]
swtpm_setup: remove redundant delete_state function

...and use delete_swtpm_statefiles instead. This function iterates the
folder instead of just deleting one file, but since it is already called
before the init call guarded here, it can only affect files created by
this run anyway.

Note that delete_state had slightly different return semantics, but it
doesn't matter, as the return value is ignored here anyway (best effort
cleanup).

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm: Add "nvram-backend-linear" capability
Stefan Reiter [Thu, 5 Aug 2021 12:22:46 +0000 (14:22 +0200)]
swtpm: Add "nvram-backend-linear" capability

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm: Add "file://" backend to man page
Stefan Reiter [Thu, 5 Aug 2021 12:18:09 +0000 (14:18 +0200)]
swtpm: Add "file://" backend to man page

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm: Add tests for "linear file" backend
Stefan Reiter [Thu, 5 Aug 2021 12:14:15 +0000 (14:14 +0200)]
swtpm: Add tests for "linear file" backend

Adapt save_load_state tests to include coverage of the "linear file"
backend mode. "tpm2" is save/load is tested with both a regular file and
a loop device to excercise the blockdev mmap code.

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agoswtpm: Add "linear file" nvram store backend
Stefan Reiter [Thu, 5 Aug 2021 12:09:55 +0000 (14:09 +0200)]
swtpm: Add "linear file" nvram store backend

Implements a second abstraction layer as an NVRAM storage backend: The
"linear" backend stores data in a simple format that can contain
multiple files (multiple TPM states and numbers) in one linear address
space. This can then be mapped to files or other "block-device-like"
interfaces using nvram_linear_file_ops implementations.

A simple one using mmap is provided with the URI type "file://".

Does not support any locking at the moment, users must ensure exclusive
access themselves.

Signed-off-by: Stefan Reiter <stefan@pimaker.at>
2 years agotests: Skip TPM 2 pkcs11-related test when ASAN is used
Stefan Berger [Mon, 4 Oct 2021 22:07:43 +0000 (18:07 -0400)]
tests: Skip TPM 2 pkcs11-related test when ASAN is used

The key is freed using 'gnutls_privkey_deinit(pkcs11key)', yet the
following memory leaks show up that are most likely in the pkcs11 module.
Skip the test if ASAN is being used to avoid the test failure.

Direct leak of 55080 byte(s) in 1 object(s) allocated from:
    #0 0x7fdabb152af7 in calloc (/lib64/libasan.so.6+0xaeaf7)
    #1 0x7fdab6b737c6 in C_Initialize (/usr/lib64/pkcs11/libtpm2_pkcs11.so+0x147c6)
    #2 0x7fdab9a5f8a9 in initialize_module_inlock_reentrant (/lib64/libp11-kit.so.0+0x2b8a9)
    #3 0x7fdab9a5fc88 in managed_C_Initialize (/lib64/libp11-kit.so.0+0x2bc88)
    #4 0x7fdab9a66018 in p11_kit_modules_initialize (/lib64/libp11-kit.so.0+0x32018)
    #5 0x7fdab9a66778 in p11_kit_modules_load_and_initialize (/lib64/libp11-kit.so.0+0x32778)
    #6 0x7fdabab10dc5 in auto_load (/lib64/libgnutls.so.30+0x9cdc5)
    #7 0x7fdabab12656 in gnutls_pkcs11_init (/lib64/libgnutls.so.30+0x9e656)
    #8 0x7fdabab12779 in _gnutls_pkcs11_check_init (/lib64/libgnutls.so.30+0x9e779)
    #9 0x7fdabab1af1f in gnutls_pkcs11_privkey_import_url (/lib64/libgnutls.so.30+0xa6f1f)
    #10 0x7fdabaaee0e3 in gnutls_privkey_import_url (/lib64/libgnutls.so.30+0x7a0e3)
    #11 0x40abee in main /home/stefanb/dev/swtpm/src/swtpm_cert/ek-cert.c:1399
    #12 0x7fdab9f5ab74 in __libc_start_main (/lib64/libc.so.6+0x27b74)
    #13 0x40366d in _start (/home/stefanb/dev/swtpm/src/swtpm_cert/swtpm_cert+0x40366d)

Indirect leak of 8208 byte(s) in 1 object(s) allocated from:
    #0 0x7fdabb152af7 in calloc (/lib64/libasan.so.6+0xaeaf7)
    #1 0x7fdab6b736f9 in C_Initialize (/usr/lib64/pkcs11/libtpm2_pkcs11.so+0x146f9)
    #2 0x7fdab9a5f8a9 in initialize_module_inlock_reentrant (/lib64/libp11-kit.so.0+0x2b8a9)
    #3 0x7fdab9a5fc88 in managed_C_Initialize (/lib64/libp11-kit.so.0+0x2bc88)
    #4 0x7fdab9a66018 in p11_kit_modules_initialize (/lib64/libp11-kit.so.0+0x32018)
    #5 0x7fdab9a66778 in p11_kit_modules_load_and_initialize (/lib64/libp11-kit.so.0+0x32778)
    #6 0x7fdabab10dc5 in auto_load (/lib64/libgnutls.so.30+0x9cdc5)
    #7 0x7fdabab12656 in gnutls_pkcs11_init (/lib64/libgnutls.so.30+0x9e656)
    #8 0x7fdabab12779 in _gnutls_pkcs11_check_init (/lib64/libgnutls.so.30+0x9e779)
    #9 0x7fdabab1af1f in gnutls_pkcs11_privkey_import_url (/lib64/libgnutls.so.30+0xa6f1f)
    #10 0x7fdabaaee0e3 in gnutls_privkey_import_url (/lib64/libgnutls.so.30+0x7a0e3)
    #11 0x40abee in main /home/stefanb/dev/swtpm/src/swtpm_cert/ek-cert.c:1399
    #12 0x7fdab9f5ab74 in __libc_start_main (/lib64/libc.so.6+0x27b74)
    #13 0x40366d in _start (/home/stefanb/dev/swtpm/src/swtpm_cert/swtpm_cert+0x40366d)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Make fsync-related errors non-fatal (for libvirt using AppArmor)
Stefan Berger [Fri, 1 Oct 2021 20:50:07 +0000 (16:50 -0400)]
swtpm: Make fsync-related errors non-fatal (for libvirt using AppArmor)

Only recent libvirt versions have the patch for the AppArmor profile for
libvirt to allow fsync after opening a directory for reading. Rather
than failing hard on the open-directory-for-reading error, log it once
and continue and do not try it again after.

This patch addresses the problems seen on Ubuntu related to an older
version of libvirt without the AppArmor profile update.
- issue #484
- issue #549
- issue #559

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoRevert "swtpm: Make fsync() errors non-fatal (for libvirt using AppArmor)"
Stefan Berger [Fri, 1 Oct 2021 20:43:18 +0000 (16:43 -0400)]
Revert "swtpm: Make fsync() errors non-fatal (for libvirt using AppArmor)"

This reverts commit 04cb07fa6c02afdf16c1adb4b5c202d93c6b190c.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoUpdate bug_report.md
Stefan Berger [Sat, 2 Oct 2021 15:18:02 +0000 (11:18 -0400)]
Update bug_report.md

Ask users to include log files, such as libvirt log files.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Make fsync() errors non-fatal (for libvirt using AppArmor)
Stefan Berger [Fri, 1 Oct 2021 13:18:58 +0000 (09:18 -0400)]
swtpm: Make fsync() errors non-fatal (for libvirt using AppArmor)

Only recent libvirt versions have the patch for the AppArmor profile
for libvirt to allow fsync on dir and directory. Rather than failing
hard on this error, log it once and continue and do not try fsync
again after.

This patch addresses the problems seen on Ubuntu related to an older
version of libvirt without the AppArmor profile update.
- issue #484
- issue #549
- issue #559

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Fix errno comparison on end-of-directory (FreeBSD)
Stefan Berger [Thu, 30 Sep 2021 17:40:26 +0000 (13:40 -0400)]
swtpm_setup: Fix errno comparison on end-of-directory (FreeBSD)

FreeBSD may return errno EINVAL beside ENOENT once there are no more
entries in a directory to walk over. It claims that readdir() follows
the getdirentries() return codes, which do include EINVAL but not
ENOENT. But ENOENT is also being used.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_localca: Fix memory leak on arrays of strings
Stefan Berger [Wed, 29 Sep 2021 23:58:56 +0000 (19:58 -0400)]
swtpm_localca: Fix memory leak on arrays of strings

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_localca: Use return from main rather than exit to resolve ASAN issue
Stefan Berger [Wed, 29 Sep 2021 23:20:32 +0000 (19:20 -0400)]
swtpm_localca: Use return from main rather than exit to resolve ASAN issue

Use return rather than exit() when returning from main so that g_autofree'd
variables can be freed.

This resolves issue #568 that occurs with clang only.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Use return from main rather than exit to resolve ASAN issue
Stefan Berger [Wed, 29 Sep 2021 23:17:59 +0000 (19:17 -0400)]
swtpm_setup: Use return from main rather than exit to resolve ASAN issue

Use return rather than exit() when returning from main so that g_autofree'd
variables can be freed.

This resolves issue #568 that occurs with clang only.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Use nm and grep to check for ASAN
Stefan Berger [Wed, 29 Sep 2021 16:35:58 +0000 (12:35 -0400)]
tests: Use nm and grep to check for ASAN

clang doesn't link executables built with ASAN support to libasan, like
gcc does, so we have to use nm rather than ldd for checking for whether
the executable was built with ASAN. nm is part of the binutils package
and should be available on all systems where gcc was installed.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_localca: Fix a TPM 1.2/TCSD related memory leak
Stefan Berger [Wed, 29 Sep 2021 15:55:39 +0000 (11:55 -0400)]
swtpm_localca: Fix a TPM 1.2/TCSD related memory leak

Auto-free the variables used for holding values read from the config
file.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Replace bad '~' with '\!'
Stefan Berger [Wed, 29 Sep 2021 16:07:35 +0000 (12:07 -0400)]
tests: Replace bad '~' with '\!'

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Forward --logfile option to swtpm
Eiichi Tsukata [Wed, 22 Sep 2021 06:22:28 +0000 (15:22 +0900)]
swtpm_setup: Forward --logfile option to swtpm

Whenever swtpm_setup is executed with --logfile option, forward the
option to swtpm (--log file=...). This helps debugging swtpm
initialization issues.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agoswtpm: Initialize logging as early as possible
Eiichi Tsukata [Wed, 22 Sep 2021 06:59:34 +0000 (15:59 +0900)]
swtpm: Initialize logging as early as possible

Parse "--log" option earlier to help debugging initialization issues.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agobuild-sys: Minor error message typo fix for glib
Eiichi Tsukata [Wed, 29 Sep 2021 00:53:12 +0000 (09:53 +0900)]
build-sys: Minor error message typo fix for glib

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agobuild-sys: Introduce --enable-sanitizers to configure
Eiichi Tsukata [Tue, 28 Sep 2021 05:35:20 +0000 (14:35 +0900)]
build-sys: Introduce --enable-sanitizers to configure

This enables address and undefined sanitizers.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
2 years agotest: Fix test_tpm2_file_permissions for BSD
Stefan Berger [Tue, 28 Sep 2021 14:08:29 +0000 (10:08 -0400)]
test: Fix test_tpm2_file_permissions for BSD

BSD cp does not understand the -d option, so remove it.
It's better to use "su -u nobody -c '...'" than sudo, which makes
this test also work on the BSDs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Add a test case for testing --runas and ability to access files
Stefan Berger [Sun, 26 Sep 2021 02:26:40 +0000 (22:26 -0400)]
tests: Add a test case for testing --runas and ability to access files

Add a test case for testing the --runas parameter and the ability to access
existing files that have restrictive access permission so that only allow
the --runas user is able to access these files. This is to ensure that
swtpm can access these files properly when the handling of options and the
changing to the --runas user is moved around within swtpm.

Skip the test case if swtpm is linked with ASAN since then we get these
types of error messages that fail tests:

==== Starting swtpm with interfaces socket+socket ====
==3303263==LeakSanitizer has encountered a fatal error.
==3303263==HINT: For debugging, try setting environment variable LSAN_OPTIONS=verbosity=1:log_threads=1
==3303263==HINT: LeakSanitizer does not work under ptrace (strace, gdb, etc)

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm_setup: Fix exit code on error to be '1'.
Stefan Berger [Mon, 27 Sep 2021 22:26:43 +0000 (18:26 -0400)]
swtpm_setup: Fix exit code on error to be '1'.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Add size to each type of state and use JSON object
Stefan Berger [Mon, 27 Sep 2021 15:02:47 +0000 (11:02 -0400)]
swtpm: Add size to each type of state and use JSON object

Add the size of the type state to the --print-states output and switch
back to a JSON object when enumerating the blobs.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agotests: Fix tests using tpm2-abrmd by preventing concurrency
Stefan Berger [Mon, 27 Sep 2021 02:38:50 +0000 (22:38 -0400)]
tests: Fix tests using tpm2-abrmd by preventing concurrency

The two tests test_tpm2_samples_create_tpmca and
test_tpm2_swtpm_localca_pkcs11 cannot complete successfully if run in
parallel. To solve this issue, introduce a dependency via the log files
to prevent parallel execution of the two test. We have to append the
.test suffix to their names to be able to do this.

docs:
https://www.gnu.org/software/automake/manual/html_node/Parallel-Test-Harness.html

Resolves issue #501, though the problem with stability of the tpm2 pkcs11
module is not resolved.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Search for all state files and use abstracted names in JSON
Stefan Berger [Sat, 25 Sep 2021 00:23:22 +0000 (20:23 -0400)]
swtpm: Search for all state files and use abstracted names in JSON

Search for all the state files not just the permanent state and
when printing the JSON use the abstracted names rather than concrete
filenames that are only valid for the dir backend but will likely
not exist in other backends.

Adjust swtpm_setup to search for the abstracted name and also
adjust the error message to print out the abstracted name.

Adjust the test cases.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Implement CheckState interface function for checking for stateblob
Stefan Berger [Sat, 25 Sep 2021 00:24:52 +0000 (20:24 -0400)]
swtpm: Implement CheckState interface function for checking for stateblob

Implement a CheckState interface function for checking for the
TPM_PERMANENT_ALL_NAME blog. The dirctory backend does a simple stat on the
file without actually reading it, which otherwise may require the (correct)
key if it was encrypted.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2 years agoswtpm: Remove all interface functions from swtpm_nvstore_dir.h
Stefan Berger [Sat, 25 Sep 2021 00:24:32 +0000 (20:24 -0400)]
swtpm: Remove all interface functions from swtpm_nvstore_dir.h

Remove all interface functions from swtpm_nvstore_dir.h and make them
static in swtpm_nvstore_dir.c. This way we avoid direct calls to these
functions from elsewhere.

Move the declaration of the interface structure into swtpm_nvstore.h
to get rid of swtpm_nvstore_dir.h entirely.

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