1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Purgatory code running between two kernels. 4 * 5 * Copyright IBM Corp. 2018 6 * 7 * Author(s): Philipp Rudo <prudo@linux.vnet.ibm.com> 8 */ 9 10 #include <linux/kexec.h> 11 #include <linux/sha256.h> 12 #include <linux/string.h> 13 #include <asm/purgatory.h> 14 15 struct kexec_sha_region purgatory_sha_regions[KEXEC_SEGMENT_MAX]; 16 u8 purgatory_sha256_digest[SHA256_DIGEST_SIZE]; 17 18 u64 kernel_entry; 19 u64 kernel_type; 20 21 u64 crash_start; 22 u64 crash_size; 23 24 int verify_sha256_digest(void) 25 { 26 struct kexec_sha_region *ptr, *end; 27 u8 digest[SHA256_DIGEST_SIZE]; 28 struct sha256_state sctx; 29 30 sha256_init(&sctx); 31 end = purgatory_sha_regions + ARRAY_SIZE(purgatory_sha_regions); 32 33 for (ptr = purgatory_sha_regions; ptr < end; ptr++) 34 sha256_update(&sctx, (uint8_t *)(ptr->start), ptr->len); 35 36 sha256_final(&sctx, digest); 37 38 if (memcmp(digest, purgatory_sha256_digest, sizeof(digest))) 39 return 1; 40 41 return 0; 42 } 43