Stefan Berger [Tue, 18 Dec 2018 00:13:04 +0000 (19:13 -0500)]
tests: Add simple test case reading PCRs and writing state file
Add a simple test case to make sure that reading the PCRs
works as expected and that the state file is written
as expected. This state file (NVChip) is only written because
libtpms doesn't have any callbacks registered.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Stefan Berger [Sun, 9 Dec 2018 19:01:22 +0000 (14:01 -0500)]
tpm2: Check returned buffer pointer after call to _rpc__Send_Command()
_rcp__SendCommand() may come back with a different buffer than what was
passed in. This happens when the TPM 2 is in failure more and the TPM 2
code uses an internal buffer. In this case we just copy from that inter-
nal buffer into the buffer that was passed into the function.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Stefan Berger [Sat, 24 Nov 2018 01:52:24 +0000 (20:52 -0500)]
tpm2: ubsan: prevent address calc on member of pointer with NULL address
name maybe NULL and we may calculate the address of &name->b, which
is a member access error following ubsan. Solve this by treating the name
NULL pointer case separately.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Stefan Berger [Sat, 24 Nov 2018 00:51:34 +0000 (19:51 -0500)]
tpm2: ubsan: prevent address calc on member of pointer with NULL address
pAuth maybe NULL and we may calculate the address of &pAuth->b, which
is a member access error following ubsan. Solve this by treating the pAuth
NULL pointer case separately.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Stefan Berger [Sat, 24 Nov 2018 00:21:54 +0000 (19:21 -0500)]
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>
Stefan Berger [Mon, 19 Nov 2018 15:19:13 +0000 (10:19 -0500)]
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>
Stefan Berger [Mon, 19 Nov 2018 14:59:52 +0000 (09:59 -0500)]
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>
Stefan Berger [Thu, 18 Oct 2018 19:22:11 +0000 (15:22 -0400)]
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>
Stefan Berger [Fri, 5 Oct 2018 23:00:50 +0000 (19:00 -0400)]
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>
Stefan Berger [Fri, 5 Oct 2018 21:03:58 +0000 (17:03 -0400)]
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>
Stefan Berger [Wed, 26 Sep 2018 21:55:41 +0000 (17:55 -0400)]
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>
Stefan Berger [Wed, 26 Sep 2018 21:09:55 +0000 (17:09 -0400)]
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>
Stefan Berger [Thu, 27 Sep 2018 00:41:50 +0000 (20:41 -0400)]
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>
Stefan Berger [Mon, 17 Sep 2018 13:07:24 +0000 (09:07 -0400)]
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>
Stefan Berger [Wed, 5 Sep 2018 22:27:53 +0000 (22:27 +0000)]
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>
Stefan Berger [Thu, 30 Aug 2018 21:44:18 +0000 (21:44 +0000)]
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>
Stefan Berger [Wed, 8 Aug 2018 22:16:59 +0000 (18:16 -0400)]
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>
Stefan Berger [Fri, 27 Jul 2018 21:17:18 +0000 (17:17 -0400)]
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>
Stefan Berger [Tue, 17 Jul 2018 02:31:16 +0000 (22:31 -0400)]
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>
Stefan Berger [Tue, 17 Jul 2018 14:32:20 +0000 (10:32 -0400)]
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>