#885: GHC doesn't work with Data Execution Prevention on Windows
-----------------------+----------------------------------------------------
Reporter: guest | Owner:
Type: bug | Status: new
Priority: normal | Milestone: _|_
Component: Compiler | Version: 6.4.2
Severity: major | Resolution:
Keywords: | Os: Windows
Difficulty: Unknown | Architecture: x86
-----------------------+----------------------------------------------------
Comment (by briansmith):
This particular case is caused by the linker allocating memory using
stgMallocBytes instead of allocateExec. But, allocateExec does not work
either, for reasons I will explain below. I have attached a patch that
fixes the problem using VirtualAlloc directly. With this patch, GHCi will
work correctly for programs that do not use the FFI.
MBlock.c allocates memory with VirtualAlloc as PAGE_READWRITE, and then
later setExecutable tries to covert it to PAGE_EXECUTE_READWRITE. However,
the execute permission cannot be added by VirtualProtect--it must be
requested in the initial VirtualAlloc. See
http://msdn.microsoft.com/security/productinfo/XPSP2/memoryprotection/exec_imp.aspx
section "Action Required." That is, the initial VirtualAlloc call must be,
e.g. PAGE_EXECUTE_READWRITE, and then VirtualProtect can covert it to
PAGE_EXECUTE or PAGE_EXECUTE_READ. The practical implication is that
setExecutable cannot be implemented on Windows.
There are some improvements that could be made to the patch. In
particular, the PAGE_EXECUTE permission should be removed from all
non-.text sections. Similarly, PAGE_WRITE (and maybe PAGE_READ) should be
removed from .text sections after the linker fixes up the addresses.
PAGE_WRITE should be removed from .rodata sections. I did not make these
changes because I merely wanted to get ghci to be executable with DEP
enabled. I will file a separate bug if the patch is accepted.
Programs that use the FFI will still fail until ByteCodeFFI is modified to
allocate memory using VirtualAlloc(...PAGE_EXECUTE_READWRITE...). I tried
to do so but I was unsuccessful in getting something working.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/885>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs