From 6ba54cf64ec7e5dcf8002c32b872685c905a9be8 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Fri, 7 Aug 2020 12:46:48 -0400 Subject: 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. --- executor/executor_bsd.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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. -- cgit mrf-deployment