This is an archive of the discontinued LLVM Phabricator instance.

Add NetBSD PaX MPROTECT support in allocateMappedMemory
AbandonedPublic

Authored by krytarowski on Jul 23 2017, 8:28 AM.

Details

Reviewers
joerg
rnk
Summary

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>

Diff Detail

Repository
rL LLVM

Event Timeline

krytarowski created this revision.Jul 23 2017, 8:28 AM
joerg edited edge metadata.Jul 23 2017, 9:44 AM

While more localized, this seems to be an even greater hack than adopting the JIT users to use AllocateRWXMemory.

The following code triggers failure specific to NetBSD:

$ cat mprotect.c                                                                                                               
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <stdio.h>

int
main(int argc, char **argv)
{
	void *p = mmap(0, 0x1000, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
	int ret = mprotect(p, 0x1000, PROT_READ | PROT_WRITE);

	printf("ret=%d errno=%d\n", ret, errno);

	return 0;
}
$ ./a.out                                                                                                                      
ret=-1 errno=13
krytarowski abandoned this revision.Aug 4 2017, 3:03 AM
krytarowski added a subscriber: lhames.

@lhames FYI.

Closing this, this should be solved differently, hopefully by refactoring the interface.