aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorAlon Zahavi <zahavi.alon@gmail.com>2023-11-28 11:15:26 +0000
committerAleksandr Nogikh <nogikh@google.com>2023-12-07 10:16:22 +0000
commit28b24332d95f2f7df44ec7e7a5e0025bcadc6277 (patch)
tree0fd034868b3b507331a8c1fe6acddf9bd5a8df1c /pkg
parent0a02ce36aee886cafdc6907db66a49859cf17caf (diff)
sys/linux, pkg/host, executor: add NVMe-oF/TCP subsystem support
Add new pseudo-syscall for creating a socket in init netns and connecting to NVMe-oF/TCP server on 127.0.0.1:4420. Also add descriptions for NVMe-oF/TCP.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/csource/generated.go47
-rw-r--r--pkg/host/syscalls_linux.go5
2 files changed, 50 insertions, 2 deletions
diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go
index 60a1ff964..4c3fae47c 100644
--- a/pkg/csource/generated.go
+++ b/pkg/csource/generated.go
@@ -3365,7 +3365,7 @@ static void initialize_tun(void)
}
#endif
-#if SYZ_EXECUTOR || __NR_syz_init_net_socket || SYZ_DEVLINK_PCI
+#if SYZ_EXECUTOR || __NR_syz_init_net_socket || SYZ_DEVLINK_PCI || __NR_syz_socket_connect_nvme_tcp
const int kInitNetNsFd = 201;
#endif
@@ -6296,6 +6296,49 @@ static long syz_init_net_socket(volatile long domain, volatile long type, volati
#endif
#endif
+#if SYZ_EXECUTOR || __NR_syz_socket_connect_nvme_tcp
+#if SYZ_EXECUTOR || SYZ_SANDBOX_NONE || SYZ_SANDBOX_SETUID || SYZ_SANDBOX_NAMESPACE
+#include <arpa/inet.h>
+#include <fcntl.h>
+#include <netinet/in.h>
+#include <sched.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+static long syz_socket_connect_nvme_tcp()
+{
+ struct sockaddr_in nvme_local_address;
+ int netns = open("/proc/self/ns/net", O_RDONLY);
+ if (netns == -1)
+ return netns;
+ if (setns(kInitNetNsFd, 0))
+ return -1;
+ int sock = syscall(__NR_socket, AF_INET, SOCK_STREAM, 0x0);
+ int err = errno;
+ if (setns(netns, 0))
+ fail("setns(netns) failed");
+ close(netns);
+ errno = err;
+ nvme_local_address.sin_family = AF_INET;
+ nvme_local_address.sin_port = htobe16(4420);
+ nvme_local_address.sin_addr.s_addr = htobe32(0x7f000001);
+ err = syscall(__NR_connect, sock, &nvme_local_address, sizeof(nvme_local_address));
+ if (err != 0) {
+ close(sock);
+ return -1;
+ }
+ return sock;
+}
+#else
+static long syz_socket_connect_nvme_tcp()
+{
+ return syscall(__NR_socket, -1, 0, 0);
+}
+#endif
+#endif
+
#if SYZ_EXECUTOR || SYZ_VHCI_INJECTION
#include <errno.h>
#include <fcntl.h>
@@ -9212,7 +9255,7 @@ static void sandbox_common()
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
setsid();
-#if SYZ_EXECUTOR || __NR_syz_init_net_socket || SYZ_DEVLINK_PCI
+#if SYZ_EXECUTOR || __NR_syz_init_net_socket || SYZ_DEVLINK_PCI || __NR_syz_socket_connect_nvme_tcp
int netns = open("/proc/self/ns/net", O_RDONLY);
if (netns == -1)
fail("open(/proc/self/ns/net) failed");
diff --git a/pkg/host/syscalls_linux.go b/pkg/host/syscalls_linux.go
index 7037dc001..b1bcbfb8b 100644
--- a/pkg/host/syscalls_linux.go
+++ b/pkg/host/syscalls_linux.go
@@ -230,6 +230,10 @@ func isSyzInitNetSocketSupported(c *prog.Syscall, target *prog.Target, sandbox s
return isSupportedSocket(c)
}
+func isSyzSocketConnectNvmeTCPSupported(c *prog.Syscall, target *prog.Target, sandbox string) (bool, string) {
+ return onlySandboxNone(sandbox)
+}
+
func isSyzGenetlinkGetFamilyIDSupported(c *prog.Syscall, target *prog.Target, sandbox string) (bool, string) {
fd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, syscall.NETLINK_GENERIC)
if fd == -1 {
@@ -322,6 +326,7 @@ var syzkallSupport = map[string]func(*prog.Syscall, *prog.Target, string) (bool,
"syz_clone": alwaysSupported,
"syz_clone3": alwaysSupported,
"syz_pkey_set": isSyzPkeySetSupported,
+ "syz_socket_connect_nvme_tcp": isSyzSocketConnectNvmeTCPSupported,
}
func isSupportedSyzkall(c *prog.Syscall, target *prog.Target, sandbox string) (bool, string) {