aboutsummaryrefslogtreecommitdiffstats
path: root/executor/executor_bsd.h
diff options
context:
space:
mode:
authorMark Johnston <markjdb@gmail.com>2020-08-07 12:46:48 -0400
committerDmitry Vyukov <dvyukov@google.com>2020-08-08 11:09:48 +0200
commit6ba54cf64ec7e5dcf8002c32b872685c905a9be8 (patch)
treeebcdbe28de1d99e468a8d1cfff5ddcdfb8080b7f /executor/executor_bsd.h
parentff51e5229e0ee846d2fd687cb0dbca13de758c66 (diff)
executor: use MAP_EXCL to map the data region on FreeBSD
We've had some problems where the default SYZ_DATA_OFFSET collides with a mapping created by the C runtime. MAP_EXCL ensures that mmap() will fail in this case, so such problems become a bit easier to diagnose.
Diffstat (limited to 'executor/executor_bsd.h')
-rw-r--r--executor/executor_bsd.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/executor/executor_bsd.h b/executor/executor_bsd.h
index d3ef16bce..65617d6b1 100644
--- a/executor/executor_bsd.h
+++ b/executor/executor_bsd.h
@@ -26,7 +26,13 @@ static void os_init(int argc, char** argv, void* data, size_t data_size)
int prot = PROT_READ | PROT_WRITE | PROT_EXEC;
#endif
- if (mmap(data, data_size, prot, MAP_ANON | MAP_PRIVATE | MAP_FIXED, -1, 0) != data)
+ int flags = MAP_ANON | MAP_PRIVATE | MAP_FIXED;
+#if GOOS_freebsd
+ // Fail closed if the chosen data offset conflicts with an existing mapping.
+ flags |= MAP_EXCL;
+#endif
+
+ if (mmap(data, data_size, prot, flags, -1, 0) != data)
fail("mmap of data segment failed");
// Makes sure the file descriptor limit is sufficient to map control pipes.