From 5681358a2a14647b64cdb97e0d19d3614986d31c Mon Sep 17 00:00:00 2001 From: Marco Elver Date: Tue, 22 Oct 2019 13:33:27 +0200 Subject: syz-fuzzer, executor: Add support for blacklisting data race frames This adds support to add frames that have already been in data races, to the KCSAN report blacklist. --- executor/common_linux.h | 26 +++++++++++++++++++++++++- executor/executor.cc | 8 ++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'executor') diff --git a/executor/common_linux.h b/executor/common_linux.h index 5888b65cf..b56453510 100644 --- a/executor/common_linux.h +++ b/executor/common_linux.h @@ -2784,9 +2784,33 @@ static void setup_binfmt_misc() #endif #if SYZ_EXECUTOR || SYZ_ENABLE_KCSAN +#define KCSAN_DEBUGFS_FILE "/sys/kernel/debug/kcsan" + static void setup_kcsan() { - if (!write_file("/sys/kernel/debug/kcsan", "on")) + if (!write_file(KCSAN_DEBUGFS_FILE, "on")) fail("failed to enable KCSAN"); } + +#if SYZ_EXECUTOR // currently only used by executor +static void setup_kcsan_filterlist(char** frames, int nframes, bool blacklist) +{ + int fd = open(KCSAN_DEBUGFS_FILE, O_WRONLY); + if (fd == -1) + fail("failed to open(\"%s\")", KCSAN_DEBUGFS_FILE); + + const char* const filtertype = blacklist ? "blacklist" : "whitelist"; + printf("adding functions to KCSAN %s: ", filtertype); + dprintf(fd, "%s\n", filtertype); + for (int i = 0; i < nframes; ++i) { + printf("'%s' ", frames[i]); + dprintf(fd, "!%s\n", frames[i]); + } + printf("\n"); + + close(fd); +} + +#define SYZ_HAVE_KCSAN 1 +#endif #endif diff --git a/executor/executor.cc b/executor/executor.cc index 1f51ec279..30d497ea9 100644 --- a/executor/executor.cc +++ b/executor/executor.cc @@ -344,6 +344,14 @@ int main(int argc, char** argv) check_leaks(argv + 2, argc - 2); #else fail("leak checking is not implemented"); +#endif + return 0; + } + if (argc >= 2 && strcmp(argv[1], "setup_kcsan_blacklist") == 0) { +#if SYZ_HAVE_KCSAN + setup_kcsan_filterlist(argv + 2, argc - 2, /*blacklist=*/true); +#else + fail("KCSAN is not implemented"); #endif return 0; } -- cgit mrf-deployment