summaryrefslogtreecommitdiffstats
path: root/src/security
diff options
context:
space:
mode:
authorJon Murphy <jpmurphy@google.com>2023-09-05 10:37:05 -0600
committerKarthik Ramasubramanian <kramasub@google.com>2023-09-18 16:20:09 +0000
commit24604810252c8af7b7f350485f57a646718a5157 (patch)
treef4a1607df0a43278c5bd7166b02fed36d1affddb /src/security
parent277db94ebbb635f93cce426af2450ad0581485d4 (diff)
downloadcoreboot-24604810252c8af7b7f350485f57a646718a5157.tar.gz
coreboot-24604810252c8af7b7f350485f57a646718a5157.tar.bz2
coreboot-24604810252c8af7b7f350485f57a646718a5157.zip
drivers/tpm: Make temp test value naming consistent
Make naming convention consistent across all functions return values. BUG=b:296439237 TEST=Boot to OS on Skyrim BRANCH=None Change-Id: If86805b39048800276ab90b7687644ec2a0d4bee Signed-off-by: Jon Murphy <jpmurphy@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/77536 Reviewed-by: Yu-Ping Wu <yupingso@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Karthik Ramasubramanian <kramasub@google.com> Reviewed-by: Eric Lai <eric_lai@quanta.corp-partner.google.com>
Diffstat (limited to 'src/security')
-rw-r--r--src/security/tpm/tspi/crtm.c6
-rw-r--r--src/security/tpm/tspi/tspi.c116
-rw-r--r--src/security/tpm/tss/tcg-1.2/tss.c72
-rw-r--r--src/security/vboot/secdata_tpm.c148
-rw-r--r--src/security/vboot/tpm_common.c8
-rw-r--r--src/security/vboot/vboot_logic.c28
6 files changed, 191 insertions, 187 deletions
diff --git a/src/security/tpm/tspi/crtm.c b/src/security/tpm/tspi/crtm.c
index 36dffb857630..4f29ad134b22 100644
--- a/src/security/tpm/tspi/crtm.c
+++ b/src/security/tpm/tspi/crtm.c
@@ -192,11 +192,11 @@ int tspi_measure_cache_to_pcr(void)
i = 0;
while (!tpm_log_get(i++, &pcr, &digest_data, &digest_algo, &event_name)) {
printk(BIOS_DEBUG, "TPM: Write digest for %s into PCR %d\n", event_name, pcr);
- int result = tlcl_extend(pcr, digest_data, digest_algo);
- if (result != TPM_SUCCESS) {
+ int rc = tlcl_extend(pcr, digest_data, digest_algo);
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR,
"TPM: Writing digest of %s into PCR failed with error %d\n",
- event_name, result);
+ event_name, rc);
return VB2_ERROR_UNKNOWN;
}
}
diff --git a/src/security/tpm/tspi/tspi.c b/src/security/tpm/tspi/tspi.c
index ec695819fd84..22383d40276e 100644
--- a/src/security/tpm/tspi/tspi.c
+++ b/src/security/tpm/tspi/tspi.c
@@ -15,49 +15,49 @@ static uint32_t tpm1_invoke_state_machine(void)
{
uint8_t disabled;
uint8_t deactivated;
- uint32_t result = TPM_SUCCESS;
+ uint32_t rc = TPM_SUCCESS;
/* Check that the TPM is enabled and activated. */
- result = tlcl_get_flags(&disabled, &deactivated, NULL);
- if (result != TPM_SUCCESS) {
+ rc = tlcl_get_flags(&disabled, &deactivated, NULL);
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't read capabilities.\n");
- return result;
+ return rc;
}
if (disabled) {
printk(BIOS_INFO, "TPM: is disabled. Enabling...\n");
- result = tlcl_set_enable();
- if (result != TPM_SUCCESS) {
+ rc = tlcl_set_enable();
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't set enabled state.\n");
- return result;
+ return rc;
}
}
if (!!deactivated != CONFIG(TPM_DEACTIVATE)) {
printk(BIOS_INFO,
"TPM: Unexpected TPM deactivated state. Toggling...\n");
- result = tlcl_set_deactivated(!deactivated);
- if (result != TPM_SUCCESS) {
+ rc = tlcl_set_deactivated(!deactivated);
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR,
"TPM: Can't toggle deactivated state.\n");
- return result;
+ return rc;
}
deactivated = !deactivated;
- result = TPM_E_MUST_REBOOT;
+ rc = TPM_E_MUST_REBOOT;
}
- return result;
+ return rc;
}
#endif
static uint32_t tpm_setup_s3_helper(void)
{
- uint32_t result;
+ uint32_t rc;
- result = tlcl_resume();
- switch (result) {
+ rc = tlcl_resume();
+ switch (rc) {
case TPM_SUCCESS:
break;
@@ -67,25 +67,25 @@ static uint32_t tpm_setup_s3_helper(void)
* in S3, so it's already initialized.
*/
printk(BIOS_INFO, "TPM: Already initialized.\n");
- result = TPM_SUCCESS;
+ rc = TPM_SUCCESS;
break;
default:
- printk(BIOS_ERR, "TPM: Resume failed (%#x).\n", result);
+ printk(BIOS_ERR, "TPM: Resume failed (%#x).\n", rc);
break;
}
- return result;
+ return rc;
}
-static uint32_t tpm_setup_epilogue(uint32_t result)
+static uint32_t tpm_setup_epilogue(uint32_t rc)
{
- if (result != TPM_SUCCESS)
+ if (rc != TPM_SUCCESS)
post_code(POSTCODE_TPM_FAILURE);
else
printk(BIOS_INFO, "TPM: setup succeeded\n");
- return result;
+ return rc;
}
static int tpm_is_setup;
@@ -135,12 +135,12 @@ static inline int tspi_tpm_is_setup(void)
*/
uint32_t tpm_setup(int s3flag)
{
- uint32_t result;
+ uint32_t rc;
- result = tlcl_lib_init();
- if (result != TPM_SUCCESS) {
+ rc = tlcl_lib_init();
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't initialize.\n");
- return tpm_setup_epilogue(result);
+ return tpm_setup_epilogue(rc);
}
/* Handle special init for S3 resume path */
@@ -149,69 +149,69 @@ uint32_t tpm_setup(int s3flag)
return tpm_setup_epilogue(tpm_setup_s3_helper());
}
- result = tlcl_startup();
+ rc = tlcl_startup();
if (CONFIG(TPM_STARTUP_IGNORE_POSTINIT)
- && result == TPM_E_INVALID_POSTINIT) {
+ && rc == TPM_E_INVALID_POSTINIT) {
printk(BIOS_DEBUG, "TPM: ignoring invalid POSTINIT\n");
- result = TPM_SUCCESS;
+ rc = TPM_SUCCESS;
}
- if (result != TPM_SUCCESS) {
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't run startup command.\n");
- return tpm_setup_epilogue(result);
+ return tpm_setup_epilogue(rc);
}
- result = tlcl_assert_physical_presence();
- if (result != TPM_SUCCESS) {
+ rc = tlcl_assert_physical_presence();
+ if (rc != TPM_SUCCESS) {
/*
* It is possible that the TPM was delivered with the physical
* presence command disabled. This tries enabling it, then
* tries asserting PP again.
*/
- result = tlcl_physical_presence_cmd_enable();
- if (result != TPM_SUCCESS) {
+ rc = tlcl_physical_presence_cmd_enable();
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't enable physical presence command.\n");
- return tpm_setup_epilogue(result);
+ return tpm_setup_epilogue(rc);
}
- result = tlcl_assert_physical_presence();
- if (result != TPM_SUCCESS) {
+ rc = tlcl_assert_physical_presence();
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't assert physical presence.\n");
- return tpm_setup_epilogue(result);
+ return tpm_setup_epilogue(rc);
}
}
#if CONFIG(TPM1)
- result = tpm1_invoke_state_machine();
+ rc = tpm1_invoke_state_machine();
#endif
if (CONFIG(TPM_MEASURED_BOOT))
- result = tspi_measure_cache_to_pcr();
+ rc = tspi_measure_cache_to_pcr();
tpm_is_setup = 1;
- return tpm_setup_epilogue(result);
+ return tpm_setup_epilogue(rc);
}
uint32_t tpm_clear_and_reenable(void)
{
- uint32_t result;
+ uint32_t rc;
printk(BIOS_INFO, "TPM: Clear and re-enable\n");
- result = tlcl_force_clear();
- if (result != TPM_SUCCESS) {
+ rc = tlcl_force_clear();
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't initiate a force clear.\n");
- return result;
+ return rc;
}
#if CONFIG(TPM1)
- result = tlcl_set_enable();
- if (result != TPM_SUCCESS) {
+ rc = tlcl_set_enable();
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't set enabled state.\n");
- return result;
+ return rc;
}
- result = tlcl_set_deactivated(0);
- if (result != TPM_SUCCESS) {
+ rc = tlcl_set_deactivated(0);
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't set deactivated state.\n");
- return result;
+ return rc;
}
#endif
@@ -221,24 +221,24 @@ uint32_t tpm_clear_and_reenable(void)
uint32_t tpm_extend_pcr(int pcr, enum vb2_hash_algorithm digest_algo,
const uint8_t *digest, size_t digest_len, const char *name)
{
- uint32_t result;
+ uint32_t rc;
if (!digest)
return TPM_E_IOERROR;
if (tspi_tpm_is_setup()) {
- result = tlcl_lib_init();
- if (result != TPM_SUCCESS) {
+ rc = tlcl_lib_init();
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Can't initialize library.\n");
- return result;
+ return rc;
}
printk(BIOS_DEBUG, "TPM: Extending digest for `%s` into PCR %d\n", name, pcr);
- result = tlcl_extend(pcr, digest, digest_algo);
- if (result != TPM_SUCCESS) {
+ rc = tlcl_extend(pcr, digest, digest_algo);
+ if (rc != TPM_SUCCESS) {
printk(BIOS_ERR, "TPM: Extending hash for `%s` into PCR %d failed.\n",
name, pcr);
- return result;
+ return rc;
}
}
diff --git a/src/security/tpm/tss/tcg-1.2/tss.c b/src/security/tpm/tss/tcg-1.2/tss.c
index 39c44eca9f32..9c19f7f3cbc0 100644
--- a/src/security/tpm/tss/tcg-1.2/tss.c
+++ b/src/security/tpm/tss/tcg-1.2/tss.c
@@ -57,9 +57,9 @@ static inline int tpm_command_size(const uint8_t *buffer)
/* Gets the code field of a TPM command. */
static inline int tpm_command_code(const uint8_t *buffer)
{
- uint32_t code;
- from_tpm_uint32(buffer + sizeof(uint16_t) + sizeof(uint32_t), &code);
- return code;
+ uint32_t rc;
+ from_tpm_uint32(buffer + sizeof(uint16_t) + sizeof(uint32_t), &rc);
+ return rc;
}
/* Gets the return code field of a TPM result. */
@@ -76,27 +76,27 @@ static uint32_t tlcl_send_receive_no_retry(const uint8_t *request,
uint8_t *response, int max_length)
{
uint32_t response_length = max_length;
- uint32_t result;
+ uint32_t rc;
- result = tpm_send_receive(request, tpm_command_size(request),
+ rc = tpm_send_receive(request, tpm_command_size(request),
response, &response_length);
- if (result != 0) {
+ if (rc != 0) {
/* Communication with TPM failed, so response is garbage */
VBDEBUG("TPM: command 0x%x send/receive failed: 0x%x\n",
- tpm_command_code(request), result);
- return result;
+ tpm_command_code(request), rc);
+ return rc;
}
/* Otherwise, use the result code from the response */
- result = tpm_return_code(response);
+ rc = tpm_return_code(response);
/* TODO: add paranoia about returned response_length vs. max_length
* (and possibly expected length from the response header). See
* crosbug.com/17017 */
VBDEBUG("TPM: command 0x%x returned 0x%x\n",
- tpm_command_code(request), result);
+ tpm_command_code(request), rc);
-return result;
+return rc;
}
/* Sends a TPM command and gets a response. Returns 0 if success or the TPM
@@ -104,17 +104,17 @@ return result;
uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
int max_length)
{
- uint32_t result = tlcl_send_receive_no_retry(request, response,
+ uint32_t rc = tlcl_send_receive_no_retry(request, response,
max_length);
/* If the command fails because the self test has not completed, try it
* again after attempting to ensure that the self test has completed. */
- if (result == TPM_E_NEEDS_SELFTEST || result == TPM_E_DOING_SELFTEST) {
- result = tlcl_continue_self_test();
- if (result != TPM_SUCCESS)
- return result;
+ if (rc == TPM_E_NEEDS_SELFTEST || rc == TPM_E_DOING_SELFTEST) {
+ rc = tlcl_continue_self_test();
+ if (rc != TPM_SUCCESS)
+ return rc;
#if defined(TPM_BLOCKING_CONTINUESELFTEST) || defined(VB_RECOVERY_MODE)
/* Retry only once */
- result = tlcl_send_receive_no_retry(request, response,
+ rc = tlcl_send_receive_no_retry(request, response,
max_length);
#else
/* This needs serious testing. The TPM specification says: "iii.
@@ -123,12 +123,12 @@ uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
* ContinueSelfTest is non-blocking, how do we know that the
* actions have completed other than trying again? */
do {
- result = tlcl_send_receive_no_retry(request, response,
+ rc = tlcl_send_receive_no_retry(request, response,
max_length);
- } while (result == TPM_E_DOING_SELFTEST);
+ } while (rc == TPM_E_DOING_SELFTEST);
#endif
}
- return result;
+ return rc;
}
/* Sends a command and returns the error code. */
@@ -226,15 +226,15 @@ uint32_t tlcl_read(uint32_t index, void *data, uint32_t length)
struct s_tpm_nv_read_cmd cmd;
uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
uint32_t result_length;
- uint32_t result;
+ uint32_t rc;
VBDEBUG("TPM: %s(0x%x, %d)\n", __func__, index, length);
memcpy(&cmd, &tpm_nv_read_cmd, sizeof(cmd));
to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.index, index);
to_tpm_uint32(cmd.buffer + tpm_nv_read_cmd.length, length);
- result = tlcl_send_receive(cmd.buffer, response, sizeof(response));
- if (result == TPM_SUCCESS && length > 0) {
+ rc = tlcl_send_receive(cmd.buffer, response, sizeof(response));
+ if (rc == TPM_SUCCESS && length > 0) {
uint8_t *nv_read_cursor = response + kTpmResponseHeaderLength;
from_tpm_uint32(nv_read_cursor, &result_length);
if (result_length > length)
@@ -243,7 +243,7 @@ uint32_t tlcl_read(uint32_t index, void *data, uint32_t length)
memcpy(data, nv_read_cursor, result_length);
}
- return result;
+ return rc;
}
uint32_t tlcl_assert_physical_presence(void)
@@ -295,24 +295,24 @@ uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags)
{
uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
uint32_t size;
- uint32_t result = tlcl_send_receive(tpm_getflags_cmd.buffer, response,
+ uint32_t rc = tlcl_send_receive(tpm_getflags_cmd.buffer, response,
sizeof(response));
- if (result != TPM_SUCCESS)
- return result;
+ if (rc != TPM_SUCCESS)
+ return rc;
from_tpm_uint32(response + kTpmResponseHeaderLength, &size);
if (size != sizeof(TPM_PERMANENT_FLAGS))
return TPM_E_IOERROR;
memcpy(pflags, response + kTpmResponseHeaderLength + sizeof(size),
sizeof(TPM_PERMANENT_FLAGS));
- return result;
+ return rc;
}
uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
uint8_t *nvlocked)
{
TPM_PERMANENT_FLAGS pflags;
- uint32_t result = tlcl_get_permanent_flags(&pflags);
- if (result == TPM_SUCCESS) {
+ uint32_t rc = tlcl_get_permanent_flags(&pflags);
+ if (rc == TPM_SUCCESS) {
if (disable)
*disable = pflags.disable;
if (deactivated)
@@ -322,7 +322,7 @@ uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
VBDEBUG("TPM: flags disable=%d, deactivated=%d, nvlocked=%d\n",
pflags.disable, pflags.deactivated, pflags.nvLocked);
}
- return result;
+ return rc;
}
uint32_t tlcl_set_global_lock(void)
@@ -352,16 +352,16 @@ uint32_t tlcl_get_permissions(uint32_t index, uint32_t *permissions)
struct s_tpm_getpermissions_cmd cmd;
uint8_t response[TPM_LARGE_ENOUGH_COMMAND_SIZE];
uint8_t *nvdata;
- uint32_t result;
+ uint32_t rc;
uint32_t size;
memcpy(&cmd, &tpm_getpermissions_cmd, sizeof(cmd));
to_tpm_uint32(cmd.buffer + tpm_getpermissions_cmd.index, index);
- result = tlcl_send_receive(cmd.buffer, response, sizeof(response));
- if (result != TPM_SUCCESS)
- return result;
+ rc = tlcl_send_receive(cmd.buffer, response, sizeof(response));
+ if (rc != TPM_SUCCESS)
+ return rc;
nvdata = response + kTpmResponseHeaderLength + sizeof(size);
from_tpm_uint32(nvdata + kNvDataPublicPermissionsOffset, permissions);
- return result;
+ return rc;
}
diff --git a/src/security/vboot/secdata_tpm.c b/src/security/vboot/secdata_tpm.c
index 3229dd022f07..27d16e1776fb 100644
--- a/src/security/vboot/secdata_tpm.c
+++ b/src/security/vboot/secdata_tpm.c
@@ -18,11 +18,11 @@
printk(BIOS_INFO, "%s():%d: " format, __func__, __LINE__, ## args)
#define RETURN_ON_FAILURE(tpm_cmd) do { \
- uint32_t result_; \
- if ((result_ = (tpm_cmd)) != TPM_SUCCESS) { \
+ uint32_t rc_; \
+ if ((rc_ = (tpm_cmd)) != TPM_SUCCESS) { \
VBDEBUG("Antirollback: %08x returned by " #tpm_cmd \
- "\n", (int)result_); \
- return result_; \
+ "\n", (int)rc_); \
+ return rc_; \
} \
} while (0)
@@ -51,17 +51,17 @@ uint32_t antirollback_read_space_kernel(struct vb2_context *ctx)
}
uint8_t size = VB2_SECDATA_KERNEL_SIZE;
- uint32_t ret;
+ uint32_t rc;
/* Start with the version 1.0 size used by all modern Cr50/Ti50 boards. */
- ret = tlcl_read(KERNEL_NV_INDEX, ctx->secdata_kernel, size);
- if (ret == TPM_E_RANGE) {
+ rc = tlcl_read(KERNEL_NV_INDEX, ctx->secdata_kernel, size);
+ if (rc == TPM_E_RANGE) {
/* Fallback to version 0.2(minimum) size and re-read. */
VBDEBUG("Antirollback: NV read out of range, trying min size\n");
size = VB2_SECDATA_KERNEL_MIN_SIZE;
- ret = tlcl_read(KERNEL_NV_INDEX, ctx->secdata_kernel, size);
+ rc = tlcl_read(KERNEL_NV_INDEX, ctx->secdata_kernel, size);
}
- RETURN_ON_FAILURE(ret);
+ RETURN_ON_FAILURE(rc);
if (vb2api_secdata_kernel_check(ctx, &size) == VB2_ERROR_SECDATA_KERNEL_INCOMPLETE)
/* Re-read. vboot will run the check and handle errors. */
@@ -206,11 +206,11 @@ static uint32_t define_space(const char *name, uint32_t index, uint32_t length,
const TPMA_NV nv_attributes,
const uint8_t *nv_policy, size_t nv_policy_size)
{
- uint32_t rv;
+ uint32_t rc;
- rv = tlcl_define_space(index, length, nv_attributes, nv_policy,
+ rc = tlcl_define_space(index, length, nv_attributes, nv_policy,
nv_policy_size);
- if (rv == TPM_E_NV_DEFINED) {
+ if (rc == TPM_E_NV_DEFINED) {
/*
* Continue with writing: it may be defined, but not written
* to. In that case a subsequent tlcl_read() would still return
@@ -220,10 +220,10 @@ static uint32_t define_space(const char *name, uint32_t index, uint32_t length,
* in writing once again even if it was written already.
*/
VBDEBUG("%s: %s space already exists\n", __func__, name);
- rv = TPM_SUCCESS;
+ rc = TPM_SUCCESS;
}
- return rv;
+ return rc;
}
/* Nothing special in the TPM2 path yet. */
@@ -236,12 +236,12 @@ static uint32_t setup_space(const char *name, uint32_t index, const void *data,
uint32_t length, const TPMA_NV nv_attributes,
const uint8_t *nv_policy, size_t nv_policy_size)
{
- uint32_t rv;
+ uint32_t rc;
- rv = define_space(name, index, length, nv_attributes, nv_policy,
+ rc = define_space(name, index, length, nv_attributes, nv_policy,
nv_policy_size);
- if (rv != TPM_SUCCESS)
- return rv;
+ if (rc != TPM_SUCCESS)
+ return rc;
return safe_write(index, data, length);
}
@@ -291,7 +291,7 @@ static uint32_t set_mrc_hash_space(uint32_t index, const uint8_t *data)
*/
static uint32_t setup_zte_spaces(void)
{
- uint32_t rv;
+ uint32_t rc;
uint64_t rma_bytes_counter_default = 0;
uint8_t rma_sn_bits_default[16];
uint8_t board_id_default[12];
@@ -302,47 +302,47 @@ static uint32_t setup_zte_spaces(void)
memset(board_id_default, 0xFF, ARRAY_SIZE(board_id_default));
/* Set up RMA + SN Bits */
- rv = setup_space("RMA + SN Bits", ZTE_RMA_SN_BITS_INDEX,
+ rc = setup_space("RMA + SN Bits", ZTE_RMA_SN_BITS_INDEX,
rma_sn_bits_default, sizeof(rma_sn_bits_default),
zte_attr,
unsatisfiable_policy, sizeof(unsatisfiable_policy));
- if (rv != TPM_SUCCESS) {
+ if (rc != TPM_SUCCESS) {
VBDEBUG("%s: Failed to set up RMA + SN Bits space\n", __func__);
- return rv;
+ return rc;
}
- rv = setup_space("Board ID", ZTE_BOARD_ID_NV_INDEX,
+ rc = setup_space("Board ID", ZTE_BOARD_ID_NV_INDEX,
board_id_default, sizeof(board_id_default),
zte_attr,
unsatisfiable_policy, sizeof(unsatisfiable_policy));
- if (rv != TPM_SUCCESS) {
+ if (rc != TPM_SUCCESS) {
VBDEBUG("%s: Failed to set up Board ID space\n", __func__);
- return rv;
+ return rc;
}
/* Set up RMA Bytes counter */
- rv = define_space("RMA Bytes Counter", ZTE_RMA_BYTES_COUNTER_INDEX,
+ rc = define_space("RMA Bytes Counter", ZTE_RMA_BYTES_COUNTER_INDEX,
sizeof(rma_bytes_counter_default),
zte_rma_bytes_attr,
unsatisfiable_policy, sizeof(unsatisfiable_policy));
- if (rv != TPM_SUCCESS) {
+ if (rc != TPM_SUCCESS) {
VBDEBUG("%s: Failed to define RMA Bytes space\n", __func__);
- return rv;
+ return rc;
}
/*
* Since the RMA counter has the BITS attribute, we need to call
* TPM2_NV_SetBits() in order to initialize it.
*/
- rv = tlcl_set_bits(ZTE_RMA_BYTES_COUNTER_INDEX,
+ rc = tlcl_set_bits(ZTE_RMA_BYTES_COUNTER_INDEX,
rma_bytes_counter_default);
- if (rv != TPM_SUCCESS) {
+ if (rc != TPM_SUCCESS) {
VBDEBUG("%s: Failed to init RMA Bytes counter space\n",
__func__);
- return rv;
+ return rc;
}
- return rv;
+ return rc;
}
/*
@@ -363,13 +363,17 @@ static uint32_t enterprise_rollback_create_space(void)
static uint32_t setup_widevine_counter_spaces(void)
{
- uint32_t index, rv;
+ uint32_t index, rc;
for (index = 0; index < NUM_WIDEVINE_COUNTERS; index++) {
- rv = define_space(WIDEVINE_COUNTER_NAME, WIDEVINE_COUNTER_NV_INDEX(index),
- WIDEVINE_COUNTER_SIZE, rw_orderly_counter_attributes, NULL, 0);
- if (rv != TPM_SUCCESS)
- return rv;
+ rc = define_space(WIDEVINE_COUNTER_NAME,
+ WIDEVINE_COUNTER_NV_INDEX(index),
+ WIDEVINE_COUNTER_SIZE,
+ rw_orderly_counter_attributes,
+ NULL,
+ 0);
+ if (rc != TPM_SUCCESS)
+ return rc;
}
return TPM_SUCCESS;
}
@@ -443,7 +447,7 @@ uint32_t antirollback_read_space_mrc_hash(uint32_t index, uint8_t *data, uint32_
uint32_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data, uint32_t size)
{
uint8_t spc_data[HASH_NV_SIZE];
- uint32_t rv;
+ uint32_t rc;
if (size != HASH_NV_SIZE) {
VBDEBUG("TPM: Incorrect buffer size for hash idx 0x%x. "
@@ -452,8 +456,8 @@ uint32_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data,
return TPM_E_WRITE_FAILURE;
}
- rv = read_space_mrc_hash(index, spc_data);
- if (rv == TPM_E_BADINDEX) {
+ rc = read_space_mrc_hash(index, spc_data);
+ if (rc == TPM_E_BADINDEX) {
/*
* If space is not defined already for hash, define
* new space.
@@ -462,8 +466,8 @@ uint32_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data,
return set_mrc_hash_space(index, data);
}
- if (rv != TPM_SUCCESS)
- return rv;
+ if (rc != TPM_SUCCESS)
+ return rc;
return safe_write(index, data, size);
}
@@ -493,7 +497,7 @@ uint32_t antirollback_read_space_vbios_hash(uint8_t *data, uint32_t size)
uint32_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size)
{
uint8_t spc_data[HASH_NV_SIZE];
- uint32_t rv;
+ uint32_t rc;
if (size != HASH_NV_SIZE) {
VBDEBUG("TPM: Incorrect buffer size for hash idx 0x%x. "
@@ -502,8 +506,8 @@ uint32_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size)
return TPM_E_WRITE_FAILURE;
}
- rv = read_space_vbios_hash(spc_data);
- if (rv == TPM_E_BADINDEX) {
+ rc = read_space_vbios_hash(spc_data);
+ if (rc == TPM_E_BADINDEX) {
/*
* If space is not defined already for hash, define
* new space.
@@ -513,8 +517,8 @@ uint32_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size)
rw_space_attributes, NULL, 0);
}
- if (rv != TPM_SUCCESS)
- return rv;
+ if (rc != TPM_SUCCESS)
+ return rc;
return safe_write(VBIOS_CACHE_NV_INDEX, data, size);
}
@@ -530,12 +534,12 @@ uint32_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size)
static uint32_t safe_write(uint32_t index, const void *data, uint32_t length)
{
- uint32_t result = tlcl_write(index, data, length);
- if (result == TPM_E_MAXNVWRITES) {
+ uint32_t rc = tlcl_write(index, data, length);
+ if (rc == TPM_E_MAXNVWRITES) {
RETURN_ON_FAILURE(tpm_clear_and_reenable());
return tlcl_write(index, data, length);
} else {
- return result;
+ return rc;
}
}
@@ -547,26 +551,26 @@ static uint32_t safe_write(uint32_t index, const void *data, uint32_t length)
*/
static uint32_t safe_define_space(uint32_t index, uint32_t perm, uint32_t size)
{
- uint32_t result = tlcl_define_space(index, perm, size);
- if (result == TPM_E_MAXNVWRITES) {
+ uint32_t rc = tlcl_define_space(index, perm, size);
+ if (rc == TPM_E_MAXNVWRITES) {
RETURN_ON_FAILURE(tpm_clear_and_reenable());
return tlcl_define_space(index, perm, size);
} else {
- return result;
+ return rc;
}
}
static uint32_t _factory_initialize_tpm(struct vb2_context *ctx)
{
TPM_PERMANENT_FLAGS pflags;
- uint32_t result;
+ uint32_t rc;
vb2api_secdata_firmware_create(ctx);
vb2api_secdata_kernel_create_v0(ctx);
- result = tlcl_get_permanent_flags(&pflags);
- if (result != TPM_SUCCESS)
- return result;
+ rc = tlcl_get_permanent_flags(&pflags);
+ if (rc != TPM_SUCCESS)
+ return rc;
/*
* TPM may come from the factory without physical presence finalized.
@@ -630,7 +634,7 @@ uint32_t antirollback_lock_space_firmware(void)
*/
static uint32_t factory_initialize_tpm(struct vb2_context *ctx)
{
- uint32_t result;
+ uint32_t rc;
VBDEBUG("TPM: factory initialization\n");
@@ -642,13 +646,13 @@ static uint32_t factory_initialize_tpm(struct vb2_context *ctx)
* test---specifically the ones that set lifetime flags, and are only
* executed once per physical TPM.
*/
- result = tlcl_self_test_full();
- if (result != TPM_SUCCESS)
- return result;
+ rc = tlcl_self_test_full();
+ if (rc != TPM_SUCCESS)
+ return rc;
- result = _factory_initialize_tpm(ctx);
- if (result != TPM_SUCCESS)
- return result;
+ rc = _factory_initialize_tpm(ctx);
+ if (rc != TPM_SUCCESS)
+ return rc;
/* _factory_initialize_tpm() writes initial secdata values to TPM
immediately, so let vboot know that it's up to date now. */
@@ -662,15 +666,15 @@ static uint32_t factory_initialize_tpm(struct vb2_context *ctx)
uint32_t antirollback_read_space_firmware(struct vb2_context *ctx)
{
- uint32_t rv;
+ uint32_t rc;
- rv = tlcl_read(FIRMWARE_NV_INDEX, ctx->secdata_firmware, VB2_SECDATA_FIRMWARE_SIZE);
- if (rv == TPM_E_BADINDEX) {
+ rc = tlcl_read(FIRMWARE_NV_INDEX, ctx->secdata_firmware, VB2_SECDATA_FIRMWARE_SIZE);
+ if (rc == TPM_E_BADINDEX) {
/* This seems the first time we've run. Initialize the TPM. */
VBDEBUG("TPM: Not initialized yet\n");
RETURN_ON_FAILURE(factory_initialize_tpm(ctx));
- } else if (rv != TPM_SUCCESS) {
- printk(BIOS_ERR, "TPM: Failed to read firmware space: %#x\n", rv);
+ } else if (rc != TPM_SUCCESS) {
+ printk(BIOS_ERR, "TPM: Failed to read firmware space: %#x\n", rc);
return TPM_E_CORRUPTED_STATE;
}
@@ -706,10 +710,10 @@ uint32_t antirollback_write_space_kernel(struct vb2_context *ctx)
vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *ctx)
{
- uint32_t rv;
+ uint32_t rc;
printk(BIOS_INFO, "Clearing TPM owner\n");
- rv = tpm_clear_and_reenable();
- if (rv)
+ rc = tpm_clear_and_reenable();
+ if (rc)
return VB2_ERROR_EX_TPM_CLEAR_OWNER;
return VB2_SUCCESS;
}
diff --git a/src/security/vboot/tpm_common.c b/src/security/vboot/tpm_common.c
index e67cc0132225..ad333c6f9ba6 100644
--- a/src/security/vboot/tpm_common.c
+++ b/src/security/vboot/tpm_common.c
@@ -10,13 +10,13 @@
uint32_t vboot_setup_tpm(struct vb2_context *ctx)
{
- uint32_t result;
+ uint32_t rc;
- result = tpm_setup(ctx->flags & VB2_CONTEXT_S3_RESUME);
- if (result == TPM_E_MUST_REBOOT)
+ rc = tpm_setup(ctx->flags & VB2_CONTEXT_S3_RESUME);
+ if (rc == TPM_E_MUST_REBOOT)
ctx->flags |= VB2_CONTEXT_SECDATA_WANTS_REBOOT;
- return result;
+ return rc;
}
vb2_error_t vboot_extend_pcr(struct vb2_context *ctx, int pcr,
diff --git a/src/security/vboot/vboot_logic.c b/src/security/vboot/vboot_logic.c
index 8494a1ba66dd..213ebcce9960 100644
--- a/src/security/vboot/vboot_logic.c
+++ b/src/security/vboot/vboot_logic.c
@@ -127,7 +127,7 @@ static vb2_error_t hash_body(struct vb2_context *ctx,
const size_t hash_digest_sz = sizeof(hash_digest);
size_t block_size = sizeof(block);
size_t offset;
- vb2_error_t rv;
+ vb2_error_t rc;
/* Clear the full digest so that any hash digests less than the
* max have trailing zeros. */
@@ -146,9 +146,9 @@ static vb2_error_t hash_body(struct vb2_context *ctx,
offset = 0;
/* Start the body hash */
- rv = vb2api_init_hash(ctx, VB2_HASH_TAG_FW_BODY);
- if (rv)
- return rv;
+ rc = vb2api_init_hash(ctx, VB2_HASH_TAG_FW_BODY);
+ if (rc)
+ return rc;
/* Extend over the body */
while (remaining) {
@@ -161,9 +161,9 @@ static vb2_error_t hash_body(struct vb2_context *ctx,
return VB2_ERROR_UNKNOWN;
load_ts += timestamp_get() - temp_ts;
- rv = vb2api_extend_hash(ctx, block, block_size);
- if (rv)
- return rv;
+ rc = vb2api_extend_hash(ctx, block, block_size);
+ if (rc)
+ return rc;
remaining -= block_size;
offset += block_size;
@@ -173,9 +173,9 @@ static vb2_error_t hash_body(struct vb2_context *ctx,
timestamp_add_now(TS_HASHING_END);
/* Check the result (with RSA signature verification) */
- rv = vb2api_check_hash_get_digest(ctx, hash_digest, hash_digest_sz);
- if (rv)
- return rv;
+ rc = vb2api_check_hash_get_digest(ctx, hash_digest, hash_digest_sz);
+ if (rc)
+ return rc;
timestamp_add_now(TS_HASH_BODY_END);
@@ -210,10 +210,10 @@ static const char *get_boot_mode_string(uint8_t boot_mode)
static void check_boot_mode(struct vb2_context *ctx)
{
uint8_t boot_mode;
- int rv;
+ int rc;
- rv = tlcl_cr50_get_boot_mode(&boot_mode);
- switch (rv) {
+ rc = tlcl_cr50_get_boot_mode(&boot_mode);
+ switch (rc) {
case TPM_E_NO_SUCH_COMMAND:
printk(BIOS_WARNING, "GSC does not support GET_BOOT_MODE.\n");
/* Proceed to legacy boot model. */
@@ -223,7 +223,7 @@ static void check_boot_mode(struct vb2_context *ctx)
default:
printk(BIOS_ERR,
"Communication error in getting GSC boot mode.\n");
- vb2api_fail(ctx, VB2_RECOVERY_GSC_BOOT_MODE, rv);
+ vb2api_fail(ctx, VB2_RECOVERY_GSC_BOOT_MODE, rc);
return;
}