Commit Graph

1523 Commits

Author SHA1 Message Date
Stefan Berger
85ec64573b 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>
2022-05-03 13:27:13 -04:00
Stefan Berger
15d446885b 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>
2022-05-03 13:27:13 -04:00
Stefan Berger
607f1f800a 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>
2022-04-04 11:45:36 -04:00
Stefan Berger
f4cdeb61b9 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>
2022-04-04 11:45:36 -04:00
Stefan Berger
9918259c6e 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>
2022-03-29 07:38:12 -04:00
Stefan Berger
71965cda6c 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>
2022-03-29 07:38:12 -04:00
Stefan Berger
47638ebc36 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>
2022-03-28 09:21:38 -04:00
Stefan Berger
81d4b3e0cd 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>
2022-03-28 09:21:38 -04:00
Stefan Berger
2579038d76 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>
2022-03-24 08:40:00 -04:00
Stefan Berger
b7f55fd041 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>
2022-03-24 08:40:00 -04:00
Stefan Berger
e735328e3c 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>
2022-03-24 08:40:00 -04:00
Stefan Berger
646cf413b1 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>
2022-03-04 07:44:22 -05:00
Stefan Berger
8a05e8fd52 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>
2022-03-02 21:20:26 -05:00
Stefan Berger
5796d4895f 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
2022-02-23 09:17:11 -05:00
Stefan Berger
b34da36cde 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>
2022-02-23 09:17:11 -05:00
Stefan Berger
00eb426004 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
2022-02-23 09:17:11 -05:00
Stefan Berger
9b42d2d503 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>
2022-02-17 16:41:53 -05:00
Stefan Berger
9f740868fc 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>
2022-02-16 15:53:56 -05:00
Stefan Berger
48773fe3ea 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>
2022-02-16 15:53:56 -05:00
Stefan Berger
fbbb56b52b 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>
2022-02-16 15:53:56 -05:00
Stefan Berger
49b4b30500 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>
2022-02-16 15:53:56 -05:00
наб
0599e40053 swtpm_setup: fix newline before full stop in swtpm-not-found error
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
2021-11-26 21:30:51 -05:00
Seunghun Han
33aa135545 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>
2021-11-22 18:30:17 -05:00
Stefan Berger
6d1a7abbfc 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>
2021-11-22 07:39:28 -05:00
Stefan Berger
3115dff02f build-sys: Bump up version to 0.8.0 at beginning of dev cycle
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-20 12:02:11 -05:00
Stefan Berger
b79fd91c4b debian/rpm: Adjust changelog for 0.7.0 release
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-09 10:49:45 -05:00
Stefan Berger
0a1947451b CHANGES: Add more documentation for changes in 0.7.0
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-09 10:49:45 -05:00
Stefan Berger
9726af516f 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>
2021-11-08 09:03:44 -05:00
Stefan Berger
7bf77806f4 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>
2021-11-05 18:47:12 -04:00
Stefan Berger
3de27959e6 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>
2021-11-05 18:47:12 -04:00
Stefan Berger
13aaff6b8f 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>
2021-11-05 16:58:54 -04:00
Stefan Berger
59d813574f 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>
2021-11-05 16:58:54 -04:00
Stefan Berger
f894b45f99 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>
2021-11-05 12:59:42 -04:00
Stefan Berger
25d4ac2d3a 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>
2021-11-05 06:39:49 -04:00
Stefan Berger
15b9ca6bc3 tests: Support filenames with spaces in some functions
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-05 06:39:49 -04:00
Stefan Berger
8422d06868 swtpm_setup: Create flags by shifting '1'
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-05 06:39:49 -04:00
Stefan Berger
cce7503cbf tests: exit with error code if mktemp fails
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-11-02 08:35:49 -04:00
Stefan Berger
b08876722a 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>
2021-11-01 10:27:10 -04:00
Stefan Berger
30fa8b47d2 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>
2021-10-29 15:36:35 -04:00
Stefan Berger
a5cc0bf6e2 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>
2021-10-29 15:36:35 -04:00
Stefan Berger
87755f8cc4 swtpm_setup: Move code to activate PCR banks into own function
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-29 15:36:35 -04:00
Stefan Berger
df4046d0e4 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>
2021-10-29 15:36:35 -04:00
Stefan Berger
4641f19f21 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>
2021-10-29 15:16:15 -04:00
Stefan Berger
1ffa0cc472 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>
2021-10-28 15:14:01 -04:00
Stefan Berger
d766b58d17 swtpm_setup: Add missing sys/wait.h include (BSDs)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-27 20:13:39 -04:00
Stefan Berger
343a038b58 swtpm: Add missing signal.h include (BSDs)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-27 20:13:39 -04:00
Stefan Berger
743b4d1b61 tests: Convert 2 test cases to use --daemon option
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-27 18:58:25 -04:00
Stefan Berger
122106b8f2 tests: Add test case for chardev for swtpm --print-states option
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-27 18:58:25 -04:00
Nicolas Williams
98d1d126cd swtpm: Make --daemon not racy
Signed-off-by: Nicolas Williams <nico@cryptonector.com>
2021-10-27 16:51:35 -04:00
Stefan Berger
26cdfc77df swtpm_setup: Only activate SHA256 PCR bank, not SHA1 bank anymore
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2021-10-22 07:39:55 -04:00