summaryrefslogtreecommitdiff
path: root/sys/arch/amd64
diff options
context:
space:
mode:
authorStefan Sperling <stsp@cvs.openbsd.org>2017-01-05 11:18:55 +0000
committerStefan Sperling <stsp@cvs.openbsd.org>2017-01-05 11:18:55 +0000
commit1197886a3ec36e59181c881b0b35834155919d8f (patch)
treef211f65fc9a54fccdee141c40d7a2ef41ba6b7de /sys/arch/amd64
parent0f0c5d75e3773cca3e130c948d4ac3ea284d63f9 (diff)
Fix boot(8) crashing on some amd64 machines when booting from softraid crypto.
Allocate a 4k temp buffer on the heap instead of the stack. Problem was introduced in arch/amd64/stand/libsa/softraid_amd64.c r1.3. Reported by Andreas Bartelt on bugs@ ok krw@ kettenis@ yasuoka@
Diffstat (limited to 'sys/arch/amd64')
-rw-r--r--sys/arch/amd64/stand/libsa/softraid_amd64.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/sys/arch/amd64/stand/libsa/softraid_amd64.c b/sys/arch/amd64/stand/libsa/softraid_amd64.c
index e464efa1c9e..fee685c7532 100644
--- a/sys/arch/amd64/stand/libsa/softraid_amd64.c
+++ b/sys/arch/amd64/stand/libsa/softraid_amd64.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: softraid_amd64.c,v 1.3 2016/12/24 22:49:38 yasuoka Exp $ */
+/* $OpenBSD: softraid_amd64.c,v 1.4 2017/01/05 11:18:54 stsp Exp $ */
/*
* Copyright (c) 2012 Joel Sing <jsing@openbsd.org>
@@ -435,7 +435,7 @@ findopenbsd_gpt(struct sr_boot_volume *bv, const char **err)
const char openbsd_uuid_code[] = GPT_UUID_OPENBSD;
struct gpt_partition gp;
static struct uuid *openbsd_uuid = NULL, openbsd_uuid_space;
- static u_char buf[4096];
+ u_char *buf;
/* Prepare OpenBSD UUID */
if (openbsd_uuid == NULL) {
@@ -456,6 +456,12 @@ findopenbsd_gpt(struct sr_boot_volume *bv, const char **err)
*err = "disk sector > 4096 bytes\n";
return (-1);
}
+ buf = alloc(bv->sbv_secsize);
+ if (buf == NULL) {
+ *err = "out of memory\n";
+ return (-1);
+ }
+ bzero(buf, bv->sbv_secsize);
/* LBA1: GPT Header */
lba = 1;
@@ -466,17 +472,20 @@ findopenbsd_gpt(struct sr_boot_volume *bv, const char **err)
/* Check signature */
if (letoh64(gh.gh_sig) != GPTSIGNATURE) {
*err = "bad GPT signature\n";
+ free(buf, bv->sbv_secsize);
return (-1);
}
if (letoh32(gh.gh_rev) != GPTREVISION) {
*err = "bad GPT revision\n";
+ free(buf, bv->sbv_secsize);
return (-1);
}
ghsize = letoh32(gh.gh_size);
if (ghsize < GPTMINHDRSIZE || ghsize > sizeof(struct gpt_header)) {
*err = "bad GPT header size\n";
+ free(buf, bv->sbv_secsize);
return (-1);
}
@@ -487,6 +496,7 @@ findopenbsd_gpt(struct sr_boot_volume *bv, const char **err)
gh.gh_csum = orig_csum;
if (letoh32(orig_csum) != new_csum) {
*err = "bad GPT header checksum\n";
+ free(buf, bv->sbv_secsize);
return (-1);
}
@@ -514,6 +524,9 @@ findopenbsd_gpt(struct sr_boot_volume *bv, const char **err)
found = 1;
}
}
+
+ free(buf, bv->sbv_secsize);
+
if (new_csum != letoh32(gh.gh_part_csum)) {
*err = "bad GPT entries checksum\n";
return (-1);