summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/arch/alpha/stand/boot/boot.c29
-rw-r--r--sys/arch/luna88k/stand/boot/boot.c24
-rw-r--r--sys/arch/sgi/stand/boot/boot.c30
-rw-r--r--sys/arch/sparc64/stand/ofwboot/boot.c28
-rw-r--r--sys/stand/boot/boot.c27
-rw-r--r--sys/stand/boot/bootarg.h4
6 files changed, 81 insertions, 61 deletions
diff --git a/sys/arch/alpha/stand/boot/boot.c b/sys/arch/alpha/stand/boot/boot.c
index cc570d44407..916d9ea3bc2 100644
--- a/sys/arch/alpha/stand/boot/boot.c
+++ b/sys/arch/alpha/stand/boot/boot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.c,v 1.26 2020/05/25 15:00:23 deraadt Exp $ */
+/* $OpenBSD: boot.c,v 1.27 2020/05/25 15:49:41 deraadt Exp $ */
/* $NetBSD: boot.c,v 1.10 1997/01/18 01:58:33 cgd Exp $ */
/*
@@ -43,6 +43,7 @@
#include <sys/param.h>
#include <sys/exec.h>
#include <sys/stat.h>
+#include <sys/reboot.h>
#define _KERNEL
#include <sys/fcntl.h>
#undef _KERNEL
@@ -65,24 +66,29 @@ int debug;
char rnddata[BOOTRANDOM_MAX];
struct rc4_ctx randomctx;
-void
+int
loadrandom(char *name, char *buf, size_t buflen)
{
struct stat sb;
- int fd, i;
+ int fd, i, error = 0;
fd = open(name, O_RDONLY);
if (fd == -1) {
if (errno != EPERM)
printf("cannot open %s: %s\n", name, strerror(errno));
- return;
+ return -1;
}
- 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);
-fail:
+ if (fstat(fd, &sb) == -1) {
+ error = -1;
+ goto done;
+ }
+ if (read(fd, buf, buflen) != buflen) {
+ error = -1;
+ goto done;
+ }
+done:
close(fd);
+ return (error);
}
int
@@ -90,7 +96,7 @@ main()
{
char *name, **namep;
u_int64_t entry;
- int rc;
+ int rc, boothowto = 0;
uint64_t marks[MARK_MAX];
#ifdef DEBUG
struct rpb *r;
@@ -120,7 +126,8 @@ main()
}
#endif
- loadrandom(BOOTRANDOM, rnddata, sizeof(rnddata));
+ if (loadrandom(BOOTRANDOM, rnddata, sizeof(rnddata)) == 0)
+ boothowto |= RB_GOODRANDOM;
rc4_keysetup(&randomctx, rnddata, sizeof rnddata);
rc4_skip(&randomctx, 1536);
diff --git a/sys/arch/luna88k/stand/boot/boot.c b/sys/arch/luna88k/stand/boot/boot.c
index 2251fe07713..f23bf94a2f3 100644
--- a/sys/arch/luna88k/stand/boot/boot.c
+++ b/sys/arch/luna88k/stand/boot/boot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.c,v 1.8 2019/10/29 02:55:51 deraadt Exp $ */
+/* $OpenBSD: boot.c,v 1.9 2020/05/25 15:49:42 deraadt Exp $ */
/* $NetBSD: boot.c,v 1.3 2013/03/05 15:34:53 tsutsui Exp $ */
/*
@@ -228,21 +228,23 @@ int
loadrandom(const char *name, char *buf, size_t buflen)
{
struct stat sb;
- int fd;
- int rc = 0;
+ int fd, error = 0;
fd = open(name, O_RDONLY);
if (fd == -1) {
if (errno != EPERM)
printf("cannot open %s: %s\n", name, strerror(errno));
- return 0;
+ return -1;
}
- 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:
+ if (fstat(fd, &sb) == -1) {
+ error = -1;
+ goto done;
+ }
+ if (read(fd, buf, buflen) != buflen) {
+ error = -1;
+ goto done;
+ }
+done:
close(fd);
- return rc;
+ return (error);
}
diff --git a/sys/arch/sgi/stand/boot/boot.c b/sys/arch/sgi/stand/boot/boot.c
index 58a1c121c87..69d5e16d265 100644
--- a/sys/arch/sgi/stand/boot/boot.c
+++ b/sys/arch/sgi/stand/boot/boot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.c,v 1.27 2019/10/29 02:55:52 deraadt Exp $ */
+/* $OpenBSD: boot.c,v 1.28 2020/05/25 15:49:42 deraadt Exp $ */
/*
* Copyright (c) 2004 Opsycon AB, www.opsycon.se.
@@ -44,7 +44,7 @@
#include "loadfile.h"
void dobootopts(int, char **);
-void loadrandom(const char *, const char *, void *, size_t);
+int loadrandom(const char *, const char *, void *, size_t);
char *strstr(char *, const char *); /* strstr.c */
enum {
@@ -107,8 +107,9 @@ boot_main(int argc, char *argv[])
if (bootauto != AUTO_MINI &&
strstr(OSLoadPartition, "bootp(") == NULL &&
strstr(OSLoadPartition, "cdrom(") == NULL) {
- loadrandom(OSLoadPartition, BOOTRANDOM, rnddata,
- sizeof(rnddata));
+ if (loadrandom(OSLoadPartition, BOOTRANDOM, rnddata,
+ sizeof(rnddata)) == 0)
+ boothowto |= RB_GOODRANDOM;
}
rc4_keysetup(&randomctx, rnddata, sizeof rnddata);
@@ -286,12 +287,12 @@ check_phdr(void *v)
/*
* Load the saved randomness file.
*/
-void
+int
loadrandom(const char *partition, const char *name, void *buf, size_t buflen)
{
char path[MAXPATHLEN];
struct stat sb;
- int fd;
+ int fd, error = 0;
strlcpy(path, partition, sizeof path);
strlcat(path, name, sizeof path);
@@ -300,12 +301,17 @@ loadrandom(const char *partition, const char *name, void *buf, size_t buflen)
if (fd == -1) {
if (errno != EPERM)
printf("cannot open %s: %s\n", path, strerror(errno));
- return;
+ return (-1);
+ }
+ if (fstat(fd, &sb) == -1) {
+ error = -1;
+ goto done;
+ }
+ if (read(fd, buf, buflen) != buflen) {
+ error = -1;
+ goto done;
}
- 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);
-fail:
+done:
close(fd);
+ return (error);
}
diff --git a/sys/arch/sparc64/stand/ofwboot/boot.c b/sys/arch/sparc64/stand/ofwboot/boot.c
index 839a2193ad6..8357c7652a5 100644
--- a/sys/arch/sparc64/stand/ofwboot/boot.c
+++ b/sys/arch/sparc64/stand/ofwboot/boot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.c,v 1.33 2020/01/04 18:32:15 kettenis Exp $ */
+/* $OpenBSD: boot.c,v 1.34 2020/05/25 15:49:42 deraadt Exp $ */
/* $NetBSD: boot.c,v 1.3 2001/05/31 08:55:19 mrg Exp $ */
/*
* Copyright (c) 1997, 1999 Eduardo E. Horvath. All rights reserved.
@@ -285,24 +285,24 @@ int
loadrandom(char *path, char *buf, size_t buflen)
{
struct stat sb;
- int fd, i;
+ int fd, i, error = 0;
#define O_RDONLY 0
fd = open(path, O_RDONLY);
if (fd == -1)
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:
+ if (fstat(fd, &sb) == -1) {
+ error = -1;
+ goto done;
+ }
+ if (read(fd, buf, buflen) != buflen) {
+ error = -1;
+ goto done;
+ }
+done:
close(fd);
- return (-1);
+ return (error);
}
#ifdef SOFTRAID
@@ -471,8 +471,8 @@ main(void)
_rtt();
}
}
- if (loadrandom(BOOTRANDOM, rnddata, sizeof(rnddata)))
- printf("open %s: %s\n", BOOTRANDOM, strerror(errno));
+ if (loadrandom(BOOTRANDOM, rnddata, sizeof(rnddata)) == 0)
+ boothowto |= RB_GOODRANDOM;
rc4_keysetup(&randomctx, rnddata, sizeof rnddata);
rc4_skip(&randomctx, 1536);
diff --git a/sys/stand/boot/boot.c b/sys/stand/boot/boot.c
index 570b9cde6f6..ab9fb5ba2fc 100644
--- a/sys/stand/boot/boot.c
+++ b/sys/stand/boot/boot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.c,v 1.51 2020/05/25 15:28:21 deraadt Exp $ */
+/* $OpenBSD: boot.c,v 1.52 2020/05/25 15:49:42 deraadt Exp $ */
/*
* Copyright (c) 2003 Dale Rahn
@@ -107,7 +107,8 @@ boot(dev_t bootdev)
} while(!getcmd());
}
- loadrandom(BOOTRANDOM, rnddata, sizeof(rnddata));
+ if (loadrandom(BOOTRANDOM, rnddata, sizeof(rnddata)) == 0)
+ cmd.boothowto |= RB_GOODRANDOM;
#ifdef MDRANDOM
if (mdrandom(rnddata, sizeof(rnddata)) == 0)
cmd.boothowto |= RB_GOODRANDOM;
@@ -160,12 +161,12 @@ boot(dev_t bootdev)
run_loadfile(marks, cmd.boothowto);
}
-void
+int
loadrandom(char *name, char *buf, size_t buflen)
{
char path[MAXPATHLEN];
struct stat sb;
- int fd, i;
+ int fd, i, error = 0;
#define O_RDONLY 0
@@ -186,13 +187,17 @@ loadrandom(char *name, char *buf, size_t buflen)
if (fd == -1) {
if (errno != EPERM)
printf("cannot open %s: %s\n", path, strerror(errno));
- return;
+ return -1;
+ }
+ if (fstat(fd, &sb) == -1) {
+ error = -1;
+ goto done;
+ }
+ if (read(fd, buf, buflen) != buflen) {
+ error = -1;
+ goto done;
}
- if (fstat(fd, &sb) == -1 ||
- sb.st_uid != 0 ||
- (sb.st_mode & (S_IWOTH|S_IROTH)))
- goto fail;
- (void) read(fd, buf, buflen);
-fail:
+done:
close(fd);
+ return (error);
}
diff --git a/sys/stand/boot/bootarg.h b/sys/stand/boot/bootarg.h
index 9ccc3c3a5fd..c06685d1595 100644
--- a/sys/stand/boot/bootarg.h
+++ b/sys/stand/boot/bootarg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bootarg.h,v 1.16 2020/05/25 14:53:57 deraadt Exp $ */
+/* $OpenBSD: bootarg.h,v 1.17 2020/05/25 15:49:42 deraadt Exp $ */
/*
* Copyright (c) 1996-1999 Michael Shalayeff
@@ -49,7 +49,7 @@ extern int bootargc;
extern bootarg_t *bootargp;
#endif
-void loadrandom(char *name, char *buf, size_t buflen);
+int loadrandom(char *name, char *buf, size_t buflen);
int mdrandom(char *buf, size_t buflen);
int fwrandom(char *buf, size_t buflen);