summaryrefslogtreecommitdiffstats
path: root/lib/csu
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csu')
-rw-r--r--lib/csu/boot.h14
-rw-r--r--lib/csu/crt0.c6
-rw-r--r--lib/csu/extern.h4
3 files changed, 18 insertions, 6 deletions
diff --git a/lib/csu/boot.h b/lib/csu/boot.h
index c899af9303b..6ec5256bb06 100644
--- a/lib/csu/boot.h
+++ b/lib/csu/boot.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: boot.h,v 1.29 2018/11/22 21:37:29 guenther Exp $ */
+/* $OpenBSD: boot.h,v 1.30 2019/05/10 13:29:21 guenther Exp $ */
/*
* Copyright (c) 1998 Per Fogelstrom, Opsycon AB
@@ -81,6 +81,14 @@ struct boot_dyn {
#endif
};
+static void *relro_addr;
+static size_t relro_size;
+#define RCRT0_RELRO() \
+ do { \
+ if (relro_addr != NULL && relro_size != 0) \
+ mprotect(relro_addr, relro_size, PROT_READ); \
+ } while (0)
+
/*
* Local decls.
*/
@@ -220,8 +228,8 @@ _dl_boot_bind(const long sp, long *dl_data, Elf_Dyn *dynamicp)
break;
#endif
case PT_GNU_RELRO:
- mprotect((void *)(phdp->p_vaddr + loff), phdp->p_memsz,
- PROT_READ);
+ relro_addr = (void *)(phdp->p_vaddr + loff);
+ relro_size = phdp->p_memsz;
/*
* GNU_RELRO (a) covers the GOT, and (b) comes after
* all LOAD sections, so if we found it then we're done
diff --git a/lib/csu/crt0.c b/lib/csu/crt0.c
index ac2966b5490..2c113e73428 100644
--- a/lib/csu/crt0.c
+++ b/lib/csu/crt0.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crt0.c,v 1.13 2019/05/08 20:27:29 guenther Exp $ */
+/* $OpenBSD: crt0.c,v 1.14 2019/05/10 13:29:21 guenther Exp $ */
/*
* Copyright (c) 1995 Christopher G. Demetriou
@@ -49,6 +49,9 @@ static void ___start(MD_START_ARGS) __used;
#ifndef MD_EPROL_LABEL
#define MD_EPROL_LABEL __asm(" .text\n_eprol:")
#endif
+#ifndef RCRT0_RELRO
+#define RCRT0_RELRO() do {} while (0)
+#endif
char ***_csu_finish(char **_argv, char **_envp, void (*_cleanup)(void));
@@ -89,6 +92,7 @@ ___start(MD_START_ARGS)
size = __preinit_array_end - __preinit_array_start;
for (i = 0; i < size; i++)
__preinit_array_start[i](argc, argv, envp, NULL);
+ RCRT0_RELRO();
size = __init_array_end - __init_array_start;
for (i = 0; i < size; i++)
__init_array_start[i](argc, argv, envp, NULL);
diff --git a/lib/csu/extern.h b/lib/csu/extern.h
index 5cc17413c8a..92dc12a0437 100644
--- a/lib/csu/extern.h
+++ b/lib/csu/extern.h
@@ -17,8 +17,8 @@
void __init(void) __dso_hidden;
int main(int argc, char *argv[], char *envp[]);
-struct dl_cb;
-typedef void (*initarray_f)(int, char **, char **, const struct dl_cb *);
+typedef const void *dl_cb_cb(int);
+typedef void (*initarray_f)(int, char **, char **, dl_cb_cb *);
typedef void (*init_f)(void);
/*