]> git.proxmox.com Git - libtpms.git/log
libtpms.git
6 years agotpm2: Enable compilation on DragonflyBSD
Stefan Berger [Mon, 10 Sep 2018 16:15:26 +0000 (16:15 +0000)]
tpm2: Enable compilation on DragonflyBSD

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild-sys: Make 'make check' work on FreeBSD
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>
6 years agobuild-sys: Fix undefined symbol check on Darwin (OS X)
Stefan Berger [Tue, 4 Sep 2018 12:00:11 +0000 (08:00 -0400)]
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>
6 years agotravis: use 'distcheck' rather than 'check'
Stefan Berger [Sat, 1 Sep 2018 15:14:54 +0000 (11:14 -0400)]
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>
6 years agobuild-sys: work around broken linker when testing --version-script support
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>
6 years agobuild-sys: Remove libtpms_tpm2_la_LDFLAGS
Stefan Berger [Thu, 30 Aug 2018 21:42:26 +0000 (17:42 -0400)]
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>
6 years agotpm2: Make compileable on OS X/Darwin
Stefan Berger [Thu, 30 Aug 2018 18:55:04 +0000 (14:55 -0400)]
tpm2: Make compileable on OS X/Darwin

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild-sys: Check for supported linker flag --version-script
Stefan Berger [Thu, 30 Aug 2018 16:50:06 +0000 (12:50 -0400)]
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>
6 years agotpm2: activate field 'a' as renamed 'a_unused' in PRC_POLICY
Stefan Berger [Thu, 30 Aug 2018 10:31:04 +0000 (06:31 -0400)]
tpm2: activate field 'a' as renamed 'a_unused' in PRC_POLICY

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild-sys: Use X="$X ..." rather than X+="..." in configure.ac
Stefan Berger [Wed, 29 Aug 2018 17:47:19 +0000 (17:47 +0000)]
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>
6 years agoconfigure.ac: Replace tests with '==' through '='
Stefan Berger [Wed, 29 Aug 2018 12:12:34 +0000 (12:12 +0000)]
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>
6 years agotpm2: Make compileable on NetBSD
Stefan Berger [Wed, 29 Aug 2018 11:52:03 +0000 (11:52 +0000)]
tpm2: Make compileable on NetBSD

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Make compileable on FreeBSD
Stefan Berger [Wed, 29 Aug 2018 01:03:28 +0000 (01:03 +0000)]
tpm2: Make compileable on FreeBSD

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Do padding of bytes for i386 via additional bytes in array
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>
6 years agotpm2: Fix printf format for 32 bit machines
Stefan Berger [Wed, 8 Aug 2018 16:10:48 +0000 (12:10 -0400)]
tpm2: Fix printf format for 32 bit machines

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild-sys: Include autogen.sh in the tarball and use for RPM building
Stefan Berger [Wed, 8 Aug 2018 11:08:10 +0000 (07:08 -0400)]
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>
6 years agobuild-sys: Only remove generated .3 man files
Stefan Berger [Fri, 3 Aug 2018 17:14:36 +0000 (13:14 -0400)]
build-sys: Only remove generated .3 man files

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agopkg-config: add cryptolib to libtpms.pc
Stefan Berger [Fri, 3 Aug 2018 17:06:26 +0000 (13:06 -0400)]
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>
6 years agobuild-sys: fix make distcheck
Marc-André Lureau [Thu, 2 Aug 2018 16:15:02 +0000 (18:15 +0200)]
build-sys: fix make distcheck

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
6 years agoFix regression from 'Recalculate the entrysize in front of ...'
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>
6 years agotpm2: Determine which PCR banks need to be restored
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>
6 years agotpm2: Recalculate the entrysize in front of every USER_NVRAM blob
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>
6 years agotpm2: Add function to display USER_NVRAM contents
Stefan Berger [Tue, 17 Jul 2018 13:50:04 +0000 (09:50 -0400)]
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>
6 years agotpm2: disable the failure mode on totalResetCount return to 0
Stefan Berger [Wed, 18 Jul 2018 00:40:11 +0000 (20:40 -0400)]
tpm2: disable the failure mode on totalResetCount return to 0

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoNVMarshal: Fix handling of future header version handling
Stefan Berger [Fri, 13 Jul 2018 00:44:47 +0000 (20:44 -0400)]
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.

