~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/purgatory/purgatory.c

Version: ~ [ linux-5.3 ] ~ [ linux-5.2.15 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.73 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.144 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.193 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.193 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.73 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * purgatory: Runs between two kernels
  3  *
  4  * Copyright (C) 2014 Red Hat Inc.
  5  *
  6  * Author:
  7  *       Vivek Goyal <vgoyal@redhat.com>
  8  *
  9  * This source code is licensed under the GNU General Public License,
 10  * Version 2.  See the file COPYING for more details.
 11  */
 12 
 13 #include "sha256.h"
 14 #include "../boot/string.h"
 15 
 16 struct sha_region {
 17         unsigned long start;
 18         unsigned long len;
 19 };
 20 
 21 unsigned long backup_dest = 0;
 22 unsigned long backup_src = 0;
 23 unsigned long backup_sz = 0;
 24 
 25 u8 sha256_digest[SHA256_DIGEST_SIZE] = { 0 };
 26 
 27 struct sha_region sha_regions[16] = {};
 28 
 29 /*
 30  * On x86, second kernel requries first 640K of memory to boot. Copy
 31  * first 640K to a backup region in reserved memory range so that second
 32  * kernel can use first 640K.
 33  */
 34 static int copy_backup_region(void)
 35 {
 36         if (backup_dest)
 37                 memcpy((void *)backup_dest, (void *)backup_src, backup_sz);
 38 
 39         return 0;
 40 }
 41 
 42 int verify_sha256_digest(void)
 43 {
 44         struct sha_region *ptr, *end;
 45         u8 digest[SHA256_DIGEST_SIZE];
 46         struct sha256_state sctx;
 47 
 48         sha256_init(&sctx);
 49         end = &sha_regions[sizeof(sha_regions)/sizeof(sha_regions[0])];
 50         for (ptr = sha_regions; ptr < end; ptr++)
 51                 sha256_update(&sctx, (uint8_t *)(ptr->start), ptr->len);
 52 
 53         sha256_final(&sctx, digest);
 54 
 55         if (memcmp(digest, sha256_digest, sizeof(digest)))
 56                 return 1;
 57 
 58         return 0;
 59 }
 60 
 61 void purgatory(void)
 62 {
 63         int ret;
 64 
 65         ret = verify_sha256_digest();
 66         if (ret) {
 67                 /* loop forever */
 68                 for (;;)
 69                         ;
 70         }
 71         copy_backup_region();
 72 }
 73 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp