Commit Graph

259 Commits

Author SHA1 Message Date
Stefan Berger
8b4944fec2 tpm12: ubsan: prevent source address NULL passed to memcpy
memcpy() is called with source address NULL, which causes an error
with ubsan. Coincidentally data_length is also 0, so nothing bad happens.
So we simply intercept the data_length = 0 case.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-23 20:28:40 -05:00
Stefan Berger
60c64ddaaf tpm2: Fix coverity scan issue related to error log output
Do not display the datasize, which is not initialized at this point,
but display the comparison between two size variables that is the
source of the problem.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-19 12:22:50 -05:00
Stefan Berger
208218cc59 tpm2: Address a coverity issue related to buffer size
Initialize the buffer size to 0 before passing it to the function filling
it from the byte stream. When comparing sizes of TPM2B, use the integers
rather than doing a memory comparison.

I don't think existing code was wrong, but this gets rid of a coverity
issue.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-11-19 12:22:50 -05:00
Stefan Berger
0466fcf6a4 docs: Update the INSTALL file to reflect current build system
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-29 19:50:35 -04:00
Stefan Berger
be9b50f1f8 build-sys: Support --disable-hardening as an option
By default the hardening compiler flags are enabled and
--disable-hardening disables them.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-29 19:50:35 -04:00
Stefan Berger
8cc7807655 tpm2: Only write STATE_RESET and STATE_CLEAR blobs when needed
STATE_RESET_DATA and STATE_CLEAR_DATA need to only be written if the
orderlyState has TPM_SU_STATE (after masking out some other bits) set.

We bump up the version of the PERSISTENT_STATE to 3 and since previous
versions cannot deal with the missing STATE_{RESET,CLEAR}_DATA we require
that the minimum supported version understood by the implementation is
also '3'. This prevents downgrading of libtpms to a version prior to this
(patch).

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-23 11:45:05 -04:00
Stefan Berger
2f3334d657 tpm2: Fix license headers in files written by 'me'
Some files have an incorrect license header. Fix this.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-06 11:00:26 -04:00
Stefan Berger
dd9c2f2138 build-sys: Only use AX_CHECK_LINK_FLAG with autoconf >= 2.64
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-06 11:00:26 -04:00
Stefan Berger
79275ce87c build-sys: Pass header file to compiler for checking for supported flag
Older versions of gcc need some input file to compile so that
we learn whether -fstack-protector-strong is supported.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-05 21:47:15 -04:00
Stefan Berger
73cad883ba tpm2: Introduce TPM_HAVE_TPM2_DECLARATIONS to avoid re-declarations
Older gcc versions are unhappy that some types declared by TPM 1.2
headers are re-declared by TPM 2 headers. All of these types have
the same UINT32 datatype and we can avoid having the re-declared
by introducing TPM_HAVE_TPM2_DECLARATIONS and inlcuding the TPM2
headers first and then the TPM 1.2 headers where we then do not re-
declare those datatypes that are clashing.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-10-05 21:47:15 -04:00
Stefan Berger
8df4b30270 tpm2: Remove unnecessary re-definition of TPM_RC in header
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-05 21:47:15 -04:00
Stefan Berger
a48ea0a23d tpm2: Move callback invocations into their own file
Move all handling of callback invokcations in the TPM 2 code into
their own file so that we have less mixing of TPM 2 headers and
TPM 1.2 headers from the library.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
2018-10-05 21:47:15 -04:00
Stefan Berger
85eddd74ce tpm12: Initialize a few pointers with NULL
gcc 4.2.1 on i386 OpenBSD complains about a few uninitialized pointers
being used. These seem to be false positives but we can still initialize
the pointers to NULL.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-26 17:57:43 -04:00
Stefan Berger
3606971639 tpm2: Initialize needed_size with 0
gcc 4.2.1 on i386 OpenBSD complains about needed_size being used
uninitilized. It seems a false positive but we can still initialize
it to 0.

Also set t = NULL in the error case to speed up the exit from the loop.

Signed-off-by: Stefam Berger <stefanb@linux.vnet.ibm.com>
2018-09-26 17:53:32 -04:00
Stefan Berger
7827f8450b tpm2: Address two more complaints by gcc 4.2.1 on i386 OpenBSD
gcc 4.2.1 on i386 OpenBSD complains about two variables not having the
proper data type for %zu. This patch just casts the variables to size_t.

