From c7c20675f58e3edaa53538928c0963144fd524e5 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Thu, 2 Dec 2021 10:39:37 +0000 Subject: executor: reserve fds that will belong to kcov As now kcov instances may get set up during fuzzing, performing dup2 in cover_open is no longer safe as it may close some important resource. Prevent that by reserving most of fds that belong to the kcov fds range. Unfortunately we must duplicate the code because of the way kcov implementations are organized. --- executor/executor_linux.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'executor/executor_linux.h') diff --git a/executor/executor_linux.h b/executor/executor_linux.h index bd43f2a5b..7d2780c0f 100644 --- a/executor/executor_linux.h +++ b/executor/executor_linux.h @@ -147,6 +147,14 @@ static void cover_collect(cover_t* cov) cov->size = *(uint32*)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(uint32 pc) { return true; -- cgit mrf-deployment