VTPM mini-os: vtpm_manager bug fixes and changes
PATCH 7/12 VTPM mini-os: vtpm_manager bug fixes and changes
This is a rather large path for vtpm_managerd. It can be broken up if requested but seeing as nobody else seems to be maintaining the vtpm code I don't think anyone will mind.
Bug fixes:
-A new routine to flush all handles from the tpm everytime vtpm_managerd is started. Previously if the manager would crash it would leave stale keys and auth handles in the tpm. After restarting the manager several times and letting it crash, the tpm would run out of memory and the manager would fail to start with a TPM_NO_SPACE error. -Several memory errors fixed such as uninitialized reads and memory leaks.
-Fixed the signal handler to work with blocking IO and threads correctly. Previously the manager would not shutdown correctly when you tried to Ctrl+C close it on 64 bit.
-Removal of VTPM_MULTI_VM #defines. These were supposed to be a partial implementation for a way to run vtpms in multiple domains but it was never finished. It doesn't appear there has been any development on this for several years. Since vtpm-stubdom performs this functionality I removed these #defines and #ifdefs to make the code a little cleaner.
VTPM Stubdom functionality:
-New vTPM ordinals: VTPM_SAVE_KEY and VTPM_LOAD_KEY. The vtpm domains encrypt their persistent state themselves, they only request the manager to store the key. -#define VTPM_STUBDOM will build the manager in stubdom mode. The manager can only work in either vtpm-stubdom or vtpmd mode. You cannot combine them. Clearing out the manager state will be required.
# rm /var/vtpm/VTPM /var/vtpm/vtpm_dm* -See the vtpm-stubdom patch for more info
Hotplug fixes:
-Changes to how the ipc pipes are setup and used to avoid hanging in the hotplug system.
-vtpmmgrtalk: A c program for the dom0 scripts to correctly speak to the vtpm manager. The next patch which fixes hotplug errors requires this program.
Build changes:
-Changed the way certain pieces of the vtpm manager are built. This allows pieces of it to be included in vtpmmgrdom.
Other:
-vtpmconnd: A simple program to pass tpm commands from the xen tpm backend in dom0 to the hardware tpm. This is needed if you don't want to passthrough the tpm directly to vtpmmgrdom (see the vtpmmgrdom patch for more information).
Signed off by: Matthew Fioravante <[email protected]>
tools/vtpm_manager/crypto/crypto.c +4 -2
@@ -45,6 +45,8 @@#include "crypto.h" #include "log.h" +extern const EVP_CIPHER *SYM_CIPHER ; +/** * Initialize cryptography library * @rand: random seed
@@ -83,6 +85,6 @@ result =RAND_pseudo_bytes ((BYTE *) data, size);if (result <=0 ) -vtpmlogerror (VTPM_LOG_CRYPTO ,"RAND_pseudo_bytes failed: %s\n" , -ERR_error_string (ERR_get_error (),NULL )); +vtpmlogerror (VTPM_LOG_CRYPTO ,"RAND_pseudo_bytes failed: rc=%d errstr=%s\n" , + result,ERR_error_string (ERR_get_error (),NULL )); }
tools/vtpm_manager/crypto/crypto.h +3 -1
@@ -76,7 +76,7 @@void Crypto_Init (const BYTE * rand,int size); -void Crypto_Exit (); +void Crypto_Exit (void );void Crypto_GetRandom (void * data,int size);
@@ -127,6 +127,8 @@/*[IN]*/ BYTE *modulus, CRYPTO_INFO* cryptoInfo); +void Crypto_RSACryptoInfoFree (CRYPTO_INFO * cryptoInfo); +// // symmetric pack and unpack operations //
tools/vtpm_manager/crypto/Makefile +7 -1
@@ -1,5 +1,11 @@ XEN_ROOT = ../../.. -include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk +include ../Rules.mk + +CFLAGS += -I../util +CFLAGS += -I../tcs +CFLAGS += -I../manager + + BIN = libtcpaCrypto.a
tools/vtpm_manager/crypto/rsa.c +5 -0
@@ -149,6 +149,10 @@ } +void Crypto_RSACryptoInfoFree (CRYPTO_INFO * cryptoInfo) { +RSA_free (cryptoInfo->keyInfo); +} + int Crypto_RSAEnc( CRYPTO_INFO *key, UINT32 inDataSize, BYTE *inData,
@@ -161,6 +165,7 @@if (paddedData ==NULL )return -1 ; +memset (paddedData,0 ,sizeof (BYTE ) * paddedDataSize); *outDataSize =0 ;
tools/vtpm_manager/crypto/sym_crypto.c +40 -18
127 lines not on this page · raw message
tools/vtpm_manager/crypto/sym_crypto.h +9 -12
@@ -40,21 +40,15 @@#ifndef _SYM_CRYPTO_H#define _SYM_CRYPTO_H -#include <openssl/evp.h> #include "buffer.h" -typedef struct symkey_t { -buffer_t key; - -EVP_CIPHER_CTX context; -const EVP_CIPHER * cipher; -}symkey_t ; +typedef struct symkey_t symkey_t ; -extern const EVP_CIPHER *SYM_CIPHER ; +//Allocates a symkey with random bits +TPM_RESULT Crypto_symcrypto_genkey (symkey_t ** key); -TPM_RESULT Crypto_symcrypto_genkey (symkey_t * key); - -TPM_RESULT Crypto_symcrypto_initkey (symkey_t * key,const buffer_t * keybits); +//Allocates a symkey with given keybits +TPM_RESULT Crypto_symcrypto_initkey (symkey_t ** key,const buffer_t * keybits);// these functions will allocate their output buffers
@@ -66,7 +60,10 @@const buffer_t * cipher, buffer_t* o_clear); -// only free the internal parts, not the 'key' ptr +//Frees the symkey TPM_RESULT Crypto_symcrypto_freekey (symkey_t * key); +//Get the raw key byte buffer +buffer_t *Crypto_symkey_getkey (symkey_t * key); +#endif /* _SYM_CRYPTO_H */
tools/vtpm_manager/Makefile +2 -2
@@ -1,9 +1,9 @@ XEN_ROOT = ../.. # Base definitions and rules -include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk +include Rules.mk -SUBDIRS = crypto tcs util manager migration +SUBDIRS = crypto tcs util manager migration vtpmmgrtalk vtpmconnd OPENSSL_HEADER = /usr/include/openssl/crypto.h .PHONY: all clean install
tools/vtpm_manager/manager/dmictl.c +167 -2
199 lines not on this page · raw message
tools/vtpm_manager/manager/Makefile +20 -3
@@ -1,7 +1,18 @@ XEN_ROOT = ../../.. -include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk +include ../Rules.mk + +CFLAGS += -I../crypto +CFLAGS += -I../util +CFLAGS += -I../tcs + + +MAINS := vtpmd.o +MGRLIB := libvtpmmanager.a +VTSPOBJS := vtsp.o +VTSPLIB := libvtsp.a +BIN := vtpm_managerd +OBJS := $(filter-out $(MAINS) $(VTSPOBJS), $(OBJS)) -BIN = vtpm_managerd .PHONY: all all: build
@@ -28,9 +39,15 @@ mrproper: clean rm -f *~ -$(BIN): $(OBJS) +$(BIN): $(MAINS) $(MGRLIB) $(VTSPLIB) $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) -o $@ +$(VTSPLIB): $(VTSPOBJS) + $(AR) rcs $@ $^ + +$(MGRLIB): $(OBJS) + $(AR) rcs $@ $^ + # libraries LIBS += ../tcs/libTCS.a ../util/libTCGUtils.a ../crypto/libtcpaCrypto.a LIBS += -lcrypto -lpthread -lm
tools/vtpm_manager/manager/migration.c +3 -2
@@ -40,6 +40,7 @@#include <stdio.h> #include <unistd.h> #include <string.h> +#include <stdlib.h> #include "vtpmpriv.h" #include "bsg.h"
@@ -263,7 +264,7 @@TPM_RESULT VTPM_Handle_Load_Migration_key (const buffer_t *param_buf,buffer_t *result_buf) { -TPM_RESULT status=TPM_FAIL ; +TPM_RESULT status=TPM_SUCCESS ;VTPM_MIGKEY_LIST *mig_key;vtpmloginfo (VTPM_LOG_VTPM ,"Loading Migration Public Key.\n" );
@@ -303,5 +304,5 @@free (pubkey_exp_pack.data);free (pubkey_mod_pack.data); -return TPM_SUCCESS ; +return status; }
tools/vtpm_manager/manager/securestorage.c +213 -29
400 lines not on this page · raw message
tools/vtpm_manager/manager/vtpmd.c +73 -197
386 lines not on this page · raw message
tools/vtpm_manager/manager/vtpm_ipc.c +54 -9
115 lines not on this page · raw message
tools/vtpm_manager/manager/vtpm_ipc.h +5 -1
@@ -39,10 +39,14 @@ #ifndef __VTPM_IO_H__ #define __VTPM_IO_H__ +#include <signal.h> + #include "tcg.h" #define VTPM_IPC_CLOSED -1 +extern volatile sig_atomic_t IPC_QUIT_FLAG; + // Represents an (somewhat) abstracted io handle. typedef struct vtpm_ipc_handle_t { int fh; // IO handle.
@@ -53,7 +57,7 @@ } vtpm_ipc_handle_t; -int vtpm_ipc_init (vtpm_ipc_handle_t *ioh,char * name,int flags,BOOL create); +int vtpm_ipc_init (vtpm_ipc_handle_t *ioh,char * name,int flags,BOOL create,BOOL preopen);// Create the file that needs opening. Used only for FIFOs // FYI: This may cause problems in other file IO schemes. We'll see.
tools/vtpm_manager/manager/vtpm_lock.c +5 -5
@@ -40,24 +40,24 @@static pthread_rwlock_t vtpm_lock; -void vtpm_lock_init () { +void vtpm_lock_init (void ) {pthread_rwlock_init ( &vtpm_lock,NULL ); } -void vtpm_lock_destroy (){ +void vtpm_lock_destroy (void ){pthread_rwlock_destroy (&vtpm_lock); } -void vtpm_lock_rdlock (){ +void vtpm_lock_rdlock (void ){pthread_rwlock_rdlock (&vtpm_lock); } -void vtpm_lock_wrlock (){ +void vtpm_lock_wrlock (void ){pthread_rwlock_wrlock (&vtpm_lock); } -void vtpm_lock_unlock (){ +void vtpm_lock_unlock (void ){pthread_rwlock_unlock (&vtpm_lock); }
tools/vtpm_manager/manager/vtpm_lock.h +5 -5
@@ -38,11 +38,11 @@#ifndef __VTPM_LOCK_H__#define __VTPM_LOCK_H__ -void vtpm_lock_init (); -void vtpm_lock_destroy (); +void vtpm_lock_init (void ); +void vtpm_lock_destroy (void ); -void vtpm_lock_rdlock (); -void vtpm_lock_wrlock (); -void vtpm_lock_unlock (); +void vtpm_lock_rdlock (void ); +void vtpm_lock_wrlock (void ); +void vtpm_lock_unlock (void );#endif
tools/vtpm_manager/manager/vtpm_manager.c +29 -8
@@ -40,10 +40,12 @@#include <stdio.h> #include <unistd.h> #include <string.h> +#include <stdlib.h> #include "vtpm_manager.h" #include "vtpmpriv.h" #include "vtsp.h" +#include "tpmddl.h" #include "bsg.h" #include "hashtable.h" #include "hashtable_itr.h"
@@ -54,8 +56,8 @@VTPM_GLOBALS *vtpm_globals=NULL ;// --------------------------- Well Known Auths -------------------------- -const TPM_AUTHDATA SRK_AUTH = {0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff , -0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff }; +const TPM_AUTHDATA SRK_AUTH = {0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 , +0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 };#ifdef WELL_KNOWN_OWNER_AUTH static BYTE FIXED_OWNER_AUTH[20] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@@ -74,7 +76,6 @@ }// --------------------------- Functions ------------------------------ -TPM_RESULT VTPM_Create_Manager (){TPM_RESULT status =TPM_SUCCESS ;
@@ -104,6 +105,7 @@TPMTRYRETURN (VTSP_DisablePubekRead (vtpm_globals->manager_tcs_handle, (const TPM_AUTHDATA *)&vtpm_globals->owner_usage_auth, &vtpm_globals->keyAuth)); +Crypto_RSACryptoInfoFree (&ek_cryptoInfo); }else {vtpmloginfo (VTPM_LOG_VTPM ,"Failed to readEK meaning TPM has an owner. Creating Keys off existing SRK.\n" ); }
@@ -181,7 +183,7 @@ }/////////////////////////////////////////////////////////////////////////////// -TPM_RESULT VTPM_Init_Manager () { +TPM_RESULT VTPM_Init_Manager (void ) {TPM_RESULT status =TPM_FAIL , serviceStatus;BYTE *randomsead;UINT32 randomsize=256 ;
@@ -203,6 +205,11 @@ vtpm_globals->manager_tcs_handle =0 ;TPMTRYRETURN (TCS_create ()); + +// Blow away all stale handles left in the tpm +if (TDDL_FlushAllResources () !=TPM_SUCCESS ) { +vtpmlogerror (VTPM_LOG_VTPM ,"VTPM_FlushResources failed, continuing anyway..\n" ); + }// Create TCS Context for service TPMTRYRETURN (TCS_OpenContext (&vtpm_globals->manager_tcs_handle ) );
@@ -228,7 +235,7 @@TPMTRYRETURN (VTPM_Create_Manager () );TPMTRYRETURN (VTPM_SaveManagerData () ); }else if (serviceStatus !=TPM_SUCCESS ) { -vtpmlogerror (VTPM_LOG_VTPM ,"Failed to read existing manager file" ); +vtpmlogerror (VTPM_LOG_VTPM ,"Failed to read existing manager file\n" );exit (1 ); }
@@ -254,7 +261,7 @@ }/////////////////////////////////////////////////////////////////////////////// -void VTPM_Stop_Manager () { +void VTPM_Stop_Manager (void ) {VTPM_DMI_RESOURCE *dmi_res;struct hashtable_itr *dmi_itr;
@@ -267,7 +274,7 @@close_dmi ( dmi_res );// Not really interested in return code }while (hashtable_iterator_advance (dmi_itr)); -free (dmi_itr); +free (dmi_itr); }if (VTPM_SaveManagerData () !=TPM_SUCCESS )
@@ -276,7 +283,21 @@TCS_CloseContext (vtpm_globals->manager_tcs_handle);TCS_destroy (); -hashtable_destroy (vtpm_globals->dmi_map,1 ); +if (hashtable_count (vtpm_globals->dmi_map) >0 ) { + dmi_itr =hashtable_iterator (vtpm_globals->dmi_map); +do { + dmi_res = (VTPM_DMI_RESOURCE *)hashtable_iterator_value (dmi_itr); +free_dmi (dmi_res); + }while (hashtable_iterator_advance (dmi_itr)); +free (dmi_itr); + } +hashtable_destroy (vtpm_globals->dmi_map,0 ); + +/* Cleanup resources */ +Crypto_RSACryptoInfoFree (&vtpm_globals->bootKey); +Crypto_RSACryptoInfoFree (&vtpm_globals->storageKey); +buffer_free (&vtpm_globals->bootKeyWrap); +buffer_free (&vtpm_globals->storageKeyWrap);free (vtpm_globals);Crypto_Exit ();
tools/vtpm_manager/manager/vtpm_manager.h +21 -0
@@ -61,6 +61,8 @@#define VTPM_ORD_TPMCOMMAND (VTPM_ORD_BASE + 3) // DMI issues HW TPM Command#define VTPM_ORD_GET_MIG_KEY (VTPM_ORD_BASE + 4) // Get manager's migration key#define VTPM_ORD_LOAD_MIG_KEY (VTPM_ORD_BASE + 5) // load dest migration key +#define VTPM_ORD_SAVEHASHKEY (VTPM_ORD_BASE + 7) // DMI requests encryption key for persistent storage +#define VTPM_ORD_LOADHASHKEY (VTPM_ORD_BASE + 8) // DMI requests symkey to be regenerated// Priviledged VTPM Commands (From management console) #define VTPM_ORD_OPEN (VTPM_PRIV_BASE + 1) // Creates/reopens DMI
@@ -147,4 +149,23 @@*********************************************************************/ +#ifndef VTPM_STUBDOM +#define TPM_EMULATOR_PATH "/usr/bin/vtpmd" +#endif + +#define VTPM_BE_FNAME "/dev/vtpm" +#define VTPM_DUMMY_TX_BE_FNAME "/var/vtpm/fifos/dummy_out.fifo" +#define VTPM_DUMMY_RX_BE_FNAME "/var/vtpm/fifos/dummy_in.fifo" +#ifndef VTPM_STUBDOM +#define VTPM_TX_TPM_FNAME "/var/vtpm/fifos/tpm_cmd_to_%d.fifo" +#define VTPM_RX_TPM_FNAME "/var/vtpm/fifos/tpm_rsp_from_all.fifo" +#define VTPM_TX_VTPM_FNAME "/var/vtpm/fifos/vtpm_rsp_to_%d.fifo" +#define VTPM_RX_VTPM_FNAME "/var/vtpm/fifos/vtpm_cmd_from_all.fifo" +#endif +#define VTPM_TX_HP_FNAME "/var/vtpm/fifos/to_console.fifo" +#define VTPM_RX_HP_FNAME "/var/vtpm/fifos/from_console.fifo" + +#define VTPM_TYPE_PVM_STRING "pvm" +#define VTPM_TYPE_HVM_STRING "hvm" +#endif //_VTPM_MANAGER_H_
tools/vtpm_manager/manager/vtpm_manager_handler.c +72 -37
225 lines not on this page · raw message
tools/vtpm_manager/manager/vtpm_manager_handler.h +21 -0
@@ -0,0 +1,21 @@ +#ifndef VTPM_MANAGER_HANDLER_H +#define VTPM_MANAGER_HANDLER_H +// ---------------------- Prototypes ------------------- +TPM_RESULT vtpm_manager_handle_vtpm_cmd (VTPM_DMI_RESOURCE *dmi_res, +TPM_COMMAND_CODE ord, +buffer_t *command_buf, +buffer_t *result_buf, +BOOL is_priv, +char *thread_name); + +#ifndef VTPM_STUBDOM +TPM_RESULT vtpm_manager_handle_tpm_cmd (vtpm_ipc_handle_t *tx_ipc_h, +vtpm_ipc_handle_t *rx_ipc_h, +VTPM_DMI_RESOURCE *dmi_res, +BYTE *cmd_header, +buffer_t *param_buf, +buffer_t *result_buf, +char *thread_name); +#endif + +#endif
tools/vtpm_manager/manager/vtpmpriv.h +30 -8
@@ -40,6 +40,8 @@#ifndef __VTPMPRIV_H__#define __VTPMPRIV_H__ +#include <signal.h> +#include "vtpm_manager.h" #include "tcg.h" #include "tcs.h"
@@ -54,16 +56,19 @@#define DMI_NVM_FILE "/var/vtpm/vtpm_dm_%d.data"#define VTPM_CTL_DM 0 +extern volatile sig_atomic_t HANDLER_QUIT_FLAG ; +// ------------------------ Private Structures ----------------------- typedef struct VTPM_DMI_RESOURCE_T { +#ifndef VTPM_STUBDOM // I/O info for Manager to talk to DMI's and controllers vtpm_ipc_handle_t *tx_vtpm_ipc_h; // TX VTPM Results to DMI vtpm_ipc_handle_t *rx_vtpm_ipc_h; // RX VTPM Commands from DMI vtpm_ipc_handle_t *tx_tpm_ipc_h; // TX TPM Commands to DMI vtpm_ipc_handle_t *rx_tpm_ipc_h; // RX TPM Results from DMI + + pid_t dmi_pid; -#ifndef VTPM_MULTI_VM - pid_t dmi_pid; #endif // Non-persistent Information
@@ -77,6 +82,9 @@BYTE dmi_type;TPM_DIGEST NVM_measurement;// Equal to the SHA1 of the blob TPM_DIGEST DMI_measurement;// Correct measurement of the owning DMI + +char * uuid; + }VTPM_DMI_RESOURCE ; typedef struct tdVTPM_MIGKEY_LIST {
@@ -89,10 +97,6 @@ typedef struct tdVTPM_GLOBALS { // Non-persistent data -#ifndef VTPM_MULTI_VM - pid_t master_pid; -#endif - int connected_dmis; // To close guest_rx when no dmis are connected struct hashtable *dmi_map; // Table of all DMI's known indexed by persistent instance #
@@ -123,8 +127,8 @@extern const TPM_AUTHDATA SRK_AUTH ;// SRK Well Known Auth Value // ********************** VTPM Functions ************************* -TPM_RESULT VTPM_Init_Manager ();// Start VTPM Service -void VTPM_Stop_Manager ();// Stop VTPM Service +TPM_RESULT VTPM_Init_Manager (void );// Start VTPM Service +void VTPM_Stop_Manager (void );// Stop VTPM Service TPM_RESULT VTPM_Manager_Handler(vtpm_ipc_handle_t *tx_ipc_h, vtpm_ipc_handle_t *rx_ipc_h, BOOL fw_tpm, // Should forward TPM cmds
@@ -143,6 +147,11 @@const buffer_t *inbuf, buffer_t *outbuf); +TPM_RESULT VTPM_Handle_Get_NVM_Size (VTPM_DMI_RESOURCE *myDMI, +const buffer_t *inbuf, +buffer_t *outbuf); + +TPM_RESULT VTPM_Handle_TPM_Command (VTPM_DMI_RESOURCE *dmi,buffer_t *inbuf,buffer_t *outbuf);
@@ -173,6 +182,9 @@TPM_RESULT close_dmi (VTPM_DMI_RESOURCE *dmi_res);TPM_RESULT init_dmi (UINT32 dmi_id,BYTE type,VTPM_DMI_RESOURCE **dmi_res); +/* Free's dmi_res and all of it's resources */ +void free_dmi (VTPM_DMI_RESOURCE *dmi_res); +TPM_RESULT envelope_encrypt (const buffer_t *inbuf,CRYPTO_INFO *asymkey,buffer_t *sealed_data);
@@ -183,4 +195,14 @@const TPM_AUTHDATA *key_usage_auth, buffer_t *unsealed_data); +TPM_RESULT symkey_encrypt (const buffer_t *inbuf, +CRYPTO_INFO *asymkey, +buffer_t *sealed_key); + +TPM_RESULT symkey_decrypt (const buffer_t *cipher, +TCS_CONTEXT_HANDLE TCSContext, +TPM_HANDLE keyHandle, +const TPM_AUTHDATA *key_usage_auth, +buffer_t *symkey_clear); +#endif // __VTPMPRIV_H__
tools/vtpm_manager/manager/vtsp.c +8 -10
@@ -38,6 +38,7 @@// ================================================================== #include <string.h> +#include <stdlib.h> #include "tcg.h" #include "tcs.h" #include "bsg.h"
@@ -312,7 +313,7 @@TPM_PROTOCOL_ID proto_id =TPM_PID_OWNER ;BYTE *new_srk; -BYTE *paramText;// Digest to make Auth. +BYTE *paramText =NULL ;// Digest to make Auth. UINT32 paramTextSize;// vars for srkpubkey parameter
@@ -458,7 +459,7 @@vtpmloginfo (VTPM_LOG_VTSP ,"Creating new key of type %d.\n" , usage);// vars for Calculate encUsageAuth -BYTE *paramText; +BYTE *paramText =NULL ;UINT32 paramTextSize;// vars for Calculate encUsageAuth
@@ -567,8 +568,7 @@ osapSharedSecret, auth, 0) );// Unpack/return key structure -TPMTRYRETURN (buffer_init (pubKeyBuf,0 ,0 ) ); -TPMTRYRETURN (buffer_append_raw (pubKeyBuf, newKeyText.size, newKeyText.data) ); +TPMTRYRETURN (buffer_init (pubKeyBuf, newKeyText.size, newKeyText.data) ); goto egress;
@@ -664,6 +664,7 @@// Destroy rsaKeyParms BSG_Destroy (BSG_TPM_RSA_KEY_PARMS , &rsaKeyParms); +BSG_Destroy (BSG_TPM_KEY , &newKey);// Set encryption scheme cryptoinfo->encScheme =CRYPTO_ES_RSAESOAEP_SHA1_MGF1 ;
@@ -733,8 +734,7 @@ hContext) );// Unpack/return key structure -TPMTRYRETURN (buffer_init (clear_data,0 ,0 )); -TPMTRYRETURN (buffer_append_raw (clear_data, clear_data_size, clear_data_text) ); +TPMTRYRETURN (buffer_init (clear_data, clear_data_size, clear_data_text) ); goto egress;
@@ -793,8 +793,7 @@vtpmlogerror (VTPM_LOG_VTSP ,"Enc buffer just overflowed.\n" ); } -buffer_init (outData,0 ,NULL ); -buffer_append_raw (outData, out_tmp_size, out_tmp); +buffer_init (outData, out_tmp_size, out_tmp);vtpmloginfo (VTPM_LOG_TXDATA ,"Bind Generated[%d] = 0x" , out_tmp_size);for (i =0 ; i < out_tmp_size ; i++) {
@@ -1005,8 +1004,6 @@vtpmloginfo (VTPM_LOG_VTSP ,"Calling TPM_SaveState.\n" ); -TPM_RESULT status =TPM_SUCCESS ; -// Call TCS return (TCSP_SaveState ( hContext ) );
@@ -1040,3 +1037,4 @@free (resultText);return status; } +
tools/vtpm_manager/manager/vtsp.h +1 -0
@@ -42,6 +42,7 @@#include "tcg.h" #include "tcs.h" +#include "crypto.h" #define KEY_BUFFER_SIZE 2048
tools/vtpm_manager/migration/Makefile +7 -1
@@ -1,5 +1,11 @@ XEN_ROOT = ../../.. -include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk +include ../Rules.mk + +CFLAGS += -I../crypto +CFLAGS += -I../util +CFLAGS += -I../tcs +CFLAGS += -I../manager + VPATH = ../manager
tools/vtpm_manager/migration/vtpm_manager_if.c +2 -5
@@ -50,15 +50,12 @@#include "vtpm_migrator.h" #include "vtpm_manager.h" -#define VTPM_TX_HP_FNAME "/var/vtpm/fifos/from_console.fifo" -#define VTPM_RX_HP_FNAME "/var/vtpm/fifos/to_console.fifo" -static vtpm_ipc_handle_t tx_ipc_h, rx_ipc_h;TPM_RESULT vtpm_manager_open (){ -if ( (vtpm_ipc_init (&tx_ipc_h,VTPM_TX_HP_FNAME ,O_RDWR , TRUE) !=0 ) ||//FIXME: wronly - (vtpm_ipc_init (&rx_ipc_h,VTPM_RX_HP_FNAME ,O_RDWR , TRUE) !=0 ) ) {//FIXME: rdonly +if ( (vtpm_ipc_init (&tx_ipc_h,VTPM_TX_HP_FNAME ,O_RDWR , TRUE, TRUE) !=0 ) ||//FIXME: wronly + (vtpm_ipc_init (&rx_ipc_h,VTPM_RX_HP_FNAME ,O_RDWR , TRUE, TRUE) !=0 ) ) {//FIXME: rdonly vtpmlogerror (VTPM_LOG_VTPM ,"Unable to connect to vtpm_manager.\n" );return TPM_IOERROR ; }
tools/vtpm_manager/README +4 -3
@@ -43,9 +43,6 @@ LOGGING_MODULES -> How extensive logging happens see util/log.h for more info -VTPM_MULTI_VM -> Defined: VTPMs run in their own VMs - Not Defined (default): VTPMs are processes - # Debugging flags that may disappear without notice in the future DUMMY_BACKEND -> vtpm_manager listens on /tmp/in.fifo and
@@ -59,6 +56,10 @@ lost. However this has no protection from malicious app issuing a TPM_OwnerClear to wipe the TPM +VTPM_STUBDOM -> vtpm_manager runs in vtpm_stubdom mode with + vtpm instances running in mini-os domains + (see: stubdom/vtpm/README for details) + Requirements ============ - xen-unstable
tools/vtpm_manager/Rules.mk +3 -8
@@ -40,12 +40,12 @@ #CFLAGS += -DLOGGING_MODULES=0x0 #CFLAGS += -DLOGGING_MODULES=0xff -# Use frontend/backend pairs between manager & DMs? -#CFLAGS += -DVTPM_MULTI_VM - # vtpm_manager listens on fifo's rather than backend #CFLAGS += -DDUMMY_BACKEND +# Build for use with vtpm-stubdom +CFLAGS += -DVTPM_STUBDOM + # TCS talks to fifo's rather than /dev/tpm. TPM Emulator assumed on fifos #CFLAGS += -DDUMMY_TPM
@@ -55,8 +55,3 @@ # Fixed OwnerAuth #CFLAGS += -DWELL_KNOWN_OWNER_AUTH -# Include -CFLAGS += -I$(XEN_ROOT)/tools/vtpm_manager/crypto -CFLAGS += -I$(XEN_ROOT)/tools/vtpm_manager/util -CFLAGS += -I$(XEN_ROOT)/tools/vtpm_manager/tcs -CFLAGS += -I$(XEN_ROOT)/tools/vtpm_manager/manager
tools/vtpm_manager/tcs/contextmgr.c +3 -1
@@ -195,6 +195,7 @@BOOL FreeHandleList (CONTEXT_HANDLE * pContextHandle) {// in HANDLE_LIST * pCurrentHandle; +HANDLE_LIST * pNext;BOOL returncode = TRUE;vtpmloginfo (VTPM_LOG_TCS_DEEP ,"Freeing all handles for context\n" );
@@ -205,6 +206,7 @@ pCurrentHandle = pContextHandle->pHandleList;while (pCurrentHandle !=NULL ) { + pNext = pCurrentHandle->pNextHandle;switch (pCurrentHandle->type) {case TPM_RT_KEY : returncode = returncode && !TCSP_EvictKey (pContextHandle->handle, pCurrentHandle->handle);
@@ -216,7 +218,7 @@ returncode = FALSE; } - pCurrentHandle = pCurrentHandle->pNextHandle; + pCurrentHandle = pNext; }
tools/vtpm_manager/tcs/Makefile +6 -1
@@ -1,5 +1,10 @@ XEN_ROOT = ../../.. -include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk +include ../Rules.mk + +CFLAGS += -I../crypto +CFLAGS += -I../util +CFLAGS += -I../manager + BIN = libTCS.a
tools/vtpm_manager/tcs/tcs.c +17 -16
@@ -77,7 +77,7 @@// --------------------------------------------------------------------------------- // Initialization/Uninitialization SubComponent API // --------------------------------------------------------------------------------- -TPM_RESULT TCS_create () { +TPM_RESULT TCS_create (void ) {TDDL_RESULT hRes =TDDL_E_FAIL ;TPM_RESULT result =TPM_FAIL ;
@@ -101,7 +101,7 @@ } -void TCS_destroy () +void TCS_destroy (void ) { TCS_m_nCount--;
@@ -113,14 +113,13 @@TCS_CONTEXT_HANDLE *hContext;// Close all the TCS contexts. TCS should evict keys based on this -if (hashtable_count (context_ht) >0 ) { +while (hashtable_count (context_ht) >0 ) { context_itr =hashtable_iterator (context_ht); -do { - hContext = (TCS_CONTEXT_HANDLE *)hashtable_iterator_key (context_itr); -if (TCS_CloseContext (*hContext) !=TPM_SUCCESS ) -vtpmlogerror (VTPM_LOG_TCS ,"Failed to close context %d properly.\n" , *hContext); + + hContext = (TCS_CONTEXT_HANDLE *)hashtable_iterator_key (context_itr); +if (TCS_CloseContext (*hContext) !=TPM_SUCCESS ) +vtpmlogerror (VTPM_LOG_TCS ,"Failed to close context %d properly.\n" , *hContext); - }while (hashtable_iterator_advance (context_itr));free (context_itr); }hashtable_destroy (context_ht,1 );
@@ -534,6 +533,10 @@ BSG_TYPE_UINT32, &handle);// fill paramSize again as we now have the correct size BSG_Pack (BSG_TYPE_UINT32 , &InLength, InBuf+2 ); + +if (!DeleteHandleFromList (hContext, handle)) { +vtpmlogerror (VTPM_LOG_TCS ,"KeyHandle not removed from list\n" ); + }// call the TPM driver if ((hRes = TDDL_TransmitData(InBuf, InLength, OutBuf, &OutLength))
@@ -545,9 +548,6 @@BSG_TYPE_UINT32 , ¶mSize, BSG_TPM_COMMAND_CODE, &returnCode); -if (!DeleteHandleFromList (hContext, handle)) -vtpmlogerror (VTPM_LOG_TCS ,"KeyHandle not removed from list\n" ); -if (returnCode ==TPM_SUCCESS && tag ==TPM_TAG_RSP_COMMAND ) {// Print debug info
@@ -882,6 +882,7 @@memcpy (*prgbKey, tempBuf, *pcKeySize); +BSG_Destroy (BSG_TPM_KEY , &wrappedKey);vtpmloginfo (VTPM_LOG_TCS_DEEP ,"Received paramSize : %d\n" , paramSize); }else vtpmlogerror (VTPM_LOG_TCS ,"TCSP_CreateWrapKey Failed with return code %s\n" ,tpm_get_error_name (returnCode));
@@ -980,6 +981,10 @@BSG_Pack (BSG_TYPE_UINT32 , &InLength, InBuf+2 );vtpmloginfo (VTPM_LOG_TCS_DEEP ,"Sending paramSize = %d\n" , InLength); + +if (!DeleteHandleFromList (hContext, hKey)) { +vtpmlogerror (VTPM_LOG_TCS ,"KeyHandle not removed from list\n" ); + }// call the TPM driver if ((hRes =TDDL_TransmitData (InBuf, InLength, OutBuf, &OutLength)) ==TDDL_SUCCESS ) {
@@ -989,10 +994,6 @@BSG_TYPE_UINT32 , ¶mSize, BSG_TPM_COMMAND_CODE, &returnCode); -if (!DeleteHandleFromList (hContext, hKey)) { -vtpmlogerror (VTPM_LOG_TCS ,"KeyHandle not removed from list\n" ); - } -if (returnCode ==TPM_SUCCESS && tag ==TPM_TAG_RSP_COMMAND ) {vtpmloginfo (VTPM_LOG_TCS_DEEP ,"Received paramSize : %d\n" , paramSize); }else {
@@ -1019,7 +1020,7 @@TDDL_UINT32 OutLength =TCPA_MAX_BUFFER_LENGTH ;// check input params -if (bytesRequested ==NULL || *randomBytes ==NULL ){ +if (bytesRequested ==NULL || randomBytes ==NULL ){return TPM_BAD_PARAMETER ; }
tools/vtpm_manager/tcs/tcs.h +2 -2
@@ -50,8 +50,8 @@// Exposed API // ------------------------------------------------------------------ -TPM_RESULT TCS_create (); -void TCS_destroy (); +TPM_RESULT TCS_create (void ); +void TCS_destroy (void );TPM_RESULT TCS_OpenContext (/* OUT */ TCS_CONTEXT_HANDLE * hContext );
tools/vtpm_manager/tcs/tpmddl.c +191 -0
191 lines not on this page · raw message
tools/vtpm_manager/tcs/tpmddl.h +10 -3
@@ -50,13 +50,14 @@typedef TDDL_UINT32 TDDL_RESULT ;typedef unsigned char TDDL_BYTE ; -TDDL_RESULT TDDL_Open (); -void TDDL_Close (); +TDDL_RESULT TDDL_Open (void ); +TDDL_RESULT TDDL_Open_use_fd (int fd); +void TDDL_Close (void );TDDL_RESULT TDDL_TransmitData (TDDL_BYTE * in,TDDL_UINT32 insize,TDDL_BYTE * out,TDDL_UINT32 * outsize); -TDDL_RESULT TDDL_GetStatus (); +TDDL_RESULT TDDL_GetStatus (void ); TDDL_RESULT TDDL_GetCapability( TDDL_UINT32 cap, TDDL_UINT32 sub, TDDL_BYTE* buffer,
@@ -66,4 +67,10 @@TDDL_BYTE * buffer, TDDL_UINT32* size); +TDDL_RESULT TDDL_FlushSpecific (TDDL_UINT32 handle, +TDDL_UINT32 res); + +TDDL_RESULT TDDL_FlushAllResources (void ); + +#endif // __TPMDDL_H__
tools/vtpm_manager/tcs/transmit.c +18 -4
@@ -104,12 +104,13 @@return status; } -TPM_RESULT TDDL_Open () { +TDDL_RESULT TDDL_Open (void ) {TDDL_RESULT status =TDDL_SUCCESS ; +/* If tpm device is already open just silently return success */ if (g_TDDL_open) -return TPM_FAIL ; +return TPM_SUCCESS ;#ifdef DUMMY_TPM *g_rx_fdp =open (TPM_RX_FNAME ,O_RDWR );
@@ -117,7 +118,7 @@ g_tx_fd =open (TPM_TX_FNAME ,O_RDWR );if (g_tx_fd <0 ) { -vtpmlogerror (VTPM_LOG_TXDATA ,"TPM open failed" ); +vtpmlogerror (VTPM_LOG_TXDATA ,"TPM open failed\n" );return TPM_IOERROR ; }
@@ -126,7 +127,20 @@return status; } -void TDDL_Close () { +TDDL_RESULT TDDL_Open_use_fd (int fd) { +TDDL_RESULT status =TDDL_SUCCESS ; + +if (g_TDDL_open) +return TPM_FAIL ; + + g_tx_fd = fd; + + g_TDDL_open =1 ; + +return status; +} + +void TDDL_Close (void ) {if (! g_TDDL_open)return ;
tools/vtpm_manager/util/bsg.c +2 -1
@@ -41,6 +41,7 @@#include <string.h> #include <stdarg.h> #include <malloc.h> +#include <stdlib.h> #include "tcg.h" #include "crypto.h" #include "bsg.h"
@@ -317,7 +318,7 @@// FIXME: should have a function be passed in here which is called if the test // fails. Then the caller can decide what to do: abort, notify, whatever // -BOOL BSG_static_selfcheck () +BOOL BSG_static_selfcheck (void ) {int i;
tools/vtpm_manager/util/bsg.h +1 -1
@@ -161,6 +161,6 @@void BSG_PackConst (BSG_UINT32 val,int size,BSG_BYTE * dst);BSG_UINT32 BSG_UnpackConst (const BSG_BYTE * src,int size); -BOOL BSG_static_selfcheck (); +BOOL BSG_static_selfcheck (void );#endif
tools/vtpm_manager/util/buffer.c +39 -2
75 lines not on this page · raw message
tools/vtpm_manager/util/buffer.h +5 -0
@@ -92,4 +92,9 @@TPM_RESULT buffer_append_raw (buffer_t * buf,tpm_size_t len,const BYTE * bytes); +TPM_RESULT buffer_prepend_raw (buffer_t * buf,tpm_size_t len,const BYTE * bytes); + +//Reduce the size of the buffer, if len > buffer size returns an error +TPM_RESULT buffer_truncate (buffer_t * buf,tpm_size_t len); +#endif // _TOOLS_H_
tools/vtpm_manager/util/log.c +11 -0
@@ -38,6 +38,17 @@#include "buffer.h" #include "tcg.h" +char *module_names[] = {"" , +"CRYPTO" , +"BSG" , +"TXDATA" , +"TCS" , +"TCS" , +"VTSP" , +"VTPM" , +"VTPM" , +"VTSP" + };// Helper code for the consts, eg. to produce messages for error codes. typedef struct error_code_entry_t {
tools/vtpm_manager/util/log.h +3 -11
@@ -36,6 +36,8 @@#include <stdint.h> // for uint32_t #include <stddef.h> // for pointer NULL +#include <stdio.h> +#include <tcg.h> // =========================== LOGGING ==============================
@@ -50,17 +52,7 @@#define VTPM_LOG_VTPM_DEEP 8#define VTPM_LOG_VTSP_DEEP 9 -static char *module_names[] = {"" , -"CRYPTO" , -"BSG" , -"TXDATA" , -"TCS" , -"TCS" , -"VTSP" , -"VTPM" , -"VTPM" , -"VTSP" - }; +extern char *module_names[];// Default to standard logging #ifndef LOGGING_MODULES
tools/vtpm_manager/util/Makefile +6 -1
@@ -1,5 +1,10 @@ XEN_ROOT = ../../.. -include $(XEN_ROOT)/tools/vtpm_manager/Rules.mk +include ../Rules.mk + +CFLAGS += -I../crypto +CFLAGS += -I../tcs +CFLAGS += -I../manager + BIN = libTCGUtils.a
tools/vtpm_manager/util/tcg.h +96 -0
122 lines not on this page · raw message
tools/vtpm_manager/vtpmconnd/Makefile +19 -0
@@ -0,0 +1,19 @@ +XEN_ROOT = ../.. +TOOLS_INSTALL_DIR = $(DESTDIR)/usr/bin + +BIN=vtpmconnd +OBJS=vtpmconnd.o +CFLAGS=-O2 -Wall + +all: ${BIN} + +${BIN}: ${OBJS} + gcc -o $@ $< + +install: ${BIN} + install -m 0755 ${BIN} ${TOOLS_INSTALL_DIR} + +.PHONY: mrproper +mrproper: clean +clean: + -rm ${BIN} ${OBJS}
tools/vtpm_manager/vtpmconnd/vtpmconnd.c +241 -0
228 lines not on this page · raw message
tools/vtpm_manager/vtpmmgrtalk/Makefile +59 -0
59 lines not on this page · raw message
tools/vtpm_manager/vtpmmgrtalk/vtpmmgrtalk.c +129 -0
129 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Part of the diff is not shown here. View the raw message.