Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 1 | /* |
David Brown | aac7111 | 2020-02-03 16:13:42 -0700 | [diff] [blame] | 2 | * SPDX-License-Identifier: Apache-2.0 |
| 3 | * |
| 4 | * Copyright (c) 2017-2019 Linaro LTD |
| 5 | * Copyright (c) 2016-2019 JUUL Labs |
Roland Mikhel | 206b914 | 2023-02-23 15:28:52 +0100 | [diff] [blame] | 6 | * Copyright (c) 2019-2023 Arm Limited |
David Brown | aac7111 | 2020-02-03 16:13:42 -0700 | [diff] [blame] | 7 | * |
| 8 | * Original license: |
| 9 | * |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 10 | * Licensed to the Apache Software Foundation (ASF) under one |
| 11 | * or more contributor license agreements. See the NOTICE file |
| 12 | * distributed with this work for additional information |
| 13 | * regarding copyright ownership. The ASF licenses this file |
| 14 | * to you under the Apache License, Version 2.0 (the |
| 15 | * "License"); you may not use this file except in compliance |
| 16 | * with the License. You may obtain a copy of the License at |
| 17 | * |
| 18 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 19 | * |
| 20 | * Unless required by applicable law or agreed to in writing, |
| 21 | * software distributed under the License is distributed on an |
| 22 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 23 | * KIND, either express or implied. See the License for the |
| 24 | * specific language governing permissions and limitations |
| 25 | * under the License. |
| 26 | */ |
| 27 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 28 | #include <stddef.h> |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 29 | #include <stdint.h> |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 30 | #include <inttypes.h> |
| 31 | #include <string.h> |
| 32 | |
Andrzej Puzdrowski | b788c71 | 2018-04-12 12:42:49 +0200 | [diff] [blame] | 33 | #include <flash_map_backend/flash_map_backend.h> |
| 34 | |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 35 | #include "bootutil/image.h" |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 36 | #include "bootutil/crypto/sha.h" |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 37 | #include "bootutil/sign_key.h" |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 38 | #include "bootutil/security_cnt.h" |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 39 | #include "bootutil/fault_injection_hardening.h" |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 40 | |
Fabio Utzig | ba1fbe6 | 2017-07-21 14:01:20 -0300 | [diff] [blame] | 41 | #include "mcuboot_config/mcuboot_config.h" |
Fabio Utzig | eed80b6 | 2017-06-10 08:03:05 -0300 | [diff] [blame] | 42 | |
Fabio Utzig | ba82904 | 2018-09-18 08:29:34 -0300 | [diff] [blame] | 43 | #ifdef MCUBOOT_ENC_IMAGES |
| 44 | #include "bootutil/enc_key.h" |
| 45 | #endif |
| 46 | #if defined(MCUBOOT_SIGN_RSA) |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 47 | #include "mbedtls/rsa.h" |
David Brown | d7e350d | 2017-04-24 13:29:28 -0600 | [diff] [blame] | 48 | #endif |
Roland Mikhel | 206b914 | 2023-02-23 15:28:52 +0100 | [diff] [blame] | 49 | #if defined(MCUBOOT_SIGN_EC256) |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 50 | #include "mbedtls/ecdsa.h" |
David Brown | d7e350d | 2017-04-24 13:29:28 -0600 | [diff] [blame] | 51 | #endif |
Arvin Farahmand | f824019 | 2020-05-05 11:43:52 -0400 | [diff] [blame] | 52 | #if defined(MCUBOOT_ENC_IMAGES) || defined(MCUBOOT_SIGN_RSA) || \ |
Roland Mikhel | 206b914 | 2023-02-23 15:28:52 +0100 | [diff] [blame] | 53 | defined(MCUBOOT_SIGN_EC256) |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 54 | #include "mbedtls/asn1.h" |
Arvin Farahmand | f824019 | 2020-05-05 11:43:52 -0400 | [diff] [blame] | 55 | #endif |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 56 | |
| 57 | #include "bootutil_priv.h" |
| 58 | |
| 59 | /* |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 60 | * Compute SHA hash over the image. |
| 61 | * (SHA384 if ECDSA-P384 is being used, |
| 62 | * SHA256 otherwise). |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 63 | */ |
| 64 | static int |
Fabio Utzig | 10ee648 | 2019-08-01 12:04:52 -0300 | [diff] [blame] | 65 | bootutil_img_hash(struct enc_key_data *enc_state, int image_index, |
| 66 | struct image_header *hdr, const struct flash_area *fap, |
| 67 | uint8_t *tmp_buf, uint32_t tmp_buf_sz, uint8_t *hash_result, |
| 68 | uint8_t *seed, int seed_len) |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 69 | { |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 70 | bootutil_sha_context sha_ctx; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 71 | uint32_t blk_sz; |
| 72 | uint32_t size; |
Fabio Utzig | 2fc80df | 2018-12-14 06:47:38 -0200 | [diff] [blame] | 73 | uint16_t hdr_size; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 74 | uint32_t off; |
| 75 | int rc; |
Fabio Utzig | ba82904 | 2018-09-18 08:29:34 -0300 | [diff] [blame] | 76 | uint32_t blk_off; |
Fabio Utzig | e52c08e | 2019-09-11 19:32:00 -0300 | [diff] [blame] | 77 | uint32_t tlv_off; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 78 | |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 79 | #if (BOOT_IMAGE_NUMBER == 1) || !defined(MCUBOOT_ENC_IMAGES) || \ |
| 80 | defined(MCUBOOT_RAM_LOAD) |
Fabio Utzig | 10ee648 | 2019-08-01 12:04:52 -0300 | [diff] [blame] | 81 | (void)enc_state; |
Fabio Utzig | b0f0473 | 2019-07-31 09:49:19 -0300 | [diff] [blame] | 82 | (void)image_index; |
Fabio Utzig | c962135 | 2019-08-08 12:15:51 -0300 | [diff] [blame] | 83 | (void)hdr_size; |
Fabio Utzig | e52c08e | 2019-09-11 19:32:00 -0300 | [diff] [blame] | 84 | (void)blk_off; |
| 85 | (void)tlv_off; |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 86 | #ifdef MCUBOOT_RAM_LOAD |
| 87 | (void)blk_sz; |
| 88 | (void)off; |
| 89 | (void)rc; |
David Brown | 122f9e7 | 2021-05-21 15:58:56 -0600 | [diff] [blame] | 90 | (void)fap; |
| 91 | (void)tmp_buf; |
| 92 | (void)tmp_buf_sz; |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 93 | #endif |
Fabio Utzig | b0f0473 | 2019-07-31 09:49:19 -0300 | [diff] [blame] | 94 | #endif |
| 95 | |
Fabio Utzig | bc07793 | 2019-08-26 11:16:34 -0300 | [diff] [blame] | 96 | #ifdef MCUBOOT_ENC_IMAGES |
| 97 | /* Encrypted images only exist in the secondary slot */ |
| 98 | if (MUST_DECRYPT(fap, image_index, hdr) && |
| 99 | !boot_enc_valid(enc_state, image_index, fap)) { |
| 100 | return -1; |
| 101 | } |
| 102 | #endif |
| 103 | |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 104 | bootutil_sha_init(&sha_ctx); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 105 | |
| 106 | /* in some cases (split image) the hash is seeded with data from |
| 107 | * the loader image */ |
Fabio Utzig | 5398604 | 2017-12-12 14:57:07 -0200 | [diff] [blame] | 108 | if (seed && (seed_len > 0)) { |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 109 | bootutil_sha_update(&sha_ctx, seed, seed_len); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 110 | } |
| 111 | |
David Vincze | e32483f | 2019-06-13 10:46:24 +0200 | [diff] [blame] | 112 | /* Hash is computed over image header and image itself. */ |
Fabio Utzig | e52c08e | 2019-09-11 19:32:00 -0300 | [diff] [blame] | 113 | size = hdr_size = hdr->ih_hdr_size; |
| 114 | size += hdr->ih_img_size; |
| 115 | tlv_off = size; |
David Vincze | e32483f | 2019-06-13 10:46:24 +0200 | [diff] [blame] | 116 | |
Fabio Utzig | e52c08e | 2019-09-11 19:32:00 -0300 | [diff] [blame] | 117 | /* If protected TLVs are present they are also hashed. */ |
| 118 | size += hdr->ih_protect_tlv_size; |
David Vincze | e32483f | 2019-06-13 10:46:24 +0200 | [diff] [blame] | 119 | |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 120 | #ifdef MCUBOOT_RAM_LOAD |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 121 | bootutil_sha_update(&sha_ctx, |
| 122 | (void*)(IMAGE_RAM_BASE + hdr->ih_load_addr), |
| 123 | size); |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 124 | #else |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 125 | for (off = 0; off < size; off += blk_sz) { |
| 126 | blk_sz = size - off; |
Fabio Utzig | e52c08e | 2019-09-11 19:32:00 -0300 | [diff] [blame] | 127 | if (blk_sz > tmp_buf_sz) { |
| 128 | blk_sz = tmp_buf_sz; |
| 129 | } |
Fabio Utzig | c21c210 | 2019-09-10 10:10:42 -0300 | [diff] [blame] | 130 | #ifdef MCUBOOT_ENC_IMAGES |
| 131 | /* The only data that is encrypted in an image is the payload; |
| 132 | * both header and TLVs (when protected) are not. |
| 133 | */ |
| 134 | if ((off < hdr_size) && ((off + blk_sz) > hdr_size)) { |
| 135 | /* read only the header */ |
| 136 | blk_sz = hdr_size - off; |
Fabio Utzig | e52c08e | 2019-09-11 19:32:00 -0300 | [diff] [blame] | 137 | } |
| 138 | if ((off < tlv_off) && ((off + blk_sz) > tlv_off)) { |
| 139 | /* read only up to the end of the image payload */ |
| 140 | blk_sz = tlv_off - off; |
Fabio Utzig | c21c210 | 2019-09-10 10:10:42 -0300 | [diff] [blame] | 141 | } |
| 142 | #endif |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 143 | rc = flash_area_read(fap, off, tmp_buf, blk_sz); |
| 144 | if (rc) { |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 145 | bootutil_sha_drop(&sha_ctx); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 146 | return rc; |
| 147 | } |
Fabio Utzig | ba82904 | 2018-09-18 08:29:34 -0300 | [diff] [blame] | 148 | #ifdef MCUBOOT_ENC_IMAGES |
Fabio Utzig | c21c210 | 2019-09-10 10:10:42 -0300 | [diff] [blame] | 149 | if (MUST_DECRYPT(fap, image_index, hdr)) { |
Fabio Utzig | e52c08e | 2019-09-11 19:32:00 -0300 | [diff] [blame] | 150 | /* Only payload is encrypted (area between header and TLVs) */ |
| 151 | if (off >= hdr_size && off < tlv_off) { |
Fabio Utzig | c21c210 | 2019-09-10 10:10:42 -0300 | [diff] [blame] | 152 | blk_off = (off - hdr_size) & 0xf; |
| 153 | boot_encrypt(enc_state, image_index, fap, off - hdr_size, |
| 154 | blk_sz, blk_off, tmp_buf); |
| 155 | } |
Fabio Utzig | ba82904 | 2018-09-18 08:29:34 -0300 | [diff] [blame] | 156 | } |
| 157 | #endif |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 158 | bootutil_sha_update(&sha_ctx, tmp_buf, blk_sz); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 159 | } |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 160 | #endif /* MCUBOOT_RAM_LOAD */ |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 161 | bootutil_sha_finish(&sha_ctx, hash_result); |
| 162 | bootutil_sha_drop(&sha_ctx); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | /* |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 168 | * Currently, we only support being able to verify one type of |
| 169 | * signature, because there is a single verification function that we |
| 170 | * call. List the type of TLV we are expecting. If we aren't |
| 171 | * configured for any signature, don't define this macro. |
| 172 | */ |
Fabio Utzig | 4876484 | 2019-05-10 19:28:24 -0300 | [diff] [blame] | 173 | #if (defined(MCUBOOT_SIGN_RSA) + \ |
Fabio Utzig | 4876484 | 2019-05-10 19:28:24 -0300 | [diff] [blame] | 174 | defined(MCUBOOT_SIGN_EC256) + \ |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 175 | defined(MCUBOOT_SIGN_EC384) + \ |
Fabio Utzig | 4876484 | 2019-05-10 19:28:24 -0300 | [diff] [blame] | 176 | defined(MCUBOOT_SIGN_ED25519)) > 1 |
Fabio Utzig | 3501c01 | 2019-05-13 15:07:25 -0700 | [diff] [blame] | 177 | #error "Only a single signature type is supported!" |
| 178 | #endif |
| 179 | |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 180 | #if defined(MCUBOOT_SIGN_RSA) |
Fabio Utzig | 3501c01 | 2019-05-13 15:07:25 -0700 | [diff] [blame] | 181 | # if MCUBOOT_SIGN_RSA_LEN == 2048 |
| 182 | # define EXPECTED_SIG_TLV IMAGE_TLV_RSA2048_PSS |
| 183 | # elif MCUBOOT_SIGN_RSA_LEN == 3072 |
| 184 | # define EXPECTED_SIG_TLV IMAGE_TLV_RSA3072_PSS |
| 185 | # else |
| 186 | # error "Unsupported RSA signature length" |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 187 | # endif |
Fabio Utzig | 3501c01 | 2019-05-13 15:07:25 -0700 | [diff] [blame] | 188 | # define SIG_BUF_SIZE (MCUBOOT_SIGN_RSA_LEN / 8) |
| 189 | # define EXPECTED_SIG_LEN(x) ((x) == SIG_BUF_SIZE) /* 2048 bits */ |
Roland Mikhel | 63d2346 | 2023-02-08 14:00:54 +0100 | [diff] [blame] | 190 | #elif defined(MCUBOOT_SIGN_EC256) || \ |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 191 | defined(MCUBOOT_SIGN_EC384) || \ |
Roland Mikhel | 63d2346 | 2023-02-08 14:00:54 +0100 | [diff] [blame] | 192 | defined(MCUBOOT_SIGN_EC) |
| 193 | # define EXPECTED_SIG_TLV IMAGE_TLV_ECDSA_SIG |
Fabio Utzig | 3501c01 | 2019-05-13 15:07:25 -0700 | [diff] [blame] | 194 | # define SIG_BUF_SIZE 128 |
Roland Mikhel | 63d2346 | 2023-02-08 14:00:54 +0100 | [diff] [blame] | 195 | # define EXPECTED_SIG_LEN(x) (1) /* always true, ASN.1 will validate */ |
Fabio Utzig | 4876484 | 2019-05-10 19:28:24 -0300 | [diff] [blame] | 196 | #elif defined(MCUBOOT_SIGN_ED25519) |
| 197 | # define EXPECTED_SIG_TLV IMAGE_TLV_ED25519 |
| 198 | # define SIG_BUF_SIZE 64 |
| 199 | # define EXPECTED_SIG_LEN(x) ((x) == SIG_BUF_SIZE) |
Fabio Utzig | 3501c01 | 2019-05-13 15:07:25 -0700 | [diff] [blame] | 200 | #else |
| 201 | # define SIG_BUF_SIZE 32 /* no signing, sha256 digest only */ |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 202 | #endif |
| 203 | |
| 204 | #ifdef EXPECTED_SIG_TLV |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 205 | #if !defined(MCUBOOT_HW_KEY) |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 206 | static int |
| 207 | bootutil_find_key(uint8_t *keyhash, uint8_t keyhash_len) |
| 208 | { |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 209 | bootutil_sha_context sha_ctx; |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 210 | int i; |
| 211 | const struct bootutil_key *key; |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 212 | uint8_t hash[IMAGE_HASH_SIZE]; |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 213 | |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 214 | if (keyhash_len > IMAGE_HASH_SIZE) { |
Fabio Utzig | 15c1467 | 2019-08-09 07:45:20 -0300 | [diff] [blame] | 215 | return -1; |
| 216 | } |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 217 | |
| 218 | for (i = 0; i < bootutil_key_cnt; i++) { |
| 219 | key = &bootutil_keys[i]; |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 220 | bootutil_sha_init(&sha_ctx); |
| 221 | bootutil_sha_update(&sha_ctx, key->key, *key->len); |
| 222 | bootutil_sha_finish(&sha_ctx, hash); |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 223 | if (!memcmp(hash, keyhash, keyhash_len)) { |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 224 | bootutil_sha_drop(&sha_ctx); |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 225 | return i; |
| 226 | } |
| 227 | } |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 228 | bootutil_sha_drop(&sha_ctx); |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 229 | return -1; |
| 230 | } |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 231 | #else |
| 232 | extern unsigned int pub_key_len; |
| 233 | static int |
| 234 | bootutil_find_key(uint8_t image_index, uint8_t *key, uint16_t key_len) |
| 235 | { |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 236 | bootutil_sha_context sha_ctx; |
| 237 | uint8_t hash[IMAGE_HASH_SIZE]; |
| 238 | uint8_t key_hash[IMAGE_HASH_SIZE]; |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 239 | size_t key_hash_size = sizeof(key_hash); |
| 240 | int rc; |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 241 | FIH_DECLARE(fih_rc, FIH_FAILURE); |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 242 | |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 243 | bootutil_sha_init(&sha_ctx); |
| 244 | bootutil_sha_update(&sha_ctx, key, key_len); |
| 245 | bootutil_sha_finish(&sha_ctx, hash); |
| 246 | bootutil_sha_drop(&sha_ctx); |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 247 | |
| 248 | rc = boot_retrieve_public_key_hash(image_index, key_hash, &key_hash_size); |
| 249 | if (rc) { |
Mark Horvath | 7ebf0e8 | 2021-02-19 09:55:35 +0100 | [diff] [blame] | 250 | return -1; |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 251 | } |
| 252 | |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 253 | /* Adding hardening to avoid this potential attack: |
| 254 | * - Image is signed with an arbitrary key and the corresponding public |
| 255 | * key is added as a TLV field. |
| 256 | * - During public key validation (comparing against key-hash read from |
| 257 | * HW) a fault is injected to accept the public key as valid one. |
| 258 | */ |
| 259 | FIH_CALL(boot_fih_memequal, fih_rc, hash, key_hash, key_hash_size); |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 260 | if (FIH_EQ(fih_rc, FIH_SUCCESS)) { |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 261 | bootutil_keys[0].key = key; |
| 262 | pub_key_len = key_len; |
| 263 | return 0; |
| 264 | } |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 265 | |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 266 | return -1; |
| 267 | } |
| 268 | #endif /* !MCUBOOT_HW_KEY */ |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 269 | #endif |
| 270 | |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 271 | /** |
| 272 | * Reads the value of an image's security counter. |
| 273 | * |
| 274 | * @param hdr Pointer to the image header structure. |
| 275 | * @param fap Pointer to a description structure of the image's |
| 276 | * flash area. |
| 277 | * @param security_cnt Pointer to store the security counter value. |
| 278 | * |
| 279 | * @return 0 on success; nonzero on failure. |
| 280 | */ |
| 281 | int32_t |
| 282 | bootutil_get_img_security_cnt(struct image_header *hdr, |
| 283 | const struct flash_area *fap, |
| 284 | uint32_t *img_security_cnt) |
| 285 | { |
| 286 | struct image_tlv_iter it; |
| 287 | uint32_t off; |
| 288 | uint16_t len; |
| 289 | int32_t rc; |
| 290 | |
| 291 | if ((hdr == NULL) || |
| 292 | (fap == NULL) || |
| 293 | (img_security_cnt == NULL)) { |
| 294 | /* Invalid parameter. */ |
| 295 | return BOOT_EBADARGS; |
| 296 | } |
| 297 | |
| 298 | /* The security counter TLV is in the protected part of the TLV area. */ |
| 299 | if (hdr->ih_protect_tlv_size == 0) { |
| 300 | return BOOT_EBADIMAGE; |
| 301 | } |
| 302 | |
| 303 | rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_SEC_CNT, true); |
| 304 | if (rc) { |
| 305 | return rc; |
| 306 | } |
| 307 | |
| 308 | /* Traverse through the protected TLV area to find |
| 309 | * the security counter TLV. |
| 310 | */ |
| 311 | |
| 312 | rc = bootutil_tlv_iter_next(&it, &off, &len, NULL); |
| 313 | if (rc != 0) { |
| 314 | /* Security counter TLV has not been found. */ |
| 315 | return -1; |
| 316 | } |
| 317 | |
| 318 | if (len != sizeof(*img_security_cnt)) { |
| 319 | /* Security counter is not valid. */ |
| 320 | return BOOT_EBADIMAGE; |
| 321 | } |
| 322 | |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 323 | rc = LOAD_IMAGE_DATA(hdr, fap, off, img_security_cnt, len); |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 324 | if (rc != 0) { |
| 325 | return BOOT_EFLASH; |
| 326 | } |
| 327 | |
| 328 | return 0; |
| 329 | } |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 330 | |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 331 | /* |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 332 | * Verify the integrity of the image. |
| 333 | * Return non-zero if image could not be validated/does not validate. |
| 334 | */ |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 335 | fih_ret |
Fabio Utzig | 10ee648 | 2019-08-01 12:04:52 -0300 | [diff] [blame] | 336 | bootutil_img_validate(struct enc_key_data *enc_state, int image_index, |
| 337 | struct image_header *hdr, const struct flash_area *fap, |
| 338 | uint8_t *tmp_buf, uint32_t tmp_buf_sz, uint8_t *seed, |
| 339 | int seed_len, uint8_t *out_hash) |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 340 | { |
| 341 | uint32_t off; |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 342 | uint16_t len; |
David Brown | d13318a | 2019-12-04 17:28:40 -0700 | [diff] [blame] | 343 | uint16_t type; |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 344 | int image_hash_valid = 0; |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 345 | #ifdef EXPECTED_SIG_TLV |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 346 | FIH_DECLARE(valid_signature, FIH_FAILURE); |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 347 | int key_id = -1; |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 348 | #ifdef MCUBOOT_HW_KEY |
| 349 | /* Few extra bytes for encoding and for public exponent. */ |
| 350 | uint8_t key_buf[SIG_BUF_SIZE + 24]; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 351 | #endif |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 352 | #endif /* EXPECTED_SIG_TLV */ |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 353 | struct image_tlv_iter it; |
Fabio Utzig | 3501c01 | 2019-05-13 15:07:25 -0700 | [diff] [blame] | 354 | uint8_t buf[SIG_BUF_SIZE]; |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 355 | uint8_t hash[IMAGE_HASH_SIZE]; |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 356 | int rc = 0; |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 357 | FIH_DECLARE(fih_rc, FIH_FAILURE); |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 358 | #ifdef MCUBOOT_HW_ROLLBACK_PROT |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 359 | fih_int security_cnt = fih_int_encode(INT_MAX); |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 360 | uint32_t img_security_cnt = 0; |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 361 | FIH_DECLARE(security_counter_valid, FIH_FAILURE); |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 362 | #endif |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 363 | |
Fabio Utzig | 10ee648 | 2019-08-01 12:04:52 -0300 | [diff] [blame] | 364 | rc = bootutil_img_hash(enc_state, image_index, hdr, fap, tmp_buf, |
| 365 | tmp_buf_sz, hash, seed, seed_len); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 366 | if (rc) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 367 | goto out; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | if (out_hash) { |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 371 | memcpy(out_hash, hash, IMAGE_HASH_SIZE); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 372 | } |
| 373 | |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 374 | rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_ANY, false); |
David Brown | f5b33d8 | 2017-09-01 10:58:27 -0600 | [diff] [blame] | 375 | if (rc) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 376 | goto out; |
David Brown | f5b33d8 | 2017-09-01 10:58:27 -0600 | [diff] [blame] | 377 | } |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 378 | |
Andrzej Puzdrowski | 334b6a6 | 2022-01-21 16:59:18 +0100 | [diff] [blame] | 379 | if (it.tlv_end > bootutil_max_image_size(fap)) { |
| 380 | rc = -1; |
| 381 | goto out; |
| 382 | } |
| 383 | |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 384 | /* |
| 385 | * Traverse through all of the TLVs, performing any checks we know |
| 386 | * and are able to do. |
| 387 | */ |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 388 | while (true) { |
| 389 | rc = bootutil_tlv_iter_next(&it, &off, &len, &type); |
| 390 | if (rc < 0) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 391 | goto out; |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 392 | } else if (rc > 0) { |
| 393 | break; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 394 | } |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 395 | |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 396 | if (type == EXPECTED_HASH_TLV) { |
| 397 | /* Verify the image hash. This must always be present. */ |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 398 | if (len != sizeof(hash)) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 399 | rc = -1; |
| 400 | goto out; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 401 | } |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 402 | rc = LOAD_IMAGE_DATA(hdr, fap, off, buf, sizeof(hash)); |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 403 | if (rc) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 404 | goto out; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 405 | } |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 406 | |
| 407 | FIH_CALL(boot_fih_memequal, fih_rc, hash, buf, sizeof(hash)); |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 408 | if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) { |
| 409 | FIH_SET(fih_rc, FIH_FAILURE); |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 410 | goto out; |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 411 | } |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 412 | |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 413 | image_hash_valid = 1; |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 414 | #ifdef EXPECTED_SIG_TLV |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 415 | #ifndef MCUBOOT_HW_KEY |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 416 | } else if (type == IMAGE_TLV_KEYHASH) { |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 417 | /* |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 418 | * Determine which key we should be checking. |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 419 | */ |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 420 | if (len > IMAGE_HASH_SIZE) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 421 | rc = -1; |
| 422 | goto out; |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 423 | } |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 424 | rc = LOAD_IMAGE_DATA(hdr, fap, off, buf, len); |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 425 | if (rc) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 426 | goto out; |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 427 | } |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 428 | key_id = bootutil_find_key(buf, len); |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 429 | /* |
| 430 | * The key may not be found, which is acceptable. There |
| 431 | * can be multiple signatures, each preceded by a key. |
| 432 | */ |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 433 | #else |
| 434 | } else if (type == IMAGE_TLV_PUBKEY) { |
| 435 | /* |
| 436 | * Determine which key we should be checking. |
| 437 | */ |
| 438 | if (len > sizeof(key_buf)) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 439 | rc = -1; |
| 440 | goto out; |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 441 | } |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 442 | rc = LOAD_IMAGE_DATA(hdr, fap, off, key_buf, len); |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 443 | if (rc) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 444 | goto out; |
David Vincze | 03368b8 | 2020-04-01 12:53:53 +0200 | [diff] [blame] | 445 | } |
| 446 | key_id = bootutil_find_key(image_index, key_buf, len); |
| 447 | /* |
| 448 | * The key may not be found, which is acceptable. There |
| 449 | * can be multiple signatures, each preceded by a key. |
| 450 | */ |
| 451 | #endif /* !MCUBOOT_HW_KEY */ |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 452 | } else if (type == EXPECTED_SIG_TLV) { |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 453 | /* Ignore this signature if it is out of bounds. */ |
| 454 | if (key_id < 0 || key_id >= bootutil_key_cnt) { |
| 455 | key_id = -1; |
| 456 | continue; |
| 457 | } |
Fabio Utzig | 61fd888 | 2019-09-14 20:00:20 -0300 | [diff] [blame] | 458 | if (!EXPECTED_SIG_LEN(len) || len > sizeof(buf)) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 459 | rc = -1; |
| 460 | goto out; |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 461 | } |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 462 | rc = LOAD_IMAGE_DATA(hdr, fap, off, buf, len); |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 463 | if (rc) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 464 | goto out; |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 465 | } |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 466 | FIH_CALL(bootutil_verify_sig, valid_signature, hash, sizeof(hash), |
| 467 | buf, len, key_id); |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 468 | key_id = -1; |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 469 | #endif /* EXPECTED_SIG_TLV */ |
| 470 | #ifdef MCUBOOT_HW_ROLLBACK_PROT |
| 471 | } else if (type == IMAGE_TLV_SEC_CNT) { |
| 472 | /* |
| 473 | * Verify the image's security counter. |
| 474 | * This must always be present. |
| 475 | */ |
| 476 | if (len != sizeof(img_security_cnt)) { |
| 477 | /* Security counter is not valid. */ |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 478 | rc = -1; |
| 479 | goto out; |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 480 | } |
| 481 | |
Tamas Ban | fe03109 | 2020-09-10 17:32:39 +0200 | [diff] [blame] | 482 | rc = LOAD_IMAGE_DATA(hdr, fap, off, &img_security_cnt, len); |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 483 | if (rc) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 484 | goto out; |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 485 | } |
| 486 | |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 487 | FIH_CALL(boot_nv_security_counter_get, fih_rc, image_index, |
| 488 | &security_cnt); |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 489 | if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) { |
| 490 | FIH_SET(fih_rc, FIH_FAILURE); |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 491 | goto out; |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /* Compare the new image's security counter value against the |
| 495 | * stored security counter value. |
| 496 | */ |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 497 | fih_rc = fih_ret_encode_zero_equality(img_security_cnt < |
Roland Mikhel | 61962b9 | 2023-04-25 14:03:08 +0200 | [diff] [blame] | 498 | (uint32_t)fih_int_decode(security_cnt)); |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 499 | if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) { |
| 500 | FIH_SET(fih_rc, FIH_FAILURE); |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 501 | goto out; |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /* The image's security counter has been successfully verified. */ |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 505 | security_counter_valid = fih_rc; |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 506 | #endif /* MCUBOOT_HW_ROLLBACK_PROT */ |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 507 | } |
| 508 | } |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 509 | |
Roland Mikhel | 03c9ad0 | 2023-03-08 15:56:43 +0100 | [diff] [blame] | 510 | rc = !image_hash_valid; |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 511 | if (rc) { |
| 512 | goto out; |
| 513 | } |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 514 | #ifdef EXPECTED_SIG_TLV |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 515 | FIH_SET(fih_rc, valid_signature); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 516 | #endif |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 517 | #ifdef MCUBOOT_HW_ROLLBACK_PROT |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 518 | if (FIH_NOT_EQ(security_counter_valid, FIH_SUCCESS)) { |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 519 | rc = -1; |
| 520 | goto out; |
| 521 | } |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 522 | #endif |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 523 | |
| 524 | out: |
| 525 | if (rc) { |
Michael Grand | 5047f03 | 2022-11-24 16:49:56 +0100 | [diff] [blame] | 526 | FIH_SET(fih_rc, FIH_FAILURE); |
David Vincze | c308413 | 2020-02-18 14:50:47 +0100 | [diff] [blame] | 527 | } |
David Brown | 43cda33 | 2017-09-01 09:53:23 -0600 | [diff] [blame] | 528 | |
Raef Coles | e8fe6cf | 2020-05-26 13:07:40 +0100 | [diff] [blame] | 529 | FIH_RET(fih_rc); |
Christopher Collins | 92ea77f | 2016-12-12 15:59:26 -0800 | [diff] [blame] | 530 | } |