coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
secdata_tpm.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 /*
4  * Functions for querying, manipulating and locking rollback indices
5  * stored in the TPM NVRAM.
6  */
7 
10 #include <security/tpm/tspi.h>
11 #include <security/tpm/tss.h>
14 #include <vb2_api.h>
15 #include <console/console.h>
16 
17 #define VBDEBUG(format, args...) \
18  printk(BIOS_INFO, "%s():%d: " format, __func__, __LINE__, ## args)
19 
20 #define RETURN_ON_FAILURE(tpm_cmd) do { \
21  uint32_t result_; \
22  if ((result_ = (tpm_cmd)) != TPM_SUCCESS) { \
23  VBDEBUG("Antirollback: %08x returned by " #tpm_cmd \
24  "\n", (int)result_); \
25  return result_; \
26  } \
27  } while (0)
28 
29 static uint32_t safe_write(uint32_t index, const void *data, uint32_t length);
30 
31 static uint32_t read_space_firmware(struct vb2_context *ctx)
32 {
34  ctx->secdata_firmware,
35  VB2_SECDATA_FIRMWARE_SIZE));
36  return TPM_SUCCESS;
37 }
38 
39 uint32_t antirollback_read_space_kernel(struct vb2_context *ctx)
40 {
41  if (!CONFIG(TPM2)) {
42  /*
43  * Before reading the kernel space, verify its permissions. If
44  * the kernel space has the wrong permission, we give up. This
45  * will need to be fixed by the recovery kernel. We will have
46  * to worry about this because at any time (even with PP turned
47  * off) the TPM owner can remove and redefine a PP-protected
48  * space (but not write to it).
49  */
50  uint32_t perms;
51 
53  &perms));
54  if (perms != TPM_NV_PER_PPWRITE) {
56  "TPM: invalid secdata_kernel permissions\n");
57  return TPM_E_CORRUPTED_STATE;
58  }
59  }
60 
61  uint8_t size = VB2_SECDATA_KERNEL_SIZE;
62  uint32_t ret;
63 
64  /* Start with the version 1.0 size used by all modern cr50-boards. */
65  ret = tlcl_read(KERNEL_NV_INDEX, ctx->secdata_kernel, size);
66  if (ret == TPM_E_RANGE) {
67  /* Fallback to version 0.2(minimum) size and re-read. */
68  VBDEBUG("Antirollback: NV read out of range, trying min size\n");
69  size = VB2_SECDATA_KERNEL_MIN_SIZE;
70  ret = tlcl_read(KERNEL_NV_INDEX, ctx->secdata_kernel, size);
71  }
72  RETURN_ON_FAILURE(ret);
73 
74  if (vb2api_secdata_kernel_check(ctx, &size) == VB2_ERROR_SECDATA_KERNEL_INCOMPLETE)
75  /* Re-read. vboot will run the check and handle errors. */
76  RETURN_ON_FAILURE(tlcl_read(KERNEL_NV_INDEX, ctx->secdata_kernel, size));
77 
78  return TPM_SUCCESS;
79 }
80 
81 #if CONFIG(TPM2)
82 
83 static uint32_t read_space_mrc_hash(uint32_t index, uint8_t *data)
84 {
85  RETURN_ON_FAILURE(tlcl_read(index, data,
86  HASH_NV_SIZE));
87  return TPM_SUCCESS;
88 }
89 
90 /*
91  * This is used to initialize the TPM space for recovery hash after defining
92  * it. Since there is no data available to calculate hash at the point where TPM
93  * space is defined, initialize it to all 0s.
94  */
95 static const uint8_t mrc_hash_data[HASH_NV_SIZE] = { };
96 
97 /*
98  * Different sets of NVRAM space attributes apply to the "ro" spaces,
99  * i.e. those which should not be possible to delete or modify once
100  * the RO exits, and the rest of the NVRAM spaces.
101  */
102 static const TPMA_NV ro_space_attributes = {
103  .TPMA_NV_PPWRITE = 1,
104  .TPMA_NV_AUTHREAD = 1,
105  .TPMA_NV_PPREAD = 1,
106  .TPMA_NV_PLATFORMCREATE = 1,
107  .TPMA_NV_WRITE_STCLEAR = 1,
108  .TPMA_NV_POLICY_DELETE = 1,
109 };
110 
111 static const TPMA_NV rw_space_attributes = {
112  .TPMA_NV_PPWRITE = 1,
113  .TPMA_NV_AUTHREAD = 1,
114  .TPMA_NV_PPREAD = 1,
115  .TPMA_NV_PLATFORMCREATE = 1,
116  .TPMA_NV_WRITE_STCLEAR = 1,
117 };
118 
119 static const TPMA_NV fwmp_attr = {
121  .TPMA_NV_OWNERWRITE = 1,
122  .TPMA_NV_AUTHREAD = 1,
123  .TPMA_NV_PPREAD = 1,
124  .TPMA_NV_PPWRITE = 1,
125 };
126 
127 /* Attributes for spaces that enable zero-touch enrollment (ZTE) */
128 static const TPMA_NV zte_attr = {
130  .TPMA_NV_WRITEDEFINE = 1,
131  .TPMA_NV_AUTHWRITE = 1,
132  .TPMA_NV_AUTHREAD = 1,
133  .TPMA_NV_PPWRITE = 1,
134  .TPMA_NV_PPREAD = 1,
135  .TPMA_NV_NO_DA = 1,
136  .TPMA_NV_POLICY_DELETE = 1,
137 };
138 
139 static const TPMA_NV zte_rma_bytes_attr = {
141  .TPMA_NV_BITS = 1,
142  .TPMA_NV_AUTHWRITE = 1,
143  .TPMA_NV_AUTHREAD = 1,
144  .TPMA_NV_PPWRITE = 1,
145  .TPMA_NV_PPREAD = 1,
146  .TPMA_NV_NO_DA = 1,
147  .TPMA_NV_POLICY_DELETE = 1,
148 };
149 
150 static const TPMA_NV rw_orderly_counter_attributes = {
151  .TPMA_NV_COUNTER = 1,
152  .TPMA_NV_ORDERLY = 1,
153  .TPMA_NV_AUTHREAD = 1,
154  .TPMA_NV_AUTHWRITE = 1,
155  .TPMA_NV_PLATFORMCREATE = 1,
156  .TPMA_NV_WRITE_STCLEAR = 1,
157  .TPMA_NV_PPREAD = 1,
158  .TPMA_NV_PPWRITE = 1,
159  .TPMA_NV_NO_DA = 1,
160 };
161 
162 /*
163  * This policy digest was obtained using TPM2_PolicyOR on 3 digests
164  * corresponding to a sequence of
165  * -) TPM2_PolicyCommandCode(TPM_CC_NV_UndefineSpaceSpecial),
166  * -) TPM2_PolicyPCR(PCR0, <extended_value>).
167  * where <extended value> is
168  * 1) all zeros = initial, unextended state:
169  * - Value to extend to initial PCR0:
170  * <none>
171  * - Resulting PCR0:
172  * 0000000000000000000000000000000000000000000000000000000000000000
173  * - Policy digest for PolicyCommandCode + PolicyPCR:
174  * 4B44FC4192DB5AD7167E0135708FD374890A06BFB56317DF01F24F2226542A3F
175  * 2) result of extending (SHA1(0x00|0x01|0x00) | 00s to SHA256 size)
176  * - Value to extend to initial PCR0:
177  * 62571891215b4efc1ceab744ce59dd0b66ea6f73000000000000000000000000
178  * - Resulting PCR0:
179  * 9F9EA866D3F34FE3A3112AE9CB1FBABC6FFE8CD261D42493BC6842A9E4F93B3D
180  * - Policy digest for PolicyCommandCode + PolicyPCR:
181  * CB5C8014E27A5F7586AAE42DB4F9776A977BCBC952CA61E33609DA2B2C329418
182  * 3) result of extending (SHA1(0x01|0x01|0x00) | 00s to SHA256 size)
183  * - Value to extend to initial PCR0:
184  * 47ec8d98366433dc002e7721c9e37d5067547937000000000000000000000000
185  * - Resulting PCR0:
186  * 2A7580E5DA289546F4D2E0509CC6DE155EA131818954D36D49E027FD42B8C8F8
187  * - Policy digest for PolicyCommandCode + PolicyPCR:
188  * E6EF4F0296AC3EF0F53906480985B1BE8058E0E517E5F74A5B8A415EFE339D87
189  * Values #2 and #3 correspond to two forms of recovery mode as extended by
190  * vb2api_get_pcr_digest().
191  * As a result, the digest allows deleting the space with UndefineSpaceSpecial
192  * at early RO stages (before extending PCR0) or from recovery mode.
193  */
194 static const uint8_t pcr0_allowed_policy[] = {
195  0x44, 0x44, 0x79, 0x00, 0xCB, 0xB8, 0x3F, 0x5B, 0x15, 0x76, 0x56,
196  0x50, 0xEF, 0x96, 0x98, 0x0A, 0x2B, 0x96, 0x6E, 0xA9, 0x09, 0x04,
197  0x4A, 0x01, 0xB8, 0x5F, 0xA5, 0x4A, 0x96, 0xFC, 0x59, 0x84};
198 
199 static const uint8_t unsatisfiable_policy[VB2_SHA256_DIGEST_SIZE] =
200  "hmwhat if RBR beat merc in 2021";
201 
202 static uint32_t define_space(const char *name, uint32_t index, uint32_t length,
203  const TPMA_NV nv_attributes,
204  const uint8_t *nv_policy, size_t nv_policy_size)
205 {
206  uint32_t rv;
207 
208  rv = tlcl_define_space(index, length, nv_attributes, nv_policy,
209  nv_policy_size);
210  if (rv == TPM_E_NV_DEFINED) {
211  /*
212  * Continue with writing: it may be defined, but not written
213  * to. In that case a subsequent tlcl_read() would still return
214  * TPM_E_BADINDEX on TPM 2.0. The cases when some non-firmware
215  * space is defined while the firmware space is not there
216  * should be rare (interrupted initialization), so no big harm
217  * in writing once again even if it was written already.
218  */
219  VBDEBUG("%s: %s space already exists\n", __func__, name);
220  rv = TPM_SUCCESS;
221  }
222 
223  return rv;
224 }
225 
226 /* Nothing special in the TPM2 path yet. */
227 static uint32_t safe_write(uint32_t index, const void *data, uint32_t length)
228 {
229  return tlcl_write(index, data, length);
230 }
231 
232 static uint32_t setup_space(const char *name, uint32_t index, const void *data,
233  uint32_t length, const TPMA_NV nv_attributes,
234  const uint8_t *nv_policy, size_t nv_policy_size)
235 {
236  uint32_t rv;
237 
238  rv = define_space(name, index, length, nv_attributes, nv_policy,
239  nv_policy_size);
240  if (rv != TPM_SUCCESS)
241  return rv;
242 
243  return safe_write(index, data, length);
244 }
245 
246 static uint32_t setup_firmware_space(struct vb2_context *ctx)
247 {
248  uint32_t firmware_space_size = vb2api_secdata_firmware_create(ctx);
249 
250  return setup_space("firmware", FIRMWARE_NV_INDEX,
251  ctx->secdata_firmware, firmware_space_size,
252  ro_space_attributes, pcr0_allowed_policy,
253  sizeof(pcr0_allowed_policy));
254 }
255 
256 static uint32_t setup_fwmp_space(struct vb2_context *ctx)
257 {
258  uint32_t fwmp_space_size = vb2api_secdata_fwmp_create(ctx);
259 
260  return setup_space("FWMP", FWMP_NV_INDEX, ctx->secdata_fwmp, fwmp_space_size,
261  fwmp_attr, NULL, 0);
262 }
263 
264 static uint32_t setup_kernel_space(struct vb2_context *ctx)
265 {
266  uint32_t kernel_space_size = vb2api_secdata_kernel_create(ctx);
267 
268  return setup_space("kernel", KERNEL_NV_INDEX, ctx->secdata_kernel,
269  kernel_space_size, rw_space_attributes, NULL, 0);
270 }
271 
272 static uint32_t set_mrc_hash_space(uint32_t index, const uint8_t *data)
273 {
274  if (index == MRC_REC_HASH_NV_INDEX) {
275  return setup_space("RO MRC Hash", index, data, HASH_NV_SIZE,
276  ro_space_attributes, pcr0_allowed_policy,
277  sizeof(pcr0_allowed_policy));
278  } else {
279  return setup_space("RW MRC Hash", index, data, HASH_NV_SIZE,
280  rw_space_attributes, NULL, 0);
281  }
282 }
283 
284 /**
285  * Set up the Zero-Touch Enrollment(ZTE) related spaces.
286  *
287  * These spaces are not used by firmware, but we do need to initialize them.
288  */
289 static uint32_t setup_zte_spaces(void)
290 {
291  uint32_t rv;
292  uint64_t rma_bytes_counter_default = 0;
293  uint8_t rma_sn_bits_default[16];
294  uint8_t board_id_default[12];
295 
296  /* Initialize defaults: Board ID and RMA+SN Bits must be initialized
297  to all 0xFFs. */
298  memset(rma_sn_bits_default, 0xFF, ARRAY_SIZE(rma_sn_bits_default));
299  memset(board_id_default, 0xFF, ARRAY_SIZE(board_id_default));
300 
301  /* Set up RMA + SN Bits */
302  rv = setup_space("RMA + SN Bits", ZTE_RMA_SN_BITS_INDEX,
303  rma_sn_bits_default, sizeof(rma_sn_bits_default),
304  zte_attr,
305  unsatisfiable_policy, sizeof(unsatisfiable_policy));
306  if (rv != TPM_SUCCESS) {
307  VBDEBUG("%s: Failed to set up RMA + SN Bits space\n", __func__);
308  return rv;
309  }
310 
311  rv = setup_space("Board ID", ZTE_BOARD_ID_NV_INDEX,
312  board_id_default, sizeof(board_id_default),
313  zte_attr,
314  unsatisfiable_policy, sizeof(unsatisfiable_policy));
315  if (rv != TPM_SUCCESS) {
316  VBDEBUG("%s: Failed to set up Board ID space\n", __func__);
317  return rv;
318  }
319 
320  /* Set up RMA Bytes counter */
321  rv = define_space("RMA Bytes Counter", ZTE_RMA_BYTES_COUNTER_INDEX,
322  sizeof(rma_bytes_counter_default),
323  zte_rma_bytes_attr,
324  unsatisfiable_policy, sizeof(unsatisfiable_policy));
325  if (rv != TPM_SUCCESS) {
326  VBDEBUG("%s: Failed to define RMA Bytes space\n", __func__);
327  return rv;
328  }
329 
330  /*
331  * Since the RMA counter has the BITS attribute, we need to call
332  * TPM2_NV_SetBits() in order to initialize it.
333  */
335  rma_bytes_counter_default);
336  if (rv != TPM_SUCCESS) {
337  VBDEBUG("%s: Failed to init RMA Bytes counter space\n",
338  __func__);
339  return rv;
340  }
341 
342  return rv;
343 }
344 
345 static uint32_t setup_widevine_counter_spaces(void)
346 {
347  uint32_t index, rv;
348 
349  for (index = 0; index < NUM_WIDEVINE_COUNTERS; index++) {
350  rv = define_space(WIDEVINE_COUNTER_NAME, WIDEVINE_COUNTER_NV_INDEX(index),
351  WIDEVINE_COUNTER_SIZE, rw_orderly_counter_attributes, NULL, 0);
352  if (rv != TPM_SUCCESS)
353  return rv;
354  }
355  return TPM_SUCCESS;
356 }
357 
358 static uint32_t _factory_initialize_tpm(struct vb2_context *ctx)
359 {
361 
362  /*
363  * Of all NVRAM spaces defined by this function the firmware space
364  * must be defined last, because its existence is considered an
365  * indication that TPM factory initialization was successfully
366  * completed.
367  */
368  RETURN_ON_FAILURE(setup_kernel_space(ctx));
369 
370  /*
371  * Define and set rec hash space, if available. No need to
372  * create the RW hash space because we will definitely boot
373  * once in normal mode before shipping, meaning that the space
374  * will get created with correct permissions while still in
375  * our hands.
376  */
377  if (CONFIG(VBOOT_HAS_REC_HASH_SPACE))
378  RETURN_ON_FAILURE(set_mrc_hash_space(MRC_REC_HASH_NV_INDEX, mrc_hash_data));
379 
380  /* Define and write firmware management parameters space. */
381  RETURN_ON_FAILURE(setup_fwmp_space(ctx));
382 
383  /*
384  * Define and write zero-touch enrollment (ZTE) spaces. For Cr50 devices,
385  * these are set up elsewhere via TPM vendor commands.
386  */
387  if (CONFIG(CHROMEOS) && !(CONFIG(TPM_GOOGLE)))
388  RETURN_ON_FAILURE(setup_zte_spaces());
389 
390  /* Define widevine counter space. No need to increment/write to the secure counters
391  and are expected to be incremented during the first use. */
392  if (CONFIG(VBOOT_DEFINE_WIDEVINE_COUNTERS))
393  RETURN_ON_FAILURE(setup_widevine_counter_spaces());
394 
395  RETURN_ON_FAILURE(setup_firmware_space(ctx));
396 
397  return TPM_SUCCESS;
398 }
399 
401 {
403 }
404 
406 {
407  if (size != HASH_NV_SIZE) {
408  VBDEBUG("TPM: Incorrect buffer size for hash idx 0x%x. "
409  "(Expected=0x%x Actual=0x%x).\n", index, HASH_NV_SIZE,
410  size);
411  return TPM_E_READ_FAILURE;
412  }
413  return read_space_mrc_hash(index, data);
414 }
415 
417 {
418  uint8_t spc_data[HASH_NV_SIZE];
419  uint32_t rv;
420 
421  if (size != HASH_NV_SIZE) {
422  VBDEBUG("TPM: Incorrect buffer size for hash idx 0x%x. "
423  "(Expected=0x%x Actual=0x%x).\n", index, HASH_NV_SIZE,
424  size);
425  return TPM_E_WRITE_FAILURE;
426  }
427 
428  rv = read_space_mrc_hash(index, spc_data);
429  if (rv == TPM_E_BADINDEX) {
430  /*
431  * If space is not defined already for hash, define
432  * new space.
433  */
434  VBDEBUG("TPM: Initializing hash space.\n");
435  return set_mrc_hash_space(index, data);
436  }
437 
438  if (rv != TPM_SUCCESS)
439  return rv;
440 
441  return safe_write(index, data, size);
442 }
443 
445 {
446  return tlcl_lock_nv_write(index);
447 }
448 
449 #else
450 
451 /**
452  * Like tlcl_write(), but checks for write errors due to hitting the 64-write
453  * limit and clears the TPM when that happens. This can only happen when the
454  * TPM is unowned, so it is OK to clear it (and we really have no choice).
455  * This is not expected to happen frequently, but it could happen.
456  */
457 
458 static uint32_t safe_write(uint32_t index, const void *data, uint32_t length)
459 {
460  uint32_t result = tlcl_write(index, data, length);
461  if (result == TPM_E_MAXNVWRITES) {
463  return tlcl_write(index, data, length);
464  } else {
465  return result;
466  }
467 }
468 
469 /**
470  * Similarly to safe_write(), this ensures we don't fail a DefineSpace because
471  * we hit the TPM write limit. This is even less likely to happen than with
472  * writes because we only define spaces once at initialization, but we'd
473  * rather be paranoid about this.
474  */
476 {
477  uint32_t result = tlcl_define_space(index, perm, size);
478  if (result == TPM_E_MAXNVWRITES) {
480  return tlcl_define_space(index, perm, size);
481  } else {
482  return result;
483  }
484 }
485 
486 static uint32_t _factory_initialize_tpm(struct vb2_context *ctx)
487 {
488  TPM_PERMANENT_FLAGS pflags;
490 
491  vb2api_secdata_kernel_create_v0(ctx);
492 
493  result = tlcl_get_permanent_flags(&pflags);
494  if (result != TPM_SUCCESS)
495  return result;
496 
497  /*
498  * TPM may come from the factory without physical presence finalized.
499  * Fix if necessary.
500  */
501  VBDEBUG("TPM: physicalPresenceLifetimeLock=%d\n",
503  if (!pflags.physicalPresenceLifetimeLock) {
504  VBDEBUG("TPM: Finalizing physical presence\n");
506  }
507 
508  /*
509  * The TPM will not enforce the NV authorization restrictions until the
510  * execution of a TPM_NV_DefineSpace with the handle of
511  * TPM_NV_INDEX_LOCK. Here we create that space if it doesn't already
512  * exist. */
513  VBDEBUG("TPM: nvLocked=%d\n", pflags.nvLocked);
514  if (!pflags.nvLocked) {
515  VBDEBUG("TPM: Enabling NV locking\n");
517  }
518 
519  /* Clear TPM owner, in case the TPM is already owned for some reason. */
520  VBDEBUG("TPM: Clearing owner\n");
522 
523  /* Define and write secdata_kernel space. */
526  VB2_SECDATA_KERNEL_SIZE_V02));
528  ctx->secdata_kernel,
529  VB2_SECDATA_KERNEL_SIZE_V02));
530 
531  /* Define and write secdata_firmware space. */
535  VB2_SECDATA_FIRMWARE_SIZE));
537  ctx->secdata_firmware,
538  VB2_SECDATA_FIRMWARE_SIZE));
539 
540  return TPM_SUCCESS;
541 }
542 
544 {
545  return tlcl_set_global_lock();
546 }
547 
548 #endif
549 
550 /**
551  * Perform one-time initializations.
552  *
553  * Create the NVRAM spaces, and set their initial values as needed. Sets the
554  * nvLocked bit and ensures the physical presence command is enabled and
555  * locked.
556  */
557 static uint32_t factory_initialize_tpm(struct vb2_context *ctx)
558 {
560 
561  /*
562  * Set initial values of secdata_firmware space.
563  * kernel space is created in _factory_initialize_tpm().
564  */
565  vb2api_secdata_firmware_create(ctx);
566 
567  VBDEBUG("TPM: factory initialization\n");
568 
569  /*
570  * Do a full test. This only happens the first time the device is
571  * turned on in the factory, so performance is not an issue. This is
572  * almost certainly not necessary, but it gives us more confidence
573  * about some code paths below that are difficult to
574  * test---specifically the ones that set lifetime flags, and are only
575  * executed once per physical TPM.
576  */
578  if (result != TPM_SUCCESS)
579  return result;
580 
582  if (result != TPM_SUCCESS)
583  return result;
584 
585  /* _factory_initialize_tpm() writes initial secdata values to TPM
586  immediately, so let vboot know that it's up to date now. */
587  ctx->flags &= ~(VB2_CONTEXT_SECDATA_FIRMWARE_CHANGED |
588  VB2_CONTEXT_SECDATA_KERNEL_CHANGED);
589 
590  VBDEBUG("TPM: factory initialization successful\n");
591 
592  return TPM_SUCCESS;
593 }
594 
596 {
597  uint32_t rv;
598 
599  /* Read the firmware space. */
600  rv = read_space_firmware(ctx);
601  if (rv == TPM_E_BADINDEX) {
602  /* This seems the first time we've run. Initialize the TPM. */
603  VBDEBUG("TPM: Not initialized yet.\n");
605  } else if (rv != TPM_SUCCESS) {
606  VBDEBUG("TPM: Firmware space in a bad state; giving up.\n");
607  return TPM_E_CORRUPTED_STATE;
608  }
609 
610  return TPM_SUCCESS;
611 }
612 
614 {
615  if (CONFIG(TPM_GOOGLE_IMMEDIATELY_COMMIT_FW_SECDATA))
617  return safe_write(FIRMWARE_NV_INDEX, ctx->secdata_firmware,
618  VB2_SECDATA_FIRMWARE_SIZE);
619 }
620 
622 {
623  /* Learn the expected size. */
624  uint8_t size = VB2_SECDATA_KERNEL_MIN_SIZE;
625  vb2api_secdata_kernel_check(ctx, &size);
626 
627  /*
628  * Ensure that the TPM actually commits our changes to NVMEN in case
629  * there is a power loss or other unexpected event. The AP does not
630  * write to the TPM during normal boot flow; it only writes during
631  * recovery, software sync, or other special boot flows. When the AP
632  * wants to write, it is imporant to actually commit changes.
633  */
634  if (CONFIG(TPM_GOOGLE_IMMEDIATELY_COMMIT_FW_SECDATA))
636 
637  return safe_write(KERNEL_NV_INDEX, ctx->secdata_kernel, size);
638 }
639 
640 vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *ctx)
641 {
642  uint32_t rv;
643  printk(BIOS_INFO, "Clearing TPM owner\n");
644  rv = tpm_clear_and_reenable();
645  if (rv)
646  return VB2_ERROR_EX_TPM_CLEAR_OWNER;
647  return VB2_SUCCESS;
648 }
uint32_t antirollback_read_space_mrc_hash(uint32_t index, uint8_t *data, uint32_t size)
Definition: secdata_mock.c:62
uint32_t antirollback_lock_space_mrc_hash(uint32_t index)
Definition: secdata_mock.c:57
#define KERNEL_NV_INDEX
Definition: antirollback.h:20
uint32_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data, uint32_t size)
Definition: secdata_mock.c:67
#define ZTE_RMA_BYTES_COUNTER_INDEX
Definition: antirollback.h:39
#define MRC_REC_HASH_NV_INDEX
Definition: antirollback.h:26
#define FIRMWARE_NV_INDEX
Definition: antirollback.h:19
#define ZTE_BOARD_ID_NV_INDEX
Definition: antirollback.h:37
#define FWMP_NV_INDEX
Definition: antirollback.h:24
#define WIDEVINE_COUNTER_NAME
Definition: antirollback.h:34
#define WIDEVINE_COUNTER_NV_INDEX(n)
Definition: antirollback.h:32
#define WIDEVINE_COUNTER_SIZE
Definition: antirollback.h:35
#define ZTE_RMA_SN_BITS_INDEX
Definition: antirollback.h:38
#define HASH_NV_SIZE
Definition: antirollback.h:30
#define NUM_WIDEVINE_COUNTERS
Definition: antirollback.h:33
const char * name
Definition: mmu.c:92
void * memset(void *dstpp, int c, size_t len)
Definition: memset.c:12
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
@ CONFIG
Definition: dsi_common.h:201
uint64_t length
Definition: fw_cfg_if.h:1
@ TPM2
Definition: acpi.h:76
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
result
Definition: mrc_cache.c:35
uint32_t antirollback_lock_space_firmware(void)
Lock must be called.
Definition: secdata_tpm.c:543
vb2_error_t vb2ex_tpm_clear_owner(struct vb2_context *ctx)
Definition: secdata_tpm.c:640
uint32_t antirollback_read_space_kernel(struct vb2_context *ctx)
Read and write kernel space in TPM.
Definition: secdata_tpm.c:39
static uint32_t safe_define_space(uint32_t index, uint32_t perm, uint32_t size)
Similarly to safe_write(), this ensures we don't fail a DefineSpace because we hit the TPM write limi...
Definition: secdata_tpm.c:475
uint32_t antirollback_write_space_firmware(struct vb2_context *ctx)
Write may be called if the versions change.
Definition: secdata_tpm.c:613
static uint32_t factory_initialize_tpm(struct vb2_context *ctx)
Perform one-time initializations.
Definition: secdata_tpm.c:557
static uint32_t read_space_firmware(struct vb2_context *ctx)
Definition: secdata_tpm.c:31
uint32_t antirollback_read_space_firmware(struct vb2_context *ctx)
Definition: secdata_tpm.c:595
static uint32_t safe_write(uint32_t index, const void *data, uint32_t length)
Like tlcl_write(), but checks for write errors due to hitting the 64-write limit and clears the TPM w...
Definition: secdata_tpm.c:458
#define VBDEBUG(format, args...)
Definition: secdata_tpm.c:17
uint32_t antirollback_write_space_kernel(struct vb2_context *ctx)
Definition: secdata_tpm.c:621
static uint32_t _factory_initialize_tpm(struct vb2_context *ctx)
Definition: secdata_tpm.c:486
#define RETURN_ON_FAILURE(tpm_cmd)
Definition: secdata_tpm.c:20
uint32_t tlcl_cr50_enable_nvcommits(void)
CR50 specific tpm command to enable nvmem commits before internal timeout expires.
Definition: cr50.c:12
#define NULL
Definition: stddef.h:19
unsigned int uint32_t
Definition: stdint.h:14
unsigned long long uint64_t
Definition: stdint.h:17
unsigned char uint8_t
Definition: stdint.h:8
uint32_t TPMA_NV_PPWRITE
uint32_t TPMA_NV_PLATFORMCREATE
uint32_t TPMA_NV_COUNTER
TSS_BOOL physicalPresenceLifetimeLock
uint32_t tlcl_set_global_lock(void)
Set the bGlobalLock flag, which only a reboot can clear.
Definition: tss.c:328
uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size)
Definition: tss.c:193
uint32_t tlcl_get_permissions(uint32_t index, uint32_t *permissions)
Get the permission bits for the NVRAM space with |index|.
Definition: tss.c:355
uint32_t tlcl_force_clear(void)
Issue a ForceClear.
Definition: tss.c:273
uint32_t tlcl_self_test_full(void)
Run the self test.
Definition: tss.c:178
uint32_t tlcl_finalize_physical_presence(void)
Finalize the physical presence settings: software PP is enabled, hardware PP is disabled,...
Definition: tss.c:261
uint32_t tlcl_set_nv_locked(void)
Set the nvLocked bit.
Definition: tss.c:267
uint32_t tlcl_write(uint32_t index, const void *data, uint32_t length)
Write [length] bytes of [data] to space at [index].
Definition: tss.c:204
uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags)
Definition: tss.c:294
uint32_t tlcl_read(uint32_t index, void *data, uint32_t length)
Read [length] bytes from space at [index] into [data].
Definition: tss.c:224
#define TPM_NV_PER_PPWRITE
#define TPM_NV_PER_GLOBALLOCK
uint32_t tlcl_set_bits(uint32_t index, uint64_t bits)
Definition: tss.c:323
uint32_t tlcl_lock_nv_write(uint32_t index)
Make an NV Ram location read_only.
Definition: tss.c:276
uint32_t tpm_clear_and_reenable(void)
Issue a TPM_Clear and re-enable/reactivate the TPM.
Definition: tspi.c:192
#define TPM_SUCCESS
Definition: tss_common.h:9
#define TPM_E_NV_DEFINED
Definition: tss_errors.h:40
#define TPM_E_MAXNVWRITES
Definition: tss_errors.h:23
#define TPM_E_RANGE
Definition: tss_errors.h:44
#define TPM_E_BADINDEX
Definition: tss_errors.h:19
#define TPM_E_READ_FAILURE
Definition: tss_errors.h:39
#define TPM_E_WRITE_FAILURE
Definition: tss_errors.h:37
#define TPM_E_CORRUPTED_STATE
Definition: tss_errors.h:32