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

Side by Side Diff: firmware/lib/vboot_kernel.c

Issue 2844024: Ignore TPM return codes in recovery mode (Closed) Base URL: ssh://gitrw.chromium.org/vboot_reference.git
Patch Set: Created 10 years, 6 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 unified diff | Download patch
« no previous file with comments | « firmware/lib/include/rollback_index.h ('k') | firmware/version.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 * 4 *
5 * Functions for loading a kernel from disk. 5 * Functions for loading a kernel from disk.
6 * (Firmware portion) 6 * (Firmware portion)
7 */ 7 */
8 8
9 #include "vboot_kernel.h" 9 #include "vboot_kernel.h"
10 10
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 uint64_t part_start, part_size; 117 uint64_t part_start, part_size;
118 uint64_t blba = params->bytes_per_lba; 118 uint64_t blba = params->bytes_per_lba;
119 uint64_t kbuf_sectors = KBUF_SIZE / blba; 119 uint64_t kbuf_sectors = KBUF_SIZE / blba;
120 uint8_t* kbuf = NULL; 120 uint8_t* kbuf = NULL;
121 int found_partitions = 0; 121 int found_partitions = 0;
122 int good_partition = -1; 122 int good_partition = -1;
123 uint16_t tpm_key_version = 0; 123 uint16_t tpm_key_version = 0;
124 uint16_t tpm_kernel_version = 0; 124 uint16_t tpm_kernel_version = 0;
125 uint64_t lowest_key_version = 0xFFFF; 125 uint64_t lowest_key_version = 0xFFFF;
126 uint64_t lowest_kernel_version = 0xFFFF; 126 uint64_t lowest_kernel_version = 0xFFFF;
127 int is_dev = ((BOOT_FLAG_DEVELOPER & params->boot_flags) && 127 int is_dev = (BOOT_FLAG_DEVELOPER & params->boot_flags);
128 !(BOOT_FLAG_RECOVERY & params->boot_flags)); 128 int is_rec = (BOOT_FLAG_RECOVERY & params->boot_flags);
129 int is_normal = (!(BOOT_FLAG_DEVELOPER & params->boot_flags) && 129 int is_normal = (!is_dev && !is_rec);
130 !(BOOT_FLAG_RECOVERY & params->boot_flags));
131 130
132 /* Clear output params in case we fail */ 131 /* Clear output params in case we fail */
133 params->partition_number = 0; 132 params->partition_number = 0;
134 params->bootloader_address = 0; 133 params->bootloader_address = 0;
135 params->bootloader_size = 0; 134 params->bootloader_size = 0;
136 135
137 /* Let the TPM know if we're in recovery mode */ 136 /* Let the TPM know if we're in recovery mode */
138 if (BOOT_FLAG_RECOVERY & params->boot_flags) { 137 if (is_rec) {
139 if (0 != RollbackKernelRecovery(BOOT_FLAG_DEVELOPER & params->boot_flags 138 if (0 != RollbackKernelRecovery(is_dev ? 1 : 0)) {
Luigi Semenzato 2010/06/24 20:18:43 If our convention for booleans is 0 for false, and
140 ? 1 : 0)) {
141 VBDEBUG(("Error setting up TPM for recovery kernel\n")); 139 VBDEBUG(("Error setting up TPM for recovery kernel\n"));
142 return LOAD_KERNEL_RECOVERY; 140 /* Ignore return code, since we need to boot recovery mode to
141 * fix the TPM. */
143 } 142 }
144 } 143 }
145 144
146 if (is_normal) { 145 if (is_normal) {
147 /* Read current kernel key index from TPM. Assumes TPM is already 146 /* Read current kernel key index from TPM. Assumes TPM is already
148 * initialized. */ 147 * initialized. */
149 if (0 != RollbackKernelRead(&tpm_key_version, &tpm_kernel_version)) { 148 if (0 != RollbackKernelRead(&tpm_key_version, &tpm_kernel_version)) {
150 VBDEBUG(("Unable to get kernel versions from TPM\n")); 149 VBDEBUG(("Unable to get kernel versions from TPM\n"));
151 return LOAD_KERNEL_RECOVERY; 150 return LOAD_KERNEL_RECOVERY;
152 } 151 }
153 } else if (is_dev) { 152 } else if (is_dev && !is_rec) {
154 /* In developer mode, we ignore the kernel subkey, and just use 153 /* In developer mode, we ignore the kernel subkey, and just use
155 * the SHA-512 hash to verify the key block. */ 154 * the SHA-512 hash to verify the key block. */
156 kernel_subkey = NULL; 155 kernel_subkey = NULL;
157 } 156 }
158 157
159 do { 158 do {
160 /* Read GPT data */ 159 /* Read GPT data */
161 gpt.sector_bytes = (uint32_t)blba; 160 gpt.sector_bytes = (uint32_t)blba;
162 gpt.drive_sectors = params->ending_lba + 1; 161 gpt.drive_sectors = params->ending_lba + 1;
163 if (0 != AllocAndReadGptData(&gpt)) { 162 if (0 != AllocAndReadGptData(&gpt)) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 197
199 /* Verify the key block */ 198 /* Verify the key block */
200 key_block = (VbKeyBlockHeader*)kbuf; 199 key_block = (VbKeyBlockHeader*)kbuf;
201 if ((0 != KeyBlockVerify(key_block, KBUF_SIZE, kernel_subkey))) { 200 if ((0 != KeyBlockVerify(key_block, KBUF_SIZE, kernel_subkey))) {
202 VBDEBUG(("Verifying key block failed.\n")); 201 VBDEBUG(("Verifying key block failed.\n"));
203 continue; 202 continue;
204 } 203 }
205 204
206 /* Check the key block flags against the current boot mode */ 205 /* Check the key block flags against the current boot mode */
207 if (!(key_block->key_block_flags && 206 if (!(key_block->key_block_flags &&
208 ((BOOT_FLAG_DEVELOPER & params->boot_flags) ? 207 (is_dev ? KEY_BLOCK_FLAG_DEVELOPER_1 :
209 KEY_BLOCK_FLAG_DEVELOPER_1 : KEY_BLOCK_FLAG_DEVELOPER_0))) { 208 KEY_BLOCK_FLAG_DEVELOPER_0))) {
210 VBDEBUG(("Developer flag mismatch.\n")); 209 VBDEBUG(("Developer flag mismatch.\n"));
211 continue; 210 continue;
212 } 211 }
213 if (!(key_block->key_block_flags && 212 if (!(key_block->key_block_flags &&
214 ((BOOT_FLAG_RECOVERY & params->boot_flags) ? 213 (is_rec ? KEY_BLOCK_FLAG_RECOVERY_1 :
215 KEY_BLOCK_FLAG_RECOVERY_1 : KEY_BLOCK_FLAG_RECOVERY_0))) { 214 KEY_BLOCK_FLAG_RECOVERY_0))) {
216 VBDEBUG(("Recovery flag mismatch.\n")); 215 VBDEBUG(("Recovery flag mismatch.\n"));
217 continue; 216 continue;
218 } 217 }
219 218
220 /* Check for rollback of key version. Note this is implicitly 219 /* Check for rollback of key version. Note this is implicitly
221 * skipped in recovery and developer modes because those set 220 * skipped in recovery and developer modes because those set
222 * key_version=0 above. */ 221 * key_version=0 above. */
223 key_version = key_block->data_key.key_version; 222 key_version = key_block->data_key.key_version;
224 if (key_version < tpm_key_version) { 223 if (key_version < tpm_key_version) {
225 VBDEBUG(("Key version too old.\n")); 224 VBDEBUG(("Key version too old.\n"));
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 (lowest_key_version == tpm_key_version && 366 (lowest_key_version == tpm_key_version &&
368 lowest_kernel_version > tpm_kernel_version)) { 367 lowest_kernel_version > tpm_kernel_version)) {
369 if (0 != RollbackKernelWrite((uint16_t)lowest_key_version, 368 if (0 != RollbackKernelWrite((uint16_t)lowest_key_version,
370 (uint16_t)lowest_kernel_version)) { 369 (uint16_t)lowest_kernel_version)) {
371 VBDEBUG(("Error writing kernel versions to TPM.\n")); 370 VBDEBUG(("Error writing kernel versions to TPM.\n"));
372 return LOAD_KERNEL_RECOVERY; 371 return LOAD_KERNEL_RECOVERY;
373 } 372 }
374 } 373 }
375 } 374 }
376 375
377 /* Lock the kernel versions, since we're about to boot the kernel */ 376 /* Lock the kernel versions */
Luigi Semenzato 2010/06/24 20:18:43 I think that here we may want to invert the condit
378 if (0 != RollbackKernelLock()) { 377 if (0 != RollbackKernelLock()) {
379 VBDEBUG(("Error locking kernel versions.\n")); 378 VBDEBUG(("Error locking kernel versions.\n"));
380 return LOAD_KERNEL_RECOVERY; 379 /* Don't reboot to recovery mode if we're already there */
380 if (!is_rec)
381 return LOAD_KERNEL_RECOVERY;
381 } 382 }
382 383
383 /* Success! */ 384 /* Success! */
384 return LOAD_KERNEL_SUCCESS; 385 return LOAD_KERNEL_SUCCESS;
385 } 386 }
386 387
387 // Handle error cases 388 // Handle error cases
388 if (found_partitions) 389 if (found_partitions)
389 return LOAD_KERNEL_INVALID; 390 return LOAD_KERNEL_INVALID;
390 else 391 else
391 return LOAD_KERNEL_NOT_FOUND; 392 return LOAD_KERNEL_NOT_FOUND;
392 } 393 }
OLDNEW
« no previous file with comments | « firmware/lib/include/rollback_index.h ('k') | firmware/version.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698