vTPM/TPM2: Support 'tpm2' extra command line.
PATCH v3 9/14 vTPM/TPM2: Support 'tpm2' extra command line.
Make vtpm-stubdom domain compatible to launch on TPM 1.x / TPM 2.0. Add:
..
extra="tpm2"
..
to launch vtpm-stubdom domain on TPM 2.0, ignore it on TPM 1.x. for example,
vtpm-stubdom domain configuration on TPM 2.0:
kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz"
memory=16
disk=["file:/var/scale/vdisk/vmgr,hda,w"]
name="vtpmmgr"
iomem=["fed40,5"]
extra="tpm2"
vtpm-stubdom domain configuration on TPM 1.x:
kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz"
memory=16
disk=["file:/var/scale/vdisk/vmgr,hda,w"]
name="vtpmmgr"
iomem=["fed40,5"]
--- stubdom/vtpmmgr/vtpmmgr.c | 46 ++++++++++++++++++++++++++++++++++++++++------ stubdom/vtpmmgr/vtpmmgr.h | 14 ++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-)
stubdom/vtpmmgr/vtpmmgr.c +40 -6
@@ -45,6 +45,27 @@#include "vtpmmgr.h" #include "tcg.h" +struct tpm_hardware_version hardware_version = { + .hw_version =TPM1_HARDWARE , +}; + +int parse_cmdline_hw (int argc,char ** argv) +{ +int i; + +for (i =1 ; i < argc; ++i) { +if (!strncmp (argv[i],TPM2_EXTRA_OPT ,4 )) { + hardware_version.hw_version =TPM2_HARDWARE ; +break ; + } + } +return 0 ; +} + +int hw_is_tpm2 (void ) +{ +return (hardware_version.hw_version ==TPM2_HARDWARE ) ?1 :0 ; +}void main_loop (void ) {tpmcmd_t * tpmcmd;
@@ -74,12 +95,25 @@ int main(int argc, char** argv)sleep (2 );vtpmloginfo (VTPM_LOG_VTPM ,"Starting vTPM manager domain\n" ); -/* Initialize the vtpm manager */ -if (vtpmmgr_init (argc, argv) !=TPM_SUCCESS ) { -vtpmlogerror (VTPM_LOG_VTPM ,"Unable to initialize vtpmmgr domain!\n" ); - rc =-1 ; - goto exit; - } +/*Parse TPM hardware in extra command line*/ +parse_cmdline_hw (argc, argv); + +/* Initialize the vtpm manager */ +if (hw_is_tpm2 ()) { +vtpmloginfo (VTPM_LOG_VTPM ,"Hardware : --- TPM 2.0 ---\n" ); +if (vtpmmgr2_init (argc, argv) !=TPM_SUCCESS ) { +vtpmlogerror (VTPM_LOG_VTPM ,"Unable to initialize vtpmmgr domain!\n" ); + rc =-1 ; + goto exit; + } + }else { +vtpmloginfo (VTPM_LOG_VTPM ,"Hardware : --- TPM 1.x ---\n" ); +if (vtpmmgr_init (argc, argv) !=TPM_SUCCESS ) { +vtpmlogerror (VTPM_LOG_VTPM ,"Unable to initialize vtpmmgr domain!\n" ); + rc =-1 ; + goto exit; + } + }main_loop ();
stubdom/vtpmmgr/vtpmmgr.h +14 -0
@@ -46,9 +46,21 @@#include "vtpm_manager.h" #include "tpm2_types.h" +#define TPM2_EXTRA_OPT "tpm2"#define RSA_KEY_SIZE 0x0800#define RSA_CIPHER_SIZE (RSA_KEY_SIZE / 8) +enum { +TPM1_HARDWARE =1 , +TPM2_HARDWARE , +} tpm_version; + +struct tpm_hardware_version { +int hw_version; +}; + +extern struct tpm_hardware_version hardware_version; +struct vtpm_globals {int tpm_fd;TPM_AUTH_SESSION oiap;// OIAP session for storageKey
@@ -97,5 +109,7 @@ inline TPM_RESULT vtpmmgr_rand(unsigned char* bytes, size_t num_bytes) {TPM_RC tpm2_take_ownership (void );TPM_RESULT vtpmmgr2_create (void );TPM_RESULT vtpmmgr2_init (int argc,char ** argv); +int parse_cmdline_hw (int argc,char ** argv); +int hw_is_tpm2 (void );#endif
Signature · 1 line
1.8.3.2
Quoted 44 lines · Quan Xu
Make vtpm-stubdom domain compatible to launch on TPM 1.x / TPM 2.0. Add:
..extra="tpm2"..
to launch vtpm-stubdom domain on TPM 2.0, ignore it on TPM 1.x. for example,
vtpm-stubdom domain configuration on TPM 2.0:kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz" memory=16 disk=["file:/var/scale/vdisk/vmgr,hda,w"] name="vtpmmgr" iomem=["fed40,5"] extra="tpm2"vtpm-stubdom domain configuration on TPM 1.x:
kernel="/usr/lib/xen/boot/vtpmmgr-stubdom.gz" memory=16 disk=["file:/var/scale/vdisk/vmgr,hda,w"] name="vtpmmgr" iomem=["fed40,5"]Signed-off-by Quan Xu <[email protected]>--- stubdom/vtpmmgr/vtpmmgr.c | 46 ++++++++++++++++++++++++++++++++++++++++------ stubdom/vtpmmgr/vtpmmgr.h | 14 ++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-)stubdom/vtpmmgr/vtpmmgr.c +6
-0@@ -45,6 +45,27 @@#include "vtpmmgr.h" #include "tcg.h" +struct tpm_hardware_version hardware_version = { + .hw_version =TPM1_HARDWARE , +}; + +int parse_cmdline_hw (int argc,char ** argv) +{
stubdom/vtpmmgr/vtpmmgr.c line 63
Quoted 10 lines
stubdom/vtpmmgr/vtpmmgr.c +10
-0+int i; + +for (i =1 ; i < argc; ++i) { +if (!strncmp (argv[i],TPM2_EXTRA_OPT ,4 )) { + hardware_version.hw_version =TPM2_HARDWARE ; +break ; + } + } +return 0 ; +}
I would change this from strncmp to strcmp so that it does not just match any argument that starts with "tpm2". If you also want to support "tpm2=1", then checking for that explicitly is preferred. Currently, "tpm2=0" will enable the tpm2 driver, which is confusing.
Signature · 2 lines
Daniel De Graaf National Security Agency