diff options
| author | Zach Riggle <zachriggle@users.noreply.github.com> | 2017-06-26 08:32:38 -0500 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-06-26 15:32:38 +0200 |
| commit | 2420edb02ee04fc1b7dc39e7d5e17f98e3e3a24b (patch) | |
| tree | 80d02d9248808642724208e809a43062636250b4 | |
| parent | dd93f0378ab9dcfd951394cb53514bfdee67b4d9 (diff) | |
Port console to Darwin (#253)
* Port console to Darwin
* Get syz-executor to build correctly
* Do not export unix and syscall constants
* Add presubmit test
* Add myself to contributors
| -rw-r--r-- | CONTRIBUTORS | 1 | ||||
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | docs/setup_linux-host_android-device_arm64-kernel.md | 20 | ||||
| -rw-r--r-- | executor/common.h | 2 | ||||
| -rw-r--r-- | vm/vmimpl/console.go | 6 | ||||
| -rw-r--r-- | vm/vmimpl/darwin.go | 15 | ||||
| -rw-r--r-- | vm/vmimpl/linux.go | 18 |
7 files changed, 53 insertions, 10 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS index e2dfa5de7..93b92c5e3 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -11,6 +11,7 @@ Google Inc. Billy Lau Michael Pratt Jess Frazelle + Zach Riggle Baozeng Ding Lorenzo Stoakes Jeremy Huang @@ -86,6 +86,7 @@ presubmit: ARCH=amd64 go install ./... ARCH=arm64 go install ./... ARCH=ppc64le go install ./... + GOOS=darwin go build -o /dev/null ./syz-manager go test -short ./... echo LGTM diff --git a/docs/setup_linux-host_android-device_arm64-kernel.md b/docs/setup_linux-host_android-device_arm64-kernel.md index e3ff3c094..6273b0058 100644 --- a/docs/setup_linux-host_android-device_arm64-kernel.md +++ b/docs/setup_linux-host_android-device_arm64-kernel.md @@ -2,7 +2,7 @@ Prerequisites: - go1.8+ toolchain (can be downloaded from [here](https://golang.org/dl/)) - - Android NDK (tested with r12b) (can be downloaded from [here](https://developer.android.com/ndk/downloads/index.html)) + - Android NDK (tested with r15 on API24) (can be downloaded from [here](https://developer.android.com/ndk/downloads/index.html)) - Android Serial Cable or [Suzy-Q](https://chromium.googlesource.com/chromiumos/platform/ec/+/master/docs/case_closed_debugging.md) device to capture console output is preferable but optional. syzkaller can work with normal USB cable as well, but that can be somewhat unreliable and turn lots of crashes into "lost connection to test machine" crashes with no additional info. From `syzkaller` checkout: @@ -13,15 +13,21 @@ go build -o bin/syz-manager ./syz-manager - Build `syz-fuzzer` and `syz-execprog` for arm64: ``` -GOARCH=arm64 go build -o bin/syz-fuzzer ./syz-fuzzer -GOARCH=arm64 go build -o bin/syz-execprog ./tools/syz-execprog +GOOS=linux GOARCH=arm64 go build -o bin/syz-fuzzer ./syz-fuzzer +GOOS=linux GOARCH=arm64 go build -o bin/syz-execprog ./tools/syz-execprog ``` - Build `syz-executor` for arm64: -``` -/android-ndk-r12b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-g++ \ - -I/android-ndk-r12b/sources/cxx-stl/llvm-libc++/libcxx/include \ - --sysroot=/android-ndk-r12b/platforms/android-22/arch-arm64 \ + +```sh +NDK=/path/to/android-ndk-r15 +UNAME=$(uname | tr '[:upper:]' '[:lower:]') +TOOLCHAIN=aarch64-linux-android +API=24 +ARCH=arm64 +$NDK/toolchains/$TOOLCHAIN-4.9/prebuilt/$UNAME-x86_64/bin/$TOOLCHAIN-g++ \ + -I $NDK/sources/cxx-stl/llvm-libc++/include \ + --sysroot=$NDK/platforms/android-$API/arch-$ARCH \ executor/executor.cc -O1 -g -Wall -static -o bin/syz-executor ``` diff --git a/executor/common.h b/executor/common.h index 8ced8313b..e1cc3385e 100644 --- a/executor/common.h +++ b/executor/common.h @@ -509,6 +509,7 @@ static void flush_tun() #endif #if defined(SYZ_EXECUTOR) || (defined(__NR_syz_extract_tcp_res) && defined(SYZ_TUN_ENABLE)) +#ifndef __ANDROID__ // Can't include <linux/ipv6.h>, since it causes // conflicts due to some structs redefinition. struct ipv6hdr { @@ -523,6 +524,7 @@ struct ipv6hdr { struct in6_addr saddr; struct in6_addr daddr; }; +#endif struct tcp_resources { int32_t seq; diff --git a/vm/vmimpl/console.go b/vm/vmimpl/console.go index f4a0b71d1..3fa501162 100644 --- a/vm/vmimpl/console.go +++ b/vm/vmimpl/console.go @@ -29,11 +29,11 @@ func OpenConsole(con string) (rc io.ReadCloser, err error) { } }() var term unix.Termios - if _, _, errno := syscall.Syscall(unix.SYS_IOCTL, uintptr(fd), unix.TCGETS2, uintptr(unsafe.Pointer(&term))); errno != 0 { + if _, _, errno := syscall.Syscall(unix.SYS_IOCTL, uintptr(fd), syscall_TCGETS, uintptr(unsafe.Pointer(&term))); errno != 0 { return nil, fmt.Errorf("failed to get console termios: %v", errno) } // no parity bit, only need 1 stop bit, no hardware flowcontrol - term.Cflag &^= unix.CBAUD | unix.CSIZE | unix.PARENB | unix.CSTOPB | unix.CRTSCTS + term.Cflag &^= unix_CBAUD | unix.CSIZE | unix.PARENB | unix.CSTOPB | unix_CRTSCTS // ignore modem controls term.Cflag |= unix.B115200 | unix.CS8 | unix.CLOCAL | unix.CREAD // setup for non-canonical mode @@ -42,7 +42,7 @@ func OpenConsole(con string) (rc io.ReadCloser, err error) { term.Oflag &^= unix.OPOST term.Cc[unix.VMIN] = 0 term.Cc[unix.VTIME] = 10 // 1 second timeout - if _, _, errno := syscall.Syscall(unix.SYS_IOCTL, uintptr(fd), unix.TCSETS2, uintptr(unsafe.Pointer(&term))); errno != 0 { + if _, _, errno := syscall.Syscall(unix.SYS_IOCTL, uintptr(fd), syscall_TCSETS, uintptr(unsafe.Pointer(&term))); errno != 0 { return nil, fmt.Errorf("failed to get console termios: %v", errno) } tmp := fd diff --git a/vm/vmimpl/darwin.go b/vm/vmimpl/darwin.go new file mode 100644 index 000000000..87efdd881 --- /dev/null +++ b/vm/vmimpl/darwin.go @@ -0,0 +1,15 @@ +// 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 darwin + +package vmimpl + +import "syscall" + +const ( + unix_CBAUD = 0 + unix_CRTSCTS = 0 + syscall_TCGETS = syscall.TIOCGETA + syscall_TCSETS = syscall.TIOCSETA +) diff --git a/vm/vmimpl/linux.go b/vm/vmimpl/linux.go new file mode 100644 index 000000000..d25b263fc --- /dev/null +++ b/vm/vmimpl/linux.go @@ -0,0 +1,18 @@ +// 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 linux + +package vmimpl + +import ( + "syscall" + "unix" +) + +const ( + unix_CBAUD = unix.CBAUD + unix_CRTSCTS = unix.CRTSCTS + syscall_TCGETS = syscall.TCGETS + syscall_TCSETS = syscall.TCSETS +) |
