sys/netbsd: support multiple vHCI buses (#1822)

This commit is contained in:
m00nbsd 2020-06-13 12:10:16 +02:00 committed by GitHub
parent 205b2ba418
commit dbce178a0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 60 additions and 38 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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 {

View File

@ -1342,7 +1342,11 @@ static bool lookup_control_response(const struct vusb_descriptors* descs, const
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)
@ -1397,31 +1401,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) {
@ -1434,12 +1429,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) {
@ -1563,10 +1556,28 @@ static volatile long syz_usb_disconnect(volatile long a0)
#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

View File

@ -27,7 +27,7 @@ func init() {
}
func checkUSBEmulation() string {
if err := osutil.IsAccessible("/dev/vhci"); err != nil {
if err := osutil.IsAccessible("/dev/vhci0"); err != nil {
return err.Error()
}
return ""