-/* $OpenBSD: boot.c,v 1.20 2011/06/05 21:49:36 miod Exp $ */
+/* $OpenBSD: boot.c,v 1.21 2013/12/28 02:51:06 deraadt Exp $ */
/* $NetBSD: boot.c,v 1.10 1997/01/18 01:58:33 cgd Exp $ */
/*
int debug;
+char rnddata[BOOTRANDOM_MAX]; /* XXX dummy */
+
int
main()
{
-# $OpenBSD: Makefile.inc,v 1.9 2013/01/17 12:37:44 jsing Exp $
+# $OpenBSD: Makefile.inc,v 1.10 2013/12/28 02:51:06 deraadt Exp $
CFLAGS=${DEBUG} ${COPTS} -Os -Wall -Werror
-CFLAGS+= -fno-stack-protector
+CFLAGS+= -fno-stack-protector -DMDRANDOM
CDIAGFLAGS=
CPPFLAGS+=-I${S} -I${SADIR}/libsa -I. -I${.CURDIR}
SACFLAGS=-D_STANDALONE
-# $OpenBSD: Makefile,v 1.24 2013/06/02 21:01:48 guenther Exp $
+# $OpenBSD: Makefile,v 1.25 2013/12/28 02:51:06 deraadt Exp $
COPTS?=
MAN?= boot.8
LDFLAGS+=-melf_i386 -L/usr/libdata
.PATH: ${SADIR}/libsa
-SRCS+= alloca.S gidt.S
+SRCS+= alloca.S gidt.S random_i386.S
SRCS+= cmd_i386.c dev_i386.c exec_i386.c gateA20.c machdep.c
SRCS+= bioscons.c biosdev.c diskprobe.c memprobe.c time.c
.if ${SOFTRAID:L} == "yes"
-# $OpenBSD: Makefile,v 1.21 2013/06/02 21:01:48 guenther Exp $
+# $OpenBSD: Makefile,v 1.22 2013/12/28 02:51:06 deraadt Exp $
MAN= cdboot.8
.PATH: ${SADIR}/libsa
SRCS+= machdep.c dev_i386.c exec_i386.c cmd_i386.c
-SRCS+= gidt.S alloca.S biosdev.c bioscons.c gateA20.c \
+SRCS+= gidt.S random_i386.S alloca.S biosdev.c bioscons.c gateA20.c \
memprobe.c diskprobe.c time.c
SRCS+= softraid.c
-# $OpenBSD: Makefile,v 1.17 2013/04/23 16:41:13 jsing Exp $
+# $OpenBSD: Makefile,v 1.18 2013/12/28 02:51:07 deraadt Exp $
MAN= pxeboot.8
.PATH: ${SADIR}/libsa
# i386 stuff (so, it will possibly load in the same 64k)
SRCS+= machdep.c exec_i386.c cmd_i386.c
-SRCS+= gidt.S alloca.S biosdev.c bioscons.c gateA20.c \
+SRCS+= gidt.S random_i386.S alloca.S biosdev.c bioscons.c gateA20.c \
memprobe.c diskprobe.c time.c ## biosprobe.c
SRCS+= pxe.c pxe_call.S pxe_net.c
SRCS+= softraid.c
-/* $OpenBSD: cdboot.c,v 1.12 2012/06/26 16:18:45 deraadt Exp $ */
+/* $OpenBSD: cdboot.c,v 1.13 2013/12/28 02:51:07 deraadt Exp $ */
/*
* Copyright (c) 2003 Michael Shalayeff
typedef void (*startfuncp)(int, int, int, int, int, int, caddr_t)
__attribute__ ((noreturn));
+char rnddata[BOOTRANDOM_MAX]; /* XXX dummy */
+
void
boot(dev_t dev)
{
-# $OpenBSD: Makefile.inc,v 1.44 2013/01/18 04:10:16 jsing Exp $
+# $OpenBSD: Makefile.inc,v 1.45 2013/12/28 02:51:07 deraadt Exp $
CFLAGS=${DEBUG} ${COPTS} -Os -Wall -Werror
-CFLAGS+= -fno-stack-protector
+CFLAGS+= -fno-stack-protector -DMDRANDOM
CPPFLAGS+=-I${S} -I${SADIR}/libsa -I. -I${.CURDIR}
SACFLAGS=-D_STANDALONE
DEBUGLIBS=no
-# $OpenBSD: Makefile,v 1.52 2013/06/02 21:01:48 guenther Exp $
+# $OpenBSD: Makefile,v 1.53 2013/12/28 02:51:07 deraadt Exp $
COPTS?=
MAN?= boot.8
SRCS+= boot.c cmd.c vars.c bootarg.c conf.c
.PATH: ${SADIR}/libsa
-SRCS+= alloca.S debug_i386.S gidt.S
+SRCS+= alloca.S debug_i386.S gidt.S random_i386.S
SRCS+= apmprobe.c bioscons.c biosdev.c cmd_i386.c debug.c dev_i386.c \
diskprobe.c exec_i386.c gateA20.c machdep.c memprobe.c pciprobe.c \
ps2probe.c time.c
-# $OpenBSD: Makefile,v 1.19 2013/06/02 21:01:48 guenther Exp $
+# $OpenBSD: Makefile,v 1.20 2013/12/28 02:51:07 deraadt Exp $
MAN= cdboot.8
CLEANFILES+= crt0.o ${PROG}.whole
.PATH: ${SADIR}/libsa
-SRCS+= alloca.S debug_i386.S gidt.S
+SRCS+= alloca.S debug_i386.S gidt.S random_i386.S
SRCS+= cmd_i386.c dev_i386.c exec_i386.c gateA20.c machdep.c
SRCS+= apmprobe.c bioscons.c biosdev.c debug.c diskprobe.c memprobe.c \
pciprobe.c ps2probe.c time.c
-# $OpenBSD: Makefile,v 1.15 2013/04/23 16:41:13 jsing Exp $
+# $OpenBSD: Makefile,v 1.16 2013/12/28 02:51:07 deraadt Exp $
MAN= pxeboot.8
CLEANFILES+= crt0.o ${PROG}.whole
.PATH: ${SADIR}/libsa
-SRCS+= alloca.S debug_i386.S gidt.S
+SRCS+= alloca.S debug_i386.S gidt.S random_i386.S
SRCS+= cmd_i386.c exec_i386.c gateA20.c machdep.c
SRCS+= apmprobe.c bioscons.c biosdev.c debug.c diskprobe.c memprobe.c \
pciprobe.c ps2probe.c time.c
-/* $OpenBSD: boot.c,v 1.22 2012/09/29 21:40:48 miod Exp $ */
+/* $OpenBSD: boot.c,v 1.23 2013/12/28 02:51:07 deraadt Exp $ */
/*
* Copyright (c) 2004 Opsycon AB, www.opsycon.se.
int IP;
+char rnddata[BOOTRANDOM_MAX]; /* XXX dummy */
+
#include "version"
/*
/* $NetBSD: loadfile.c,v 1.10 2000/12/03 02:53:04 tsutsui Exp $ */
-/* $OpenBSD: loadfile_elf.c,v 1.6 2009/11/30 05:18:08 miod Exp $ */
+/* $OpenBSD: loadfile_elf.c,v 1.7 2013/12/28 02:51:07 deraadt Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
}
for (first = 1, i = 0; i < elf->e_phnum; i++) {
+ if (phdr[i].p_type == PT_OPENBSD_RANDOMIZE) {
+ int m;
+
+ /* Fill segment. */
+ for (pos = 0; pos < phdr[i].p_filesz; pos += m) {
+ m = MIN(phdr[i].p_filesz - pos, sizeof(rnddata));
+ BCOPY(rnddata, phdr[i].p_paddr + pos, m);
+ }
+ continue;
+ }
+
if (phdr[i].p_type != PT_LOAD ||
(phdr[i].p_flags & (PF_W|PF_R|PF_X)) == 0)
continue;
-/* $OpenBSD: stand.h,v 1.55 2013/01/07 20:02:11 miod Exp $ */
+/* $OpenBSD: stand.h,v 1.56 2013/12/28 02:51:07 deraadt Exp $ */
/* $NetBSD: stand.h,v 1.18 1996/11/30 04:35:51 gwr Exp $ */
/*-
char *getdisklabel(const char *, struct disklabel *);
u_int dkcksum(struct disklabel *);
+#define BOOTRANDOM "/etc/random.seed"
+#define BOOTRANDOM_MAX 512
+extern char rnddata[BOOTRANDOM_MAX];
+
void printf(const char *, ...);
int snprintf(char *, size_t, const char *, ...);
void vprintf(const char *, __va_list);
-/* $OpenBSD: boot.c,v 1.37 2011/04/17 09:49:48 kettenis Exp $ */
+/* $OpenBSD: boot.c,v 1.38 2013/12/28 02:51:07 deraadt Exp $ */
/*
* Copyright (c) 2003 Dale Rahn
#include <lib/libsa/loadfile.h>
#include <lib/libkern/funcs.h>
+#include <stand/boot/bootarg.h>
+
#include "cmd.h"
#ifndef KERNEL
char *kernelfile = KERNEL; /* can be changed by MD code */
int boottimeout = 5; /* can be changed by MD code */
+char rnddata[BOOTRANDOM_MAX];
+
void
boot(dev_t bootdev)
{
while (1) {
/* no boot.conf, or no boot cmd in there */
- if (bootprompt && st <= 0)
+ if (bootprompt && st <= 0) {
do {
printf("boot> ");
} while(!getcmd());
+ }
st = 0;
bootprompt = 1; /* allow reselect should we fail */
+ st = loadrandom(BOOTRANDOM, rnddata, sizeof(rnddata));
+ if (st != 0)
+ printf("loadrandom: error %d\n", st);
+#ifdef MDRANDOM
+ mdrandom(rnddata, sizeof(rnddata));
+#endif
+
printf("booting %s: ", cmd.path);
marks[MARK_START] = (u_long)cmd.addr;
if ((fd = loadfile(cmd.path, marks, LOAD_ALL)) != -1) {
run_loadfile(marks, cmd.boothowto);
}
-#ifdef _TEST
int
-main()
+loadrandom(char *name, char *buf, size_t buflen)
{
- boot(0);
- return 0;
+ char path[MAXPATHLEN];
+ struct stat sb;
+ int fd, i;
+
+#define O_RDONLY 0
+
+ /* Extract the device name from the kernel we are loading. */
+ for (i = 0; i < sizeof(cmd.path); i++) {
+ if (cmd.path[i] == ':') {
+ strlcpy(path, cmd.path, i + 1);
+ snprintf(path + i, sizeof(path) - i, ":%s", name);
+ break;
+ } else if (cmd.path[i] == '\0') {
+ snprintf(path, sizeof path, "%s:%s",
+ cmd.bootdev, name);
+ break;
+ }
+ }
+
+ printf("loadrandom: %s\n", path);
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1) {
+ printf("cannot open %s\n", path);
+ return -1;
+ }
+ if (fstat(fd, &sb) == -1 ||
+ sb.st_uid != 0 ||
+ (sb.st_mode & (S_IWOTH|S_IROTH)))
+ goto fail;
+ if (read(fd, buf, buflen) != buflen)
+ goto fail;
+ close(fd);
+ return 0;
+fail:
+ close(fd);
+ return (-1);
}
-#endif
-/* $OpenBSD: bootarg.h,v 1.11 2003/06/02 20:20:54 mickey Exp $ */
+/* $OpenBSD: bootarg.h,v 1.12 2013/12/28 02:51:07 deraadt Exp $ */
/*
* Copyright (c) 1996-1999 Michael Shalayeff
extern bootarg_t *bootargp;
#endif
+int loadrandom(char *name, char *buf, size_t buflen);
+int mdrandom(char *buf, size_t buflen);
+
#ifdef _STANDALONE
void addbootarg(int, size_t, void *);
void makebootargs(caddr_t, size_t *);