summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2014-02-24 20:15:37 +0000
committermiod <miod@openbsd.org>2014-02-24 20:15:37 +0000
commit49d624e411713eff81064a0ce75ec517a7d4badd (patch)
treec047158913a7ef33fad358b155f6060af17890dd /sys
parentrevert previous (diff)
downloadwireguard-openbsd-49d624e411713eff81064a0ce75ec517a7d4badd.tar.xz
wireguard-openbsd-49d624e411713eff81064a0ce75ec517a7d4badd.zip
/etc/random.seed support in da bootblockz.
Diffstat (limited to 'sys')
-rw-r--r--sys/arch/aviion/stand/boot/boot.c59
-rw-r--r--sys/arch/aviion/stand/boot/devopen.c60
-rw-r--r--sys/arch/aviion/stand/boot/version.c4
-rw-r--r--sys/arch/aviion/stand/libsa/exec.c4
4 files changed, 106 insertions, 21 deletions
diff --git a/sys/arch/aviion/stand/boot/boot.c b/sys/arch/aviion/stand/boot/boot.c
index aa343bde606..25f8d36a42f 100644
--- a/sys/arch/aviion/stand/boot/boot.c
+++ b/sys/arch/aviion/stand/boot/boot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.c,v 1.4 2013/10/16 16:59:34 miod Exp $ */
+/* $OpenBSD: boot.c,v 1.5 2014/02/24 20:15:37 miod Exp $ */
/*-
* Copyright (c) 1995 Theo de Raadt
@@ -57,21 +57,38 @@
#include <sys/param.h>
#include <sys/reboot.h>
+#include <sys/stat.h>
+#define _KERNEL
+#include <sys/fcntl.h>
+#undef _KERNEL
+
#include <machine/prom.h>
+#include <lib/libkern/libkern.h>
#include "stand.h"
#include "libsa.h"
+extern int devparse(const char *, uint *, uint *, uint *, uint *,
+ const char **, const char **, char **);
extern const char version[];
+
char line[80];
struct boot_info bi;
+char rnddata[BOOTRANDOM_MAX]; /* XXX dummy */
+
+int loadrandom(const char *, char *, size_t);
+
void
boot(const char *args, uint bootdev, uint bootunit, uint bootlun)
{
- char *p, *file;
+ char *p, *file, *fname;
+ char rndpath[MAXPATHLEN];
int ask;
int ret;
+ int rnd_loaded = 0;
+ uint controller, unit, lun, part;
+ const char *device, *ctrl;
printf("\n>> OpenBSD/" MACHINE " boot %s\n", version);
@@ -104,6 +121,21 @@ boot(const char *args, uint bootdev, uint bootunit, uint bootlun)
break;
}
+ /*
+ * Try and load randomness from the boot device.
+ */
+ if (rnd_loaded == 0) {
+ if (devparse(file, &controller, &unit, &lun, &part,
+ &device, &ctrl, &fname) == 0 &&
+ fname - file < sizeof(rndpath)) {
+ memcpy(rndpath, file, fname - file);
+ rndpath[fname - file] = '\0';
+ strlcat(rndpath, BOOTRANDOM, sizeof rndpath);
+ rnd_loaded = loadrandom(rndpath, rnddata,
+ sizeof(rnddata));
+ }
+ }
+
printf("%s: ", file);
exec(file, args,
bi.bootdev, bi.bootunit, bi.bootlun, bi.bootpart);
@@ -111,3 +143,26 @@ boot(const char *args, uint bootdev, uint bootunit, uint bootlun)
ask = 1;
}
}
+
+int
+loadrandom(const char *name, char *buf, size_t buflen)
+{
+ struct stat sb;
+ int fd;
+ int rc = 0;
+
+ fd = open(name, O_RDONLY);
+ if (fd == -1) {
+ if (errno != EPERM)
+ printf("cannot open %s: %s\n", name, strerror(errno));
+ return 0;
+ }
+ if (fstat(fd, &sb) == -1 || sb.st_uid != 0 || !S_ISREG(sb.st_mode) ||
+ (sb.st_mode & (S_IWOTH|S_IROTH)))
+ goto fail;
+ (void) read(fd, buf, buflen);
+ rc = 1;
+fail:
+ close(fd);
+ return rc;
+}
diff --git a/sys/arch/aviion/stand/boot/devopen.c b/sys/arch/aviion/stand/boot/devopen.c
index 585c85915d5..a8f68a496f6 100644
--- a/sys/arch/aviion/stand/boot/devopen.c
+++ b/sys/arch/aviion/stand/boot/devopen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: devopen.c,v 1.4 2013/10/16 16:59:34 miod Exp $ */
+/* $OpenBSD: devopen.c,v 1.5 2014/02/24 20:15:37 miod Exp $ */
/*
* Copyright (c) 2013 Miodrag Vallat.
@@ -22,24 +22,28 @@
#include "libsa.h"
+int devparse(const char *, uint *, uint *, uint *, uint *,
+ const char **, const char **, char **);
+
/*
* Parse the boot commandline into a proper device specification and
* kernel filename.
*/
int
-devopen(struct open_file *f, const char *fname, char **file)
+devparse(const char *fname, uint *controller, uint *unit, uint *lun, uint *part,
+ const char **dev, const char **ctrl, char **file)
{
struct devsw *dp;
- int error, i;
+ int i;
const char *po, *pc, *pc2, *p, *comma;
- char ctrl[1 + 4], device[1 + 4];
- uint controller, unit, lun, part;
+ static char devctrl[1 + 4];
+ char device[1 + 4];
size_t devlen;
/* defaults */
- controller = unit = lun = part = 0;
+ *controller = *unit = *lun = *part = 0;
device[0] = '\0';
- ctrl[0] = '\0';
+ devctrl[0] = '\0';
/*
* Attempt to parse the name as
@@ -80,28 +84,28 @@ devopen(struct open_file *f, const char *fname, char **file)
devlen = p++ - po;
if (devlen > 4)
return EINVAL;
- memcpy(ctrl, po, devlen);
- ctrl[devlen] = '\0';
+ memcpy(devctrl, po, devlen);
+ devctrl[devlen] = '\0';
- controller = strtol(p, NULL, 0);
+ *controller = strtol(p, NULL, 0);
po = pc + 1;
pc = pc2;
} else {
/* first form. extract controller number */
- controller = strtol(po, NULL, 0);
+ *controller = strtol(po, NULL, 0);
}
comma = strchr(po, ',');
if (comma != NULL && comma < pc) {
comma++;
- unit = strtol(comma, NULL, 0);
+ *unit = strtol(comma, NULL, 0);
po = comma;
}
comma = strchr(po, ',');
if (comma != NULL && comma < pc) {
comma++;
- lun = strtol(comma, NULL, 0);
+ *lun = strtol(comma, NULL, 0);
po = comma;
}
@@ -113,7 +117,7 @@ devopen(struct open_file *f, const char *fname, char **file)
p = strchr(fname, ':');
if (p != NULL) {
- part = strtol(fname, NULL, 0);
+ *part = strtol(fname, NULL, 0);
fname = p + 1;
}
@@ -128,6 +132,34 @@ devopen(struct open_file *f, const char *fname, char **file)
if (i == ndevs)
return ENXIO;
+ *dev = dp->dv_name;
+ *ctrl = devctrl;
+ return 0;
+}
+
+/*
+ * Parse the boot commandline into a proper device specification and
+ * kernel filename.
+ */
+int
+devopen(struct open_file *f, const char *fname, char **file)
+{
+ struct devsw *dp;
+ int error, i;
+ uint controller, unit, lun, part;
+ const char *device, *ctrl;
+
+ error = devparse(fname, &controller, &unit, &lun, &part, &device, &ctrl,
+ file);
+ if (error != 0)
+ return error;
+
+ for (dp = devsw, i = 0; i < ndevs; dp++, i++)
+ if (dp->dv_name != NULL && strcmp(dp->dv_name, device) == 0)
+ break;
+ if (i == ndevs)
+ return ENXIO;
+
error = (*dp->dv_open)(f, ctrl, controller, unit, lun, part);
if (error == 0) {
f->f_dev = dp;
diff --git a/sys/arch/aviion/stand/boot/version.c b/sys/arch/aviion/stand/boot/version.c
index a32e2f97d75..4069d2ddfa1 100644
--- a/sys/arch/aviion/stand/boot/version.c
+++ b/sys/arch/aviion/stand/boot/version.c
@@ -1,3 +1,3 @@
-/* $OpenBSD: version.c,v 1.5 2013/12/28 02:53:03 deraadt Exp $ */
+/* $OpenBSD: version.c,v 1.6 2014/02/24 20:15:37 miod Exp $ */
-const char version[] = "0.5";
+const char version[] = "0.6";
diff --git a/sys/arch/aviion/stand/libsa/exec.c b/sys/arch/aviion/stand/libsa/exec.c
index ccf47a9a35a..c5ecb997b0a 100644
--- a/sys/arch/aviion/stand/libsa/exec.c
+++ b/sys/arch/aviion/stand/libsa/exec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: exec.c,v 1.3 2014/01/04 10:49:21 miod Exp $ */
+/* $OpenBSD: exec.c,v 1.4 2014/02/24 20:15:37 miod Exp $ */
/*-
@@ -41,8 +41,6 @@
#include <lib/libsa/loadfile.h>
-char rnddata[BOOTRANDOM_MAX]; /* XXX dummy */
-
#define BOOT_MAGIC 0x6274ef2e /* need to match locore.S */
/*ARGSUSED*/