The comparison of a casted int against '< 0' also was a reason for
complaint since the evaluation of the variable would always be false
due to limited datatype. This patch also addresses this issue.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-26 17:21:48 -04:00
Stefan Berger
2f1f49594a tpm2: Append ULL to 64bit constants for gcc 4.2.1 on i386 OpenBSD
The i386 gcc 4.2.1 compiler complains about some 64bit constants
being too large. Append ULL to the constants to fix this issue.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-26 17:21:41 -04:00
Stefan Berger
0ae978cc21 tpm2: Initialize stack variable indexOrderlyRam to zeros
Valgrind reports uninitialized bytes when running some of the swtpm test
cases. The reason is that the indexOrderlyRam variable, which resides on
the stack, was not initialized. This patch fixes this valgrind complaint.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-26 20:41:53 -04:00
Stefan Berger
e8e8633089 tpm2: The state file exists on return code != TPM_RETRY
Modify the test for whether a state file exists by return code from the
load function being != TPM_RETRY. All other error codes indicate that some
form of state file exists, independent whether it is readable or not.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-17 09:07:27 -04:00
Stefan Berger
4111bd1bcf rpm: Address some of the rpmlint complaints
Remaining rpmlint complaint is the download URL. There's currently no
public tar to download.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com
2018-09-13 09:48:45 -04:00
Stefan Berger
5cc673f73d debian: Use autogen.sh and pass --with-tpm2 to configure
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-13 09:13:30 -04:00
Stefan Berger
1fe484ce67 scripting: Use #!/usr/bin/env bash rather than /bin/bash
On some systems /bin/bash does not exists but is somewhere else and can
be invoked with /usr/bin/env.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-10 16:33:34 +00:00
Stefan Berger
7a0e7052be build-sys: Pick up user-provided LDFLAGS
Pick up the user-provided LDFLAGS by assigning LDFLAGS using +=.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-10 12:22:07 -04:00
Stefan Berger
418d2a22cd tpm2: Enable compilation on DragonflyBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-10 16:15:29 +00:00
Stefan Berger
3300bbbcae build-sys: Make 'make check' work on FreeBSD
On FreeBSD we need to set the SHELL explicitly to /bin/bash since csh
is used otherwise and wouldn't allow us to run the check-local rule.
Besides that we need -shared for the check to pass. However, the FreeBSD
compiler doesn't allow us to recognize undefined symbols, which seem
to get suppressed with the -shared parameter. If the -shared is not passed
we get error messages due to undefined symbols _progname and environ from
libc.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-05 22:33:14 +00:00
Stefan Berger
314f8080d3 build-sys: Fix undefined symbol check on Darwin (OS X)
OS X needs the -shared parameter when running the undefined symbol
check.

Do not fail if a.out was not created, like on Cygwin.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-04 08:43:16 -04:00
Stefan Berger
5c2a46c9f8 travis: use 'distcheck' rather than 'check'
To test the creation of the tar and out-of-tree builds all the time, do
'distcheck' rather than a simple 'check'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-09-01 11:19:13 -04:00
Stefan Berger
59f46464d5 build-sys: work around broken linker when testing --version-script support
The linker on FreeBSD seems to be broken and fails for other reasons
when testing for support of the --version-script flag. The error
that is reported is:

local symbol 'environ' in /usr/lib/crt1.o is referenced by DSO.

Also __progname is needed.

To work around this problem we add a test.syms file that only has
these two symbols in it, which is enough for the test in
configure.ac and gives version script support in case of the
broken linker.

