aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorNazime Hande Harputluoglu <handeharputlu@google.com>2020-10-01 21:53:57 +0000
committerAndrey Konovalov <andreyknvl@gmail.com>2020-10-02 22:00:33 +0200
commit5910646c6c6fbb5e48801342677bff9c4609a2ea (patch)
treeb6f4779d08ce53f9c7e046054ad7c2c78890a652 /pkg
parent4969d6ca0dd952b9193c3546571a4e19a3b86718 (diff)
sys/linux: descriptions for USB/IP
Diffstat (limited to 'pkg')
-rw-r--r--pkg/csource/generated.go44
-rw-r--r--pkg/host/syscalls_linux.go8
-rw-r--r--pkg/osutil/osutil.go10
3 files changed, 62 insertions, 0 deletions
diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go
index cdef36c54..83c3616a6 100644
--- a/pkg/csource/generated.go
+++ b/pkg/csource/generated.go
@@ -3875,6 +3875,50 @@ static long syz_io_uring_submit(volatile long a0, volatile long a1, volatile lon
#endif
+#if SYZ_EXECUTOR || __NR_syz_usbip_server_init
+
+#include <errno.h>
+#include <fcntl.h>
+#include <linux/usb/ch9.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#define VHCI_HC_PORTS 8
+#define VHCI_PORTS (VHCI_HC_PORTS * 2)
+
+static long syz_usbip_server_init(volatile long a0)
+{
+ int socket_pair[2];
+ char buffer[100];
+ static int port_alloc[2];
+
+ int speed = (int)a0;
+ bool usb3 = (speed == USB_SPEED_SUPER);
+
+ int rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socket_pair);
+ if (rc < 0)
+ fail("syz_usbip_server_init : socketpair failed: %d", rc);
+
+ int client_fd = socket_pair[0];
+ int server_fd = socket_pair[1];
+
+ int available_port_num = __atomic_fetch_add(&port_alloc[usb3], 1, __ATOMIC_RELAXED);
+ if (available_port_num > VHCI_HC_PORTS) {
+ debug("syz_usbip_server_init : no more available port for : %d\n", available_port_num);
+ return -1;
+ }
+ int port_num = procid * VHCI_PORTS + usb3 * VHCI_HC_PORTS + available_port_num;
+ sprintf(buffer, "%d %d %s %d", port_num, client_fd, "0", speed);
+
+ write_file("/sys/devices/platform/vhci_hcd.0/attach", buffer);
+ return server_fd;
+}
+
+#endif
+
#if SYZ_EXECUTOR || __NR_syz_btf_id_by_name
#include <errno.h>
diff --git a/pkg/host/syscalls_linux.go b/pkg/host/syscalls_linux.go
index c66342ddf..998f6f96c 100644
--- a/pkg/host/syscalls_linux.go
+++ b/pkg/host/syscalls_linux.go
@@ -265,6 +265,13 @@ func isSyzFuseSupported(c *prog.Syscall, target *prog.Target, sandbox string) (b
return true, ""
}
+func isSyzUsbIPSupported(c *prog.Syscall, target *prog.Target, sandbox string) (bool, string) {
+ if err := osutil.IsWritable("/sys/devices/platform/vhci_hcd.0/attach"); err != nil {
+ return false, err.Error()
+ }
+ return onlySandboxNoneOrNamespace(sandbox)
+}
+
var syzkallSupport = map[string]func(*prog.Syscall, *prog.Target, string) (bool, string){
"syz_open_dev": isSyzOpenDevSupported,
"syz_open_procfs": alwaysSupported,
@@ -294,6 +301,7 @@ var syzkallSupport = map[string]func(*prog.Syscall, *prog.Target, string) (bool,
"syz_fuse_handle_req": isSyzFuseSupported,
"syz_80211_inject_frame": isWifiEmulationSupported,
"syz_80211_join_ibss": isWifiEmulationSupported,
+ "syz_usbip_server_init": isSyzUsbIPSupported,
}
func isSupportedSyzkall(c *prog.Syscall, target *prog.Target, sandbox string) (bool, string) {
diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go
index b50b6e45b..5a7a342b1 100644
--- a/pkg/osutil/osutil.go
+++ b/pkg/osutil/osutil.go
@@ -127,6 +127,16 @@ func IsAccessible(name string) error {
return nil
}
+// IsWritable checks if the file can be written.
+func IsWritable(name string) error {
+ f, err := os.OpenFile(name, os.O_WRONLY, DefaultFilePerm)
+ if err != nil {
+ return fmt.Errorf("%v can't be written (%v)", name, err)
+ }
+ f.Close()
+ return nil
+}
+
// FilesExist returns true if all files exist in dir.
// Files are assumed to be relative names in slash notation.
func FilesExist(dir string, files map[string]bool) bool {