Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 1 | /* |
Imre Kis | a48afe5 | 2022-04-11 16:33:13 +0200 | [diff] [blame] | 2 | * Copyright (c) 2020-2022, Arm Limited. All rights reserved. |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef EVENT_LOG_H |
| 8 | #define EVENT_LOG_H |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | #include <common/debug.h> |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 13 | #include <common/tbbr/tbbr_img_def.h> |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame^] | 14 | #include <drivers/auth/crypto_mod.h> |
Sandrine Bailleux | 3c2db6f | 2021-07-07 14:47:08 +0200 | [diff] [blame] | 15 | #include <drivers/measured_boot/event_log/tcg.h> |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 16 | |
| 17 | /* |
| 18 | * Set Event Log debug level to one of: |
| 19 | * |
| 20 | * LOG_LEVEL_ERROR |
| 21 | * LOG_LEVEL_INFO |
| 22 | * LOG_LEVEL_WARNING |
| 23 | * LOG_LEVEL_VERBOSE |
| 24 | */ |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 25 | #if EVENT_LOG_LEVEL == LOG_LEVEL_ERROR |
| 26 | #define LOG_EVENT ERROR |
| 27 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_NOTICE |
| 28 | #define LOG_EVENT NOTICE |
| 29 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_WARNING |
| 30 | #define LOG_EVENT WARN |
| 31 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_INFO |
| 32 | #define LOG_EVENT INFO |
| 33 | #elif EVENT_LOG_LEVEL == LOG_LEVEL_VERBOSE |
| 34 | #define LOG_EVENT VERBOSE |
| 35 | #else |
| 36 | #error "Not supported EVENT_LOG_LEVEL" |
| 37 | #endif |
| 38 | |
| 39 | /* Number of hashing algorithms supported */ |
Manish V Badarkhe | 67009c3 | 2021-10-31 14:47:49 +0000 | [diff] [blame] | 40 | #define HASH_ALG_COUNT 1U |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 41 | |
Manish V Badarkhe | 1ffa009 | 2021-10-20 22:06:40 +0100 | [diff] [blame] | 42 | #define EVLOG_INVALID_ID UINT32_MAX |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 43 | |
| 44 | #define MEMBER_SIZE(type, member) sizeof(((type *)0)->member) |
| 45 | |
Manish V Badarkhe | 72e0369 | 2021-09-08 20:04:24 +0100 | [diff] [blame] | 46 | /* |
| 47 | * Each event log entry has some metadata (i.e. a string) that identifies |
| 48 | * what is measured.These macros define these strings. |
| 49 | * Note that these strings follow the standardization recommendations |
| 50 | * defined in the Arm Server Base Security Guide (a.k.a. SBSG, Arm DEN 0086), |
| 51 | * where applicable. They should not be changed in the code. |
| 52 | * Where the SBSG does not make recommendations, we are free to choose any |
| 53 | * naming convention. |
| 54 | * The key thing is to choose meaningful strings so that when the TPM event |
| 55 | * log is used in attestation, the different components can be identified. |
| 56 | */ |
| 57 | #define EVLOG_BL2_STRING "BL_2" |
| 58 | #define EVLOG_BL31_STRING "SECURE_RT_EL3" |
| 59 | #if defined(SPD_opteed) |
| 60 | #define EVLOG_BL32_STRING "SECURE_RT_EL1_OPTEE" |
| 61 | #elif defined(SPD_tspd) |
| 62 | #define EVLOG_BL32_STRING "SECURE_RT_EL1_TSPD" |
| 63 | #elif defined(SPD_tlkd) |
| 64 | #define EVLOG_BL32_STRING "SECURE_RT_EL1_TLKD" |
| 65 | #elif defined(SPD_trusty) |
| 66 | #define EVLOG_BL32_STRING "SECURE_RT_EL1_TRUSTY" |
| 67 | #else |
| 68 | #define EVLOG_BL32_STRING "SECURE_RT_EL1_UNKNOWN" |
| 69 | #endif |
| 70 | #define EVLOG_BL32_EXTRA1_STRING "SECURE_RT_EL1_OPTEE_EXTRA1" |
| 71 | #define EVLOG_BL32_EXTRA2_STRING "SECURE_RT_EL1_OPTEE_EXTRA2" |
| 72 | #define EVLOG_BL33_STRING "BL_33" |
| 73 | #define EVLOG_FW_CONFIG_STRING "FW_CONFIG" |
| 74 | #define EVLOG_HW_CONFIG_STRING "HW_CONFIG" |
| 75 | #define EVLOG_NT_FW_CONFIG_STRING "NT_FW_CONFIG" |
| 76 | #define EVLOG_SCP_BL2_STRING "SYS_CTRL_2" |
| 77 | #define EVLOG_SOC_FW_CONFIG_STRING "SOC_FW_CONFIG" |
| 78 | #define EVLOG_STM32_STRING "STM32" |
| 79 | #define EVLOG_TB_FW_CONFIG_STRING "TB_FW_CONFIG" |
| 80 | #define EVLOG_TOS_FW_CONFIG_STRING "TOS_FW_CONFIG" |
Tamas Ban | 6101c2a | 2022-01-10 15:13:00 +0100 | [diff] [blame] | 81 | #define EVLOG_RMM_STRING "RMM" |
Imre Kis | a48afe5 | 2022-04-11 16:33:13 +0200 | [diff] [blame] | 82 | #define EVLOG_SP1_STRING "SP1" |
| 83 | #define EVLOG_SP2_STRING "SP2" |
| 84 | #define EVLOG_SP3_STRING "SP3" |
| 85 | #define EVLOG_SP4_STRING "SP4" |
| 86 | #define EVLOG_SP5_STRING "SP5" |
| 87 | #define EVLOG_SP6_STRING "SP6" |
| 88 | #define EVLOG_SP7_STRING "SP7" |
| 89 | #define EVLOG_SP8_STRING "SP8" |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 90 | |
| 91 | typedef struct { |
| 92 | unsigned int id; |
| 93 | const char *name; |
| 94 | unsigned int pcr; |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 95 | } event_log_metadata_t; |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 96 | |
| 97 | #define ID_EVENT_SIZE (sizeof(id_event_headers_t) + \ |
| 98 | (sizeof(id_event_algorithm_size_t) * HASH_ALG_COUNT) + \ |
| 99 | sizeof(id_event_struct_data_t)) |
| 100 | |
| 101 | #define LOC_EVENT_SIZE (sizeof(event2_header_t) + \ |
| 102 | sizeof(tpmt_ha) + TCG_DIGEST_SIZE + \ |
| 103 | sizeof(event2_data_t) + \ |
| 104 | sizeof(startup_locality_event_t)) |
| 105 | |
| 106 | #define LOG_MIN_SIZE (ID_EVENT_SIZE + LOC_EVENT_SIZE) |
| 107 | |
| 108 | #define EVENT2_HDR_SIZE (sizeof(event2_header_t) + \ |
| 109 | sizeof(tpmt_ha) + TCG_DIGEST_SIZE + \ |
| 110 | sizeof(event2_data_t)) |
| 111 | |
| 112 | /* Functions' declarations */ |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame^] | 113 | void event_log_buf_init(uint8_t *event_log_start, uint8_t *event_log_finish); |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 114 | void event_log_init(uint8_t *event_log_start, uint8_t *event_log_finish); |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame^] | 115 | void event_log_write_specid_event(void); |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 116 | void event_log_write_header(void); |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 117 | void dump_event_log(uint8_t *log_addr, size_t log_size); |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 118 | const event_log_metadata_t *plat_event_log_get_metadata(void); |
Manish V Badarkhe | 5a9eaa7 | 2022-06-15 15:06:43 +0100 | [diff] [blame^] | 119 | int event_log_measure(uintptr_t data_base, uint32_t data_size, |
| 120 | unsigned char hash_data[CRYPTO_MD_MAX_SIZE]); |
| 121 | void event_log_record(const uint8_t *hash, uint32_t event_type, |
| 122 | const event_log_metadata_t *metadata_ptr); |
Sandrine Bailleux | 4e9af17 | 2021-07-01 14:13:09 +0200 | [diff] [blame] | 123 | int event_log_measure_and_record(uintptr_t data_base, uint32_t data_size, |
| 124 | uint32_t data_id); |
Manish V Badarkhe | 7ca9d65 | 2021-09-14 22:41:46 +0100 | [diff] [blame] | 125 | size_t event_log_get_cur_size(uint8_t *event_log_start); |
Sandrine Bailleux | 898c099 | 2021-06-17 16:10:40 +0200 | [diff] [blame] | 126 | |
Alexei Fedorov | 71d81dc | 2020-07-13 13:58:06 +0100 | [diff] [blame] | 127 | #endif /* EVENT_LOG_H */ |