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>
Wrap the fuzzer test in a script to we can set up a per fuzzer
temporary directory where the NvChip file is written into.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
_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>
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>
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>
TPM_HT_TRANSIENT has value 0x80. We have to case it to UINT32 before
shifting it by 24 bits to make ubsan quiet,
TPM_HR_PERSISTENT has value 0x81 and needs the same cast.
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>