diff options
Diffstat (limited to 'executor')
| -rw-r--r-- | executor/common_bsd.h | 22 | ||||
| -rw-r--r-- | executor/common_usb_netbsd.h | 25 | ||||
| -rw-r--r-- | executor/executor_bsd.h | 2 |
3 files changed, 30 insertions, 19 deletions
diff --git a/executor/common_bsd.h b/executor/common_bsd.h index 82aef4211..070c512bf 100644 --- a/executor/common_bsd.h +++ b/executor/common_bsd.h @@ -17,10 +17,28 @@ #include "common_usb_netbsd.h" #endif #if SYZ_EXECUTOR || SYZ_USB +#include <dirent.h> static void setup_usb(void) { - if (chmod("/dev/vhci", 0666)) - fail("failed to chmod /dev/vhci"); + struct dirent* ent; + char path[1024]; + DIR* dir; + + dir = opendir("/dev"); + if (dir == NULL) + fail("failed to open /dev"); + + while ((ent = readdir(dir)) != NULL) { + if (ent->d_type != DT_CHR) + continue; + if (strncmp(ent->d_name, "vhci", 4)) + continue; + snprintf(path, sizeof(path), "/dev/%s", ent->d_name); + if (chmod(path, 0666)) + fail("failed to chmod %s", path); + } + + closedir(dir); } #endif diff --git a/executor/common_usb_netbsd.h b/executor/common_usb_netbsd.h index c6936993f..9ce8f72dc 100644 --- a/executor/common_usb_netbsd.h +++ b/executor/common_usb_netbsd.h @@ -159,7 +159,11 @@ struct usb_qualifier_descriptor { static int vhci_open(void) { - return open("/dev/vhci", O_RDWR); + char path[1024]; + + snprintf(path, sizeof(path), "/dev/vhci%llu", procid); + + return open(path, O_RDWR); } static int vhci_setport(int fd, u_int port) @@ -214,31 +218,22 @@ static volatile long syz_usb_connect_impl(uint64 speed, uint64 dev_len, lookup_connect_out_response_t lookup_connect_response_out) { struct usb_device_index* index; - int portnum, fd, rv; + int fd, rv; bool done; - portnum = procid + 1; - debug("syz_usb_connect: dev: %p\n", dev); if (!dev) { debug("syz_usb_connect: dev is null\n"); return -1; } - if (portnum != 1) { - /* For now, we support only one proc. */ - debug("syz_usb_connect: not proc1 %d\n", (int)procid); - return -1; - } debug("syz_usb_connect: device data:\n"); debug_dump_data(dev, dev_len); fd = vhci_open(); if (fd < 0) { - debug("syz_usb_connect: vhci_open failed with %d\n", fd); - return -1; + fail("syz_usb_connect: vhci_open failed with %d", errno); } - debug("syz_usb_connect: vhci_open success\n"); index = add_usb_index(fd, dev, dev_len); if (!index) { @@ -251,12 +246,10 @@ static volatile long syz_usb_connect_impl(uint64 speed, uint64 dev_len, NONFAILING(analyze_usb_device(index)); #endif - rv = vhci_setport(fd, portnum); + rv = vhci_setport(fd, 1); if (rv != 0) { - debug("syz_usb_connect: vhci_setport failed with %d\n", rv); - goto err; + fail("syz_usb_connect: vhci_setport failed with %d", errno); } - debug("syz_usb_connect: vhci_setport success\n"); rv = vhci_usb_attach(fd); if (rv != 0) { diff --git a/executor/executor_bsd.h b/executor/executor_bsd.h index a9440acec..d3ef16bce 100644 --- a/executor/executor_bsd.h +++ b/executor/executor_bsd.h @@ -74,7 +74,7 @@ static void cover_open(cover_t* cov, bool extra) cover_size = (256 << 10); // maximum size struct kcov_ioc_remote_attach args; args.subsystem = KCOV_REMOTE_VHCI; - args.id = procid + 1; // port number + args.id = KCOV_REMOTE_VHCI_ID(procid, 1); // first port if (ioctl(cov->fd, KCOV_IOC_REMOTE_ATTACH, &args)) fail("ioctl remote attach failed"); } else { |
