[PATCH] D35778: Add NetBSD PaX MPROTECT support in allocateMappedMemory

Kamil Rytarowski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 23 08:28:40 PDT 2017


krytarowski created this revision.

A user of the Memory::allocateMappedMemory interface
can allocate memory and request additional permission
bits in future. This breaks PaX MPROTECT model on NetBSD,
as these bits have to be reserved with PROT_MPROTECT().

This has been caught by unittests/Support/MemoryTest
and EnabledWrite tests.

This patch fixes these failures and does not introduce
regressions.

Sponsored by <The NetBSD Foundation>


Repository:
  rL LLVM

https://reviews.llvm.org/D35778

Files:
  lib/Support/Unix/Memory.inc


Index: lib/Support/Unix/Memory.inc
===================================================================
--- lib/Support/Unix/Memory.inc
+++ lib/Support/Unix/Memory.inc
@@ -102,6 +102,11 @@
 
   int Protect = getPosixProtectionFlags(PFlags);
 
+#if defined(__NetBSD__) && defined(PROT_MPROTECT)
+  // This is required in order to grant additional protection bits
+  Protect |= PROT_MPROTECT(PROT_READ | PROT_WRITE | PROT_EXEC);
+#endif
+
   // Use any near hint and the page size to set a page-aligned starting address
   uintptr_t Start = NearBlock ? reinterpret_cast<uintptr_t>(NearBlock->base()) +
                                       NearBlock->size() : 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35778.107831.patch
Type: text/x-patch
Size: 661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170723/644b9e1e/attachment.bin>


More information about the llvm-commits mailing list