From 28b24332d95f2f7df44ec7e7a5e0025bcadc6277 Mon Sep 17 00:00:00 2001 From: Alon Zahavi Date: Tue, 28 Nov 2023 11:15:26 +0000 Subject: 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. --- pkg/csource/generated.go | 47 ++++++++++++++++++++++++++++++++++++++++++++-- pkg/host/syscalls_linux.go | 5 +++++ 2 files changed, 50 insertions(+), 2 deletions(-) (limited to 'pkg') 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 +#include +#include +#include +#include +#include +#include +#include + +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 #include @@ -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) { -- cgit mrf-deployment