6 years agotpm2: Use malloc/free rather than TPM_Malloc/TPM_Free
Stefan Berger [Fri, 15 Jun 2018 19:38:05 +0000 (15:38 -0400)]
tpm2: Use malloc/free rather than TPM_Malloc/TPM_Free

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: Add missing header files for building RPM from tar file
Stefan Berger [Mon, 11 Jun 2018 14:08:12 +0000 (10:08 -0400)]
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>
6 years agotpm2: Implement TPM2B_Cmp() to compare to TPM2B's
Stefan Berger [Wed, 6 Jun 2018 00:35:28 +0000 (20:35 -0400)]
tpm2: Implement TPM2B_Cmp() to compare to TPM2B's

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agolibrary: use __attribute__((format,...) to check printf format and args
Stefan Berger [Tue, 5 Jun 2018 20:25:34 +0000 (16:25 -0400)]
library: use __attribute__((format,...) to check printf format and args

Introduce ATTRIBUTE_FORMAT for gcc and clang and use it to check the format
of the printf type function TPMLIB_LogTPM2Error() and the parameters. Fix
several places with errors.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Add comments to unmarshalling of user NVRAM
Stefan Berger [Tue, 5 Jun 2018 18:00:43 +0000 (14:00 -0400)]
tpm2: Add comments to unmarshalling of user NVRAM

The unmarshalling of the user NVRAM checks whether the NVRAM size allows us
to write the data into it. Since this function is called before writing the
other data into it (PERSISTENT DATA, etc. at lower offsets in the NVRAM),
we can be sure that the NVRAM is large enough to fit everything. Following
this logic, we should be able to loosen the restriction on the NVRAM size and
need not check what size the NVRAM was on the originating side. Since we will
test the unmarshalling of all the data we should be able to detect if the
local NVRAM size is too small and refuse to take the blob based on the failure
to unmarshal completely.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Run a compile-time check whether NVRAM is too small
Stefan Berger [Tue, 5 Jun 2018 18:06:46 +0000 (14:06 -0400)]
tpm2: Run a compile-time check whether NVRAM is too small

Add a compile-time check for whether the NVRAM is too small.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: adapt NVRAM offsets and check structure sizes
Stefan Berger [Sat, 2 Jun 2018 13:54:49 +0000 (09:54 -0400)]
tpm2: adapt NVRAM offsets and check structure sizes

Make sure that the NVRAM offsets and structure sizes are the same
on all architectures so that we can fill up the NVRAM on one system
and migrate the state to another architecture and it will fit into
the NVRAM space there.

We leave some space for the first few data structures in the NVRAM to
grow. We do this by rounding up the NV_INDEX_RAM_DATA location to the
next kb boundary. This moves it from offset 4356 to 5120 on x86_64 and
from offset 4332 to 5120 on i386. This now leaves us with the same
amount of space for user dynamic NVRAM, which starts beyond offset 5120.

We also pad the OBJECT structure with 4 bytes so that it is the same
size on 32 and 64 bit architectures. This is a data structure that
is used in user dynamic NVRAM and should be the same size on all
architectures so that a full NVRAM always fits.

Also test the size of the NV_INDEX structure, which already has the
same size on all tested architectures (x86_64, i386, arm32, ppc64).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotests: add fuzz test
Marc-André Lureau [Fri, 25 May 2018 14:55:21 +0000 (16:55 +0200)]
tests: add fuzz test

See README for details on how to use.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
6 years agotests: add an initial corpus for fuzzing
Marc-André Lureau [Fri, 25 May 2018 14:46:59 +0000 (16:46 +0200)]
tests: add an initial corpus for fuzzing

This is taken directly from chromiumos TPM2 repository:

    commit 172eec5ea9b46ddfe720c854fa719fdf8613b4ed
    Author: nagendra modadugu <ngm@google.com>
    Date:   Fri Sep 16 14:07:13 2016 -0700

        Add an initial fuzz test corpus for execute-command

        This commit introduces a minimized corpus for
        the test in fuzz/execute-command.cc.

        The corpus was generated by parsing the TCG test
        suite log for messages sent to the TPM.  The corpus
        includes test cases that produced crashes reported
        in chrome-os-partner:56767 and chrome-os-partner:56825.

        Future work includes defining a dictionary for the
        protocol so that mutations can be more effective,
        and also generating test-cases that improve coverage
        (e.g. create & store primary key, followed by test case).

        BUG=chrome-os-partner:50646
        BRANCH=none
        TEST=follow instructions in fuzz/README

        Change-Id: I24332c0f58996626de9a08e2780595b0b2d76350
Signed-off-by: nagendra modadugu <ngm@google.com>
        Reviewed-on: https://chromium-review.googlesource.com/386443
        Commit-Ready: Nagendra Modadugu <ngm@google.com>
Tested-by: Nagendra Modadugu <ngm@google.com>
Reviewed-by: Kostya Serebryany <kcc@chromium.org>
Reviewed-by: Mike Aizitsky <aizatsky@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
6 years agobuild-sys: remove -Wstrict-aliasing=3
Marc-André Lureau [Fri, 25 May 2018 12:06:20 +0000 (14:06 +0200)]
build-sys: remove -Wstrict-aliasing=3

The option doesn't exist with clang, and is default with gcc -Wall
already.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
6 years agobuild-sys: move hardening linker flags to ldflags
Marc-André Lureau [Fri, 25 May 2018 11:06:08 +0000 (13:06 +0200)]
build-sys: move hardening linker flags to ldflags

Fixes unusued flags warnings with clang.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
6 years agotpm2: enable sha512 (breaks compatiblity)
Stefan Berger [Tue, 22 May 2018 13:11:45 +0000 (09:11 -0400)]
tpm2: enable sha512 (breaks compatiblity)

Enable SHA512. Since the TPM 2 expects to see PCR values for
the SHA512 bank in some of its structures, this breaks
compatibility with existing state files.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: convert rest of structures to write downgradeable state
Stefan Berger [Wed, 16 May 2018 18:32:37 +0000 (14:32 -0400)]
tpm2: convert rest of structures to write downgradeable state

Also write those structure related to PERSISTENT_ALL to have
a header with version 2 and a tail that allows the state to be
extended and downgraded.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: tie volatile state of TPM to persistent state
Stefan Berger [Wed, 16 May 2018 17:22:44 +0000 (13:22 -0400)]
tpm2: tie volatile state of TPM to persistent state

Write the persistent state's EP,SP, and PPSeed values into the
volatile state and check them when reading. This way we can
prevent that arbitrary volatile and persistent state blobs are
used.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoExtend NVRAM memory size to 128kb
Stefan Berger [Wed, 16 May 2018 15:37:00 +0000 (11:37 -0400)]
Extend NVRAM memory size to 128kb

Increase the NVRAM memory size to 128kb. That should be it for good.

We accept smaller NVRAM sizes from stored state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoWrite different header for SHA384 and SHA512 in shared function
Stefan Berger [Wed, 16 May 2018 15:04:02 +0000 (11:04 -0400)]
Write different header for SHA384 and SHA512 in shared function

SHA512 is currently not enabled since until a short while ago the test
data was missing. So before we enable it, we should differentiate between
writing adn reading of SHA384 and SHA512 data by using a different magic
in the header. We assign the existing value of the magic for the SHA384
that we currently use and assign SHA512 a new value.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoIncrease MIN_EVICT_OBJECTS to 7 for value of TPM_PT_HR_PERSISTENT_MIN
Stefan Berger [Wed, 16 May 2018 13:13:41 +0000 (09:13 -0400)]
Increase MIN_EVICT_OBJECTS to 7 for value of TPM_PT_HR_PERSISTENT_MIN

Adapt the MIN_EVICT_OBJETCS #define value to 7 so that it meeds to
TPM Profile (PTP) Specification and TPM_PT_HR_PERSISTENT_MIN returns
the proper value.

We allow to read the state from a TPM that had a lesser value before.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoUpdate TpmToOsslMath.c to look similar to latest code
Stefan Berger [Tue, 15 May 2018 20:00:58 +0000 (16:00 -0400)]
Update TpmToOsslMath.c to look similar to latest code

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoUpdate to latest version: CryptHash.c
Stefan Berger [Tue, 15 May 2018 19:45:02 +0000 (15:45 -0400)]
Update to latest version: CryptHash.c

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoUpdate to latest version: Ecc/Hash/RsaTestData.h
Stefan Berger [Tue, 15 May 2018 19:27:11 +0000 (15:27 -0400)]
Update to latest version: Ecc/Hash/RsaTestData.h

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoUpdate to latest version: MAC_fp.h
Stefan Berger [Tue, 15 May 2018 19:19:04 +0000 (15:19 -0400)]
Update to latest version: MAC_fp.h

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoUpdate to latest version: MathOnByteBuffers.c
Stefan Berger [Tue, 15 May 2018 19:17:33 +0000 (15:17 -0400)]
Update to latest version: MathOnByteBuffers.c

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agoUpdate to latest version: TpmToOsslMath.h
Stefan Berger [Tue, 15 May 2018 19:42:11 +0000 (15:42 -0400)]
Update to latest version: TpmToOsslMath.h

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: TPM_MainInit write permanent state blob if SetState() blob was used
Stefan Berger [Sun, 18 Mar 2018 23:23:59 +0000 (19:23 -0400)]
tpm2: TPM_MainInit write permanent state blob if SetState() blob was used

If the permanent state was set using SetState() write the permanent
state once we successfully read the volatile state and can use it.
This way we have the state in a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: pass state set via SetState() to TPM 2
Stefan Berger [Thu, 15 Mar 2018 22:48:14 +0000 (18:48 -0400)]
tpm2: pass state set via SetState() to TPM 2

If state was set using SetState() then the cached blob needs
to be passed to the TPM 2 before trying to read the state from
a file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: implement TPM2_Get/SetState
Stefan Berger [Wed, 14 Mar 2018 19:08:41 +0000 (15:08 -0400)]
tpm2: implement TPM2_Get/SetState

Implement the Get/SetState functions for TPM 2 so we can
also pass a blob in the TPM 2 case.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Clear the cached states when a different TPM version is chosen
Stefan Berger [Mon, 14 May 2018 11:07:14 +0000 (07:07 -0400)]
tpm2: Clear the cached states when a different TPM version is chosen

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Implement _rpc__Signal_IsPowerOn
Stefan Berger [Wed, 14 Mar 2018 00:56:55 +0000 (20:56 -0400)]
tpm2: Implement _rpc__Signal_IsPowerOn

Implement _rcp__Signal_IsPowerOn() so we can detect whether the
TPM 2 is running.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: return TPM_RC_FAILURE in case of blockSize == 0
Stefan Berger [Thu, 29 Mar 2018 02:02:46 +0000 (22:02 -0400)]
tpm2: return TPM_RC_FAILURE in case of blockSize == 0

Coverity is complaining about the case of blockSize == 0. Later on in
CryptSymmetricDecrypt() this case is intercepted as well and
TPM_RC_FAILURE is returned. We just do this a little earlier.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Do NULL pointer check before dereferencing
Stefan Berger [Thu, 29 Mar 2018 01:40:39 +0000 (21:40 -0400)]
tpm2: Do NULL pointer check before dereferencing

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Do NULL pointer check before dereferencing
Stefan Berger [Thu, 29 Mar 2018 01:39:20 +0000 (21:39 -0400)]
tpm2: Do NULL pointer check before dereferencing

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Do NULL pointer check before dereferencing
Stefan Berger [Thu, 29 Mar 2018 01:37:34 +0000 (21:37 -0400)]
tpm2: Do NULL pointer check before dereferencing

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: initialize a couple of variable to make coverity happy
Stefan Berger [Tue, 27 Mar 2018 22:09:52 +0000 (18:09 -0400)]
tpm2: initialize a couple of variable to make coverity happy

Coverity complains that a couple of variables read from the
stream may not be initialized. It shouldn't be possible to
have them not initialized since we would otherwise have an
error value in rc. Nevertheless, initialize them.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Check against unreasonably large datasize value from stream
Stefan Berger [Tue, 27 Mar 2018 22:07:46 +0000 (18:07 -0400)]
tpm2: Check against unreasonably large datasize value from stream

Check the read datasize against an unreasonably large value and
log in case we encounter a bad value. This particular value cannot
be larger than 64k and a few bytes.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Get return value into rc
Stefan Berger [Tue, 27 Mar 2018 22:04:34 +0000 (18:04 -0400)]
tpm2: Get return value into rc

In one case we missed to assign the return value for rc.
In another case check rc value before doing operation.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Cast values to proper datatypes
Stefan Berger [Tue, 27 Mar 2018 22:03:17 +0000 (18:03 -0400)]
tpm2: Cast values to proper datatypes

The unsigned int needs to be checked as an int against >= 0.
The bit to move needs to be a 1ULL type.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Fix calculation of array_size
Stefan Berger [Tue, 27 Mar 2018 22:25:08 +0000 (18:25 -0400)]
tpm2: Fix calculation of array_size

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Make loop counter a size_t
Stefan Berger [Tue, 27 Mar 2018 20:48:13 +0000 (16:48 -0400)]
tpm2: Make loop counter a size_t

Some versions of gcc complain about the loop counter being
a signed int when compared against a sizeof() results. This
patch fixes this.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Enable a few more algorithms
Stefan Berger [Sun, 25 Mar 2018 15:57:41 +0000 (11:57 -0400)]
tpm2: Enable a few more algorithms

Enable a few more algorithm for the TPM2. We have to adapt NVMarshal.c
to allow the enablement of these algorithms without rejecting existing
state. We do this through the 'LE' comparison operator that allows us
to read state from an implementation that didn't have it enabled while
we now have it enabled.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Enable support for SM2
Stefan Berger [Sun, 25 Mar 2018 15:55:33 +0000 (11:55 -0400)]
tpm2: Enable support for SM2

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Enable support for ECMQV
Stefan Berger [Sun, 25 Mar 2018 15:41:19 +0000 (11:41 -0400)]
tpm2: Enable support for ECMQV

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Write comments about comparison operators
Stefan Berger [Sun, 25 Mar 2018 14:39:17 +0000 (10:39 -0400)]
tpm2: Write comments about comparison operators

Write comments about the comparison operators used for comparing
compile time options/switches of the state that's being read from
another implementation versus the ones used in the current
implementation.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agomerge into Allow state downgrading
Stefan Berger [Wed, 16 May 2018 18:08:12 +0000 (14:08 -0400)]
merge into Allow state downgrading

6 years agotpm2: Allow state downgrading starting with version 2 headers
Stefan Berger [Sun, 25 Mar 2018 00:26:58 +0000 (20:26 -0400)]
tpm2: Allow state downgrading starting with version 2 headers

Write version 2 headers for all versioned structures and append
a trailer that can hold future version data and that can be
skipped. The skipping allows us to downgrade state, meaning if
version 3 appended some data but we read it with version 2,
we don't need the version 3 data but can skip it. We loose data
this way, but can keep the TPM 2 running.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Prepare header for v2 including min. necessary version to parse
Stefan Berger [Sat, 24 Mar 2018 21:33:59 +0000 (17:33 -0400)]
tpm2: Prepare header for v2 including min. necessary version to parse

Prepare the header we are using for writing out the state blobs
for version 2 where we will including the minimum version necessary
to read a particular structure.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Throw error on missing data for hash algorithms
Stefan Berger [Sun, 25 Mar 2018 00:56:36 +0000 (20:56 -0400)]
tpm2: Throw error on missing data for hash algorithms

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: cast to long int for match to %ld on 32bit platform
Stefan Berger [Fri, 16 Mar 2018 10:53:12 +0000 (06:53 -0400)]
tpm2: cast to long int for match to %ld on 32bit platform

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Implement TPM2_PersistentAllStore and use it
Stefan Berger [Wed, 14 Mar 2018 18:41:14 +0000 (14:41 -0400)]
tpm2: Implement TPM2_PersistentAllStore and use it

Implement TPM2_PersistentAllStore that allocates a buffer big
enough to store all the persistent state and returns that buffer
along with the number of valid bytes.

In this patch we move code from _plat__NvCommit() into this new
function and call this new function now.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Call _rpc__Signal_PowerOff inside TPM2_Terminate
Stefan Berger [Wed, 14 Mar 2018 18:45:13 +0000 (14:45 -0400)]
tpm2: Call _rpc__Signal_PowerOff inside TPM2_Terminate

This way we can later on detect whether the TPM 2 is running
(= powered on).

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: add missing newline after error message
Stefan Berger [Sun, 25 Feb 2018 20:02:34 +0000 (15:02 -0500)]
tpm2: add missing newline after error message

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Build libtpms with TPM 2 code now
Stefan Berger [Mon, 24 Jul 2017 18:08:25 +0000 (14:08 -0400)]
tpm2: Build libtpms with TPM 2 code now

Now that patches for writing the state into files and extensions
to their headers have all been applied we can build the TPM 2
code into the library.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Write marshalled NvChip into file and read it
Stefan Berger [Fri, 23 Feb 2018 22:32:37 +0000 (17:32 -0500)]
tpm2: Write marshalled NvChip into file and read it

When storing, marshalled the NvChip memory's contents and write the byte
stream into the file rather than the NvChip directly. When reading, assume
we get a marshalled NvChip file and we now need to unmarshal the byte
stream and reconstruct the NvChip.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Add test harness for marshalling and reconstructing NVChip
Stefan Berger [Thu, 22 Feb 2018 19:02:25 +0000 (14:02 -0500)]
tpm2: Add test harness for marshalling and reconstructing NVChip

6 years agotpm2: Enable skipping of compile-time optional variables when unmarshalling
Stefan Berger [Sat, 24 Feb 2018 20:01:58 +0000 (15:01 -0500)]
tpm2: Enable skipping of compile-time optional variables when unmarshalling

Some variables are compile-time optional and can be skipped if they are
contained in the byte stream but the implementation does not need them.
We enable this with a few simple macros that we use to replace those parts
where the has_block variables are written into the byte stream. On the
unmarshalling side we check whether the block is in the byte stream and
whether the implementation needs the block and react appropriately
including skipping over the block in the byte stream or skipping over the
code unmarshalling the data.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Remove first parameter from NV_HEADER_Marshal
Stefan Berger [Fri, 23 Feb 2018 23:53:58 +0000 (18:53 -0500)]
tpm2: Remove first parameter from NV_HEADER_Marshal

Remove the NV_HEADER parameter from NV_Header_Marshal() function.
In the single case where it was needed, initialize a UINT32 with
the 'magic'.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Revert NVChip memory layout to native
Stefan Berger [Fri, 23 Feb 2018 18:49:17 +0000 (13:49 -0500)]
tpm2: Revert NVChip memory layout to native

Get rid of all the changes to have the NvChip written in big
endian format. Remove test case.

Now the NvChip in memory holds data in native format.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Implement function to marshal and reconstruct the NvChip
Stefan Berger [Thu, 22 Feb 2018 18:50:46 +0000 (13:50 -0500)]
tpm2: Implement function to marshal and reconstruct the NvChip

Marshal the NvChip memory into a byte stream and reconstruct the
NvChip memory from the byte stream.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Push nvOffset and structure size parameters into functions
Stefan Berger [Tue, 20 Feb 2018 19:28:55 +0000 (14:28 -0500)]
tpm2: Push nvOffset and structure size parameters into functions

Push the nvOffset parameter where either one of the 4 state blobs
found in the NVRAM file can be found. Also push the size parameter
into the functions.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Major rework of state marshalling breaking compatibility
Stefan Berger [Mon, 19 Feb 2018 22:09:03 +0000 (17:09 -0500)]
tpm2: Major rework of state marshalling breaking compatibility

In one big step, marshal more variables and constants for volatilestate:

- compile-time constants related to data structures marshalled as part
  of the volatile state as well as some other ones

- variables related to time that fix problems with dictionary attack
  related timeouts

- 3 failure related variables

Also introduce magic and version headers when marshalling all the
internal data structures.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Add missing offset checks and comments about gaps to test case
Stefan Berger [Tue, 20 Feb 2018 16:00:04 +0000 (11:00 -0500)]
tpm2: Add missing offset checks and comments about gaps to test case

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Make tpmclock() a public function
Stefan Berger [Mon, 19 Feb 2018 22:07:32 +0000 (17:07 -0500)]
tpm2: Make tpmclock() a public function

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Update comments on variables stored in volatile state
Stefan Berger [Mon, 19 Feb 2018 21:07:07 +0000 (16:07 -0500)]
tpm2: Update comments on variables stored in volatile state

Update the comments on some of the variables we are storing
as part of storing volatile state.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Fix memory leak in VolatileLoad()
Stefan Berger [Sun, 18 Feb 2018 02:21:38 +0000 (21:21 -0500)]
tpm2: Fix memory leak in VolatileLoad()

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Implement TPM2_ValidateState
Stefan Berger [Sat, 17 Feb 2018 20:24:42 +0000 (15:24 -0500)]
tpm2: Implement TPM2_ValidateState

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Have VolatileLoad() return TPM_RC
Stefan Berger [Sat, 17 Feb 2018 16:36:32 +0000 (11:36 -0500)]
tpm2: Have VolatileLoad() return TPM_RC

Have VolatileLoad return a TPM_RC so the caller can see
whether the loading of the volatiles state succeeded.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Activate failure mode if any blobs could not be handled
Stefan Berger [Sat, 17 Feb 2018 03:17:33 +0000 (22:17 -0500)]
tpm2: Activate failure mode if any blobs could not be handled

When any of the NVRAM blobs could not be handled properly we put
the TPM into failure mode. This should only happen if someone
corrupts the state or if the state blobs are more recent than
what the TPM supports.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: extract header init and check from SWAP functions
Stefan Berger [Sat, 17 Feb 2018 02:19:11 +0000 (21:19 -0500)]
tpm2: extract header init and check from SWAP functions

Extract the initialization of the header fom the SWAP functions
and initialize the header by the appropriat callers of the SWAP
functions.

Version and magic can be 0 when first read after NVRAM was
initialized. So we initialize it then.

Add skeleton code where the upgrade of the data structure would
have to happen later on.

Refuse to accept newer versions of structures than what is supported
at the moment. In particular, return error codes in case the blobs
that were read are not supported.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Enforce version of volatile state blob
Stefan Berger [Fri, 9 Feb 2018 18:11:29 +0000 (13:11 -0500)]
tpm2: Enforce version of volatile state blob

Enforce the version of the volatile state blob. Do not accept a more
recent version than what we support at this point, so downgrading of
state is prevented this way.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Fix compiler error due to comparison with different signedness
Stefan Berger [Tue, 19 Dec 2017 12:12:39 +0000 (07:12 -0500)]
tpm2: Fix compiler error due to comparison with different signedness

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: Build Debian 0.6.0-1-dev1
Stefan Berger [Mon, 13 Nov 2017 18:09:31 +0000 (13:09 -0500)]
build: Build Debian 0.6.0-1-dev1

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agobuild: Build RPM 0.6.0-1_dev1
Stefan Berger [Mon, 13 Nov 2017 17:58:31 +0000 (12:58 -0500)]
build: Build RPM 0.6.0-1_dev1

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: NVRAM file does exist if we get TPM_DECRYPT_ERROR
Stefan Berger [Tue, 14 Nov 2017 00:28:12 +0000 (19:28 -0500)]
tpm2: NVRAM file does exist if we get TPM_DECRYPT_ERROR

In case the NVRAM file cannot be decrypted we get a TPM_DECRYPT_ERROR
error which also indicates that the file exists. So do not return FALSE
in this case, which would delete the existing file and start over with
a blank file.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: add missing header filenames
Stefan Berger [Mon, 13 Nov 2017 17:24:47 +0000 (12:24 -0500)]
tpm2: add missing header filenames

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: Handle failures better
Stefan Berger [Sat, 11 Nov 2017 04:02:28 +0000 (23:02 -0500)]
tpm2: Handle failures better

The current TpmFail() implementation invokes longjmp() at the end
and crashes with a segmentation fault if setjmp() wasn't called before.
To avoid this we implement TpmSetFailureMode() that logs the failure and
sets the TPM into failure mode. Since NVRAM may set failure mode before
the CryptInit() is called, we need to make sure we don't reset the failure
mode variable in case CryptInit() succeeds. In this case we now call the
FAIL_NOCMD() macro.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
6 years agotpm2: make I/O buffer sizes adjustable
Stefan Berger [Sun, 5 Nov 2017 16:28:19 +0000 (11:28 -0500)]
tpm2: make I/O buffer sizes adjustable

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