summaryrefslogtreecommitdiff
path: root/rts/linker/SymbolExtras.c
diff options
context:
space:
mode:
authorSantiago MunĂ­n <santimunin@gmail.com>2018-06-21 17:00:58 -0400
committerBen Gamari <ben@smart-cactus.org>2018-06-22 15:58:13 -0400
commit67c422ca0e7b94e021430e3dfc9b19f3de21ed16 (patch)
treeaf23a39c507d9c28b20c9a73282a71519cd25d3b /rts/linker/SymbolExtras.c
parentc7b1e93b47915a5276dfdb04f09030f5abaed290 (diff)
downloadhaskell-67c422ca0e7b94e021430e3dfc9b19f3de21ed16.tar.gz
rts/linker/{SymbolExtras,elf_got}.c: map code as read-only
protect mmaped addresses from writes after being initially manipulated Test Plan: ./validate Reviewers: bgamari, erikd, simonmar Reviewed By: bgamari Subscribers: angerman, carlostome, rwbarton, thomie, carter GHC Trac Issues: #14069 Differential Revision: https://phabricator.haskell.org/D4817
Diffstat (limited to 'rts/linker/SymbolExtras.c')
-rw-r--r--rts/linker/SymbolExtras.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/rts/linker/SymbolExtras.c b/rts/linker/SymbolExtras.c
index 486fa4a572..88541f44d0 100644
--- a/rts/linker/SymbolExtras.c
+++ b/rts/linker/SymbolExtras.c
@@ -51,8 +51,9 @@ int ocAllocateSymbolExtras( ObjectCode* oc, int count, int first )
n = roundUpToPage(oc->fileSize);
/* Keep image and symbol_extras contiguous */
- void *new = mmapForLinker(n + (sizeof(SymbolExtra) * count),
- MAP_ANONYMOUS, -1, 0);
+
+ size_t allocated_size = n + (sizeof(SymbolExtra) * count);
+ void *new = mmapForLinker(allocated_size, MAP_ANONYMOUS, -1, 0);
if (new) {
memcpy(new, oc->image, oc->fileSize);
if (oc->imageMapped) {
@@ -62,6 +63,9 @@ int ocAllocateSymbolExtras( ObjectCode* oc, int count, int first )
oc->imageMapped = true;
oc->fileSize = n + (sizeof(SymbolExtra) * count);
oc->symbol_extras = (SymbolExtra *) (oc->image + n);
+ if(mprotect(new, allocated_size, PROT_READ | PROT_EXEC) != 0) {
+ sysErrorBelch("unable to protect memory");
+ }
}
else {
oc->symbol_extras = NULL;