diff options
author | 2017-06-22 15:56:29 +0000 | |
---|---|---|
committer | 2017-06-22 15:56:29 +0000 | |
commit | bee1d453050075cf36cedf741986cb44cb65658c (patch) | |
tree | dc833882fe57d2566d58db129c685d65ad8292a2 /sys/kern/subr_hibernate.c | |
parent | Drop support for old (>4yr) timestamp formats in leases (diff) | |
download | wireguard-openbsd-bee1d453050075cf36cedf741986cb44cb65658c.tar.xz wireguard-openbsd-bee1d453050075cf36cedf741986cb44cb65658c.zip |
calculate a "sum" based upon pointers to functions all over the kernel,
so that an unhibernate kernel can detect if it is running with the
kernel it booted.
ok mlarkin
Diffstat (limited to 'sys/kern/subr_hibernate.c')
-rw-r--r-- | sys/kern/subr_hibernate.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/sys/kern/subr_hibernate.c b/sys/kern/subr_hibernate.c index 31cff230b07..1cc4ed2f6cd 100644 --- a/sys/kern/subr_hibernate.c +++ b/sys/kern/subr_hibernate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_hibernate.c,v 1.121 2017/03/27 20:26:39 deraadt Exp $ */ +/* $OpenBSD: subr_hibernate.c,v 1.122 2017/06/22 15:56:29 deraadt Exp $ */ /* * Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl> @@ -546,6 +546,17 @@ uvm_page_rle(paddr_t addr) } /* + * Calculate a hopefully unique version # for this kernel, based upon + * how it was linked. + */ +u_int32_t +hibsum(void) +{ + return ((long)malloc ^ (long)km_alloc ^ (long)printf ^ (long)strlen); +} + + +/* * Fills out the hibernate_info union pointed to by hib * with information about this machine (swap signature block * offsets, number of memory ranges, kernel in use, etc) @@ -597,6 +608,7 @@ get_hibernate_info(union hibernate_info *hib, int suspend) memset(&hib->kernel_version, 0, 128); bcopy(version, &hib->kernel_version, min(strlen(version), sizeof(hib->kernel_version)-1)); + hib->kernel_sum = hibsum(); if (suspend) { /* Grab the previously-allocated piglet addresses */ @@ -927,6 +939,12 @@ hibernate_compare_signature(union hibernate_info *mine, return (1); } + if (hibsum() != disk->kernel_sum) { + DPRINTF("hibernate sum version mismatch %x %x\n", + hibsum(), disk->kernel_sum); + return (1); + } + for (i = 0; i < mine->nranges; i++) { if ((mine->ranges[i].base != disk->ranges[i].base) || (mine->ranges[i].end != disk->ranges[i].end) ) { |