-/* $OpenBSD: boot.c,v 1.19 2013/03/21 21:51:01 deraadt Exp $ */
+/* $OpenBSD: boot.c,v 1.20 2013/12/28 21:00:21 kettenis 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.
int boothowto;
int debug;
+char rnddata[BOOTRANDOM_MAX];
+
int elf64_exec(int, Elf64_Ehdr *, u_int64_t *, void **, void **);
#if 0
return (rval);
}
+int
+loadrandom(char *path, char *buf, size_t buflen)
+{
+ struct stat sb;
+ int fd, i;
+
+#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:
+ close(fd);
+ return (-1);
+}
+
int
main()
{
_rtt();
}
}
+ if (loadrandom(BOOTRANDOM, rnddata, sizeof(rnddata)))
+ printf("open %s: %s\n", opened_name, strerror(errno));
if ((fd = open(bootline, 0)) < 0) {
printf("open %s: %s\n", opened_name, strerror(errno));
continue;
-/* $OpenBSD: elf64_exec.c,v 1.3 2013/03/21 21:51:01 deraadt Exp $ */
+/* $OpenBSD: elf64_exec.c,v 1.4 2013/12/28 21:00:21 kettenis Exp $ */
/* $NetBSD: elfXX_exec.c,v 1.2 2001/08/15 20:08:15 eeh Exp $ */
/*
printf("read phdr: %s\n", strerror(errno));
return (1);
}
+
+ if (phdr.p_type == PT_OPENBSD_RANDOMIZE) {
+ int m, pos;
+
+ /* Fill segment. */
+ for (pos = 0; pos < phdr.p_filesz; pos += m) {
+ m = MIN(phdr.p_filesz - pos, sizeof(rnddata));
+ bcopy(rnddata, (void *)(long)phdr.p_paddr + pos, m);
+ }
+ continue;
+ }
+
if (phdr.p_type != PT_LOAD ||
(phdr.p_flags & (PF_W|PF_X)) == 0)
continue;