linux/arch/x86/purgatory/purgatory.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0-only
   2/*
   3 * purgatory: Runs between two kernels
   4 *
   5 * Copyright (C) 2014 Red Hat Inc.
   6 *
   7 * Author:
   8 *       Vivek Goyal <vgoyal@redhat.com>
   9 */
  10
  11#include <linux/bug.h>
  12#include <linux/kernel.h>
  13#include <linux/types.h>
  14#include <crypto/sha2.h>
  15#include <asm/purgatory.h>
  16
  17#include "../boot/string.h"
  18
  19u8 purgatory_sha256_digest[SHA256_DIGEST_SIZE] __section(".kexec-purgatory");
  20
  21struct kexec_sha_region purgatory_sha_regions[KEXEC_SEGMENT_MAX] __section(".kexec-purgatory");
  22
  23static int verify_sha256_digest(void)
  24{
  25        struct kexec_sha_region *ptr, *end;
  26        u8 digest[SHA256_DIGEST_SIZE];
  27        struct sha256_state sctx;
  28
  29        sha256_init(&sctx);
  30        end = purgatory_sha_regions + ARRAY_SIZE(purgatory_sha_regions);
  31
  32        for (ptr = purgatory_sha_regions; ptr < end; ptr++)
  33                sha256_update(&sctx, (uint8_t *)(ptr->start), ptr->len);
  34
  35        sha256_final(&sctx, digest);
  36
  37        if (memcmp(digest, purgatory_sha256_digest, sizeof(digest)))
  38                return 1;
  39
  40        return 0;
  41}
  42
  43void purgatory(void)
  44{
  45        int ret;
  46
  47        ret = verify_sha256_digest();
  48        if (ret) {
  49                /* loop forever */
  50                for (;;)
  51                        ;
  52        }
  53}
  54
  55/*
  56 * Defined in order to reuse memcpy() and memset() from
  57 * arch/x86/boot/compressed/string.c
  58 */
  59void warn(const char *msg) {}
  60