blob: ab7c43aac9937f38d6d77d13d5e7abfda35116cb [file] [log] [blame]
Patrick Georgi593124d2020-05-10 19:44:08 +02001/* SPDX-License-Identifier: BSD-3-Clause */
Martin Roth842253b2018-07-05 18:42:45 -06002
3/*
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -07004 * Functions for querying, manipulating and locking rollback indices
5 * stored in the TPM NVRAM.
6 */
7
Daisuke Nojiri57990972014-07-15 19:47:32 -07008#ifndef ANTIROLLBACK_H_
9#define ANTIROLLBACK_H_
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070010
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010011#include <types.h>
12#include <security/tpm/tspi.h>
Joel Kitching2eb89c82019-04-25 17:45:12 +080013#include <vb2_sha.h>
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070014
Randall Spangler144c2282014-12-03 17:35:53 -080015struct vb2_context;
Julius Werner76e33032015-01-30 18:45:27 -080016enum vb2_pcr_digest;
Randall Spangler144c2282014-12-03 17:35:53 -080017
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070018/* TPM NVRAM location indices. */
19#define FIRMWARE_NV_INDEX 0x1007
Daisuke Nojiri97ea9c02014-09-29 13:02:29 -070020#define KERNEL_NV_INDEX 0x1008
Daisuke Nojiri03bf3012016-10-07 13:59:36 -070021/* 0x1009 used to be used as a backup space. Think of conflicts if you
22 * want to use 0x1009 for something else. */
Furquan Shaikh4b2fed52016-11-07 23:50:12 -080023#define BACKUP_NV_INDEX 0x1009
24#define FWMP_NV_INDEX 0x100a
Shelley Chena79803c2020-10-16 13:15:59 -070025/* 0x100b: Hash of MRC_CACHE training data for recovery boot */
26#define MRC_REC_HASH_NV_INDEX 0x100b
Shelley Chendf0481e2020-10-16 13:37:09 -070027/* 0x100c: OOBE autoconfig public key hashes */
28/* 0x100d: Hash of MRC_CACHE training data for non-recovery boot */
29#define MRC_RW_HASH_NV_INDEX 0x100d
Shelley Chena79803c2020-10-16 13:15:59 -070030#define HASH_NV_SIZE VB2_SHA256_DIGEST_SIZE
Miriam Polzer2c389332022-08-11 06:38:46 +000031#define ENT_ROLLBACK_SPACE_INDEX 0x100e
Matt DeVillier9ce755d2023-01-23 18:31:27 -060032#define VBIOS_CACHE_NV_INDEX 0x100f
Karthikeyan Ramasubramanian4fcf13a2021-11-17 17:33:08 -070033/* Widevine Secure Counter space */
34#define WIDEVINE_COUNTER_NV_INDEX(n) (0x3000 + (n))
35#define NUM_WIDEVINE_COUNTERS 4
36#define WIDEVINE_COUNTER_NAME "Widevine Secure Counter"
37#define WIDEVINE_COUNTER_SIZE sizeof(uint64_t)
Aseda Aboagye08938a92021-05-24 17:04:38 -070038/* Zero-Touch Enrollment related spaces */
39#define ZTE_BOARD_ID_NV_INDEX 0x3fff00
40#define ZTE_RMA_SN_BITS_INDEX 0x3fff01
41#define ZTE_RMA_BYTES_COUNTER_INDEX 0x3fff04
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070042
43/* Structure definitions for TPM spaces */
44
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070045/* Flags for firmware space */
Daisuke Nojiri57990972014-07-15 19:47:32 -070046
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070047/*
48 * Last boot was developer mode. TPM ownership is cleared when transitioning
49 * to/from developer mode.
50 */
51#define FLAG_LAST_BOOT_DEVELOPER 0x01
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070052
53/* All functions return TPM_SUCCESS (zero) if successful, non-zero if error */
54
Daisuke Nojiri57990972014-07-15 19:47:32 -070055uint32_t antirollback_read_space_firmware(struct vb2_context *ctx);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070056
57/**
58 * Write may be called if the versions change.
59 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070060uint32_t antirollback_write_space_firmware(struct vb2_context *ctx);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070061
62/**
dnojiridff56a02020-04-03 10:56:43 -070063 * Read and write kernel space in TPM.
64 */
65uint32_t antirollback_read_space_kernel(struct vb2_context *ctx);
66uint32_t antirollback_write_space_kernel(struct vb2_context *ctx);
67
68/**
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070069 * Lock must be called.
70 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070071uint32_t antirollback_lock_space_firmware(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070072
Shelley Chena79803c2020-10-16 13:15:59 -070073/*
Shelley Chendf0481e2020-10-16 13:37:09 -070074 * Read MRC hash data from TPM.
75 * @param index index into TPM NVRAM where hash is stored The index
76 * can be set to either MRC_REC_HASH_NV_INDEX or
77 * MRC_RW_HASH_NV_INDEX depending upon whether we are
78 * booting in recovery or normal mode.
Shelley Chena79803c2020-10-16 13:15:59 -070079 * @param data pointer to buffer where hash from TPM read into
80 * @param size size of buffer
81 */
82uint32_t antirollback_read_space_mrc_hash(uint32_t index, uint8_t *data, uint32_t size);
83/*
Shelley Chendf0481e2020-10-16 13:37:09 -070084 * Write new hash data to MRC space in TPM.\
85 * @param index index into TPM NVRAM where hash is stored The index
86 * can be set to either MRC_REC_HASH_NV_INDEX or
87 * MRC_RW_HASH_NV_INDEX depending upon whether we are
88 * booting in recovery or normal mode.
Shelley Chena79803c2020-10-16 13:15:59 -070089 * @param data pointer to buffer of hash value to be written
90 * @param size size of buffer
91*/
92uint32_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data,
93 uint32_t size);
94/*
Shelley Chendf0481e2020-10-16 13:37:09 -070095 * Lock down MRC hash space in TPM.
96 * @param index index into TPM NVRAM where hash is stored The index
97 * can be set to either MRC_REC_HASH_NV_INDEX or
98 * MRC_RW_HASH_NV_INDEX depending upon whether we are
99 * booting in recovery or normal mode.
Shelley Chena79803c2020-10-16 13:15:59 -0700100*/
101uint32_t antirollback_lock_space_mrc_hash(uint32_t index);
Furquan Shaikhb038f412016-11-07 23:47:11 -0800102
Matt DeVillier9ce755d2023-01-23 18:31:27 -0600103/*
104 * Read VBIOS hash data from TPM.
105 * @param data pointer to buffer where hash from TPM read into
106 * @param size size of buffer
107 */
108uint32_t antirollback_read_space_vbios_hash(uint8_t *data, uint32_t size);
109/*
110 * Write new hash data to VBIOS space in TPM.
111 * @param data pointer to buffer of hash value to be written
112 * @param size size of buffer
113*/
114uint32_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size);
115
Daisuke Nojiri57990972014-07-15 19:47:32 -0700116#endif /* ANTIROLLBACK_H_ */