summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2009-11-30 05:19:21 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2009-11-30 05:19:21 +0000
commitfeebd111ddd2c056aaf1d298579fa7c2335065bb (patch)
treee2da801da863a771a865a59998c303f8b92b842b
parentad09fdc7ec83e11cbd34700b0c24c204bbc05cdb (diff)
Use the new Elfxx_Phdr check hook to prevent loading a kernel not compiled
for the platform we are running on (i.e. trying to boot e.g. bsd.IP32 on an IP27 machine).
-rw-r--r--sys/arch/sgi/include/loadfile_machdep.h6
-rw-r--r--sys/arch/sgi/stand/boot/boot.c40
2 files changed, 43 insertions, 3 deletions
diff --git a/sys/arch/sgi/include/loadfile_machdep.h b/sys/arch/sgi/include/loadfile_machdep.h
index 85b30239159..5bdbd672515 100644
--- a/sys/arch/sgi/include/loadfile_machdep.h
+++ b/sys/arch/sgi/include/loadfile_machdep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: loadfile_machdep.h,v 1.3 2008/06/26 05:42:12 ray Exp $ */
+/* $OpenBSD: loadfile_machdep.h,v 1.4 2009/11/30 05:19:18 miod Exp $ */
/* $NetBSD: loadfile_machdep.h,v 1.2 2001/10/31 17:20:49 thorpej Exp $ */
/*-
@@ -47,4 +47,6 @@
#define PROGRESS(a) (void) printf a
#define ALLOC(a) alloc(a)
#define FREE(a, b) free(a, b)
-#define OKMAGIC(a) ((a) == OMAGIC)
+
+extern int check_phdr(void *);
+#define CHECK_PHDR(sz,phdr) check_phdr(phdr)
diff --git a/sys/arch/sgi/stand/boot/boot.c b/sys/arch/sgi/stand/boot/boot.c
index 27c597ec9ff..c5451b603bf 100644
--- a/sys/arch/sgi/stand/boot/boot.c
+++ b/sys/arch/sgi/stand/boot/boot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.c,v 1.14 2009/11/24 13:31:41 miod Exp $ */
+/* $OpenBSD: boot.c,v 1.15 2009/11/30 05:19:20 miod Exp $ */
/*
* Copyright (c) 2004 Opsycon AB, www.opsycon.se.
@@ -34,6 +34,7 @@
#include <mips64/arcbios.h>
#include <mips64/cpu.h>
+#include <sys/exec_elf.h>
#include "loadfile.h"
char *strstr(char *, const char *); /* strstr.c */
@@ -175,3 +176,40 @@ dobootopts(int argc, char **argv)
}
}
}
+
+/*
+ * Prevent loading a wrong kernel.
+ */
+int
+check_phdr(void *v)
+{
+ Elf64_Phdr *phdr = (Elf64_Phdr *)v;
+ uint64_t addr;
+
+ switch (IP) {
+ case 27:
+ addr = 0xa800000000000000ULL >> 28;
+ break;
+ case 30:
+ addr = 0xa800000020000000ULL >> 28;
+ break;
+ case 32:
+ addr = 0xffffffff80000000ULL >> 28;
+ break;
+ default:
+ /*
+ * If the system could not be identified, accept any
+ * address and hope the user knows what's he's doing.
+ */
+ return 0;
+ }
+
+ if ((phdr->p_vaddr >> 28) != addr) {
+ /* I'm sorry Dave, I can't let you do that. */
+ printf("This kernel does not seem to be compiled for this"
+ " machine type.\nYou need to boot an IP%d kernel.\n", IP);
+ return 1;
+ }
+
+ return 0;
+}