From: deraadt Date: Thu, 22 Jun 2017 15:56:29 +0000 (+0000) Subject: calculate a "sum" based upon pointers to functions all over the kernel, X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=bee1d453050075cf36cedf741986cb44cb65658c;p=openbsd 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 --- 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 @@ -545,6 +545,17 @@ uvm_page_rle(paddr_t addr) return min((pg_end - pg), HIBERNATE_CHUNK_SIZE/PAGE_SIZE); } +/* + * 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 @@ -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) ) { diff --git a/sys/sys/hibernate.h b/sys/sys/hibernate.h index b959a11dc65..ff960101f8c 100644 --- a/sys/sys/hibernate.h +++ b/sys/sys/hibernate.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hibernate.h,v 1.40 2016/09/27 02:53:49 dlg Exp $ */ +/* $OpenBSD: hibernate.h,v 1.41 2017/06/22 15:56:29 deraadt Exp $ */ /* * Copyright (c) 2011 Ariane van der Steldt @@ -93,6 +93,7 @@ union hibernate_info { paddr_t piglet_pa; vaddr_t piglet_va; char kernel_version[128]; + u_int32_t kernel_sum; hibio_fn io_func; void *io_page; #ifndef NO_PROPOLICE