From 70ebecdf6ad9b55fc9dc46c7ebbce285a5a51a9d Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Thu, 22 Jul 2021 11:02:09 -0400 Subject: [PATCH] tests: fuzz: Register callbacks to avoid creating NVChip file Register callbacks so that we don't create the NVChip file. Signed-off-by: Stefan Berger --- tests/fuzz.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/tests/fuzz.cc b/tests/fuzz.cc index 5cff22bf..9227efac 100644 --- a/tests/fuzz.cc +++ b/tests/fuzz.cc @@ -16,6 +16,43 @@ static void die(const char *msg) assert(false); } +static TPM_RESULT mytpm_io_init(void) +{ + return TPM_SUCCESS; +} + +static TPM_RESULT mytpm_io_getlocality(TPM_MODIFIER_INDICATOR *locModif, + uint32_t tpm_number) +{ + *locModif = 0; + + return TPM_SUCCESS; +} + +static TPM_RESULT mytpm_io_getphysicalpresence(TPM_BOOL *phyPres, + uint32_t tpm_number) +{ + *phyPres = FALSE; + + return TPM_SUCCESS; +} + +static TPM_RESULT mytpm_nvram_loaddata(unsigned char **data, + uint32_t *length, + uint32_t tpm_number, + const char *name) +{ + return TPM_RETRY; +} + +static TPM_RESULT mytpm_nvram_storedata(const unsigned char *data, + uint32_t length, + uint32_t tpm_number, + const char *name) +{ + return TPM_SUCCESS; +} + extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { unsigned char *rbuffer = NULL; @@ -25,6 +62,19 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) unsigned char startup[] = { 0x80, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x44, 0x00, 0x00 }; + struct libtpms_callbacks cbs = { + .sizeOfStruct = sizeof(struct libtpms_callbacks), + .tpm_nvram_init = NULL, + .tpm_nvram_loaddata = mytpm_nvram_loaddata, + .tpm_nvram_storedata = mytpm_nvram_storedata, + .tpm_nvram_deletename = NULL, + .tpm_io_init = mytpm_io_init, + .tpm_io_getlocality = mytpm_io_getlocality, + .tpm_io_getphysicalpresence = mytpm_io_getphysicalpresence, + }; + res = TPMLIB_RegisterCallbacks(&cbs); + if (res != TPM_SUCCESS) + die("Could not register callbacks\n"); res = TPMLIB_ChooseTPMVersion(TPMLIB_TPM_VERSION_2); if (res != TPM_SUCCESS)