aboutsummaryrefslogtreecommitdiffstats
path: root/executor/executor_bsd.h
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2021-12-03 13:58:21 +0000
committerAleksandr Nogikh <wp32pw@gmail.com>2021-12-03 18:20:11 +0100
commita617004c2317ce7443e2fff7415ddab9ac765afc (patch)
tree93e1acdcbf47ebab69eb573cca4e4e93b40f181e /executor/executor_bsd.h
parentc7c20675f58e3edaa53538928c0963144fd524e5 (diff)
executor: delay kcov mmap until it is needed
The previous strategy (delay kcov instance creation) seems not to work very well in carefully sandboxed environments. Let's see if the new approach is more versatile. Open a kcov handle for each thread at syz-executor's initialization, but don't mmap it right away.
Diffstat (limited to 'executor/executor_bsd.h')
-rw-r--r--executor/executor_bsd.h23
1 files changed, 10 insertions, 13 deletions
diff --git a/executor/executor_bsd.h b/executor/executor_bsd.h
index 80b56f317..dc3ebbdd8 100644
--- a/executor/executor_bsd.h
+++ b/executor/executor_bsd.h
@@ -61,7 +61,7 @@ static void cover_open(cover_t* cov, bool extra)
#if GOOS_freebsd
if (ioctl(cov->fd, KIOSETBUFSIZE, kCoverSize))
fail("ioctl init trace write failed");
- size_t mmap_alloc_size = kCoverSize * KCOV_ENTRY_SIZE;
+ cov->mmap_alloc_size = kCoverSize * KCOV_ENTRY_SIZE;
#elif GOOS_openbsd
unsigned long cover_size = kCoverSize;
if (ioctl(cov->fd, KIOSETBUFSIZE, &cover_size))
@@ -73,7 +73,7 @@ static void cover_open(cover_t* cov, bool extra)
if (ioctl(cov->fd, KIOREMOTEATTACH, &args))
fail("ioctl remote attach failed");
}
- size_t mmap_alloc_size = kCoverSize * (is_kernel_64_bit ? 8 : 4);
+ cov->mmap_alloc_size = kCoverSize * (is_kernel_64_bit ? 8 : 4);
#elif GOOS_netbsd
uint64_t cover_size;
if (extra) {
@@ -90,15 +90,20 @@ static void cover_open(cover_t* cov, bool extra)
if (ioctl(cov->fd, KCOV_IOC_SETBUFSIZE, &cover_size))
fail("ioctl init trace write failed");
}
- size_t mmap_alloc_size = cover_size * KCOV_ENTRY_SIZE;
+ cov->mmap_alloc_size = cover_size * KCOV_ENTRY_SIZE;
#endif
+}
- void* mmap_ptr = mmap(NULL, mmap_alloc_size, PROT_READ | PROT_WRITE,
+static void cover_mmap(cover_t* cov)
+{
+ if (cov->data != NULL)
+ fail("cover_mmap invoked on an already mmapped cover_t object");
+ void* mmap_ptr = mmap(NULL, cov->mmap_alloc_size, PROT_READ | PROT_WRITE,
MAP_SHARED, cov->fd, 0);
if (mmap_ptr == MAP_FAILED)
fail("cover mmap failed");
cov->data = (char*)mmap_ptr;
- cov->data_end = cov->data + mmap_alloc_size;
+ cov->data_end = cov->data + cov->mmap_alloc_size;
cov->data_offset = is_kernel_64_bit ? sizeof(uint64_t) : sizeof(uint32_t);
cov->pc_offset = 0;
}
@@ -164,14 +169,6 @@ static void cover_collect(cover_t* cov)
cov->size = *(uint64*)cov->data;
}
-static void cover_reserve_fd(cover_t* cov)
-{
- int fd = open("/dev/null", O_RDONLY);
- if (fd < 0)
- fail("failed to open /dev/null");
- dup2(fd, cov->fd);
-}
-
static bool use_cover_edges(uint64 pc)
{
return true;