OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. |
| 4 * |
| 5 * Data structure and API definitions for a verified boot kernel image. |
| 6 * (Firmware Portion) |
| 7 */ |
| 8 |
| 9 #ifndef VBOOT_REFERENCE_KERNEL_IMAGE_FW_H_ |
| 10 #define VBOOT_REFERENCE_KERNEL_IMAGE_FW_H_ |
| 11 |
| 12 #include <stdint.h> |
| 13 #include "rsa.h" |
| 14 #include "sha.h" |
| 15 |
| 16 #define KERNEL_MAGIC "CHROMEOS" |
| 17 #define KERNEL_MAGIC_SIZE 8 |
| 18 #define KERNEL_CMD_LINE_SIZE 4096 |
| 19 |
| 20 #define DEV_MODE_ENABLED 1 |
| 21 #define DEV_MODE_DISABLED 0 |
| 22 |
| 23 /* Kernel config file options according to the Chrome OS drive map design. */ |
| 24 typedef struct kconfig_options { |
| 25 uint32_t version[2]; /* Configuration file version. */ |
| 26 uint8_t cmd_line[KERNEL_CMD_LINE_SIZE]; /* Kernel command line option string |
| 27 * terminated by a NULL character. */ |
| 28 uint64_t kernel_len; /* Size of the kernel. */ |
| 29 uint64_t kernel_load_addr; /* Load address in memory for the kernel image */ |
| 30 uint64_t kernel_entry_addr; /* Address to jump to after kernel is loaded. */ |
| 31 } kconfig_options; |
| 32 |
| 33 typedef struct KernelImage { |
| 34 uint8_t magic[KERNEL_MAGIC_SIZE]; |
| 35 /* Key header */ |
| 36 uint16_t header_version; /* Header version. */ |
| 37 uint16_t header_len; /* Length of the header. */ |
| 38 uint16_t firmware_sign_algorithm; /* Signature algorithm used by the firmware |
| 39 * signing key (used to sign this kernel |
| 40 * header. */ |
| 41 uint16_t kernel_sign_algorithm; /* Signature algorithm used by the kernel |
| 42 * signing key. */ |
| 43 uint16_t kernel_key_version; /* Key Version# for preventing rollbacks. */ |
| 44 uint8_t* kernel_sign_key; /* Pre-processed public half of signing key. */ |
| 45 /* TODO(gauravsh): Do we need a choice of digest algorithms for the header |
| 46 * checksum? */ |
| 47 uint8_t header_checksum[SHA512_DIGEST_SIZE]; /* SHA-512 Crytographic hash of |
| 48 * the concatenation of the |
| 49 * header fields, i.e. |
| 50 * [header_len, |
| 51 * firmware_sign_algorithm, |
| 52 * sign_algorithm, sign_key, |
| 53 * key_version] */ |
| 54 |
| 55 uint8_t* kernel_key_signature; /* Signature of the header above. */ |
| 56 |
| 57 uint16_t kernel_version; /* Kernel Version# for preventing rollbacks. */ |
| 58 kconfig_options options; /* Other kernel/bootloader options. */ |
| 59 |
| 60 uint8_t* config_signature; /* Signature of the kernel config file. */ |
| 61 |
| 62 /* The kernel signature comes first as it may allow us to parallelize |
| 63 * the kernel data fetch and RSA public key operation. |
| 64 */ |
| 65 uint8_t* kernel_signature; /* Signature on the concatenation of |
| 66 * [kernel_version], [options] and |
| 67 * [kernel_data]. */ |
| 68 uint8_t* kernel_data; /* Actual kernel data. */ |
| 69 |
| 70 } KernelImage; |
| 71 |
| 72 /* Error Codes for VerifyFirmware. */ |
| 73 #define VERIFY_KERNEL_SUCCESS 0 |
| 74 #define VERIFY_KERNEL_INVALID_IMAGE 1 |
| 75 #define VERIFY_KERNEL_KEY_SIGNATURE_FAILED 2 |
| 76 #define VERIFY_KERNEL_INVALID_ALGORITHM 3 |
| 77 #define VERIFY_KERNEL_CONFIG_SIGNATURE_FAILED 4 |
| 78 #define VERIFY_KERNEL_SIGNATURE_FAILED 5 |
| 79 #define VERIFY_KERNEL_WRONG_MAGIC 6 |
| 80 #define VERIFY_KERNEL_MAX 7 /* Generic catch-all. */ |
| 81 |
| 82 extern char* kVerifyKernelErrors[VERIFY_KERNEL_MAX]; |
| 83 |
| 84 /* Checks for the sanity of the kernel header pointed by [kernel_header_blob]. |
| 85 * If [dev_mode] is enabled, also checks the firmware key signature using the |
| 86 * pre-processed public firmware signing key [firmware_sign_key_blob]. |
| 87 * |
| 88 * On success, put firmware signature algorithm in [firmware_algorithm], |
| 89 * kernel signature algorithm in [kernel_algorithm], kernel header |
| 90 * length in [header_len], and return 0. |
| 91 * Else, return error code on failure. |
| 92 */ |
| 93 int VerifyKernelHeader(const uint8_t* firmware_sign_key_blob, |
| 94 const uint8_t* kernel_header_blob, |
| 95 const int dev_mode, |
| 96 int* firmware_algorithm, |
| 97 int* kernel_algorithm, |
| 98 int* header_len); |
| 99 |
| 100 /* Checks the kernel config (analogous to preamble for firmware) signature on |
| 101 * kernel config pointed by [kernel_config_blob] using the signing key |
| 102 * [kernel_sign_key]. |
| 103 * |
| 104 * On success, put kernel length into [kernel_len], and return 0. |
| 105 * Else, return error code on failure. |
| 106 */ |
| 107 int VerifyKernelConfig(RSAPublicKey* kernel_sign_key, |
| 108 const uint8_t* kernel_config_blob, |
| 109 int algorithm, |
| 110 uint64_t* kernel_len); |
| 111 |
| 112 /* Checks the signature on the kernel data at location [kernel_data_start]. |
| 113 * The length of the actual kernel data is kernel _len and it is assumed to |
| 114 * be prepended with the signature whose size depends on the signature_algorithm |
| 115 * [algorithm]. |
| 116 * |
| 117 * Return 0 on success, error code on failure. |
| 118 */ |
| 119 int VerifyKernelData(RSAPublicKey* kernel_sign_key, |
| 120 const uint8_t* kernel_config_start, |
| 121 const uint8_t* kernel_data_start, |
| 122 uint64_t kernel_len, |
| 123 int algorithm); |
| 124 |
| 125 /* Performs a chained verify of the kernel blob [kernel_blob]. If |
| 126 * [dev_mode] is 0 [inactive], then the pre-processed public signing key |
| 127 * [root_key_blob] is used to verify the signature of the signing key, |
| 128 * else the check is skipped. |
| 129 * |
| 130 * TODO(gauravsh): Does the dev mode only effect the R/W firmware verification, |
| 131 * or kernel verification, or both? |
| 132 * |
| 133 * Returns 0 on success, error code on failure. |
| 134 * |
| 135 * NOTE: The length of the kernel blob is derived from reading the fields |
| 136 * in the first few bytes of the buffer. This might look risky but in firmware |
| 137 * land, the start address of the kernel_blob will always be fixed depending |
| 138 * on the memory map on the particular platform. In addition, the signature on |
| 139 * length itself is checked early in the verification process for extra safety. |
| 140 */ |
| 141 int VerifyKernel(const uint8_t* signing_key_blob, |
| 142 const uint8_t* kernel_blob, |
| 143 const int dev_mode); |
| 144 |
| 145 /* Returns the logical version of a kernel blob which is calculated as |
| 146 * (kernel_key_version << 16 | kernel_version). */ |
| 147 uint32_t GetLogicalKernelVersion(uint8_t* kernel_blob); |
| 148 |
| 149 #define BOOT_KERNEL_A_CONTINUE 1 |
| 150 #define BOOT_KERNEL_B_CONTINUE 2 |
| 151 #define BOOT_KERNEL_RECOVERY_CONTINUE 3 |
| 152 |
| 153 /* Contains information about the kernel paritition |
| 154 * gleaned from the GPT partition table. |
| 155 * |
| 156 * Based on the Chromium OS Drive Map design document by |
| 157 * rspangler@chromium.org. |
| 158 * |
| 159 */ |
| 160 typedef struct kernel_entry { |
| 161 uint8_t* kernel_blob; /* Pointer to actual kernel. */ |
| 162 uint8_t boot_priority; /* 15 = highest, 1 = lowest, 0 = not bootable. */ |
| 163 uint8_t boot_tries_remaining; /* Used when boot_priority = 0. */ |
| 164 uint8_t boot_success_flag; /* Set to 1 on successful boot by AU. */ |
| 165 } kernel_entry; |
| 166 |
| 167 /* This function is the driver used by the RW firmware to |
| 168 * determine which copy of the kernel to boot from. It performs |
| 169 * the requisite priority and remaining tries checking for a specific |
| 170 * kernel partition, does rollback index checking, including updating |
| 171 * if required. |
| 172 * |
| 173 * Returns the code path to follow. It is one of: |
| 174 * BOOT_KERNEL_A_CONTINUE Boot from Kenrel A |
| 175 * BOOT_KERNEL_B_CONTINUE Boot from Kernel B |
| 176 * BOOT_KERNEL_RECOVERY_CONTINUE Jump to recovery mode |
| 177 */ |
| 178 int VerifyKernelDriver_f(uint8_t* firmware_key_blob, |
| 179 kernel_entry* kernelA, |
| 180 kernel_entry* kernelB, |
| 181 int dev_mode); |
| 182 |
| 183 #endif /* VBOOT_REFERENCE_KERNEL_IMAGE_FW_H_ */ |
OLD | NEW |