[commit: ghc] master: rts/linker/{SymbolExtras, elf_got}.c: map code as read-only (67c422c)
git at git.haskell.org
git at git.haskell.org
Fri Jun 22 20:00:04 UTC 2018
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/67c422ca0e7b94e021430e3dfc9b19f3de21ed16/ghc
>---------------------------------------------------------------
commit 67c422ca0e7b94e021430e3dfc9b19f3de21ed16
Author: Santiago MunĂn <santimunin at gmail.com>
Date: Thu Jun 21 17:00:58 2018 -0400
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
>---------------------------------------------------------------
67c422ca0e7b94e021430e3dfc9b19f3de21ed16
rts/linker/SymbolExtras.c | 8 ++++++--
rts/linker/elf_got.c | 3 +++
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/rts/linker/SymbolExtras.c b/rts/linker/SymbolExtras.c
index 486fa4a..88541f4 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;
diff --git a/rts/linker/elf_got.c b/rts/linker/elf_got.c
index 0395d16..10ea25b 100644
--- a/rts/linker/elf_got.c
+++ b/rts/linker/elf_got.c
@@ -62,6 +62,9 @@ makeGot(ObjectCode * oc) {
symTab->symbols[i].got_addr
= (uint8_t *)oc->info->got_start
+ (slot++ * sizeof(void*));
+ if(mprotect(mem, oc->info->got_size, PROT_READ) != 0) {
+ sysErrorBelch("unable to protect memory");
+ }
}
return EXIT_SUCCESS;
}
More information about the ghc-commits
mailing list