vtpm: TPM groups and deep quotes
v3 cover vtpm: TPM groups and deep quotes
This is an updated vTPM Manager domain which adds support for using the physical TPM to protect vTPM secrets according to its PCR values, and to allow virtual machines (including dom0) to attest to both the platform's state and to their own state.
Changes since v2:
- Clean up example tool dispatch functions
- Add two patches to check XSM labels on peers, allowing communication with the vTPM to be secure without needing to trust Xenstore and any control domain with privileged access to Xenstore.
Changes since v1:
- Move documentation for the vTPM and vTPM Manager to docs/
- Add patches from Jason Andryuk fixing support for Infineon TPMs
- Add example control tool scripts
[PATCH 1/9] vtpmmgr: add TPM group support
[PATCH 2/9] vtpmmgr: add example control tools [PATCH 3/9] vtpmmgr: Store hardware TPM Locality [PATCH 4/9] vtpmmgr: Convert TPM_Seal to use TPM_PCR_INFO_LONG [PATCH 5/9] vtpm: passthru requests to manager [PATCH 6/9] vtpm: add ordinal for obtaining an EK signature [PATCH 7/9] vtpm: add deep quote support
[PATCH 8/9] stubdom/grub: verify vTPM label if requested [PATCH 9/9] vtpmmgr: use XSM label as vTPM kernel hash
PATCH v3 1/9 vtpmmgr: add TPM group support
This is a complete rewrite of the disk format and key hierarchy for the TPM Manager. The new format supports multiple groups of vTPMs which define the permitted configurations where a given vTPM's keys are available, allowing upgrades of critical components while retaining the secrecy of cryptographic keys.
New features of the TPM Manager are explained in the README and in the definitions of the management commands in vtpm_manager.h.
New features for vTPMs:
1. The size of the state blob for a vTPM is expanded from 52 to 64 bytes in order to support future vTPMs using SHA-2/3 instead of SHA-1.
2. vTPMs can obtain a quote from the physical TPM with certain resettable PCRs set to include information about the vTPM. This can be used by a vTPM to provide evidence of its integrity, including the secrecy of its EK, and for deep quotes.
Some additional changes made by this rewrite that may impact existing users:
1. The value of WELLKNOWN_OWNER_AUTH was incorrect for the physical TPM; the convention is to use all zero bits for well-known authentication values, not all one bits.
2. Randomly generating the owner auth value for the physical TPM is no longer supported, as it prevents later creation or certification of AIKs (which the old manager did not support).
3. The vTPM Manager needs to be provisioned with a PCR composite and an upgrade authority's public key before it will save data across boots.
The current implementation still has some limitations:
* 5 valid system PCR selections per group
* The vTPM Manager's disk can use at most 2MB of space
* The vTPM domain's build hash is always set to null/zero
Most of the code relating to upgrade and rollback protection is currently stubbed out, but future versions can add:
* Support for using the TPM's monotonic counter to prevent rollback of vTPM data by taking and restoring disk snapshots
* Masking the master disk encryption key using a value stored in the TPM's NVRAM so that revocation of old data is possible without relying on all previously authorized software stacks to respect the monotonic counter's value
--- docs/misc/vtpm-platforms.txt | 127 ++++ docs/misc/vtpm.txt | 247 ++++--- docs/misc/vtpmmgr.txt | 163 +++++ stubdom/vtpm/README | 75 -- stubdom/vtpmmgr/Makefile | 4 +- stubdom/vtpmmgr/README | 75 -- stubdom/vtpmmgr/disk_crypto.c | 231 ++++++ stubdom/vtpmmgr/disk_crypto.h | 17 + stubdom/vtpmmgr/disk_format.h | 193 +++++ stubdom/vtpmmgr/disk_io.c | 125 ++++ stubdom/vtpmmgr/disk_io.h | 25 + stubdom/vtpmmgr/disk_read.c | 606 ++++++++++++++++ stubdom/vtpmmgr/disk_tpm.c | 238 +++++++ stubdom/vtpmmgr/disk_tpm.h | 25 + stubdom/vtpmmgr/disk_write.c | 410 +++++++++++ stubdom/vtpmmgr/endian_int.h | 72 ++ stubdom/vtpmmgr/init.c | 104 +-- stubdom/vtpmmgr/log.h | 8 +- stubdom/vtpmmgr/marshal.h | 824 ++++++++++++++-------- stubdom/vtpmmgr/mgmt_authority.c | 323 +++++++++ stubdom/vtpmmgr/mgmt_authority.h | 11 + stubdom/vtpmmgr/tcg.h | 7 + stubdom/vtpmmgr/tpm.c | 1360 ++++++++++++++++++------------------ stubdom/vtpmmgr/tpm.h | 104 +-- stubdom/vtpmmgr/tpmrsa.c | 25 + stubdom/vtpmmgr/tpmrsa.h | 3 + stubdom/vtpmmgr/vtpm_cmd_handler.c | 858 ++++++++++++++++++++--- stubdom/vtpmmgr/vtpm_disk.c | 237 +++++++ stubdom/vtpmmgr/vtpm_disk.h | 233 ++++++ stubdom/vtpmmgr/vtpm_manager.h | 391 ++++++++++- stubdom/vtpmmgr/vtpm_storage.c | 794 --------------------- stubdom/vtpmmgr/vtpm_storage.h | 68 -- stubdom/vtpmmgr/vtpmmgr.h | 12 +- 33 files changed, 5639 insertions(+), 2356 deletions(-) create mode 100644 docs/misc/vtpm-platforms.txt create mode 100644 docs/misc/vtpmmgr.txt delete mode 100644 stubdom/vtpm/README delete mode 100644 stubdom/vtpmmgr/README create mode 100644 stubdom/vtpmmgr/disk_crypto.c create mode 100644 stubdom/vtpmmgr/disk_crypto.h create mode 100644 stubdom/vtpmmgr/disk_format.h create mode 100644 stubdom/vtpmmgr/disk_io.c create mode 100644 stubdom/vtpmmgr/disk_io.h create mode 100644 stubdom/vtpmmgr/disk_read.c create mode 100644 stubdom/vtpmmgr/disk_tpm.c create mode 100644 stubdom/vtpmmgr/disk_tpm.h create mode 100644 stubdom/vtpmmgr/disk_write.c create mode 100644 stubdom/vtpmmgr/endian_int.h create mode 100644 stubdom/vtpmmgr/mgmt_authority.c create mode 100644 stubdom/vtpmmgr/mgmt_authority.h create mode 100644 stubdom/vtpmmgr/vtpm_disk.c create mode 100644 stubdom/vtpmmgr/vtpm_disk.h delete mode 100644 stubdom/vtpmmgr/vtpm_storage.c delete mode 100644 stubdom/vtpmmgr/vtpm_storage.h
docs/misc/vtpm-platforms.txt new file +127 -0
@@ -0,0 +1,127 @@ +Author: Daniel De Graaf <[email protected]> + +================================================================================ +Overview +================================================================================ + +This document describes example platforms which use virtual TPMs to provide +security properties for guests running on the platforms. There are several +tradeoffs between flexibility and trust which must be considered when +implementing a platform containing vTPMs. + +================================================================================ +Example 1: Trusted Domain 0 +================================================================================ + +This is the simplest example and provides maximal flexibility for testing the +vTPM Manager and vTPMs. The vtpmmgr, vtpm, and guest domains are created using +xl from the command line on domain 0. + +Provisioning on domain 0: +# dd if=/dev/zero of=/images/vtpmmgr-stubdom.img bs=2M count=1 +# dd if=/dev/zero of=/images/vtpm-guest1.img bs=2M count=1 +# dd if=/dev/zero of=/images/vtpm-guest2.img bs=2M count=1 + +The vtpmmgr configuration file (vtpmmgr.cfg): + +name="vtpmmgr" +kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz" +extra="tpmlocality=2" +memory=8 +disk=["file:/images/vtpmmgr-stubdom.img,hda,w"] +iomem=["fed42,1"] + +The vtpm configuration files (vtpm-guest1.cfg, vtpm-guest2.cfg): + +name="vtpm-guest1" +kernel="/usr/lib/xen/boot/vtpm-stubdom.gz" +extra="loglevel=debug" +memory=8 +disk=["file:/images/vtpm-guest1.img,hda,w"] +vtpm=["backend=vtpmmgr,uuid=ac0a5b9e-cbe2-4c07-b43b-1d69e46fb839"] + +name="vtpm-guest2" +kernel="/usr/lib/xen/boot/vtpm-stubdom.gz" +extra="loglevel=debug" +memory=8 +disk=["file:/images/vtpm-guest2.img,hda,w"] +vtpm=["backend=vtpmmgr,uuid=6c3ff5f1-8d58-4fed-b00d-a5ea9a817f7f"] + +The guest configuration files (guest1.cfg, guest2.cfg): + +name="guest1" +kernel="/usr/lib/xen/boot/pv-grub-x86_64.gz" +memory=1024 +disk=["file:/images/guest1.img,xvda,w"] +vif=['mac=00:01:02:03:04:05,bridge=br0'] +vtpm=["backend=vtpm-guest1"] + +name="guest2" +kernel="/usr/lib/xen/boot/pv-grub-x86_64.gz" +memory=1024 +disk=["file:/images/guest2.img,xvda,w"] +vif=['mac=00:01:02:03:04:06,bridge=br0'] +vtpm=["backend=vtpm-guest2"] + +Starting domains: + +# xl create vtpmmgr.cfg +# xl create vtpm-guest1.cfg +# xl create guest1.cfg + +================================================================================ +Example 2: Domain Builder with Static vTPMs +================================================================================ + +This example uses the domain builder to construct a TPM Manager and vTPM which +do not require trusting the hardware domain with the vTPM's secrets. However, +it is not possible to construct additional vTPMs after the system is booted, and +the guests with access to vTPMs may not be rebooted without rebooting the entire +platform. + +The domain builder (dom0) constructs: + dom1 - xenstore system_u:system_r:xenstore_t + dom2 - hardware system_u:system_r:hwdom_t + dom3 - vtpmmgr system_u:system_r:vtpmmgr_t + dom4 - vtpm-hw system_u:system_r:vtpm_t + dom5 - vtpm-g1 guest1_u:vm_r:vtpm_t + dom6 - vtpm-g2 guest2_u:vm_r:vtpm_t + dom7 - guest1 guest1_u:vm_r:guest_t + dom8 - guest2 guest2_u:vm_r:guest_t + +It unpauses dom1 and dom2 after setting up Xenstore. The hardware domain is not +permitted access to IO memory at 0xfed42; this IO memory is accessible to the +vtpmmgr domain. The two guest domains may be instantiated using pv-grub or +using the same kernel as the hardware domain to conserve space in the domain +builder's initrd. + +Once the hardware domain boots, it runs: + +# xl block-attach vtpmmgr 'backendtype=phy,backend=hardware,vdev=hda,access=w,target=/dev/lvm/vtpmmgr' +# xl block-attach vtpm-hw 'backendtype=phy,backend=hardware,vdev=hda,access=w,target=/dev/lvm/vtpm-hw' +# xl block-attach vtpm-g1 'backendtype=phy,backend=hardware,vdev=hda,access=w,target=/dev/lvm/vtpm-g1' +# xl block-attach vtpm-g2 'backendtype=phy,backend=hardware,vdev=hda,access=w,target=/dev/lvm/vtpm-g2' +# xl block-attach guest1 'backendtype=phy,backend=hardware,vdev=xvda,access=w,target=/dev/lvm/guest1' +# xl block-attach guest2 'backendtype=phy,backend=hardware,vdev=xvda,access=w,target=/dev/lvm/guest2' +# xl vtpm-attach vtpm-hw uuid=062b6416-ed46-492a-9e65-a2f92dc07f7f backend=vtpmmgr +# xl vtpm-attach vtpm-g1 uuid=e9aa9d0f-ece5-4b84-b129-93004ba61a5f backend=vtpmmgr +# xl vtpm-attach vtpm-g2 uuid=3fb2caf0-d305-4516-96c7-420618d98efb backend=vtpmmgr +# xl vtpm-attach hardware uuid=062b6416-ed46-492a-9e65-a2f92dc07f7f backend=vtpm-hw +# xl vtpm-attach guest1 uuid=e9aa9d0f-ece5-4b84-b129-93004ba61a5f backend=vtpm-g1 +# xl vtpm-attach guest2 uuid=3fb2caf0-d305-4516-96c7-420618d98efb backend=vtpm-g2 + +Once these commands are complete, the domains are unpaused and may boot. The XSM +policy must be configured to not allow any of the domain types named above to be +created by any domain except the domain builder; guests created by the hardware +domain or one of the primary guests acting as a control domain must have a +different type. The type vtpmmgr_t may only map grants from vtpm_t; vtpm_t may +only map grants from a domain of type guest_t or hwdom_t with the same user +field. + +This example may be extended to allow dynamic creation of domains by using a +domain builder that accepts build requests. A single build request would create +a pair of domains using an unused XSM user field: a vTPM and a pv-grub domain +which requires the presence of a vTPM. To bind the configuration of the guest +to the vTPM, the guest may use full-disk encryption which can be unlocked using +an unseal operation; using the wrong vTPM will then yield a non-functioning +guest.
docs/misc/vtpm.txt +137 -110
329 lines not on this page · raw message
docs/misc/vtpmmgr.txt new file +163 -0
163 lines not on this page · raw message
stubdom/vtpm/README deleted +0 -75
75 lines not on this page · raw message
stubdom/vtpmmgr/Makefile +3 -1
@@ -12,7 +12,9 @@ XEN_ROOT=../.. TARGET=vtpmmgr.a -OBJS=vtpmmgr.o vtpm_cmd_handler.o vtpm_storage.o init.o tpmrsa.o tpm.o log.o +OBJS=vtpmmgr.o vtpm_cmd_handler.o init.o tpmrsa.o tpm.o log.o +OBJS += vtpm_disk.o disk_tpm.o disk_io.o disk_crypto.o disk_read.o disk_write.o +OBJS += mgmt_authority.o CFLAGS+=-Werror -Iutil -Icrypto -Itcs CFLAGS+=-Wno-declaration-after-statement -Wno-unused-label
stubdom/vtpmmgr/README deleted +0 -75
75 lines not on this page · raw message
stubdom/vtpmmgr/disk_crypto.c new file +231 -0
231 lines not on this page · raw message
stubdom/vtpmmgr/disk_crypto.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __VTPMMGR_DISK_CRYPTO_H +#define __VTPMMGR_DISK_CRYPTO_H + +void do_random (void *buf,size_t size); +void aes_encrypt_one (void *target,const void *src,const struct key128 *key); +void aes_decrypt_one (void *target,const void *src,const struct key128 *key); + +void aes_setup (aes_context *ctx,const struct key128 *key); +void aes_encrypt_ctr (void *target,size_t target_size,const void *srcv,size_t src_size,const aes_context *key_e); +void aes_decrypt_ctr (void *target,size_t target_size,const void *srcv,size_t src_size,const aes_context *key_e); +void aes_cmac (struct mac128 *target,const void *src,size_t size,const aes_context *key); +int aes_cmac_verify (const struct mac128 *target,const void *src,size_t size,const aes_context *key); + +void sha256 (struct hash256 *target,const void *src,size_t size); +int sha256_verify (const struct hash256 *targ,const void *data,size_t size); + +#endif
stubdom/vtpmmgr/disk_format.h new file +193 -0
193 lines not on this page · raw message
stubdom/vtpmmgr/disk_io.c new file +125 -0
125 lines not on this page · raw message
stubdom/vtpmmgr/disk_io.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef __VTPMMGR_DISK_IO_H +#define __VTPMMGR_DISK_IO_H + +void *disk_read_sector (sector_t sector); +void disk_write_sector (sector_t sector,void * buf,size_t siz); +void *disk_write_buf (void ); +void disk_write_barrier (void ); + +sector_t disk_find_free (const struct mem_tpm_mgr *mgr); +void disk_flush_slot (const struct mem_tpm_mgr *mgr); +void disk_set_used (sector_t loc,const struct mem_tpm_mgr *mgr); + +void disk_write_all (struct mem_tpm_mgr *mgr); + +static inline sector_t seal_loc (struct mem_tpm_mgr *mgr) +{ +return native_be32 (mgr->active_root); +} + +static inline sector_t root_loc (struct mem_tpm_mgr *mgr) +{ +return native_be32 (2 + mgr->active_root); +} + +#endif
stubdom/vtpmmgr/disk_read.c new file +606 -0
606 lines not on this page · raw message
stubdom/vtpmmgr/disk_tpm.c new file +238 -0
238 lines not on this page · raw message
stubdom/vtpmmgr/disk_tpm.h new file +25 -0
@@ -0,0 +1,25 @@ +#ifndef __VTPMMGR_DISK_VTPM_H +#define __VTPMMGR_DISK_VTPM_H +#include "vtpm_disk.h" + +/* Read PCR values to determine which unseal to try */ +void TPM_read_pcrs (void ); +void TPM_pcr_digest (struct hash160 *buf,le32_t selection); + +/* Sealing for key storage */ +int TPM_disk_seal (struct disk_seal_entry *dst,const void * src,size_t size); +int TPM_disk_unseal (void *dst,size_t size,const struct disk_seal_entry *src); + +/* NVRAM to allow revocation of TM-KEY */ +int TPM_disk_nvalloc (be32_t *nvram_slot,struct tpm_authdata auth); +int TPM_disk_nvread (void *buf,size_t bufsiz,be32_t nvram_slot,struct tpm_authdata auth); +int TPM_disk_nvwrite (void *buf,size_t bufsiz,be32_t nvram_slot,struct tpm_authdata auth); +int TPM_disk_nvchange (be32_t nvram_slot,struct tpm_authdata old,struct tpm_authdata noo); + +/* Monotonic counters to detect rollback */ +int TPM_disk_alloc_counter (be32_t *slot,struct tpm_authdata auth,be32_t *value); +int TPM_disk_check_counter (be32_t slot,struct tpm_authdata auth,be32_t value); +int TPM_disk_incr_counter (be32_t slot,struct tpm_authdata auth); +int TPM_disk_change_counter (be32_t slot,struct tpm_authdata old,struct tpm_authdata noo); + +#endif
stubdom/vtpmmgr/disk_write.c new file +410 -0
410 lines not on this page · raw message
stubdom/vtpmmgr/endian_int.h new file +72 -0
72 lines not on this page · raw message
stubdom/vtpmmgr/init.c +26 -78
191 lines not on this page · raw message
stubdom/vtpmmgr/log.h +5 -3
@@ -64,18 +64,20 @@ extern char *module_names[];#define SETBIT (num,idx) (num) |= BITMASK(idx)#define CLEARBIT (num,idx) (num) &= ( ~ BITMASK(idx) ) +void printk (const char *fmt, ...); + #define vtpmloginfo(module, fmt, args...) \ if (GETBIT (LOGGING_MODULES, module) == 1) { \ - fprintf (stdout, "INFO[%s]: " fmt, module_names[module], ##args); \ + printk("INFO[%s]: " fmt, module_names[module], ##args); \ } #define vtpmloginfomore(module, fmt, args...) \ if (GETBIT (LOGGING_MODULES, module) == 1) { \ - fprintf (stdout, fmt,##args); \ + printk(fmt,##args); \ } #define vtpmlogerror(module, fmt, args...) \ - fprintf (stderr, "ERROR[%s]: " fmt, module_names[module], ##args); + printk("ERROR[%s]: " fmt, module_names[module], ##args);//typedef UINT32 tpm_size_t;
stubdom/vtpmmgr/marshal.h +532 -292
65 lines not on this page · raw message
stubdom/vtpmmgr/mgmt_authority.c new file +323 -0
323 lines not on this page · raw message
stubdom/vtpmmgr/mgmt_authority.h new file +11 -0
Lines of this file are not shown. View the raw message.
stubdom/vtpmmgr/tpm.c +662 -698
1,360 lines not on this page · raw message
stubdom/vtpmmgr/tpm.h +35 -69
104 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_cmd_handler.c +774 -84
858 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_disk.c new file +237 -0
237 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_disk.h new file +233 -0
233 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_manager.h +386 -5
391 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_storage.c deleted +0 -794
794 lines not on this page · raw message
stubdom/vtpmmgr/vtpm_storage.h deleted +0 -68
68 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.9.0
Part of the diff is not shown here. View the raw message.
PATCH v3 2/9 vtpmmgr: add example control tools
In reply to Daniel De GraafThe manage-vtpmmgr.pl script is an example client for interacting with the TPM Manager; it is intended to run in a management domain with a vTPM (which may be dom0). It is used to create and manage vTPMs and vTPM groups.
The calc.pl script is an example manager of a vTPM group. It signs the configuration lists used by the TPM Manager with a locally held private key.
--- config/Tools.mk.in | 1 + tools/Makefile | 1 + tools/vtpmmgr/Makefile | 15 ++++ tools/vtpmmgr/calc.pl | 97 ++++++++++++++++++++++++ tools/vtpmmgr/manage-vtpmmgr.pl | 160 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 274 insertions(+) create mode 100644 tools/vtpmmgr/Makefile create mode 100755 tools/vtpmmgr/calc.pl create mode 100755 tools/vtpmmgr/manage-vtpmmgr.pl
config/Tools.mk.in +1 -0
@@ -54,6 +54,7 @@ CONFIG_SEABIOS := @seabios@ CONFIG_QEMU_TRAD := @qemu_traditional@ CONFIG_QEMU_XEN := @qemu_xen@ CONFIG_BLKTAP1 := @blktap1@ +CONFIG_VTPM := @vtpm@ #System options ZLIB := @zlib@
tools/Makefile +1 -0
@@ -38,6 +38,7 @@ SUBDIRS-$(CONFIG_X86) += xenpaging SUBDIRS-$(CONFIG_X86) += debugger/gdbsx SUBDIRS-$(CONFIG_X86) += debugger/kdd SUBDIRS-$(CONFIG_TESTS) += tests +SUBDIRS-$(CONFIG_VTPM) += vtpmmgr # These don't cross-compile ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
tools/vtpmmgr/Makefile new file +15 -0
@@ -0,0 +1,15 @@ +XEN_ROOT=$(CURDIR)/../.. +include $(XEN_ROOT)/tools/Rules.mk + +all: + @true + +install: + $(INSTALL_DIR) "$(DESTDIR)$(LIBEXEC)" + $(INSTALL_DATA) calc.pl "$(DESTDIR)$(LIBEXEC)" + $(INSTALL_DATA) manage-vtpmmgr.pl "$(DESTDIR)$(LIBEXEC)" + +clean: + @true + +.PHONY: all install clean
tools/vtpmmgr/calc.pl new file +97 -0
97 lines not on this page · raw message
tools/vtpmmgr/manage-vtpmmgr.pl new file +160 -0
160 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v3 3/9 vtpmmgr: Store hardware TPM Locality
In reply to Daniel De GraafFrom: Jason Andryuk <[email protected]>
The TPM locality must be specified when using TPM_PCR_INFO_LONG for TPM_Seal. Store the locality so it can be provided later.
--- stubdom/vtpmmgr/init.c | 4 +++- stubdom/vtpmmgr/vtpmmgr.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-)
stubdom/vtpmmgr/init.c +3 -1
@@ -69,7 +69,8 @@ const TPM_AUTHDATA WELLKNOWN_AUTH = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0struct vtpm_globals vtpm_globals = { .tpm_fd =-1 , - .oiap = { .AuthHandle =0 } + .oiap = { .AuthHandle =0 }, + .hw_locality =0 };static int tpm_entropy_source (void * dummy,unsigned char * data,size_t len,size_t * olen) {
@@ -436,6 +437,7 @@ TPM_RESULT vtpmmgr_init(int argc, char** argv) { } vtpm_globals.tpm_fd =tpm_tis_open (tpm);tpm_tis_request_locality (tpm, opts.tpmlocality); + vtpm_globals.hw_locality = opts.tpmlocality; }break ;case TPMDRV_TPMFRONT :
stubdom/vtpmmgr/vtpmmgr.h +2 -0
@@ -57,6 +57,8 @@ struct vtpm_globals {entropy_context entropy;ctr_drbg_context ctr_drbg; + +int hw_locality; };struct tpm_opaque {
Signature · 1 line
1.9.0
PATCH v3 4/9 vtpmmgr: Convert TPM_Seal to use TPM_PCR_INFO_LONG
In reply to Daniel De GraafFrom: Jason Andryuk <[email protected]>
Infineon 1.2 TPMs fail TPM_Seal commands with TPM_BAD_PARAMETER when PCRS are specified by a TPM_PCR_INFO structure. Using a TPM_PCR_INFO_LONG structure to specify PCRs succeeds, so update to use that. This also requires changes to use TPM_STORED_DATA12 for the result.
--- stubdom/vtpmmgr/disk_tpm.c | 52 ++++++++++++++++++++--------- stubdom/vtpmmgr/marshal.h | 82 ++++++++++++++++++++++++++++++++++++++++++++++ stubdom/vtpmmgr/tcg.h | 42 ++++++++++++++++++++++++ stubdom/vtpmmgr/tpm.c | 22 +++++++------ stubdom/vtpmmgr/tpm.h | 8 ++--- 5 files changed, 176 insertions(+), 30 deletions(-)
stubdom/vtpmmgr/disk_tpm.c +36 -16
@@ -74,12 +74,15 @@ void TPM_pcr_digest(struct hash160 *buf, le32_t selection)int TPM_disk_seal (struct disk_seal_entry *dst,const void * src,size_t size) {uint32_t rc; -TPM_PCR_INFO info; -TPM_STORED_DATA out; +uint32_t infoSize; +TPM_PCR_INFO_LONG info; +TPM_STORED_DATA12 out;TPM_AUTH_SESSION osap =TPM_AUTH_SESSION_INIT ;TPM_AUTHDATA sharedsecret;TPM_AUTHDATA auth; +printk ("Calling TPM_disk_seal\n" ); + rc =TPM_OSAP (TPM_ET_KEYHANDLE ,TPM_SRK_KEYHANDLE , (void *)&vtpm_globals.srk_auth, &sharedsecret, &osap);
@@ -94,18 +97,26 @@ int TPM_disk_seal(struct disk_seal_entry *dst, const void* src, size_t size)#endif memset (auth,0 ,20 ); - info.pcrSelection.sizeOfSelect =3 ; - info.pcrSelection.pcrSelect = (void *)&dst->pcr_selection; + info.tag =TPM_TAG_PCR_INFO_LONG ; + info.localityAtCreation =1 << vtpm_globals.hw_locality; + info.localityAtRelease =1 << vtpm_globals.hw_locality; + info.creationPCRSelection.sizeOfSelect =3 ; + info.creationPCRSelection.pcrSelect = (void *)&dst->pcr_selection; + info.releasePCRSelection.sizeOfSelect =3 ; + info.releasePCRSelection.pcrSelect = (void *)&dst->pcr_selection;memcpy (&info.digestAtCreation, &dst->digest_at_seal,20 );memcpy (&info.digestAtRelease, &dst->digest_release,20 ); - rc =TPM_Seal (TPM_SRK_KEYHANDLE ,45 , &info, size, src, &out, + infoSize =2 +1 +1 +2 +3 +2 +3 +20 +20 ; +//infoSize = sizeof_TPM_PCR_INFO_LONG(&info); + + rc =TPM_Seal (TPM_SRK_KEYHANDLE , infoSize, &info, size, src, &out, (void *)&sharedsecret, (void *)&auth, &osap);TPM_TerminateHandle (osap.AuthHandle);#ifdef DEBUG_SEAL_OPS -printk ("TPM_Seal rc=%d encDataSize=%d sealInfoSize=%d\n" , rc, out.encDataSize, out.sealInfoSize); +printk ("TPM_Seal rc=%d encDataSize=%d sealInfoSize=%d\n" , rc, out.encDataSize, out.sealInfoLongSize);#endif if (!rc)memcpy (dst->sealed_data, out.encData,256 );
@@ -113,7 +124,7 @@ int TPM_disk_seal(struct disk_seal_entry *dst, const void* src, size_t size)#ifdef DEBUG_SEAL_OPS uint8_t buf[512 ];uint8_t *start = buf; -uint8_t *end =pack_TPM_STORED_DATA (buf, &out); +uint8_t *end =pack_TPM_STORED_DATA12 (buf, &out);printk ("stored_data:" );while (start != end) {printk (" %02x" , *start);
@@ -122,37 +133,46 @@ int TPM_disk_seal(struct disk_seal_entry *dst, const void* src, size_t size)printk ("\n" );#endif -free_TPM_STORED_DATA (&out); +free_TPM_STORED_DATA12 (&out);return rc; }int TPM_disk_unseal (void *dst,size_t size,const struct disk_seal_entry *src) {uint32_t rc; -TPM_STORED_DATA in; +TPM_STORED_DATA12 in;TPM_AUTH_SESSION oiap =TPM_AUTH_SESSION_INIT ;TPM_AUTHDATA auth;uint32_t outSize =0 ;uint8_t *out =NULL ; +printk ("Calling TPM_disk_unseal\n" ); + rc =TPM_OIAP (&oiap);if (rc)abort ();memset (auth,0 ,20 ); - in.ver =TPM_STRUCT_VER_1_1 ; - in.sealInfoSize =45 ; - in.sealInfo.pcrSelection.sizeOfSelect =3 ; - in.sealInfo.pcrSelection.pcrSelect = (void *)&src->pcr_selection; -memcpy (&in.sealInfo.digestAtCreation, &src->digest_at_seal,20 ); -memcpy (&in.sealInfo.digestAtRelease, &src->digest_release,20 ); + in.tag =TPM_TAG_STORED_DATA12 ; + in.et =0 ; +//in.sealInfoLongSize = sizeof_TPM_PCR_INFO_LONG(&in.sealInfoLong); + in.sealInfoLongSize =2 +1 +1 +2 +3 +2 +3 +20 +20 ; + in.sealInfoLong.tag =TPM_TAG_PCR_INFO_LONG ; + in.sealInfoLong.localityAtCreation =1 << vtpm_globals.hw_locality; + in.sealInfoLong.localityAtRelease =1 << vtpm_globals.hw_locality; + in.sealInfoLong.creationPCRSelection.sizeOfSelect =3 ; + in.sealInfoLong.creationPCRSelection.pcrSelect = (void *)&src->pcr_selection; + in.sealInfoLong.releasePCRSelection.sizeOfSelect =3 ; + in.sealInfoLong.releasePCRSelection.pcrSelect = (void *)&src->pcr_selection; +memcpy (&in.sealInfoLong.digestAtCreation, &src->digest_at_seal,20 ); +memcpy (&in.sealInfoLong.digestAtRelease, &src->digest_release,20 ); in.encDataSize =256 ; in.encData = (void *)src->sealed_data;#ifdef DEBUG_SEAL_OPS uint8_t buf[512 ];uint8_t *start = buf; -uint8_t *end =pack_TPM_STORED_DATA (buf, &in); +uint8_t *end =pack_TPM_STORED_DATA12 (buf, &in);printk ("stored_data:" );while (start != end) {printk (" %02x" , *start);
stubdom/vtpmmgr/marshal.h +82 -0
124 lines not on this page · raw message
stubdom/vtpmmgr/tcg.h +42 -0
60 lines not on this page · raw message
stubdom/vtpmmgr/tpm.c +12 -10
@@ -492,11 +492,11 @@ abort_egress:TPM_RESULT TPM_Seal (TPM_KEY_HANDLE keyHandle,// in -UINT32 pcrInfoSize,// in -TPM_PCR_INFO * pcrInfo,// in +UINT32 pcrInfoLongSize,// in +TPM_PCR_INFO_LONG * pcrInfoLong,// in UINT32 inDataSize,// in const BYTE * inData,// in -TPM_STORED_DATA * sealedData,//out +TPM_STORED_DATA12 * sealedData,//out const TPM_SECRET * osapSharedSecret,//in const TPM_AUTHDATA * sealedDataAuth,//in TPM_AUTH_SESSION* pubAuth // in, out
@@ -509,28 +509,30 @@ TPM_RESULT TPM_Seal(xorEncrypt (osapSharedSecret, &pubAuth->NonceEven, sealedDataAuth,IN_PTR ,NULL ,NULL ); in_pos +=sizeof (TPM_ENCAUTH ); -PACK_IN (UINT32 , pcrInfoSize); -if (pcrInfoSize) -PACK_IN (TPM_PCR_INFO , pcrInfo); + +PACK_IN (UINT32 , pcrInfoLongSize); +if (pcrInfoLongSize) { +PACK_IN (TPM_PCR_INFO_LONG , pcrInfoLong); + }PACK_IN (UINT32 , inDataSize);PACK_IN (BUFFER , inData, inDataSize);TPM_XMIT_AUTH1 (osapSharedSecret, pubAuth); -UNPACK_OUT (TPM_STORED_DATA , sealedData,UNPACK_ALLOC ); +UNPACK_OUT (TPM_STORED_DATA12 , sealedData,UNPACK_ALLOC );TPM_END_AUTH1 (osapSharedSecret, pubAuth); abort_egress:if (status) -free_TPM_STORED_DATA (sealedData); +free_TPM_STORED_DATA12 (sealedData);TPM_AUTH_ERR_CHECK (pubAuth);return status; } TPM_RESULT TPM_Unseal( TPM_KEY_HANDLE parentHandle, // in - const TPM_STORED_DATA* sealedData, + const TPM_STORED_DATA12* sealedData, UINT32* outSize, // out BYTE** out, //out const TPM_AUTHDATA* key_usage_auth, //in
@@ -544,7 +546,7 @@ TPM_RESULT TPM_Unseal(PACK_IN (TPM_KEY_HANDLE , parentHandle);TPM_HASH_IN_BEGIN ; -PACK_IN (TPM_STORED_DATA , sealedData); +PACK_IN (TPM_STORED_DATA12 , sealedData);TPM_XMIT_AUTH2 (key_usage_auth, keyAuth, data_usage_auth, dataAuth);
stubdom/vtpmmgr/tpm.h +4 -4
@@ -88,11 +88,11 @@ TPM_RESULT TPM_Reset(TPM_PCR_SELECTION *sel);TPM_RESULT TPM_Seal (TCS_KEY_HANDLE keyHandle,// in -UINT32 pcrInfoSize,// in -TPM_PCR_INFO * pcrInfo,// in +UINT32 pcrInfoLongSize,// in +TPM_PCR_INFO_LONG * pcrInfoLong,// in UINT32 inDataSize,// in const BYTE * inData,// in -TPM_STORED_DATA * sealedData,//out +TPM_STORED_DATA12 * sealedData,//out const TPM_SECRET * osapSharedSecret,//in const TPM_AUTHDATA * sealDataAuth,//in TPM_AUTH_SESSION* pubAuth // in, out
@@ -100,7 +100,7 @@ TPM_RESULT TPM_Seal( TPM_RESULT TPM_Unseal ( TPM_KEY_HANDLE parentHandle, // in - const TPM_STORED_DATA* sealedData, + const TPM_STORED_DATA12* sealedData, UINT32* outSize, // out BYTE** out, //out const TPM_AUTHDATA* key_usage_auth, //in
Signature · 1 line
1.9.0
PATCH v3 5/9 vtpm: passthru requests to manager
In reply to Daniel De GraafWhen sending commands to a vTPM, commands with the VTPM_TAG_REQ2 tag are passed directly to the TPM Manager since they are used in the management interface to the TPM Manager. The VTPM_TAG_REQ tag is translated to TPM_TAG_RQU_COMMAND to allow access to the physical TPM for certain ordinals (PCRRead, Extend, and GetRandom).
--- stubdom/vtpm/vtpm.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-)
stubdom/vtpm/vtpm.c +39 -1
@@ -33,6 +33,7 @@#include "vtpm_cmd.h" #include "vtpm_pcrs.h" #include "vtpmblk.h" +#include "vtpm_manager.h" #define TPM_LOG_INFO LOG_INFO#define TPM_LOG_ERROR LOG_ERR
@@ -117,6 +118,40 @@ int init_random(void) {return 0 ; } +int check_passthru (tpmcmd_t * tpmcmd) { +TPM_TAG tag; +UINT32 len =10 ; +BYTE * ptr; +size_t size; + +if (tpmcmd->req_len <10 ) { +return false; + } + + ptr = tpmcmd->req; +tpm_unmarshal_UINT16 (&ptr, &len, &tag); + +if (tag ==VTPM_TAG_REQ2 ) { +info ("VTPM passthru: %d bytes" , (int )tpmcmd->req_len); +tpmfront_cmd (tpmfront_dev, tpmcmd->req, tpmcmd->req_len, &tpmcmd->resp, &size); + tpmcmd->resp_len = size; +info ("VTPM passthru return: %d bytes" , (int )size); +return true; + } + +if (tag ==VTPM_TAG_REQ ) { +info ("VTPM pTPM-cmd: %d bytes" , (int )tpmcmd->req_len); + ptr = tpmcmd->req; +tpm_marshal_UINT16 (&ptr, &len,TPM_TAG_RQU_COMMAND ); +tpmfront_cmd (tpmfront_dev, tpmcmd->req, tpmcmd->req_len, &tpmcmd->resp, &size); + tpmcmd->resp_len = size; +info ("VTPM pTPM-cmd return: %d bytes" , (int )size); +return true; + } + +return false; +} +int check_ordinal (tpmcmd_t * tpmcmd) {TPM_COMMAND_CODE ord;UINT32 len =4 ;
@@ -209,6 +244,9 @@ static void main_loop(void) {error ("Invalid locality (%d) for client in tpm_handle_command" , tpmcmd->locality);create_error_response (tpmcmd,TPM_FAIL ); } +/* Check for TPM Manager passthrough command */ +else if (check_passthru (tpmcmd)) { + }/* Check for disabled ordinals */ else if (!check_ordinal (tpmcmd)) {create_error_response (tpmcmd,TPM_BAD_ORDINAL );
@@ -231,7 +269,7 @@ static void main_loop(void) { } abort_postpcrs: -info ("VTPM Shutting down\n" ); +info ("VTPM Shutting down" );tpm_emulator_shutdown (); }
Signature · 1 line
1.9.0
PATCH v3 6/9 vtpm: add ordinal for obtaining an EK signature
In reply to Daniel De GraafFor a vTPM to be useful for remote attestation, proof that the vTPM's EK was generated and held within a secure vTPM implementation is necessary. This patch adds an ordinal to the vTPM which will request a quote providing this evidence from the TPM Manager; it only functions during the first startup of a given vTPM in order to provide proof that the EK was freshly generated (and not a key whose private part is available elsewhere).
--- stubdom/Makefile | 1 + stubdom/vtpm-parent-sign-ek.patch | 196 ++++++++++++++++++++++++++++++++++++++ stubdom/vtpm/vtpm_cmd.c | 45 +++++++++ 3 files changed, 242 insertions(+) create mode 100644 stubdom/vtpm-parent-sign-ek.patch
stubdom/Makefile +1 -0
@@ -208,6 +208,7 @@ tpm_emulator-$(XEN_TARGET_ARCH): tpm_emulator-$(TPMEMU_VERSION).tar.gz patch -d $@ -p1 < tpmemu-$(TPMEMU_VERSION).patch; patch -d $@ -p1 < vtpm-bufsize.patch patch -d $@ -p1 < vtpm-locality.patch + patch -d $@ -p1 < vtpm-parent-sign-ek.patch mkdir $@/build cd $@/build; CC=${CC} $(CMAKE) .. -DCMAKE_C_FLAGS:STRING="-std=c99 -DTPM_NO_EXTERN $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-declaration-after-statement" touch $@
stubdom/vtpm-parent-sign-ek.patch new file +196 -0
196 lines not on this page · raw message
stubdom/vtpm/vtpm_cmd.c +45 -0
51 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v3 7/9 vtpm: add deep quote support
In reply to Daniel De GraafThis allows the client of a vTPM to request a quote from the physical TPM which includes PCRs from both the physical and virtual TPMs, signed by an AIK from the physical TPM. This quote can be used to provide evidence of the complete launch environment of a virtual machine.
--- stubdom/Makefile | 1 + stubdom/vtpm-deepquote.patch | 187 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 stubdom/vtpm-deepquote.patch
stubdom/Makefile +1 -0
@@ -209,6 +209,7 @@ tpm_emulator-$(XEN_TARGET_ARCH): tpm_emulator-$(TPMEMU_VERSION).tar.gz patch -d $@ -p1 < vtpm-bufsize.patch patch -d $@ -p1 < vtpm-locality.patch patch -d $@ -p1 < vtpm-parent-sign-ek.patch + patch -d $@ -p1 < vtpm-deepquote.patch mkdir $@/build cd $@/build; CC=${CC} $(CMAKE) .. -DCMAKE_C_FLAGS:STRING="-std=c99 -DTPM_NO_EXTERN $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-declaration-after-statement" touch $@
stubdom/vtpm-deepquote.patch new file +187 -0
187 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH v3 8/9 stubdom/grub: verify vTPM label if requested
In reply to Daniel De GraafThis adds an optional argument --vtpm-label=<label> to the pv-grub command line. If specified, a vtpm device must be connected to the pv-grub domain and the backend of this device must have the given XSM label (which may start with a * to indicate a wildcard). Verifying the label of the vTPM before sending measurements prevents a disaggregated control domain that has access to xenstore but not to the guest domains from causing the measurements performed by pv-grub to be discarded, allowing the forgery of arbitrary kernel measurements in the TPM.
--- stubdom/grub/kexec.c | 58 ++++++++++++++++++++++++++++++++++++++++++-------- stubdom/grub/mini-os.c | 8 ++++++- stubdom/grub/mini-os.h | 2 ++ 3 files changed, 58 insertions(+), 10 deletions(-)
stubdom/grub/kexec.c +49 -9
@@ -68,6 +68,14 @@ struct pcr_extend_cmd {unsigned char hash[20 ]; } __attribute__((packed)); +struct pcr_extend_rsp { +uint16_t tag; +uint32_t size; +uint32_t status; + +unsigned char hash[20 ]; +} __attribute__((packed)); +/* Not imported from polarssl's header since the prototype unhelpfully defines * the input as unsigned char, which causes pointer type mismatches */ void sha1 (const void *input,size_t ilen,unsigned char output[20 ]);
@@ -135,20 +143,49 @@ int kexec_allocate(struct xc_dom_image *dom, xen_vaddr_t up_to)return 0 ; } +/* Filled from mini-os command line or left as NULL */ +char *vtpm_label; +static void tpm_hash2pcr (struct xc_dom_image *dom,char *cmdline) {struct tpmfront_dev * tpm =init_tpmfront (NULL ); -uint8_t *resp; +struct pcr_extend_rsp *resp;size_t resplen =0 ;struct pcr_extend_cmd cmd; +int rv; -/* If all guests have access to a vTPM, it may be useful to replace this -* with ASSERT(tpm) to prevent configuration errors from allowing a guest -* to boot without a TPM (or with a TPM that has not been sent any -* measurements, which could allow forging the measurements). +/* +* If vtpm_label was specified on the command line, require a vTPM to be +* attached and for the domain providing the vTPM to have the given +* label. */ -if (!tpm) +if (vtpm_label) { +char ctx[128 ]; +if (!tpm) { +printf ("No TPM found and vtpm_label specified, aborting!\n" ); +do_exit (); + } + rv =evtchn_get_peercontext (tpm->evtchn, ctx,sizeof (ctx) -1 ); +if (rv <0 ) { +printf ("Could not verify vtpm_label: %d\n" , rv); +do_exit (); + } + ctx[127 ] =0 ; + rv =strcmp (ctx, vtpm_label); +if (rv && vtpm_label[0 ] =='*' ) { +int match_len =strlen (vtpm_label) -1 ; +int offset =strlen (ctx) - match_len; +if (offset >0 ) + rv =strcmp (ctx + offset, vtpm_label +1 ); + } + +if (rv) { +printf ("Mismatched vtpm_label: '%s' != '%s'\n" , ctx, vtpm_label); +do_exit (); + } + }else if (!tpm) {return ; + } cmd.tag =bswap_16 (TPM_TAG_RQU_COMMAND ); cmd.size =bswap_32 (sizeof (cmd));
@@ -156,15 +193,18 @@ static void tpm_hash2pcr(struct xc_dom_image *dom, char *cmdline) cmd.pcr =bswap_32 (4 );// PCR #4 for kernel sha1 (dom->kernel_blob, dom->kernel_size, cmd.hash); -tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), &resp, &resplen); + rv =tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), (void *)&resp, &resplen); +ASSERT (rv ==0 && resp->status ==0 ); cmd.pcr =bswap_32 (5 );// PCR #5 for cmdline sha1 (cmdline,strlen (cmdline), cmd.hash); -tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), &resp, &resplen); + rv =tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), (void *)&resp, &resplen); +ASSERT (rv ==0 && resp->status ==0 ); cmd.pcr =bswap_32 (5 );// PCR #5 for initrd sha1 (dom->ramdisk_blob, dom->ramdisk_size, cmd.hash); -tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), &resp, &resplen); + rv =tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), (void *)&resp, &resplen); +ASSERT (rv ==0 && resp->status ==0 );shutdown_tpmfront (tpm); }
stubdom/grub/mini-os.c +7 -1
@@ -735,8 +735,14 @@ void __attribute__ ((noreturn)) grub_reboot (void)* for grub's 32bit pointers to work */ char grub_scratch_mem[SCRATCH_MEMSIZE] __attribute__((aligned(PAGE_SIZE))); -int main (int argc,char *argv[]) +int main (int argc,char **argv) { +if (argc >1 &&memcmp (argv[1 ],"--vtpm-label=" ,13 ) ==0 ) { + vtpm_label = argv[1 ] +13 ; + argc--; + argv++; + } +if (argc >1 ) {strncpy (config_file, argv[1 ],sizeof (config_file) -1 ); config_file[sizeof (config_file) -1 ] =0 ;
stubdom/grub/mini-os.h +2 -0
@@ -3,3 +3,5 @@ extern struct blkfront_dev **blk_dev;extern struct netfront_dev *net_dev;extern struct kbdfront_dev *kbd_dev;extern struct fbfront_dev *fb_dev; + +extern char * vtpm_label;
Signature · 1 line
1.9.0
Re: [PATCH 8/9] stubdom/grub: verify vTPM label if requested
Quoted 9 lines · Daniel De Graaf, le Mon 21 Apr 2014 13:23:04 -0400, a écrit :
This adds an optional argument --vtpm-label=<label> to the pv-grub command line. If specified, a vtpm device must be connected to the pv-grub domain and the backend of this device must have the given XSM label (which may start with a * to indicate a wildcard). Verifying the label of the vTPM before sending measurements prevents a disaggregated control domain that has access to xenstore but not to the guest domains from causing the measurements performed by pv-grub to be discarded, allowing the forgery of arbitrary kernel measurements in the TPM.
Quoted 3 lines
Signed-off-by Daniel De Graaf <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Samuel Thibault <[email protected]>
Quoted 136 lines
--- stubdom/grub/kexec.c | 58 ++++++++++++++++++++++++++++++++++++++++++-------- stubdom/grub/mini-os.c | 8 ++++++- stubdom/grub/mini-os.h | 2 ++ 3 files changed, 58 insertions(+), 10 deletions(-)stubdom/grub/kexec.c +49
-9@@ -68,6 +68,14 @@ struct pcr_extend_cmd {unsigned char hash[20 ]; } __attribute__((packed)); +struct pcr_extend_rsp { +uint16_t tag; +uint32_t size; +uint32_t status; + +unsigned char hash[20 ]; +} __attribute__((packed)); +/* Not imported from polarssl's header since the prototype unhelpfully defines * the input as unsigned char, which causes pointer type mismatches */ void sha1 (const void *input,size_t ilen,unsigned char output[20 ]);@@ -135,20 +143,49 @@ int kexec_allocate(struct xc_dom_image *dom, xen_vaddr_t up_to)return 0 ; } +/* Filled from mini-os command line or left as NULL */ +char *vtpm_label; +static void tpm_hash2pcr (struct xc_dom_image *dom,char *cmdline) {struct tpmfront_dev * tpm =init_tpmfront (NULL ); -uint8_t *resp; +struct pcr_extend_rsp *resp;size_t resplen =0 ;struct pcr_extend_cmd cmd; +int rv; -/* If all guests have access to a vTPM, it may be useful to replace this -* with ASSERT(tpm) to prevent configuration errors from allowing a guest -* to boot without a TPM (or with a TPM that has not been sent any -* measurements, which could allow forging the measurements). +/* +* If vtpm_label was specified on the command line, require a vTPM to be +* attached and for the domain providing the vTPM to have the given +* label. */ -if (!tpm) +if (vtpm_label) { +char ctx[128 ]; +if (!tpm) { +printf ("No TPM found and vtpm_label specified, aborting!\n" ); +do_exit (); + } + rv =evtchn_get_peercontext (tpm->evtchn, ctx,sizeof (ctx) -1 ); +if (rv <0 ) { +printf ("Could not verify vtpm_label: %d\n" , rv); +do_exit (); + } + ctx[127 ] =0 ; + rv =strcmp (ctx, vtpm_label); +if (rv && vtpm_label[0 ] =='*' ) { +int match_len =strlen (vtpm_label) -1 ; +int offset =strlen (ctx) - match_len; +if (offset >0 ) + rv =strcmp (ctx + offset, vtpm_label +1 ); + } + +if (rv) { +printf ("Mismatched vtpm_label: '%s' != '%s'\n" , ctx, vtpm_label); +do_exit (); + } + }else if (!tpm) {return ; + } cmd.tag =bswap_16 (TPM_TAG_RQU_COMMAND ); cmd.size =bswap_32 (sizeof (cmd));@@ -156,15 +193,18 @@ static void tpm_hash2pcr(struct xc_dom_image *dom, char *cmdline) cmd.pcr =bswap_32 (4 );// PCR #4 for kernel sha1 (dom->kernel_blob, dom->kernel_size, cmd.hash); -tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), &resp, &resplen); + rv =tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), (void *)&resp, &resplen); +ASSERT (rv ==0 && resp->status ==0 ); cmd.pcr =bswap_32 (5 );// PCR #5 for cmdline sha1 (cmdline,strlen (cmdline), cmd.hash); -tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), &resp, &resplen); + rv =tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), (void *)&resp, &resplen); +ASSERT (rv ==0 && resp->status ==0 ); cmd.pcr =bswap_32 (5 );// PCR #5 for initrd sha1 (dom->ramdisk_blob, dom->ramdisk_size, cmd.hash); -tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), &resp, &resplen); + rv =tpmfront_cmd (tpm, (void *)&cmd,sizeof (cmd), (void *)&resp, &resplen); +ASSERT (rv ==0 && resp->status ==0 );shutdown_tpmfront (tpm); }stubdom/grub/mini-os.c +7
-1@@ -735,8 +735,14 @@ void __attribute__ ((noreturn)) grub_reboot (void)* for grub's 32bit pointers to work */ char grub_scratch_mem[SCRATCH_MEMSIZE] __attribute__((aligned(PAGE_SIZE))); -int main (int argc,char *argv[]) +int main (int argc,char **argv) { +if (argc >1 &&memcmp (argv[1 ],"--vtpm-label=" ,13 ) ==0 ) { + vtpm_label = argv[1 ] +13 ; + argc--; + argv++; + } +if (argc >1 ) {strncpy (config_file, argv[1 ],sizeof (config_file) -1 ); config_file[sizeof (config_file) -1 ] =0 ;stubdom/grub/mini-os.h +2
-0@@ -3,3 +3,5 @@ extern struct blkfront_dev **blk_dev;extern struct netfront_dev *net_dev;extern struct kbdfront_dev *kbd_dev;extern struct fbfront_dev *fb_dev; + +extern char * vtpm_label;Signature · 1 line
1.9.0
Signature · 4 lines
Samuel There are two types of Linux developers - those who can spell, and those who can't. There is a constant pitched battle between the two. (From one of the post-1.1.54 kernel update messages posted to c.o.l.a)
PATCH v3 9/9 vtpmmgr: use XSM label as vTPM kernel hash
In reply to Daniel De GraafBecause there is not currently a method for the vTPM Manager to obtain a build hash of a vTPM, use the hash of the vTPM's XSM label as a substitute. This allows the vTPM Manager to distinguish between vTPMs intended to be paired with a hardware domain kernel (which cannot use pv-grub) and vTPMs which are paired with a pv-grub domain and therefore contain reliable measurements of the guest kernel in PCRs 4 and 5.
--- docs/misc/vtpm-platforms.txt | 14 ++++++++++++++ docs/misc/vtpmmgr.txt | 10 ++++++---- stubdom/vtpmmgr/init.c | 2 ++ stubdom/vtpmmgr/vtpm_cmd_handler.c | 34 ++++++++++++++++++++++++++++++++-- stubdom/vtpmmgr/vtpmmgr.h | 6 +++++- 5 files changed, 59 insertions(+), 7 deletions(-)
docs/misc/vtpm-platforms.txt +14 -0
@@ -125,3 +125,17 @@ which requires the presence of a vTPM. To bind the configuration of the guest to the vTPM, the guest may use full-disk encryption which can be unlocked using an unseal operation; using the wrong vTPM will then yield a non-functioning guest. + +In order to use pv-grub to obtain measurements of the guest kernel in PCRs 4 and +5, it must not be possible to attach to a guest's vTPM without booting a fresh +guest image. This requires pairing every vTPM's launch with the launch of a +guest, as described above, and using the --vtpm-label= argument to pv-grub so +that it refuses to launch a guest if it could not write to the vTPM. To permit +the hardware domain, which cannot use pv-grub, to use a vTPM in this situation, +multiple vTPM groups must be used in the TPM Manager. Group 0 would be for the +hardware domain only, and would only support vTPMs with label +"system_u:system_r:vtpm_t". Group 1 would support vTPMs with label +"*:vm_r:vtpm_t", and would be used for all guest vTPMs. The EK quote used in +initial provisioning and any deep quotes produced later would include the label, +which would allow a verifier to reliably determine if the value of the vTPM's +PCR 4 contains the hash of the domain's kernel.
docs/misc/vtpmmgr.txt +6 -4
@@ -123,7 +123,9 @@ strengthen this assumption if the creation of vTPM-labeled domains is more constrained (for example, only permitted to a domain builder service): the only grants mapped by the TPM Manager should belong to vTPM domains, so restricting the ability to map other domain's granted pages will prevent other domains from -directly requesting keys from the TPM Manager. +directly requesting keys from the TPM Manager. The TPM Manager uses the hash of +the XSM label of the attached vTPM as the kernel hash, so vTPMs with distinct +labels may be further partitioned using vTPM groups. A domain with direct access to the hardware TPM will be able to decrypt the TPM Manager's disk image if the haredware TPM's PCR values are in a permitted
@@ -158,6 +160,6 @@ would look like the following: 6. Attach the vTPM migration domain's vtpm/1 device to the new vtpmmgr 7. Migration domain executes vtpmmgr_SaveHashKey on vtpm/1 -This requires the migration domain must be added to the list of valid vTPM -kernel hashes. Because the TPM Manager currently does not verify vTPM kernel -hashes, the control domain can initiate this operation at any time. +This requires the migration domain to be added to the list of valid vTPM kernel +hashes. In the current version of the vtpmmgr domain, this is the hash of the +XSM label, not the kernel.
stubdom/vtpmmgr/init.c +2 -0
@@ -386,6 +386,8 @@ static void set_opaque(domid_t domid, unsigned int handle) opq =calloc (1 ,sizeof (*opq)); opq->uuid = (uuid_t *)tpmback_get_uuid (domid, handle); + opq->domid = domid; + opq->handle = handle;tpmback_set_opaque (domid, handle, opq); }
stubdom/vtpmmgr/vtpm_cmd_handler.c +32 -2
@@ -59,10 +59,40 @@ static void gen_random_uuid(uuid_t uuid) uuid[8 ] =0x80 | (uuid[8 ] &0x3F ); } +/* +* Instead of using a kernel hash, which requires a trusted domain builder to +* report, use the XSM label as a substitute. +*/ static TPM_RESULT find_vtpm_khash (int domid,struct tpm_opaque *opq) { -// TODO getting the build hashes requires a domain builder to report them -memset (opq->kern_hash,0 ,sizeof (opq->kern_hash)); +char buf[128 ]; +int i, rv; + buf[127 ] =0 ; + rv =tpmback_get_peercontext (opq->domid, opq->handle, buf,sizeof (buf) -1 ); +if (rv <0 ) +return TPM_FAIL ; + +sha1 ((void *)buf,strlen (buf), opq->kern_hash); + +/* +* As a hack to support the use of the XSM user field as an optional +* wildcard, check the hash against the group here. If it fails, replace +* the user field with a "*" and return the hash of that value. +*/ +for (i=0 ; i <be32_native (opq->group->seal_bits.nr_kerns); i++) { +if (!memcmp (opq->group->seal_bits.kernels[i].bits, opq->kern_hash,20 )) { +return TPM_SUCCESS ; + } + } + +char * upos =strchr (buf,':' ); +if (upos ==NULL || upos == buf) +return TPM_SUCCESS ; + + upos--; + upos[0 ] ='*' ; + +sha1 ((void *)upos,strlen (upos), opq->kern_hash);return TPM_SUCCESS ; }
stubdom/vtpmmgr/vtpmmgr.h +5 -1
@@ -65,7 +65,11 @@ struct tpm_opaque {uuid_t *uuid;struct mem_group *group;struct mem_vtpm *vtpm; -uint8_t kern_hash[32 ]; + +domid_t domid; +unsigned int handle; + +uint8_t kern_hash[20 ]; };// --------------------------- Global Values --------------------------
Signature · 1 line
1.9.0
Quoted 4 lines · Daniel De Graaf
This is an updated vTPM Manager domain which adds support for using the physical TPM to protect vTPM secrets according to its PCR values, and to allow virtual machines (including dom0) to attest to both the platform's state and to their own state.
Acked the ones without and applied. Thanks.