calculate a "sum" based upon pointers to functions all over the kernel,
authorderaadt <deraadt@openbsd.org>
Thu, 22 Jun 2017 15:56:29 +0000 (15:56 +0000)
committerderaadt <deraadt@openbsd.org>
Thu, 22 Jun 2017 15:56:29 +0000 (15:56 +0000)
so that an unhibernate kernel can detect if it is running with the
kernel it booted.
ok mlarkin

sys/kern/subr_hibernate.c
sys/sys/hibernate.h

index 31cff23..1cc4ed2 100644 (file)
@@ -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>
@@ -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) ) {
index b959a11..ff96010 100644 (file)
@@ -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 <ariane@stack.nl>
@@ -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