From: miod Date: Tue, 19 May 2015 20:39:12 +0000 (+0000) Subject: Extend the libsa loadfile(9) granularity to tell apart randomness from the rest X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=cd230c960d89f0a893a1ea79bd9667802ad9a5bb;p=openbsd Extend the libsa loadfile(9) granularity to tell apart randomness from the rest of the kernel, and extend the array filled by loadfile to report the location of the randomness area. This doesn't introduce any change for bootblocks (save for a slightly larger stack usage due to the larger array), for the new {LOAD,COUNT}_RANDOM bits are included in the {LOAD,COUNT}_ALL masks everything uses or computes from. --- diff --git a/sys/lib/libsa/loadfile.h b/sys/lib/libsa/loadfile.h index 2c05e5a2a21..8cac6af5349 100644 --- a/sys/lib/libsa/loadfile.h +++ b/sys/lib/libsa/loadfile.h @@ -1,5 +1,5 @@ /* $NetBSD: loadfile.h,v 1.1 1999/04/28 09:08:50 christos Exp $ */ -/* $OpenBSD: loadfile.h,v 1.3 2008/06/26 05:42:20 ray Exp $ */ +/* $OpenBSD: loadfile.h,v 1.4 2015/05/19 20:39:12 miod Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -38,7 +38,9 @@ #define MARK_NSYM 2 #define MARK_SYM 3 #define MARK_END 4 -#define MARK_MAX 5 +#define MARK_RANDOM 5 +#define MARK_ERANDOM 6 +#define MARK_MAX 7 /* * Bit flags for sections to load @@ -49,7 +51,8 @@ #define LOAD_BSS 0x0008 #define LOAD_SYM 0x0010 #define LOAD_HDR 0x0020 -#define LOAD_ALL 0x003f +#define LOAD_RANDOM 0x0040 +#define LOAD_ALL 0x007f #define COUNT_TEXT 0x0100 #define COUNT_TEXTA 0x0200 @@ -57,7 +60,8 @@ #define COUNT_BSS 0x0800 #define COUNT_SYM 0x1000 #define COUNT_HDR 0x2000 -#define COUNT_ALL 0x3f00 +#define COUNT_RANDOM 0x4000 +#define COUNT_ALL 0x7f00 int loadfile(const char *, u_long *, int); diff --git a/sys/lib/libsa/loadfile_elf.c b/sys/lib/libsa/loadfile_elf.c index 083a286d5b0..432f977e712 100644 --- a/sys/lib/libsa/loadfile_elf.c +++ b/sys/lib/libsa/loadfile_elf.c @@ -1,5 +1,5 @@ /* $NetBSD: loadfile.c,v 1.10 2000/12/03 02:53:04 tsutsui Exp $ */ -/* $OpenBSD: loadfile_elf.c,v 1.10 2014/10/26 10:33:48 miod Exp $ */ +/* $OpenBSD: loadfile_elf.c,v 1.11 2015/05/19 20:39:12 miod Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -99,7 +99,7 @@ ELFNAME(exec)(int fd, Elf_Ehdr *elf, u_long *marks, int flags) int m; /* Fill segment if asked for. */ - if (flags & LOAD_DATA) { + if (flags & LOAD_RANDOM) { for (pos = 0; pos < phdr[i].p_filesz; pos += m) { m = MIN(phdr[i].p_filesz - pos, @@ -108,6 +108,11 @@ ELFNAME(exec)(int fd, Elf_Ehdr *elf, u_long *marks, int flags) m); } } + if (flags & (LOAD_RANDOM | COUNT_RANDOM)) { + marks[MARK_RANDOM] = LOADADDR(phdr[i].p_paddr); + marks[MARK_ERANDOM] = + marks[MARK_RANDOM] + phdr[i].p_filesz; + } continue; }