From 720b7efa99d7f3b4069af440ea7d004a6f27467d Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Fri, 31 May 2024 11:16:40 +0200 Subject: executor: rework feature setup Return failure reason from setup functions rather than crash. This will provide better error messages, but also allow setup w/o creating subprocesses which will be needed when we combine fuzzer and executor. Also close all resources created during setup. This is also useful for in-process setup, but also should improve chances of reproducing a bug with C reproducer. Currently leaked file descriptors may disturb repro execution (e.g. it may act on a wrong fd). --- executor/common_bsd.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'executor/common_bsd.h') diff --git a/executor/common_bsd.h b/executor/common_bsd.h index e0beac33f..683e7c140 100644 --- a/executor/common_bsd.h +++ b/executor/common_bsd.h @@ -18,11 +18,12 @@ #endif #if SYZ_EXECUTOR || SYZ_USB #include -static void setup_usb(void) + +static const char* setup_usb(void) { DIR* dir = opendir("/dev"); if (dir == NULL) - fail("failed to open /dev"); + return "failed to open /dev"; bool have_vhci = false; struct dirent* ent = NULL; @@ -33,14 +34,14 @@ static void setup_usb(void) continue; char path[1024]; snprintf(path, sizeof(path), "/dev/%s", ent->d_name); - if (chmod(path, 0666)) - failmsg("failed to chmod vhci", "path=%s", path); + if (chmod(path, 0666)) { + closedir(dir); + return "failed to chmod /dev/vhci"; + } have_vhci = true; } - if (!have_vhci) - fail("don't have any /dev/vhci devices"); - closedir(dir); + return have_vhci ? NULL : "don't have any /dev/vhci devices"; } #endif @@ -48,11 +49,14 @@ static void setup_usb(void) #include #include #include -static void setup_fault(void) + +static const char* setup_fault(void) { if (chmod("/dev/fault", 0666)) - fail("failed to chmod /dev/fault"); + return "failed to chmod /dev/fault"; + return NULL; } + static int inject_fault(int nth) { struct fault_ioc_enable en; @@ -71,6 +75,7 @@ static int inject_fault(int nth) return fd; } #endif + #if SYZ_EXECUTOR static int fault_injected(int fd) { -- cgit mrf-deployment