Skip to content

Commit 4980d2c

Browse files
authored
Use PROT_MPROTECT for NetBSD mprotect restrictions (#185)
NetBSD's mprotect seems to be more restrictive than other OSes, where it does not allow less restrictive mappings than the original mmap, and can be subject to PaX restrictions. According to NetBSD documentation, there is a PROT_MPROTECT macro to define allowed protections for later uses of mprotect, without granting the permissions immediately in mmap. This can be used to ensure that the full range of protections blink could make in the course of execution are permitted.
1 parent 4fdcd8d commit 4980d2c

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

blink/map.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ void *Mmap(void *addr, //
168168
void *res;
169169
#if LOG_MEM
170170
char szbuf[16];
171+
#endif
172+
#if defined(__NetBSD__)
173+
if (!(flags & MAP_SHARED)) {
174+
prot |= PROT_MPROTECT(PROT_EXEC | PROT_WRITE | PROT_READ);
175+
}
171176
#endif
172177
res = PortableMmap(addr, length, prot, flags, fd, offset);
173178
#if LOG_MEM

0 commit comments

Comments
 (0)