| 30 | } |
| 31 | |
| 32 | static int verify_fmap(const struct fmap *fmap) |
| 33 | { |
| 34 | if (memcmp(fmap->signature, FMAP_SIGNATURE, sizeof(fmap->signature))) { |
| 35 | if (ENV_INITIAL_STAGE) |
| 36 | printk(BIOS_ERR, "Invalid FMAP at %#x\n", FMAP_OFFSET); |
| 37 | return -1; |
| 38 | } |
| 39 | |
| 40 | static bool done = false; |
| 41 | if (!CONFIG(CBFS_VERIFICATION) || !ENV_INITIAL_STAGE || done) |
| 42 | return 0; /* Only need to check hash in first stage. */ |
| 43 | |
| 44 | /* On error we need to die right here, lest we risk a TOCTOU attack where the cache is |
| 45 | filled with a tampered FMAP but the later fallback path is fed a valid one. */ |
| 46 | if (metadata_hash_verify_fmap(fmap, FMAP_SIZE) != VB2_SUCCESS) |
| 47 | die("FMAP verification failure"); |
| 48 | |
| 49 | done = true; |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static void report(const struct fmap *fmap) |
| 54 | { |
no test coverage detected