On FreeBSD TPM 1.2 related tests were failing due to test case 6
failures in case no linker script was used. (Very odd.) This patch
fixes this problem.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 21:45:16 +00:00
Stefan Berger
b52c19e171 build-sys: Remove libtpms_tpm2_la_LDFLAGS
Remove libtpms_tpm2_la_LDFLAGS since they are not needed.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 17:42:29 -04:00
Stefan Berger
83f8e40ecb tpm2: Make compileable on OS X/Darwin
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 14:55:09 -04:00
Stefan Berger
27904459e3 build-sys: Check for supported linker flag --version-script
Check whether the linker supports the linker flag --version-script.
The OS X linkwer does not seem to support it.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 13:24:54 -04:00
Stefan Berger
9582b58036 tpm2: activate field 'a' as renamed 'a_unused' in PRC_POLICY
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-30 06:31:10 -04:00
Stefan Berger
b6a89b2f55 build-sys: Use X="$X ..." rather than X+="..." in configure.ac
Some configure interpreters do not like X+="...", so we have to
use X="$X ..." instead.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 17:47:25 +00:00
Stefan Berger
83ca1948bc configure.ac: Replace tests with '==' through '='
On NetBSD configure.ac cannot have '==' in tests. So we have to replace them
with '='.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 12:12:57 +00:00
Stefan Berger
bdeabedd09 tpm2: Make compileable on NetBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 11:52:07 +00:00
Stefan Berger
1c79bff666 tpm2: Make compileable on FreeBSD
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-29 01:07:13 +00:00
Stefan Berger
764dc43dc3 tpm2: Do padding of bytes for i386 via additional bytes in array
Instead of adding padding bytes to the end of the structure
extend the d array with 3 additional entries that are not going
to be used but provide the padding so that the structure has the
same size on 32 bit and 64 bit machines.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-08 18:17:02 -04:00
Stefan Berger
2aed56cc11 tpm2: Fix printf format for 32 bit machines
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-08 12:10:51 -04:00
Stefan Berger
77b11b7eda build-sys: Include autogen.sh in the tarball and use for RPM building
Include the autogen.sh in the tarball and use it for building
the RPM.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-08 08:59:04 -04:00
Stefan Berger
b899d10c18 build-sys: Only remove generated .3 man files
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-03 13:16:22 -04:00
Stefan Berger
38a7d1951f pkg-config: add cryptolib to libtpms.pc
Add the cryptolib libtpms has been compiled with to libtpms.pc[.in]

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-08-03 13:06:29 -04:00
Marc-André Lureau
bb5d837cf8 build-sys: fix make distcheck
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-08-02 12:53:20 -04:00
Stefan Berger
1d918e5426 Fix regression from 'Recalculate the entrysize in front of ...'
The patch 'Recalculate the entrysize in front of every USER_NVRAM blob'
did not properly account for the TPM_HANDLE when recalculating the
entry size of an OBJECT in NVRAM. As a consequence all OBJECTS and NVRAM
indices following the first OBJECT got lost.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-07-27 17:22:20 -04:00
Stefan Berger
a5a359f4ca tpm2: Determine which PCR banks need to be restored
Determine which PCR banks need to be restored by determining which PCR banks
are active. We only expect data for active PCR banks and the other ones do
not need data.

The tricky part here is that the TPM 2 maintains a variable that indicates
which PCR banks are active in gp.pcrAllocated and another variable in NVRAM
indicating which ones will become active after a reboot. So far we only saved
the one from NVRAM when marshalling the state but now we have to save the one
holding the current active PCR banks also. The restauration of this variable
needs to happen when we resume the VM with volatile state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-07-19 17:19:53 -04:00
Stefan Berger
073849aa46 tpm2: Recalculate the entrysize in front of every USER_NVRAM blob
Since the sizeof(TPM_NV_INDEX) and sizeof(OBJECT) may expand when new hash
algorithms are enabled, the size of each entry in the USER_NVRAM may also
expand. We have to account for this when writing the entry size into the
NVRAM and cannot use the one from the unmarshalled state unless it is 0
or the sizes were the same. So the best is to calculate the entry size and
write it again.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-07-17 20:40:45 -04:00
Stefan Berger
3ed7491323 tpm2: Add function to display USER_NVRAM contents
Add a function for displaying the USER_NVRAM contents for debugging.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-07-17 20:40:45 -04:00
Stefan Berger
dbc07c190c tpm2: disable the failure mode on totalResetCount return to 0
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-07-17 20:40:45 -04:00
Stefan Berger
d99e48eac2 NVMarshal: Fix handling of future header version handling
If we come across a header of a verions we don't know
in this implementation we just have to cause a skip.
2018-07-12 20:51:31 -04:00
Stefan Berger
5ddc17e001 tpm2: Use malloc/free rather than TPM_Malloc/TPM_Free
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-20 15:06:03 -04:00
Stefan Berger
1a24bcc550 build: Add missing header files for building RPM from tar file
2 header files were missing in the tar file and the RPM build failed.
This patch adds them.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00
Stefan Berger
1a7902bb6e tpm2: Implement TPM2B_Cmp() to compare to TPM2B's
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2018-06-15 18:07:49 -04:00