diff options
-rw-r--r-- | sys/arch/sparc/stand/boot/boot.c | 46 | ||||
-rw-r--r-- | sys/arch/sparc/stand/boot/loadfile_sparc.c | 18 | ||||
-rw-r--r-- | sys/arch/sparc/stand/common/version.c | 5 |
3 files changed, 63 insertions, 6 deletions
diff --git a/sys/arch/sparc/stand/boot/boot.c b/sys/arch/sparc/stand/boot/boot.c index edb8af6f616..8fa6a1096f7 100644 --- a/sys/arch/sparc/stand/boot/boot.c +++ b/sys/arch/sparc/stand/boot/boot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: boot.c,v 1.10 2011/04/14 18:27:49 miod Exp $ */ +/* $OpenBSD: boot.c,v 1.11 2014/02/25 21:28:30 miod Exp $ */ /* $NetBSD: boot.c,v 1.2 1997/09/14 19:27:21 pk Exp $ */ /*- @@ -34,6 +34,11 @@ #include <sys/param.h> #include <sys/reboot.h> +#include <sys/stat.h> +#define _KERNEL +#include <sys/fcntl.h> +#undef _KERNEL + #include <lib/libsa/loadfile.h> #include <lib/libsa/stand.h> @@ -55,13 +60,16 @@ int netif_debug; extern char *version; char fbuf[80], dbuf[128]; +char rnddata[BOOTRANDOM_MAX]; paddr_t bstart, bend; /* physical start & end address of the boot program */ int compat = 1; /* try to load in compat mode */ +int rnd_loaded = 0; typedef void (*entry_t)(u_long, int, int, int, long, long); -int fdloadfile(int, u_long *, int); +int fdloadfile(int, u_long *, int); +int loadrandom(const char *, void *, size_t); static paddr_t getphysmem(u_long size) @@ -160,7 +168,7 @@ loadk(char *file, u_long *marks) */ extra = 512 * 1024; - if ((fd = open(file, 0)) < 0) + if ((fd = open(file, O_RDONLY)) < 0) return (errno ? errno : ENOENT); /* @@ -179,6 +187,15 @@ loadk(char *file, u_long *marks) /* compensate for extra room below */ minsize -= extra; } else { + /* + * If we did not load a random.seed file yet, try and load + * one. + */ + if (rnd_loaded == 0) { + rnd_loaded = loadrandom(BOOTRANDOM, rnddata, + sizeof(rnddata)); + } + flags = LOAD_KERNEL; marks[MARK_START] = 0; @@ -338,3 +355,26 @@ main(int argc, char *argv[]) _rtt(); } + +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; +} diff --git a/sys/arch/sparc/stand/boot/loadfile_sparc.c b/sys/arch/sparc/stand/boot/loadfile_sparc.c index 286a87aea6d..13a3db4d6c2 100644 --- a/sys/arch/sparc/stand/boot/loadfile_sparc.c +++ b/sys/arch/sparc/stand/boot/loadfile_sparc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: loadfile_sparc.c,v 1.2 2011/04/14 18:27:49 miod Exp $ */ +/* $OpenBSD: loadfile_sparc.c,v 1.3 2014/02/25 21:28:30 miod Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -194,6 +194,22 @@ elf32_exec(int fd, off_t filepos, Elf_Ehdr *elf, u_long *marks, int flags) filepos += sz; for (first = 1, i = 0; i < elf->e_phnum; i++) { + if (phdr[i].p_type == PT_OPENBSD_RANDOMIZE) { + int m; + + /* Fill segment is asked for. */ + if (flags & LOAD_DATA) { + 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; diff --git a/sys/arch/sparc/stand/common/version.c b/sys/arch/sparc/stand/common/version.c index e14e64486ca..e269f0e2d33 100644 --- a/sys/arch/sparc/stand/common/version.c +++ b/sys/arch/sparc/stand/common/version.c @@ -1,4 +1,4 @@ -/* $OpenBSD: version.c,v 1.7 2010/08/16 14:41:29 miod Exp $ */ +/* $OpenBSD: version.c,v 1.8 2014/02/25 21:28:30 miod Exp $ */ /* $NetBSD: version.c,v 1.4 1995/09/16 23:20:39 pk Exp $ */ /* @@ -47,6 +47,7 @@ * 2.5 sun4e support * 2.6 Support for larger kernels when booting from tape, and avoid * stomping on PROM data below 4MB on sun4c + * 2.7 /etc/random.seed support */ -char *version = "2.6"; +char *version = "2.7"; |