Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/libexec/ld.elf_so binutils 2.31.1 can put copy relocations i...
details: https://anonhg.NetBSD.org/src/rev/bac768213017
branches: trunk
changeset: 995624:bac768213017
user: christos <christos%NetBSD.org@localhost>
date: Sun Dec 30 01:48:37 2018 +0000
description:
binutils 2.31.1 can put copy relocations in the relro segment. Delay
protecting the relro segment for the main object until copy relocations
are done.
diffstat:
libexec/ld.elf_so/reloc.c | 22 +++++++++-------------
libexec/ld.elf_so/rtld.c | 23 +++++++++++++++++++++--
libexec/ld.elf_so/rtld.h | 4 +++-
3 files changed, 33 insertions(+), 16 deletions(-)
diffs (121 lines):
diff -r 96ff03e3b1d5 -r bac768213017 libexec/ld.elf_so/reloc.c
--- a/libexec/ld.elf_so/reloc.c Sun Dec 30 00:42:47 2018 +0000
+++ b/libexec/ld.elf_so/reloc.c Sun Dec 30 01:48:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: reloc.c,v 1.113 2018/10/17 23:36:58 joerg Exp $ */
+/* $NetBSD: reloc.c,v 1.114 2018/12/30 01:48:37 christos Exp $ */
/*
* Copyright 1996 John D. Polstra.
@@ -39,7 +39,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: reloc.c,v 1.113 2018/10/17 23:36:58 joerg Exp $");
+__RCSID("$NetBSD: reloc.c,v 1.114 2018/12/30 01:48:37 christos Exp $");
#endif /* not lint */
#include <err.h>
@@ -102,10 +102,10 @@
return (-1);
}
srcaddr = (const void *)(srcobj->relocbase + srcsym->st_value);
- (void)memcpy(dstaddr, srcaddr, size);
rdbg(("COPY %s %s %s --> src=%p dst=%p size %ld",
dstobj->path, srcobj->path, name, srcaddr,
(void *)dstaddr, (long)size));
+ (void)memcpy(dstaddr, srcaddr, size);
return (0);
}
#endif /* RTLD_INHIBIT_COPY_RELOCS */
@@ -149,6 +149,10 @@
}
}
}
+#ifdef GNU_RELRO
+ if (_rtld_relro(dstobj, true) == -1)
+ return -1;
+#endif
#endif /* RTLD_INHIBIT_COPY_RELOCS */
return (0);
@@ -225,18 +229,10 @@
if (obj->pltgot != NULL)
_rtld_setup_pltgot(obj);
#ifdef GNU_RELRO
- if (obj->relro_size > 0) {
- if (mprotect(obj->relro_page, obj->relro_size,
- PROT_READ) == -1) {
- _rtld_error("%s: Cannot enforce relro "
- "protection: %s", obj->path,
- xstrerror(errno));
- return -1;
- }
- }
+ if (_rtld_relro(obj, false) == -1)
+ return -1;
#endif
}
-
return 0;
}
diff -r 96ff03e3b1d5 -r bac768213017 libexec/ld.elf_so/rtld.c
--- a/libexec/ld.elf_so/rtld.c Sun Dec 30 00:42:47 2018 +0000
+++ b/libexec/ld.elf_so/rtld.c Sun Dec 30 01:48:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rtld.c,v 1.194 2018/12/27 18:57:43 christos Exp $ */
+/* $NetBSD: rtld.c,v 1.195 2018/12/30 01:48:37 christos Exp $ */
/*
* Copyright 1996 John D. Polstra.
@@ -40,7 +40,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: rtld.c,v 1.194 2018/12/27 18:57:43 christos Exp $");
+__RCSID("$NetBSD: rtld.c,v 1.195 2018/12/30 01:48:37 christos Exp $");
#endif /* not lint */
#include <sys/param.h>
@@ -1746,3 +1746,22 @@
sigprocmask(SIG_SETMASK, mask, NULL);
}
+
+int
+_rtld_relro(const Obj_Entry *obj, bool wantmain)
+{
+#ifdef GNU_RELRO
+ if (obj->relro_size == 0)
+ return 0;
+ if (wantmain != (obj ==_rtld_objmain))
+ return 0;
+
+ dbg(("RELRO %s %p %lx\n", obj->path, obj->relro_page, obj->relro_size));
+ if (mprotect(obj->relro_page, obj->relro_size, PROT_READ) == -1) {
+ _rtld_error("%s: Cannot enforce relro " "protection: %s",
+ obj->path, xstrerror(errno));
+ return -1;
+ }
+#endif
+ return 0;
+}
diff -r 96ff03e3b1d5 -r bac768213017 libexec/ld.elf_so/rtld.h
--- a/libexec/ld.elf_so/rtld.h Sun Dec 30 00:42:47 2018 +0000
+++ b/libexec/ld.elf_so/rtld.h Sun Dec 30 01:48:37 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rtld.h,v 1.135 2018/11/26 17:40:26 joerg Exp $ */
+/* $NetBSD: rtld.h,v 1.136 2018/12/30 01:48:37 christos Exp $ */
/*
* Copyright 1996 John D. Polstra.
@@ -372,6 +372,8 @@
void _rtld_exclusive_enter(sigset_t *);
void _rtld_exclusive_exit(sigset_t *);
+int _rtld_relro(const Obj_Entry *, bool);
+
/* expand.c */
size_t _rtld_expand_path(char *, size_t, const char *, const char *,\
const char *);
Home |
Main Index |
Thread Index |
Old Index