From 7caa2a9eda033580cc7ef9f2de98e8e1bac6d47f Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 4 Jun 2017 10:45:42 +0200 Subject: syz-manager/config: add test for example config parsing This will ensure that the provided example config is up-to-date. --- README.md | 43 ++++++++++++++++++------------------ syz-manager/config/config_test.go | 28 +++++++++++++++++++++++ syz-manager/config/testdata/qemu.cfg | 19 ++++++++++++++++ syz-manager/example.cfg | 23 ------------------- 4 files changed, 69 insertions(+), 44 deletions(-) create mode 100644 syz-manager/config/config_test.go create mode 100644 syz-manager/config/testdata/qemu.cfg delete mode 100644 syz-manager/example.cfg diff --git a/README.md b/README.md index aaeb8814b..ae7dfabe8 100644 --- a/README.md +++ b/README.md @@ -92,40 +92,41 @@ To build additional syzkaller tools run `make all-tools`. The operation of the syzkaller `syz-manager` process is governed by a configuration file, passed at invocation time with the `-config` option. This configuration can be based on the -[syz-manager/example.cfg](syz-manager/example.cfg); the file is in JSON format with the +[example](syz-manager/config/testdata/qemu.cfg); the file is in JSON format with the following keys in its top-level object: - `http`: URL that will display information about the running `syz-manager` process. - `workdir`: Location of a working directory for the `syz-manager` process. Outputs here include: - - `/instance-x`: per VM instance temporary files - `/crashes/*`: crash output files (see [Crash Reports](#crash-reports)) - - `/corpus/*`: corpus with interesting programs + - `/corpus.db`: corpus with interesting programs + - `/instance-x`: per VM instance temporary files - `syzkaller`: Location of the `syzkaller` checkout. - `vmlinux`: Location of the `vmlinux` file that corresponds to the kernel being tested. - - `type`: Type of virtual machine to use, e.g. `qemu` or `kvm`. - - `count`: Number of VMs to run in parallel. - `procs`: Number of parallel test processes in each VM (4 or 8 would be a reasonable number). - - `leak`: Detect memory leaks with kmemleak (very slow). - - `kernel`: Location of the `bzImage` file for the kernel to be tested; this is passed as the - `-kernel` option to `qemu-system-x86_64`. - - `cmdline`: Additional command line options for the booting kernel, for example `root=/dev/sda1`. + - `leak`: Detect memory leaks with kmemleak. - `image`: Location of the disk image file for the QEMU instance; a copy of this file is passed as the `-hda` option to `qemu-system-x86_64`. - - `sshkey`: Location (on the host machine) of an SSH identity to use for communicating with - the virtual machine. - - `cpu`: Number of CPUs to simulate in the VM (*not currently used*). - - `mem`: Amount of memory (in MiB) for the VM; this is passed as the `-m` option to `qemu-system-x86_64`. - - `sandbox` : Sandboxing mode, one of "none", "setuid", "namespace". - "none": don't do anything special (has false positives, e.g. due to killing init) - "setuid": impersonate into user nobody (65534), default - "namespace": use namespaces to drop privileges, - (requires a kernel built with `CONFIG_NAMESPACES`, `CONFIG_UTS_NS`, - `CONFIG_USER_NS`, `CONFIG_PID_NS` and `CONFIG_NET_NS`). + - `sandbox` : Sandboxing mode, the following modes are supported: + - "none": don't do anything special (has false positives, e.g. due to killing init) + - "setuid": impersonate into user nobody (65534), default + - "namespace": use namespaces to drop privileges + (requires a kernel built with `CONFIG_NAMESPACES`, `CONFIG_UTS_NS`, + `CONFIG_USER_NS`, `CONFIG_PID_NS` and `CONFIG_NET_NS`) - `enable_syscalls`: List of syscalls to test (optional). - `disable_syscalls`: List of system calls that should be treated as disabled (optional). - `suppressions`: List of regexps for known bugs. - -See also [config/config.go](config/config.go) for all config parameters. + - `type`: Type of virtual machine to use, e.g. `qemu` or `adb`. + - `vm`: object with VM-type-specific parameters; for example, for `qemu` type paramters include: + - `count`: Number of VMs to run in parallel. + - `kernel`: Location of the `bzImage` file for the kernel to be tested; + this is passed as the `-kernel` option to `qemu-system-x86_64`. + - `cmdline`: Additional command line options for the booting kernel, for example `root=/dev/sda1`. + - `sshkey`: Location (on the host machine) of an SSH identity to use for communicating with + the virtual machine. + - `cpu`: Number of CPUs to simulate in the VM (*not currently used*). + - `mem`: Amount of memory (in MiB) for the VM; this is passed as the `-m` option to `qemu-system-x86_64`. + +See also [config.go](syz-manager/config/config.go) for all config parameters. ## Running syzkaller diff --git a/syz-manager/config/config_test.go b/syz-manager/config/config_test.go new file mode 100644 index 000000000..dad27f469 --- /dev/null +++ b/syz-manager/config/config_test.go @@ -0,0 +1,28 @@ +// 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. + +package config + +import ( + "testing" + + "github.com/google/syzkaller/pkg/config" + "github.com/google/syzkaller/vm/qemu" +) + +func TestCanned(t *testing.T) { + cfg := new(Config) + if err := config.LoadFile("testdata/qemu.cfg", cfg); err != nil { + t.Fatal(err) + } + var vmCfg interface{} + switch cfg.Type { + case "qemu": + vmCfg = new(qemu.Config) + default: + t.Fatalf("unknown VM type: %v", cfg.Type) + } + if err := config.LoadData(cfg.VM, vmCfg); err != nil { + t.Fatalf("failed to load %v config: %v", cfg.Type, err) + } +} diff --git a/syz-manager/config/testdata/qemu.cfg b/syz-manager/config/testdata/qemu.cfg new file mode 100644 index 000000000..9a82f2d8e --- /dev/null +++ b/syz-manager/config/testdata/qemu.cfg @@ -0,0 +1,19 @@ +{ + "http": "myhost.com:56741", + "workdir": "/syzkaller/workdir", + "vmlinux": "/linux/vmlinux", + "image": "/linux_image/wheezy.img", + "syzkaller": "/syzkaller", + "disable_syscalls": ["keyctl", "add_key", "request_key"], + "suppressions": ["some known bug"], + "procs": 4, + "type": "qemu", + "vm": { + "count": 16, + "cpu": 2, + "mem": 2048, + "kernel": "/linux/arch/x86/boot/bzImage", + "initrd": "linux/initrd", + "sshkey": "/linux_image/ssh/id_rsa" + } +} diff --git a/syz-manager/example.cfg b/syz-manager/example.cfg deleted file mode 100644 index c5142856f..000000000 --- a/syz-manager/example.cfg +++ /dev/null @@ -1,23 +0,0 @@ -{ - "http": "myhost.com:56741", - "workdir": "/syzkaller/workdir", - "kernel": "/linux/arch/x86/boot/bzImage", - "initrd": "linux/initrd", - "vmlinux": "/linux/vmlinux", - "image": "/linux_image/wheezy.img", - "sshkey": "/linux_image/ssh/id_rsa", - "syzkaller": "/syzkaller", - "type": "qemu", - "count": 16, - "procs": 4, - "cpu": 2, - "mem": 2048, - "disable_syscalls": [ - "keyctl", - "add_key", - "request_key" - ], - "suppressions": [ - "some known bug" - ] -} -- cgit mrf-deployment