event_log.h 4.1 KB

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