Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Unified Diff: firmware/lib/vboot_firmware.c

Issue 6685068: Add VbSharedData field parsing (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/vboot_reference.git@master
Patch Set: Print flags as hex Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « firmware/lib/vboot_common.c ('k') | firmware/stub/load_firmware_stub.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: firmware/lib/vboot_firmware.c
diff --git a/firmware/lib/vboot_firmware.c b/firmware/lib/vboot_firmware.c
index 9172e5c89e75ba9ab11c197c6da0b4b3c60b42f3..dd006f3a3173543dc4408edd6cf874865961451e 100644
--- a/firmware/lib/vboot_firmware.c
+++ b/firmware/lib/vboot_firmware.c
@@ -109,6 +109,8 @@ int LoadFirmware(LoadFirmwareParams* params) {
/* Parse flags */
is_dev = (params->boot_flags & BOOT_FLAG_DEVELOPER ? 1 : 0);
+ if (is_dev)
+ shared->flags |= VBSD_LF_DEV_SWITCH_ON;
/* Initialize the TPM and read rollback indices. */
VBPERFSTART("VB_TPMI");
@@ -122,12 +124,15 @@ int LoadFirmware(LoadFirmwareParams* params) {
recovery = VBNV_RECOVERY_RO_TPM_ERROR;
goto LoadFirmwareExit;
}
+ shared->fw_version_tpm_start = tpm_version;
VBPERFEND("VB_TPMI");
/* Read try-b count and decrement if necessary */
VbNvGet(vnc, VBNV_TRY_B_COUNT, &try_b_count);
- if (0 != try_b_count)
+ if (0 != try_b_count) {
VbNvSet(vnc, VBNV_TRY_B_COUNT, try_b_count - 1);
+ shared->flags |= VBSD_FWB_TRIED;
+ }
VbNvSet(vnc, VBNV_TRIED_FIRMWARE_B, try_b_count ? 1 : 0);
/* Allocate our internal data */
@@ -146,15 +151,18 @@ int LoadFirmware(LoadFirmwareParams* params) {
uint64_t key_version;
uint64_t combined_version;
uint8_t* body_digest;
+ uint8_t* check_result;
/* If try B count is non-zero try firmware B first */
index = (try_b_count ? 1 - i : i);
if (0 == index) {
key_block = (VbKeyBlockHeader*)params->verification_block_0;
vblock_size = params->verification_size_0;
+ check_result = &shared->check_fw_a_result;
} else {
key_block = (VbKeyBlockHeader*)params->verification_block_1;
vblock_size = params->verification_size_1;
+ check_result = &shared->check_fw_b_result;
}
/* Check the key block flags against the current boot mode. Do this
@@ -164,11 +172,13 @@ int LoadFirmware(LoadFirmwareParams* params) {
(is_dev ? KEY_BLOCK_FLAG_DEVELOPER_1 :
KEY_BLOCK_FLAG_DEVELOPER_0))) {
VBDEBUG(("Developer flag mismatch.\n"));
+ *check_result = VBSD_LF_CHECK_DEV_MISMATCH;
continue;
}
/* RW firmware never runs in recovery mode. */
if (!(key_block->key_block_flags & KEY_BLOCK_FLAG_RECOVERY_0)) {
VBDEBUG(("Recovery flag mismatch.\n"));
+ *check_result = VBSD_LF_CHECK_REC_MISMATCH;
continue;
}
@@ -176,6 +186,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
VBPERFSTART("VB_VKB");
if ((0 != KeyBlockVerify(key_block, vblock_size, root_key, 0))) {
VBDEBUG(("Key block verification failed.\n"));
+ *check_result = VBSD_LF_CHECK_VERIFY_KEYBLOCK;
VBPERFEND("VB_VKB");
continue;
}
@@ -185,6 +196,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
key_version = key_block->data_key.key_version;
if (key_version < (tpm_version >> 16)) {
VBDEBUG(("Key rollback detected.\n"));
+ *check_result = VBSD_LF_CHECK_KEY_ROLLBACK;
continue;
}
@@ -192,6 +204,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
data_key = PublicKeyToRSA(&key_block->data_key);
if (!data_key) {
VBDEBUG(("Unable to parse data key.\n"));
+ *check_result = VBSD_LF_CHECK_DATA_KEY_PARSE;
continue;
}
@@ -203,6 +216,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
vblock_size - key_block->key_block_size,
data_key))) {
VBDEBUG(("Preamble verfication failed.\n"));
+ *check_result = VBSD_LF_CHECK_VERIFY_PREAMBLE;
RSAPublicKeyFree(data_key);
VBPERFEND("VB_VPB");
continue;
@@ -214,10 +228,14 @@ int LoadFirmware(LoadFirmwareParams* params) {
(preamble->firmware_version & 0xFFFF));
if (combined_version < tpm_version) {
VBDEBUG(("Firmware version rollback detected.\n"));
+ *check_result = VBSD_LF_CHECK_FW_ROLLBACK;
RSAPublicKeyFree(data_key);
continue;
}
+ /* Header for this firmware is valid */
+ *check_result = VBSD_LF_CHECK_HEADER_VALID;
+
/* Check for lowest key version from a valid header. */
if (lowest_version > combined_version)
lowest_version = combined_version;
@@ -234,6 +252,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
lfi->body_size_accum = 0;
if (0 != GetFirmwareBody(params, index)) {
VBDEBUG(("GetFirmwareBody() failed for index %d\n", index));
+ *check_result = VBSD_LF_CHECK_GET_FW_BODY;
RSAPublicKeyFree(data_key);
VBPERFEND("VB_RFD");
continue;
@@ -242,6 +261,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
VBDEBUG(("Hash updated %d bytes but expected %d\n",
(int)lfi->body_size_accum,
(int)preamble->body_signature.data_size));
+ *check_result = VBSD_LF_CHECK_HASH_WRONG_SIZE;
RSAPublicKeyFree(data_key);
VBPERFEND("VB_RFD");
continue;
@@ -253,6 +273,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
body_digest = DigestFinal(&lfi->body_digest_context);
if (0 != VerifyDigest(body_digest, &preamble->body_signature, data_key)) {
VBDEBUG(("Firmware body verification failed.\n"));
+ *check_result = VBSD_LF_CHECK_VERIFY_BODY;
RSAPublicKeyFree(data_key);
Free(body_digest);
VBPERFEND("VB_VFD");
@@ -266,6 +287,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
/* If we're still here, the firmware is valid. */
VBDEBUG(("Firmware %d is valid.\n", index));
+ *check_result = VBSD_LF_CHECK_VALID;
if (-1 == good_index) {
/* Save the key we actually used */
if (0 != VbSharedDataSetKernelKey(shared, &preamble->kernel_subkey)) {
@@ -312,6 +334,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
if (good_index >= 0) {
/* Update TPM if necessary */
+ shared->fw_version_lowest = (uint32_t)lowest_version;
if (lowest_version > tpm_version) {
VBPERFSTART("VB_TPMU");
status = RollbackFirmwareWrite((uint32_t)lowest_version);
@@ -341,6 +364,7 @@ int LoadFirmware(LoadFirmwareParams* params) {
/* Success */
VBDEBUG(("Will boot firmware index %d\n", (int)params->firmware_index));
+ shared->firmware_index = (uint8_t)params->firmware_index;
retval = LOAD_FIRMWARE_SUCCESS;
} else {
/* No good firmware, so go to recovery mode. */
« no previous file with comments | « firmware/lib/vboot_common.c ('k') | firmware/stub/load_firmware_stub.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698