diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2014-02-23 19:22:41 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2014-02-23 19:22:41 +0000 |
commit | 62ca30d96c6ea2fb25fd23605253f0e71d05f8ea (patch) | |
tree | c3b74ba9b430d2a1d42e998a1fe06757c38e4a96 /sys/arch/hp300 | |
parent | d501449ba8976ac184ce2a6313826c38684c0881 (diff) |
Try and load /etc/random.seed from SYS_UBOOT.
Diffstat (limited to 'sys/arch/hp300')
-rw-r--r-- | sys/arch/hp300/stand/cdboot/cdboot.c | 4 | ||||
-rw-r--r-- | sys/arch/hp300/stand/common/version.c | 6 | ||||
-rw-r--r-- | sys/arch/hp300/stand/libsa/Makefile | 4 | ||||
-rw-r--r-- | sys/arch/hp300/stand/libsa/exec_hp300.c | 4 | ||||
-rw-r--r-- | sys/arch/hp300/stand/uboot/uboot.c | 71 |
5 files changed, 79 insertions, 10 deletions
diff --git a/sys/arch/hp300/stand/cdboot/cdboot.c b/sys/arch/hp300/stand/cdboot/cdboot.c index 3d4352b54f9..a92ee017c1b 100644 --- a/sys/arch/hp300/stand/cdboot/cdboot.c +++ b/sys/arch/hp300/stand/cdboot/cdboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cdboot.c,v 1.8 2011/08/18 20:02:58 miod Exp $ */ +/* $OpenBSD: cdboot.c,v 1.9 2014/02/23 19:22:40 miod Exp $ */ /* $NetBSD: uboot.c,v 1.3 1997/04/27 21:17:13 thorpej Exp $ */ /*- @@ -68,6 +68,8 @@ char *names[] = { static int bdev, badapt, bctlr, bunit, bpart; #endif +char rnddata[BOOTRANDOM_MAX]; /* XXX dummy */ + int main(void) { diff --git a/sys/arch/hp300/stand/common/version.c b/sys/arch/hp300/stand/common/version.c index 6b0056d78b2..84ffcd059cb 100644 --- a/sys/arch/hp300/stand/common/version.c +++ b/sys/arch/hp300/stand/common/version.c @@ -1,4 +1,4 @@ -/* $OpenBSD: version.c,v 1.15 2013/12/28 02:53:03 deraadt Exp $ */ +/* $OpenBSD: version.c,v 1.16 2014/02/23 19:22:40 miod Exp $ */ /* * Record major changes in the boot code here, and increment the version @@ -26,6 +26,8 @@ * `/'. * 2.14 Build with the ELF toolchain. * 2.15 Remove SLOWSCSI from scsi code, and increase target selection timeout. + * 2.16 Loadfile support for .openbsd.randomdata section. + * 2.17 /etc/random.seed support in uboot (SYS_UBOOT). */ -const char version[] = "2.16"; +const char version[] = "2.17"; diff --git a/sys/arch/hp300/stand/libsa/Makefile b/sys/arch/hp300/stand/libsa/Makefile index 4290dff1c02..f5ac234fbb7 100644 --- a/sys/arch/hp300/stand/libsa/Makefile +++ b/sys/arch/hp300/stand/libsa/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.17 2013/01/01 17:18:49 miod Exp $ +# $OpenBSD: Makefile,v 1.18 2014/02/23 19:22:40 miod Exp $ LIB= sa @@ -15,7 +15,7 @@ SRCS+= devopen.c exec_hp300.c rawfs.c .PATH: ${.CURDIR}/../../../../lib/libsa SRCS+= alloc.c exit.c getfile.c gets.c globals.c loadfile.c \ memcmp.c memcpy.c memset.c printf.c snprintf.c strcmp.c \ - strerror.c strlen.c strncmp.c strncpy.c + strerror.c strlcat.c strlen.c strncmp.c strncpy.c .PATH: ${.CURDIR}/../../../../lib/libkern SRCS+= __main.c diff --git a/sys/arch/hp300/stand/libsa/exec_hp300.c b/sys/arch/hp300/stand/libsa/exec_hp300.c index accea72805e..fc520b85062 100644 --- a/sys/arch/hp300/stand/libsa/exec_hp300.c +++ b/sys/arch/hp300/stand/libsa/exec_hp300.c @@ -1,4 +1,4 @@ -/* $OpenBSD: exec_hp300.c,v 1.4 2014/01/04 10:49:21 miod Exp $ */ +/* $OpenBSD: exec_hp300.c,v 1.5 2014/02/23 19:22:40 miod Exp $ */ /* $NetBSD: exec.c,v 1.15 1996/10/13 02:29:01 christos Exp $ */ /*- @@ -38,8 +38,6 @@ #include <lib/libsa/loadfile.h> -char rnddata[BOOTRANDOM_MAX]; /* XXX dummy */ - void exec(char *path, void *loadaddr, int howto) { diff --git a/sys/arch/hp300/stand/uboot/uboot.c b/sys/arch/hp300/stand/uboot/uboot.c index 66689285d0a..edf1485aaa9 100644 --- a/sys/arch/hp300/stand/uboot/uboot.c +++ b/sys/arch/hp300/stand/uboot/uboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uboot.c,v 1.6 2011/08/18 20:02:58 miod Exp $ */ +/* $OpenBSD: uboot.c,v 1.7 2014/02/23 19:22:40 miod Exp $ */ /* $NetBSD: uboot.c,v 1.3 1997/04/27 21:17:13 thorpej Exp $ */ /*- @@ -34,6 +34,11 @@ #include <sys/param.h> #include <sys/reboot.h> +#include <sys/stat.h> +#define _KERNEL +#include <sys/fcntl.h> +#undef _KERNERL + #include <machine/exec.h> #include <a.out.h> @@ -55,6 +60,8 @@ extern int noconsole; extern const char version[]; +extern int devparse(const char *, int *, int *, int *, int *, int *, char **); + /* * XXX UFS accepts a /, NFS doesn't. */ @@ -66,7 +73,11 @@ char *names[] = { static int bdev, badapt, bctlr, bunit, bpart; +void boot(char *, void *, int); void getbootdev(int *); +int loadrandom(const char *, void *, size_t); + +char rnddata[BOOTRANDOM_MAX]; int main(void) @@ -94,7 +105,7 @@ main(void) } else printf(": %s\n", name); - exec(name, lowram, howto); + boot(name, lowram, howto); printf("boot: %s\n", strerror(errno)); } return (0); @@ -148,3 +159,59 @@ getbootdev(int *howto) } else printf("\n"); } + +void +boot(char *path, void *loadaddr, int howto) +{ + static int rnd_loaded = 0; + char rndpath[MAXPATHLEN]; + int dev, adapt, ctlr, unit, part; + char *fname; + + /* + * Try and load randomness from the boot device if this is a disk. + */ + if (rnd_loaded == 0) { + if (devparse(path, &dev, &adapt, &ctlr, &unit, &part, + &fname) != 0) { + /* + * If the device name is bogus, devlookup() has + * complained loudly. No need to attempt to load a + * kernel from the same string. + */ + return; + } + if (fname - path < sizeof(rndpath)) { + memcpy(rndpath, path, fname - path); + rndpath[fname - path] = '\0'; + strlcat(rndpath, BOOTRANDOM, sizeof rndpath); + rnd_loaded = loadrandom(rndpath, rnddata, + sizeof(rnddata)); + } + } + + exec(path, loadaddr, howto); +} + +int +loadrandom(const char *path, void *buf, size_t buflen) +{ + struct stat sb; + int fd; + int rc = 0; + + fd = open(path, O_RDONLY); + if (fd == -1) { + if (errno != EPERM) + printf("cannot open %s: %s\n", path, 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; +} |