diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2014-02-20 20:34:28 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2014-02-20 20:34:28 +0000 |
commit | 2dbfc69d31141f1161066c6cb46ba67856350fc9 (patch) | |
tree | c1a281070919a9ea43d1c50d672c1e30484d3c82 /sys/arch | |
parent | aaa8590e6416862a230ce7a501fab0ba04606000 (diff) |
Support for /etc/random.seed in bootsd (disk-only boot blocks)
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/mvme68k/stand/bootsd/boot.c | 38 | ||||
-rw-r--r-- | sys/arch/mvme68k/stand/bootsd/version.c | 5 | ||||
-rw-r--r-- | sys/arch/mvme68k/stand/libsa/exec_mvme.c | 4 | ||||
-rw-r--r-- | sys/arch/mvme88k/stand/bootsd/boot.c | 45 | ||||
-rw-r--r-- | sys/arch/mvme88k/stand/bootsd/version.c | 5 | ||||
-rw-r--r-- | sys/arch/mvme88k/stand/libsa/exec_mvme.c | 4 |
6 files changed, 88 insertions, 13 deletions
diff --git a/sys/arch/mvme68k/stand/bootsd/boot.c b/sys/arch/mvme68k/stand/bootsd/boot.c index 91429b968d1..47b8001803b 100644 --- a/sys/arch/mvme68k/stand/bootsd/boot.c +++ b/sys/arch/mvme68k/stand/bootsd/boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.12 2012/12/31 21:35:32 miod Exp $ */ +/* $OpenBSD: boot.c,v 1.13 2014/02/20 20:34:27 miod Exp $ */ /* $NetBSD: boot.c,v 1.2 1995/09/23 03:42:52 gwr Exp $ */ /*- @@ -34,15 +34,22 @@ #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 "stand.h" #include "libsa.h" +int loadrandom(const char *, char *, size_t); + int debug; int errno; extern char *version; +extern char rnddata[BOOTRANDOM_MAX]; char line[80]; int @@ -51,6 +58,7 @@ main() char *cp, *file; int flag, ret; int ask = 0; + int rnd_loaded = 0; printf(">> OpenBSD MVME%x bootsd [%s]\n", bugargs.cputyp, version); @@ -73,9 +81,37 @@ main() printf("boot: -q returning to MVME-Bug\n"); break; } + + if (rnd_loaded == 0) + rnd_loaded = loadrandom(BOOTRANDOM, rnddata, + sizeof(rnddata)); + exec_mvme(file, flag); printf("boot: %s: %s\n", file, strerror(errno)); ask = 1; } return(0); } + +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/mvme68k/stand/bootsd/version.c b/sys/arch/mvme68k/stand/bootsd/version.c index fbbe05b707b..64b3aa03427 100644 --- a/sys/arch/mvme68k/stand/bootsd/version.c +++ b/sys/arch/mvme68k/stand/bootsd/version.c @@ -1,8 +1,9 @@ -/* $OpenBSD: version.c,v 1.10 2013/05/12 08:10:07 miod Exp $ */ +/* $OpenBSD: version.c,v 1.11 2014/02/20 20:34:27 miod Exp $ */ /* + * 1.11 /etc/random.seed support * 1.10 lower load address and heap location by 1MB to fit 8MB boards * 1.9 kernel loaded with loadfile, a.out and ELF formats */ -char *version = "1.10"; +char *version = "1.11"; diff --git a/sys/arch/mvme68k/stand/libsa/exec_mvme.c b/sys/arch/mvme68k/stand/libsa/exec_mvme.c index 4f40ec3b410..c2202970ba1 100644 --- a/sys/arch/mvme68k/stand/libsa/exec_mvme.c +++ b/sys/arch/mvme68k/stand/libsa/exec_mvme.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_mvme.c,v 1.10 2014/01/04 10:49:21 miod Exp $ */ +/* $OpenBSD: exec_mvme.c,v 1.11 2014/02/20 20:34:27 miod Exp $ */ /*- @@ -41,7 +41,7 @@ #include <lib/libsa/loadfile.h> -char rnddata[BOOTRANDOM_MAX]; /* XXX dummy */ +char rnddata[BOOTRANDOM_MAX]; /* set by bootsd only */ /*ARGSUSED*/ void diff --git a/sys/arch/mvme88k/stand/bootsd/boot.c b/sys/arch/mvme88k/stand/bootsd/boot.c index 061c3208aa1..b30181874d5 100644 --- a/sys/arch/mvme88k/stand/bootsd/boot.c +++ b/sys/arch/mvme88k/stand/bootsd/boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.9 2013/01/05 11:20:56 miod Exp $ */ +/* $OpenBSD: boot.c,v 1.10 2014/02/20 20:34:27 miod Exp $ */ /* $NetBSD: boot.c,v 1.2 1995/09/23 03:42:52 gwr Exp $ */ /*- @@ -34,27 +34,36 @@ #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 "stand.h" #include "libsa.h" +int loadrandom(const char *, char *, size_t); + int debug; int errno; extern const char *version; -char line[80]; +extern char rnddata[BOOTRANDOM_MAX]; +char line[80]; int main() { char *cp, *file; - int flag, ret; - int ask = 0; + int flag, ret; + int ask = 0; + int rnd_loaded = 0; printf(">> OpenBSD/mvme88k bootsd [%s]\n", version); ret = parse_args(&file, &flag); + for (;;) { if (ask) { printf("boot: "); @@ -72,9 +81,37 @@ main() printf("boot: -q returning to MVME-Bug\n"); break; } + + if (rnd_loaded == 0) + rnd_loaded = loadrandom(BOOTRANDOM, rnddata, + sizeof(rnddata)); + exec_mvme(file, flag); printf("boot: %s: %s\n", file, strerror(errno)); ask = 1; } return (0); } + +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/mvme88k/stand/bootsd/version.c b/sys/arch/mvme88k/stand/bootsd/version.c index c65a69d919d..233644e4f6e 100644 --- a/sys/arch/mvme88k/stand/bootsd/version.c +++ b/sys/arch/mvme88k/stand/bootsd/version.c @@ -1,6 +1,7 @@ -/* $OpenBSD: version.c,v 1.8 2013/01/05 11:20:56 miod Exp $ */ +/* $OpenBSD: version.c,v 1.9 2014/02/20 20:34:27 miod Exp $ */ /* + * 1.9 /etc/random.seed support * 1.8 ELF toolchain * 1.7 compiled with gcc 3.3.5 * 1.6 allocation area changed to fix netboot buffers overwriting stack @@ -8,4 +9,4 @@ * 1.4 kernel loaded with loadfile, a.out and ELF formats * 1.3 rewritten startup code and general cleanup */ -const char *version = "1.8"; +const char *version = "1.9"; diff --git a/sys/arch/mvme88k/stand/libsa/exec_mvme.c b/sys/arch/mvme88k/stand/libsa/exec_mvme.c index 288b4199cb0..d480018f953 100644 --- a/sys/arch/mvme88k/stand/libsa/exec_mvme.c +++ b/sys/arch/mvme88k/stand/libsa/exec_mvme.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_mvme.c,v 1.15 2014/01/04 10:49:21 miod Exp $ */ +/* $OpenBSD: exec_mvme.c,v 1.16 2014/02/20 20:34:27 miod Exp $ */ /*- @@ -41,7 +41,7 @@ #include <lib/libsa/loadfile.h> -char rnddata[BOOTRANDOM_MAX]; /* XXX dummy */ +char rnddata[BOOTRANDOM_MAX]; /* set by bootsd only */ /*ARGSUSED*/ void |