From b771b17ec95715c24715d730363f6f07bc46fd4f Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Tue, 28 Aug 2018 19:07:26 +0200 Subject: Add mandatory OpenBSD bits (#689) all: add openbsd support squash of the following commits: * openbsd: add mandatory bits * report: add OpenBSD support * executor: skip building kvm on OpenBSD * executor: add OpenBSD support Linking against libutil is necessary due to usage of openpty(3). * executor: fix typo in fail() message * fixup! report: add OpenBSD support * fixup! openbsd: add mandatory bits * fixup! openbsd: add mandatory bits * fixup! openbsd: add mandatory bits * fixup! report: add OpenBSD support * gometalinter: skip sys/openbsd --- executor/common.h | 6 +- executor/common_bsd.h | 31 +++++++ executor/defs.h | 15 ++++ executor/executor.cc | 2 +- executor/executor_bsd.h | 28 +++++- executor/gen.go | 2 + executor/syscalls.h | 234 ++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 312 insertions(+), 6 deletions(-) (limited to 'executor') diff --git a/executor/common.h b/executor/common.h index 81e60397f..5dbb7f7b9 100644 --- a/executor/common.h +++ b/executor/common.h @@ -170,7 +170,7 @@ static void use_temporary_dir(void) #endif #endif -#if GOOS_akaros || GOOS_netbsd || GOOS_freebsd || GOOS_test +#if GOOS_akaros || GOOS_netbsd || GOOS_freebsd || GOOS_openbsd || GOOS_test #if SYZ_EXECUTOR || SYZ_EXECUTOR_USES_FORK_SERVER && SYZ_REPEAT && SYZ_USE_TMP_DIR #include #include @@ -240,7 +240,7 @@ static void thread_start(void* (*fn)(void*), void* arg) #endif #endif -#if GOOS_freebsd || GOOS_netbsd || GOOS_akaros || GOOS_test +#if GOOS_freebsd || GOOS_netbsd || GOOS_openbsd || GOOS_akaros || GOOS_test #if SYZ_EXECUTOR || SYZ_THREADED #include @@ -366,7 +366,7 @@ static uint16 csum_inet_digest(struct csum_inet* csum) #if GOOS_akaros #include "common_akaros.h" -#elif GOOS_freebsd || GOOS_netbsd +#elif GOOS_freebsd || GOOS_netbsd || GOOS_openbsd #include "common_bsd.h" #elif GOOS_fuchsia #include "common_fuchsia.h" diff --git a/executor/common_bsd.h b/executor/common_bsd.h index b678dd968..004009861 100644 --- a/executor/common_bsd.h +++ b/executor/common_bsd.h @@ -18,3 +18,34 @@ static int do_sandbox_none(void) #define do_sandbox_setuid() 0 #define do_sandbox_namespace() 0 #endif + +#if GOOS_openbsd + +#define __syscall syscall + +#if SYZ_EXECUTOR || __NR_syz_open_pts + +#if defined(__OpenBSD__) +#include +#include +#else +// Needed when compiling on Linux. +#include +#endif + +static uintptr_t syz_open_pts(void) +{ + int master, slave; + + if (openpty(&master, &slave, NULL, NULL, NULL) == -1) + return -1; + // Move the master fd up in order to reduce the chances of the fuzzer + // generating a call to close(2) with the same fd. + if (dup2(master, master + 100) != -1) + close(master); + return slave; +} + +#endif + +#endif diff --git a/executor/defs.h b/executor/defs.h index 1a31b3c90..7567cb0f2 100644 --- a/executor/defs.h +++ b/executor/defs.h @@ -125,6 +125,21 @@ #endif +#if GOOS_openbsd +#define GOOS "openbsd" + +#if GOARCH_amd64 +#define GOARCH "amd64" +#define SYZ_REVISION "f1bde02bbb60bf849ed61dda9a552900891199ef" +#define SYZ_EXECUTOR_USES_FORK_SERVER 1 +#define SYZ_EXECUTOR_USES_SHMEM 1 +#define SYZ_PAGE_SIZE 4096 +#define SYZ_NUM_PAGES 4096 +#define SYZ_DATA_OFFSET 536870912 +#endif + +#endif + #if GOOS_test #define GOOS "test" diff --git a/executor/executor.cc b/executor/executor.cc index 1e6e9d255..22fe8d50e 100644 --- a/executor/executor.cc +++ b/executor/executor.cc @@ -298,7 +298,7 @@ static void setup_control_pipes(); #include "executor_fuchsia.h" #elif GOOS_akaros #include "executor_akaros.h" -#elif GOOS_freebsd || GOOS_netbsd +#elif GOOS_freebsd || GOOS_netbsd || GOOS_openbsd #include "executor_bsd.h" #elif GOOS_windows #include "executor_windows.h" diff --git a/executor/executor_bsd.h b/executor/executor_bsd.h index 73b026379..565a0bb3d 100644 --- a/executor/executor_bsd.h +++ b/executor/executor_bsd.h @@ -10,7 +10,7 @@ #include #include -#if !defined(__FreeBSD__) && !defined(__NetBSD__) +#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) // This is just so that "make executor TARGETOS=freebsd/netbsd" works on linux. #define __syscall syscall #endif @@ -48,6 +48,7 @@ static long execute_syscall(const call_t* c, long a[kMaxArgs]) } #if GOOS_freebsd + #define KIOENABLE _IOW('c', 2, int) // Enable coverage recording #define KIODISABLE _IO('c', 3) // Disable coverage recording #define KIOSETBUFSIZE _IOW('c', 4, unsigned int) // Set the buffer size @@ -56,16 +57,34 @@ static long execute_syscall(const call_t* c, long a[kMaxArgs]) #define KCOV_MODE_TRACE_PC 0 #define KCOV_MODE_TRACE_CMP 1 +#elif GOOS_openbsd + +#define KIOSETBUFSIZE _IOW('K', 1, unsigned long) +#define KIOENABLE _IO('K', 2) +#define KIODISABLE _IO('K', 3) + +#endif + +#if GOOS_freebsd || GOOS_openbsd + static void cover_open(cover_t* cov) { int fd = open("/dev/kcov", O_RDWR); if (fd == -1) fail("open of /dev/kcov failed"); if (dup2(fd, cov->fd) < 0) - fail("filed to dup2(%d, %d) cover fd", fd, cov->fd); + fail("failed to dup2(%d, %d) cover fd", fd, cov->fd); close(fd); + +#if GOOS_freebsd if (ioctl(cov->fd, KIOSETBUFSIZE, &kCoverSize)) fail("ioctl init trace write failed"); +#elif GOOS_openbsd + unsigned long cover_size = kCoverSize; + if (ioctl(cov->fd, KIOSETBUFSIZE, &cover_size)) + fail("ioctl init trace write failed"); +#endif + size_t mmap_alloc_size = kCoverSize * (is_kernel_64_bit ? 8 : 4); char* mmap_ptr = (char*)mmap(NULL, mmap_alloc_size, PROT_READ | PROT_WRITE, @@ -78,9 +97,14 @@ static void cover_open(cover_t* cov) static void cover_enable(cover_t* cov, bool collect_comps) { +#if GOOS_freebsd int kcov_mode = flag_collect_comps ? KCOV_MODE_TRACE_CMP : KCOV_MODE_TRACE_PC; if (ioctl(cov->fd, KIOENABLE, &kcov_mode)) exitf("cover enable write trace failed, mode=%d", kcov_mode); +#elif GOOS_openbsd + if (ioctl(cov->fd, KIOENABLE)) + exitf("cover enable write trace failed"); +#endif } static void cover_reset(cover_t* cov) diff --git a/executor/gen.go b/executor/gen.go index bd31529c0..57f2ee6dc 100644 --- a/executor/gen.go +++ b/executor/gen.go @@ -1,6 +1,8 @@ // Copyright 2017 syzkaller project authors. All rights reserved. // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. +// +build !openbsd + //go:generate bash -c "gcc kvm_gen.cc kvm.S -o kvm_gen && ./kvm_gen > kvm.S.h && rm ./kvm_gen" package executor diff --git a/executor/syscalls.h b/executor/syscalls.h index f52589a3a..c0ba5a824 100644 --- a/executor/syscalls.h +++ b/executor/syscalls.h @@ -11744,6 +11744,240 @@ const call_t syscalls[] = { #endif +#if GOOS_openbsd + +#if GOARCH_amd64 +const call_t syscalls[] = { + {"accept", 30}, + {"accept$inet", 30}, + {"accept$inet6", 30}, + {"accept$unix", 30}, + {"bind", 104}, + {"bind$inet", 104}, + {"bind$inet6", 104}, + {"bind$unix", 104}, + {"chdir", 12}, + {"chmod", 15}, + {"chown", 16}, + {"chroot", 61}, + {"clock_getres", 89}, + {"clock_gettime", 87}, + {"clock_settime", 88}, + {"close", 6}, + {"connect", 98}, + {"connect$inet", 98}, + {"connect$inet6", 98}, + {"connect$unix", 98}, + {"dup", 41}, + {"dup2", 90}, + {"execve", 59}, + {"faccessat", 313}, + {"fchdir", 13}, + {"fchmod", 124}, + {"fchmodat", 314}, + {"fchown", 123}, + {"fchownat", 315}, + {"fcntl$dupfd", 92}, + {"fcntl$getflags", 92}, + {"fcntl$getown", 92}, + {"fcntl$lock", 92}, + {"fcntl$setflags", 92}, + {"fcntl$setown", 92}, + {"fcntl$setstatus", 92}, + {"flock", 131}, + {"fsync", 95}, + {"ftruncate", 201}, + {"getdents", 99}, + {"getegid", 43}, + {"geteuid", 25}, + {"getgid", 47}, + {"getgroups", 79}, + {"getitimer", 70}, + {"getpeername", 31}, + {"getpeername$inet", 31}, + {"getpeername$inet6", 31}, + {"getpeername$unix", 31}, + {"getpgid", 207}, + {"getpgrp", 81}, + {"getpid", 20}, + {"getppid", 39}, + {"getrlimit", 194}, + {"getrusage", 19}, + {"getsockname", 32}, + {"getsockname$inet", 32}, + {"getsockname$inet6", 32}, + {"getsockname$unix", 32}, + {"getsockopt", 118}, + {"getsockopt$SO_PEERCRED", 118}, + {"getsockopt$inet_opts", 118}, + {"getsockopt$sock_cred", 118}, + {"getsockopt$sock_int", 118}, + {"getsockopt$sock_linger", 118}, + {"getsockopt$sock_timeval", 118}, + {"getuid", 24}, + {"ioctl$TIOCCBRK", 54}, + {"ioctl$TIOCCDTR", 54}, + {"ioctl$TIOCCHKVERAUTH", 54}, + {"ioctl$TIOCCLRVERAUTH", 54}, + {"ioctl$TIOCCONS", 54}, + {"ioctl$TIOCDRAIN", 54}, + {"ioctl$TIOCEXCL", 54}, + {"ioctl$TIOCFLUSH", 54}, + {"ioctl$TIOCGETA", 54}, + {"ioctl$TIOCGETD", 54}, + {"ioctl$TIOCGFLAGS", 54}, + {"ioctl$TIOCGTSTAMP", 54}, + {"ioctl$TIOCGWINSZ", 54}, + {"ioctl$TIOCMBIC", 54}, + {"ioctl$TIOCMBIS", 54}, + {"ioctl$TIOCMGET", 54}, + {"ioctl$TIOCMSET", 54}, + {"ioctl$TIOCNOTTY", 54}, + {"ioctl$TIOCNXCL", 54}, + {"ioctl$TIOCOUTQ", 54}, + {"ioctl$TIOCSBRK", 54}, + {"ioctl$TIOCSCTTY", 54}, + {"ioctl$TIOCSDTR", 54}, + {"ioctl$TIOCSETA", 54}, + {"ioctl$TIOCSETAF", 54}, + {"ioctl$TIOCSETAW", 54}, + {"ioctl$TIOCSETD", 54}, + {"ioctl$TIOCSETVERAUTH", 54}, + {"ioctl$TIOCSFLAGS", 54}, + {"ioctl$TIOCSPGRP", 54}, + {"ioctl$TIOCSTART", 54}, + {"ioctl$TIOCSTAT", 54}, + {"ioctl$TIOCSTOP", 54}, + {"ioctl$TIOCSTSTAMP", 54}, + {"ioctl$TIOCSWINSZ", 54}, + {"kevent", 72}, + {"kqueue", 269}, + {"lchown", 254}, + {"link", 9}, + {"linkat", 317}, + {"listen", 106}, + {"lseek", 199}, + {"lstat", 40}, + {"madvise", 75}, + {"mincore", 78}, + {"mkdir", 136}, + {"mkdirat", 318}, + {"mknod", 14}, + {"mknod$loop", 14}, + {"mknodat", 320}, + {"mlock", 203}, + {"mlockall", 271}, + {"mmap", 197}, + {"mprotect", 74}, + {"msgctl$IPC_RMID", 297}, + {"msgctl$IPC_SET", 297}, + {"msgctl$IPC_STAT", 297}, + {"msgget", 225}, + {"msgget$private", 225}, + {"msgrcv", 227}, + {"msgsnd", 226}, + {"munlock", 204}, + {"munlockall", 272}, + {"munmap", 73}, + {"nanosleep", 91}, + {"open", 5}, + {"open$dir", 5}, + {"openat", 321}, + {"pipe", 263}, + {"pipe2", 101}, + {"pledge", 108}, + {"poll", 252}, + {"preadv", 267}, + {"pwritev", 268}, + {"read", 3}, + {"readlink", 58}, + {"readlinkat", 322}, + {"readv", 120}, + {"recvfrom", 29}, + {"recvfrom$inet", 29}, + {"recvfrom$inet6", 29}, + {"recvfrom$unix", 29}, + {"recvmsg", 27}, + {"rename", 128}, + {"renameat", 323}, + {"rmdir", 137}, + {"select", 71}, + {"semctl$GETALL", 442}, + {"semctl$GETNCNT", 442}, + {"semctl$GETPID", 442}, + {"semctl$GETVAL", 442}, + {"semctl$GETZCNT", 442}, + {"semctl$IPC_RMID", 442}, + {"semctl$IPC_SET", 442}, + {"semctl$IPC_STAT", 442}, + {"semctl$SETALL", 442}, + {"semctl$SETVAL", 442}, + {"semget", 221}, + {"semget$private", 221}, + {"semop", 290}, + {"sendmsg", 28}, + {"sendmsg$unix", 28}, + {"sendto", 133}, + {"sendto$inet", 133}, + {"sendto$inet6", 133}, + {"sendto$unix", 133}, + {"setegid", 182}, + {"seteuid", 183}, + {"setgid", 181}, + {"setgroups", 80}, + {"setitimer", 69}, + {"setpgid", 82}, + {"setregid", 127}, + {"setreuid", 126}, + {"setrlimit", 195}, + {"setsockopt", 105}, + {"setsockopt$inet6_MRT6_ADD_MFC", 105}, + {"setsockopt$inet6_MRT6_ADD_MIF", 105}, + {"setsockopt$inet6_MRT6_DEL_MFC", 105}, + {"setsockopt$inet_opts", 105}, + {"setsockopt$sock_cred", 105}, + {"setsockopt$sock_int", 105}, + {"setsockopt$sock_linger", 105}, + {"setsockopt$sock_timeval", 105}, + {"setuid", 23}, + {"shmat", 228}, + {"shmctl$IPC_RMID", 296}, + {"shmctl$IPC_SET", 296}, + {"shmctl$IPC_STAT", 296}, + {"shmctl$SHM_LOCK", 296}, + {"shmctl$SHM_UNLOCK", 296}, + {"shmdt", 230}, + {"shmget", 289}, + {"shmget$private", 289}, + {"shutdown", 134}, + {"socket", 97}, + {"socket$inet", 97}, + {"socket$inet6", 97}, + {"socket$unix", 97}, + {"socketpair", 135}, + {"socketpair$inet", 135}, + {"socketpair$inet6", 135}, + {"socketpair$unix", 135}, + {"stat", 38}, + {"symlink", 57}, + {"symlinkat", 324}, + {"sync", 36}, + {"syz_open_pts", 0, (syscall_t)syz_open_pts}, + {"truncate", 200}, + {"unlink", 10}, + {"unlinkat", 325}, + {"unveil", 114}, + {"utimensat", 84}, + {"utimes", 76}, + {"wait4", 11}, + {"write", 4}, + {"writev", 121}, + +}; +#endif + +#endif + #if GOOS_test #if GOARCH_32_fork_shmem -- cgit mrf-deployment