Patrick Georgi | 593124d | 2020-05-10 19:44:08 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
Martin Roth | 842253b | 2018-07-05 18:42:45 -0600 | [diff] [blame] | 2 | |
| 3 | /* |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 4 | * Functions for querying, manipulating and locking rollback indices |
| 5 | * stored in the TPM NVRAM. |
| 6 | */ |
| 7 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 8 | #ifndef ANTIROLLBACK_H_ |
| 9 | #define ANTIROLLBACK_H_ |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 10 | |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 11 | #include <types.h> |
| 12 | #include <security/tpm/tspi.h> |
Joel Kitching | 2eb89c8 | 2019-04-25 17:45:12 +0800 | [diff] [blame] | 13 | #include <vb2_sha.h> |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 14 | |
Randall Spangler | 144c228 | 2014-12-03 17:35:53 -0800 | [diff] [blame] | 15 | struct vb2_context; |
Julius Werner | 76e3303 | 2015-01-30 18:45:27 -0800 | [diff] [blame] | 16 | enum vb2_pcr_digest; |
Randall Spangler | 144c228 | 2014-12-03 17:35:53 -0800 | [diff] [blame] | 17 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 18 | /* TPM NVRAM location indices. */ |
| 19 | #define FIRMWARE_NV_INDEX 0x1007 |
Daisuke Nojiri | 97ea9c0 | 2014-09-29 13:02:29 -0700 | [diff] [blame] | 20 | #define KERNEL_NV_INDEX 0x1008 |
Daisuke Nojiri | 03bf301 | 2016-10-07 13:59:36 -0700 | [diff] [blame] | 21 | /* 0x1009 used to be used as a backup space. Think of conflicts if you |
| 22 | * want to use 0x1009 for something else. */ |
Furquan Shaikh | 4b2fed5 | 2016-11-07 23:50:12 -0800 | [diff] [blame] | 23 | #define BACKUP_NV_INDEX 0x1009 |
| 24 | #define FWMP_NV_INDEX 0x100a |
Shelley Chen | a79803c | 2020-10-16 13:15:59 -0700 | [diff] [blame] | 25 | /* 0x100b: Hash of MRC_CACHE training data for recovery boot */ |
| 26 | #define MRC_REC_HASH_NV_INDEX 0x100b |
Shelley Chen | df0481e | 2020-10-16 13:37:09 -0700 | [diff] [blame] | 27 | /* 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 Chen | a79803c | 2020-10-16 13:15:59 -0700 | [diff] [blame] | 30 | #define HASH_NV_SIZE VB2_SHA256_DIGEST_SIZE |
Miriam Polzer | 2c38933 | 2022-08-11 06:38:46 +0000 | [diff] [blame] | 31 | #define ENT_ROLLBACK_SPACE_INDEX 0x100e |
Matt DeVillier | 9ce755d | 2023-01-23 18:31:27 -0600 | [diff] [blame] | 32 | #define VBIOS_CACHE_NV_INDEX 0x100f |
Karthikeyan Ramasubramanian | 4fcf13a | 2021-11-17 17:33:08 -0700 | [diff] [blame] | 33 | /* 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 Aboagye | 08938a9 | 2021-05-24 17:04:38 -0700 | [diff] [blame] | 38 | /* 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 Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 42 | |
| 43 | /* Structure definitions for TPM spaces */ |
| 44 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 45 | /* Flags for firmware space */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 46 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 47 | /* |
| 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 Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 52 | |
| 53 | /* All functions return TPM_SUCCESS (zero) if successful, non-zero if error */ |
| 54 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 55 | uint32_t antirollback_read_space_firmware(struct vb2_context *ctx); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Write may be called if the versions change. |
| 59 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 60 | uint32_t antirollback_write_space_firmware(struct vb2_context *ctx); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 61 | |
| 62 | /** |
dnojiri | dff56a0 | 2020-04-03 10:56:43 -0700 | [diff] [blame] | 63 | * Read and write kernel space in TPM. |
| 64 | */ |
| 65 | uint32_t antirollback_read_space_kernel(struct vb2_context *ctx); |
| 66 | uint32_t antirollback_write_space_kernel(struct vb2_context *ctx); |
| 67 | |
| 68 | /** |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 69 | * Lock must be called. |
| 70 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 71 | uint32_t antirollback_lock_space_firmware(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 72 | |
Shelley Chen | a79803c | 2020-10-16 13:15:59 -0700 | [diff] [blame] | 73 | /* |
Shelley Chen | df0481e | 2020-10-16 13:37:09 -0700 | [diff] [blame] | 74 | * 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 Chen | a79803c | 2020-10-16 13:15:59 -0700 | [diff] [blame] | 79 | * @param data pointer to buffer where hash from TPM read into |
| 80 | * @param size size of buffer |
| 81 | */ |
| 82 | uint32_t antirollback_read_space_mrc_hash(uint32_t index, uint8_t *data, uint32_t size); |
| 83 | /* |
Shelley Chen | df0481e | 2020-10-16 13:37:09 -0700 | [diff] [blame] | 84 | * 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 Chen | a79803c | 2020-10-16 13:15:59 -0700 | [diff] [blame] | 89 | * @param data pointer to buffer of hash value to be written |
| 90 | * @param size size of buffer |
| 91 | */ |
| 92 | uint32_t antirollback_write_space_mrc_hash(uint32_t index, const uint8_t *data, |
| 93 | uint32_t size); |
| 94 | /* |
Shelley Chen | df0481e | 2020-10-16 13:37:09 -0700 | [diff] [blame] | 95 | * 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 Chen | a79803c | 2020-10-16 13:15:59 -0700 | [diff] [blame] | 100 | */ |
| 101 | uint32_t antirollback_lock_space_mrc_hash(uint32_t index); |
Furquan Shaikh | b038f41 | 2016-11-07 23:47:11 -0800 | [diff] [blame] | 102 | |
Matt DeVillier | 9ce755d | 2023-01-23 18:31:27 -0600 | [diff] [blame] | 103 | /* |
| 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 | */ |
| 108 | uint32_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 | */ |
| 114 | uint32_t antirollback_write_space_vbios_hash(const uint8_t *data, uint32_t size); |
| 115 | |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 116 | #endif /* ANTIROLLBACK_H_ */ |