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

Side by Side Diff: src/platform/vboot_reference/vboot_firmware/lib/firmware_image_fw.c

Issue 2344002: Add recovery mode protection to new NVRAM locking scheme. (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: typo in comment Created 10 years, 7 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
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 verifying a verified boot firmware image. 5 * Functions for verifying a verified boot firmware image.
6 * (Firmware Portion) 6 * (Firmware Portion)
7 */ 7 */
8 8
9 #include "firmware_image_fw.h" 9 #include "firmware_image_fw.h"
10 10
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 uint8_t* verification_headerB, 245 uint8_t* verification_headerB,
246 uint8_t* firmwareB) { 246 uint8_t* firmwareB) {
247 /* Contains the logical firmware version (32-bit) which is calculated as 247 /* Contains the logical firmware version (32-bit) which is calculated as
248 * (firmware_key_version << 16 | firmware_version) where 248 * (firmware_key_version << 16 | firmware_version) where
249 * [firmware_key_version] [firmware_version] are both 16-bit. 249 * [firmware_key_version] [firmware_version] are both 16-bit.
250 */ 250 */
251 uint32_t firmwareA_lversion, firmwareB_lversion; 251 uint32_t firmwareA_lversion, firmwareB_lversion;
252 uint8_t firmwareA_is_verified = 0; /* Whether firmwareA verify succeeded. */ 252 uint8_t firmwareA_is_verified = 0; /* Whether firmwareA verify succeeded. */
253 uint32_t min_lversion; /* Minimum of firmware A and firmware lversion. */ 253 uint32_t min_lversion; /* Minimum of firmware A and firmware lversion. */
254 uint32_t stored_lversion; /* Stored logical version in the TPM. */ 254 uint32_t stored_lversion; /* Stored logical version in the TPM. */
255 uint16_t version, key_version; /* Temporary variables */
255 256
256 /* Initialize the TPM since we'll be reading the rollback indices. */ 257 /* Initialize the TPM since we'll be reading the rollback indices. */
257 SetupTPM(); 258 SetupTPM();
258 259
259 /* We get the key versions by reading directly from the image blobs without 260 /* We get the key versions by reading directly from the image blobs without
260 * any additional (expensive) sanity checking on the blob since it's faster to 261 * any additional (expensive) sanity checking on the blob since it's faster to
261 * outright reject a firmware with an older firmware key version. A malformed 262 * outright reject a firmware with an older firmware key version. A malformed
262 * or corrupted firmware blob will still fail when VerifyFirmware() is called 263 * or corrupted firmware blob will still fail when VerifyFirmware() is called
263 * on it. 264 * on it.
264 */ 265 */
265 firmwareA_lversion = GetLogicalFirmwareVersion(verification_headerA); 266 firmwareA_lversion = GetLogicalFirmwareVersion(verification_headerA);
266 firmwareB_lversion = GetLogicalFirmwareVersion(verification_headerB); 267 firmwareB_lversion = GetLogicalFirmwareVersion(verification_headerB);
267 min_lversion = Min(firmwareA_lversion, firmwareB_lversion); 268 min_lversion = Min(firmwareA_lversion, firmwareB_lversion);
268 stored_lversion = CombineUint16Pair(GetStoredVersion(FIRMWARE_KEY_VERSION), 269 GetStoredVersions(FIRMWARE_VERSIONS, &key_version, &version);
269 GetStoredVersion(FIRMWARE_VERSION)); 270 stored_lversion = CombineUint16Pair(key_version, version);
270 /* Always try FirmwareA first. */ 271 /* Always try FirmwareA first. */
271 if (VERIFY_FIRMWARE_SUCCESS == VerifyFirmware(root_key_blob, 272 if (VERIFY_FIRMWARE_SUCCESS == VerifyFirmware(root_key_blob,
272 verification_headerA, 273 verification_headerA,
273 firmwareA)) 274 firmwareA))
274 firmwareA_is_verified = 1; 275 firmwareA_is_verified = 1;
275 if (firmwareA_is_verified && (stored_lversion < firmwareA_lversion)) { 276 if (firmwareA_is_verified && (stored_lversion < firmwareA_lversion)) {
276 /* Stored version may need to be updated but only if FirmwareB 277 /* Stored version may need to be updated but only if FirmwareB
277 * is successfully verified and has a logical version greater than 278 * is successfully verified and has a logical version greater than
278 * the stored logical version. */ 279 * the stored logical version. */
279 if (stored_lversion < firmwareB_lversion) { 280 if (stored_lversion < firmwareB_lversion) {
280 if (VERIFY_FIRMWARE_SUCCESS == VerifyFirmware(root_key_blob, 281 if (VERIFY_FIRMWARE_SUCCESS == VerifyFirmware(root_key_blob,
281 verification_headerB, 282 verification_headerB,
282 firmwareB)) { 283 firmwareB)) {
283 WriteStoredVersion(FIRMWARE_KEY_VERSION, 284 WriteStoredVersions(FIRMWARE_VERSIONS,
284 (uint16_t) (min_lversion >> 16)); 285 (uint16_t) (min_lversion >> 16),
285 WriteStoredVersion(FIRMWARE_VERSION, 286 (uint16_t) (min_lversion & 0xFFFF));
286 (uint16_t) (min_lversion & 0x00FFFF));
287 stored_lversion = min_lversion; /* Update stored version as it's used 287 stored_lversion = min_lversion; /* Update stored version as it's used
288 * later. */ 288 * later. */
289 } 289 }
290 } 290 }
291 } 291 }
292 /* Lock Firmware TPM rollback indices from further writes. In this design, 292 /* Lock Firmware TPM rollback indices from further writes. In this design,
293 * this is done by setting the globalLock bit, which is cleared only by 293 * this is done by setting the globalLock bit, which is cleared only by
294 * TPM_Init at reboot. 294 * TPM_Init at reboot.
295 */ 295 */
296 LockFirmwareVersions(); 296 LockFirmwareVersions();
(...skipping 22 matching lines...) Expand all
319 */ 319 */
320 if (stored_lversion <= firmwareB_lversion && 320 if (stored_lversion <= firmwareB_lversion &&
321 (VERIFY_FIRMWARE_SUCCESS == VerifyFirmware(root_key_blob, 321 (VERIFY_FIRMWARE_SUCCESS == VerifyFirmware(root_key_blob,
322 verification_headerB, 322 verification_headerB,
323 firmwareB))) 323 firmwareB)))
324 return BOOT_FIRMWARE_B_CONTINUE; 324 return BOOT_FIRMWARE_B_CONTINUE;
325 } 325 }
326 /* D'oh: No bootable firmware. */ 326 /* D'oh: No bootable firmware. */
327 return BOOT_FIRMWARE_RECOVERY_CONTINUE; 327 return BOOT_FIRMWARE_RECOVERY_CONTINUE;
328 } 328 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698