summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2019-08-01 13:36:44 +0800
committerCommit Bot <commit-bot@chromium.org>2019-08-06 06:07:01 +0000
commit9c906110972f538ee5753845916ebd1f826f54b6 (patch)
tree733c4d13b29a827c45159969baf4daec5147a0e5
parent1db2f3801a8843a1d6380a0969d6836b41ca474e (diff)
downloadvboot-9c906110972f538ee5753845916ebd1f826f54b6.tar.gz
vboot/tpm: fix return type inconsistencies
TPM errors and vboot errors were getting mixed up. Note that this patch changes a function signature in the vboot1 API. Any callers of the function should be updated accordingly. BUG=b:124141368, chromium:988410 TEST=make clean && make runtests BRANCH=none Change-Id: Idf332ca9ac61b5771fccf9e2ce75e8689c0aace9 Signed-off-by: Joel Kitching <kitching@google.com> Cq-Depend: chromium:1730374 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/1729712 Reviewed-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org> Tested-by: Joel Kitching <kitching@chromium.org>
-rw-r--r--firmware/include/vboot_api.h16
-rw-r--r--firmware/lib/tpm2_lite/tlcl.c3
-rw-r--r--firmware/lib/tpm_lite/tlcl.c2
-rw-r--r--firmware/stub/tpm_lite_stub.c20
-rw-r--r--tests/tlcl_tests.c4
5 files changed, 28 insertions, 17 deletions
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h
index 6f5aab2b..86c00215 100644
--- a/firmware/include/vboot_api.h
+++ b/firmware/include/vboot_api.h
@@ -263,12 +263,22 @@ VbError_t VbExTpmClose(void);
VbError_t VbExTpmOpen(void);
/**
+ * Send request to TPM and receive response
+ *
* Send a request_length-byte request to the TPM and receive a response. On
* input, response_length is the size of the response buffer in bytes. On
* exit, response_length is set to the actual received response length in
- * bytes. */
-VbError_t VbExTpmSendReceive(const uint8_t *request, uint32_t request_length,
- uint8_t *response, uint32_t *response_length);
+ * bytes.
+ *
+ * @param request Pointer to request buffer
+ * @param request_length Number of bytes to send
+ * @param response Pointer to response buffer
+ * @param response_length Size of response buffer; on return,
+ * set to number of received bytes
+ * @return TPM_SUCCESS, or non-zero if error.
+ */
+uint32_t VbExTpmSendReceive(const uint8_t *request, uint32_t request_length,
+ uint8_t *response, uint32_t *response_length);
#ifdef CHROMEOS_ENVIRONMENT
diff --git a/firmware/lib/tpm2_lite/tlcl.c b/firmware/lib/tpm2_lite/tlcl.c
index 8705143a..9e6bc49f 100644
--- a/firmware/lib/tpm2_lite/tlcl.c
+++ b/firmware/lib/tpm2_lite/tlcl.c
@@ -38,7 +38,8 @@ static uint32_t tpm_get_response(TPM_CC command,
{
/* Command/response buffer. */
static uint8_t cr_buffer[TPM_BUFFER_SIZE];
- int out_size, res;
+ int out_size;
+ uint32_t res;
uint32_t in_size;
out_size = tpm_marshal_command(command, command_body,
diff --git a/firmware/lib/tpm_lite/tlcl.c b/firmware/lib/tpm_lite/tlcl.c
index 41f7cad9..fac992f9 100644
--- a/firmware/lib/tpm_lite/tlcl.c
+++ b/firmware/lib/tpm_lite/tlcl.c
@@ -80,7 +80,7 @@ static uint32_t TlclSendReceiveNoRetry(const uint8_t* request,
result = VbExTpmSendReceive(request, TpmCommandSize(request),
response, &response_length);
- if (0 != result) {
+ if (TPM_SUCCESS != result) {
/* Communication with TPM failed, so response is garbage */
VB2_DEBUG("TPM: command 0x%x send/receive failed: 0x%x\n",
TpmCommandCode(request), result);
diff --git a/firmware/stub/tpm_lite_stub.c b/firmware/stub/tpm_lite_stub.c
index e9994660..673a3574 100644
--- a/firmware/stub/tpm_lite_stub.c
+++ b/firmware/stub/tpm_lite_stub.c
@@ -49,7 +49,7 @@ static int exit_on_failure = 1;
/* Similar to VbExError, only handle the non-exit case.
*/
-static VbError_t DoError(VbError_t result, const char* format, ...)
+static int DoError(int result, const char* format, ...)
{
va_list ap;
va_start(ap, format);
@@ -78,8 +78,8 @@ __attribute__((unused)) static void DbgPrintBytes(const uint8_t* a, int n)
/* Executes a command on the TPM.
*/
-static VbError_t TpmExecute(const uint8_t *in, const uint32_t in_len,
- uint8_t *out, uint32_t *pout_len)
+static uint32_t TpmExecute(const uint8_t *in, const uint32_t in_len,
+ uint8_t *out, uint32_t *pout_len)
{
uint8_t response[TPM_MAX_COMMAND_SIZE];
if (in_len <= 0) {
@@ -153,7 +153,7 @@ static VbError_t TpmExecute(const uint8_t *in, const uint32_t in_len,
}
}
}
- return VBERROR_SUCCESS;
+ return TPM_SUCCESS;
}
/* Gets the tag field of a TPM command.
@@ -225,12 +225,12 @@ VbError_t VbExTpmOpen(void)
delay.tv_nsec = OPEN_RETRY_DELAY_NS;
nanosleep(&delay, NULL);
}
- return DoError(TPM_E_NO_DEVICE, "TPM: Cannot open TPM device %s: %s\n",
+ return DoError(VBERROR_UNKNOWN, "TPM: Cannot open TPM device %s: %s\n",
device_path, strerror(saved_errno));
}
-VbError_t VbExTpmSendReceive(const uint8_t* request, uint32_t request_length,
- uint8_t* response, uint32_t* response_length)
+uint32_t VbExTpmSendReceive(const uint8_t* request, uint32_t request_length,
+ uint8_t* response, uint32_t* response_length)
{
/*
* In a real firmware implementation, this function should contain
@@ -253,7 +253,7 @@ VbError_t VbExTpmSendReceive(const uint8_t* request, uint32_t request_length,
#ifndef NDEBUG
int tag, response_tag;
#endif
- VbError_t result;
+ uint32_t result;
#ifdef VBOOT_DEBUG
struct timeval before, after;
@@ -263,7 +263,7 @@ VbError_t VbExTpmSendReceive(const uint8_t* request, uint32_t request_length,
#endif
result = TpmExecute(request, request_length, response, response_length);
- if (result != VBERROR_SUCCESS)
+ if (result != TPM_SUCCESS)
return result;
#ifdef VBOOT_DEBUG
@@ -289,7 +289,7 @@ VbError_t VbExTpmSendReceive(const uint8_t* request, uint32_t request_length,
assert(*response_length == TpmResponseSize(response));
#endif
- return VBERROR_SUCCESS;
+ return TPM_SUCCESS;
}
VbError_t VbExTpmGetRandom(uint8_t *buf, uint32_t length)
diff --git a/tests/tlcl_tests.c b/tests/tlcl_tests.c
index f9f990d9..fc6dee54 100644
--- a/tests/tlcl_tests.c
+++ b/tests/tlcl_tests.c
@@ -76,8 +76,8 @@ VbError_t VbExTpmClose(void)
return mock_retval;
}
-VbError_t VbExTpmSendReceive(const uint8_t *request, uint32_t request_length,
- uint8_t *response, uint32_t *response_length)
+uint32_t VbExTpmSendReceive(const uint8_t *request, uint32_t request_length,
+ uint8_t *response, uint32_t *response_length)
{
struct srcall *c = calls + ncalls++;