OLD | NEW |
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 querying, manipulating and locking rollback indices | 5 * Functions for querying, manipulating and locking rollback indices |
6 * stored in the TPM NVRAM. | 6 * stored in the TPM NVRAM. |
7 */ | 7 */ |
8 | 8 |
9 #include "rollback_index.h" | 9 #include "rollback_index.h" |
10 | 10 |
11 #include "tlcl.h" | 11 #include "tlcl.h" |
12 #include "tss_constants.h" | 12 #include "tss_constants.h" |
13 #include "utility.h" | 13 #include "utility.h" |
14 | 14 |
15 | |
16 /* TPM PCR to use for storing dev mode measurements */ | 15 /* TPM PCR to use for storing dev mode measurements */ |
17 #define DEV_MODE_PCR 0 | 16 #define DEV_MODE_PCR 0 |
18 /* Input digests for PCR extend */ | 17 /* Input digests for PCR extend */ |
19 #define DEV_MODE_ON_SHA1_DIGEST ((uint8_t*) "\xbf\x8b\x45\x30\xd8\xd2\x46\xdd" \ | 18 #define DEV_MODE_ON_SHA1_DIGEST ((uint8_t*) "\xbf\x8b\x45\x30\xd8\xd2\x46\xdd" \ |
20 "\x74\xac\x53\xa1\x34\x71\xbb\xa1\x79\x41" \ | 19 "\x74\xac\x53\xa1\x34\x71\xbb\xa1\x79\x41" \ |
21 "\xdf\xf7") /* SHA1("\x01") */ | 20 "\xdf\xf7") /* SHA1("\x01") */ |
22 #define DEV_MODE_OFF_SHA1_DIGEST ((uint8_t*) "\x5b\xa9\x3c\x9d\xb0\xcf\xf9\x3f"\ | 21 #define DEV_MODE_OFF_SHA1_DIGEST ((uint8_t*) "\x5b\xa9\x3c\x9d\xb0\xcf\xf9\x3f"\ |
23 "\x52\xb5\x21\xd7\x42\x0e\x43\xf6\xed\xa2" \ | 22 "\x52\xb5\x21\xd7\x42\x0e\x43\xf6\xed\xa2" \ |
24 "\x78\x4f") /* SHA1("\x00") */ | 23 "\x78\x4f") /* SHA1("\x00") */ |
25 | 24 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 uint8_t disable; | 166 uint8_t disable; |
168 uint8_t deactivated; | 167 uint8_t deactivated; |
169 uint32_t result; | 168 uint32_t result; |
170 | 169 |
171 VBDEBUG(("TPM: SetupTPM(r%d, d%d)\n", recovery_mode, developer_mode)); | 170 VBDEBUG(("TPM: SetupTPM(r%d, d%d)\n", recovery_mode, developer_mode)); |
172 | 171 |
173 /* TODO: TlclLibInit() should be able to return failure */ | 172 /* TODO: TlclLibInit() should be able to return failure */ |
174 TlclLibInit(); | 173 TlclLibInit(); |
175 | 174 |
176 RETURN_ON_FAILURE(TlclStartup()); | 175 RETURN_ON_FAILURE(TlclStartup()); |
177 #ifdef USE_CONTINUE_SELF_TEST | 176 /* Use ContinueSelfTest rather than SelfTestFull(). It enables |
178 /* TODO: ContinueSelfTest() should be faster than SelfTestFull, but | 177 * access to the subset of TPM commands we need in the firmware, and |
179 * may also not work properly in older TPM firmware. For now, do | 178 * allows the full self test to run in paralle with firmware |
180 * the full self test. */ | 179 * startup. By the time we get to the OS, self test will have |
| 180 * completed. */ |
181 RETURN_ON_FAILURE(TlclContinueSelfTest()); | 181 RETURN_ON_FAILURE(TlclContinueSelfTest()); |
182 #else | |
183 RETURN_ON_FAILURE(TlclSelfTestFull()); | |
184 #endif | |
185 result = TlclAssertPhysicalPresence(); | 182 result = TlclAssertPhysicalPresence(); |
186 if (result != 0) { | 183 if (result != 0) { |
187 /* It is possible that the TPM was delivered with the physical presence | 184 /* It is possible that the TPM was delivered with the physical presence |
188 * command disabled. This tries enabling it, then tries asserting PP | 185 * command disabled. This tries enabling it, then tries asserting PP |
189 * again. | 186 * again. |
190 */ | 187 */ |
191 RETURN_ON_FAILURE(TlclPhysicalPresenceCMDEnable()); | 188 RETURN_ON_FAILURE(TlclPhysicalPresenceCMDEnable()); |
192 RETURN_ON_FAILURE(TlclAssertPhysicalPresence()); | 189 RETURN_ON_FAILURE(TlclAssertPhysicalPresence()); |
193 } | 190 } |
194 | 191 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 #ifdef DISABLE_ROLLBACK_TPM | 252 #ifdef DISABLE_ROLLBACK_TPM |
256 | 253 |
257 /* Dummy implementations which don't support TPM rollback protection */ | 254 /* Dummy implementations which don't support TPM rollback protection */ |
258 | 255 |
259 uint32_t RollbackS3Resume(void) { | 256 uint32_t RollbackS3Resume(void) { |
260 #ifndef CHROMEOS_ENVIRONMENT | 257 #ifndef CHROMEOS_ENVIRONMENT |
261 /* Initialize the TPM, but ignore return codes. In ChromeOS | 258 /* Initialize the TPM, but ignore return codes. In ChromeOS |
262 * environment, don't even talk to the TPM. */ | 259 * environment, don't even talk to the TPM. */ |
263 TlclLibInit(); | 260 TlclLibInit(); |
264 TlclResume(); | 261 TlclResume(); |
265 TlclSelfTestFull(); | 262 TlclContinueSelfTest(); |
266 #endif | 263 #endif |
267 return TPM_SUCCESS; | 264 return TPM_SUCCESS; |
268 } | 265 } |
269 | 266 |
270 uint32_t RollbackFirmwareSetup(int developer_mode, uint32_t* version) { | 267 uint32_t RollbackFirmwareSetup(int developer_mode, uint32_t* version) { |
271 #ifndef CHROMEOS_ENVIRONMENT | 268 #ifndef CHROMEOS_ENVIRONMENT |
272 /* Initializes the TPM, but ignores return codes. In ChromeOS | 269 /* Initializes the TPM, but ignores return codes. In ChromeOS |
273 * environment, doesn't even talk to the TPM. */ | 270 * environment, doesn't even talk to the TPM. */ |
274 TlclLibInit(); | 271 TlclLibInit(); |
275 TlclStartup(); | 272 TlclStartup(); |
276 TlclSelfTestFull(); | 273 TlclContinueSelfTest(); |
277 #endif | 274 #endif |
278 | 275 |
279 *version = 0; | 276 *version = 0; |
280 return TPM_SUCCESS; | 277 return TPM_SUCCESS; |
281 } | 278 } |
282 | 279 |
283 uint32_t RollbackFirmwareWrite(uint32_t version) { | 280 uint32_t RollbackFirmwareWrite(uint32_t version) { |
284 return TPM_SUCCESS; | 281 return TPM_SUCCESS; |
285 } | 282 } |
286 | 283 |
(...skipping 23 matching lines...) Expand all Loading... |
310 | 307 |
311 uint32_t RollbackKernelLock(void) { | 308 uint32_t RollbackKernelLock(void) { |
312 return TPM_SUCCESS; | 309 return TPM_SUCCESS; |
313 } | 310 } |
314 | 311 |
315 #else | 312 #else |
316 | 313 |
317 uint32_t RollbackS3Resume(void) { | 314 uint32_t RollbackS3Resume(void) { |
318 uint32_t result; | 315 uint32_t result; |
319 TlclLibInit(); | 316 TlclLibInit(); |
320 /* Check for INVALID_POSTINIT error, so we don't have to worry if this ends | |
321 * up in hardware that keeps the TPM powered on during S3. | |
322 */ | |
323 result = TlclResume(); | 317 result = TlclResume(); |
324 if (result == TPM_E_INVALID_POSTINIT) { | 318 if (result == TPM_E_INVALID_POSTINIT) { |
| 319 /* We're on a platform where the TPM maintains power in S3, so |
| 320 it's already initialized. No need for a self-test. */ |
325 return TPM_SUCCESS; | 321 return TPM_SUCCESS; |
326 } | 322 } |
327 if (result != TPM_SUCCESS) { | 323 if (result != TPM_SUCCESS) { |
328 return result; | 324 return result; |
329 } | 325 } |
330 #ifdef USE_CONTINUE_SELF_TEST | 326 |
331 /* TODO: ContinueSelfTest() should be faster than SelfTestFull, but | |
332 * may also not work properly in older TPM firmware. For now, do | |
333 * the full self test. */ | |
334 RETURN_ON_FAILURE(TlclContinueSelfTest()); | 327 RETURN_ON_FAILURE(TlclContinueSelfTest()); |
335 #else | 328 |
336 RETURN_ON_FAILURE(TlclSelfTestFull()); | |
337 #endif | |
338 return TPM_SUCCESS; | 329 return TPM_SUCCESS; |
339 } | 330 } |
340 | 331 |
341 | 332 |
342 uint32_t RollbackFirmwareSetup(int developer_mode, uint32_t* version) { | 333 uint32_t RollbackFirmwareSetup(int developer_mode, uint32_t* version) { |
343 RollbackSpaceFirmware rsf; | 334 RollbackSpaceFirmware rsf; |
344 uint8_t out_digest[20]; /* For PCR extend output */ | 335 uint8_t out_digest[20]; /* For PCR extend output */ |
345 | 336 |
346 RETURN_ON_FAILURE(SetupTPM(0, developer_mode, &rsf)); | 337 RETURN_ON_FAILURE(SetupTPM(0, developer_mode, &rsf)); |
347 *version = rsf.fw_versions; | 338 *version = rsf.fw_versions; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 417 |
427 uint32_t RollbackKernelLock(void) { | 418 uint32_t RollbackKernelLock(void) { |
428 if (g_rollback_recovery_mode) { | 419 if (g_rollback_recovery_mode) { |
429 return TPM_SUCCESS; | 420 return TPM_SUCCESS; |
430 } else { | 421 } else { |
431 return TlclLockPhysicalPresence(); | 422 return TlclLockPhysicalPresence(); |
432 } | 423 } |
433 } | 424 } |
434 | 425 |
435 #endif // DISABLE_ROLLBACK_TPM | 426 #endif // DISABLE_ROLLBACK_TPM |
OLD | NEW |