syzkaller is an unsupervised coverage-guided kernel fuzzer
Go to file
Dmitry Vyukov 3a65453870 sys: allow to specify buffer size for strings
This allows to write:
  string[salg_type, 14]
which will give a string buffer of size 14 regardless of actual string size.

Convert salg_type/salg_name to this.
2016-11-11 14:34:41 -08:00
config manager: save user tag with crash reports 2016-10-07 21:42:56 +02:00
cover cover: fix comment style 2016-09-06 19:26:18 +02:00
csource sys, prog: add tests for description parsing and serialization 2016-09-28 20:06:42 +02:00
executor sys, prog: add tests for description parsing and serialization 2016-09-28 20:06:42 +02:00
fileutil ipc: umount all mounts before removing temp dirs 2016-01-11 17:28:34 +01:00
gce vm/gce: don't wait for instance deletion on exit 2016-10-10 12:36:17 +02:00
host sys: add string flags 2016-11-11 14:33:37 -08:00
ipc ipc: read out executor output 2016-08-13 14:44:46 -07:00
log log: actually prepend time to messages 2016-10-10 14:10:07 +02:00
prog sys: allow to specify buffer size for strings 2016-11-11 14:34:41 -08:00
report report: add ability to ignore some kernel INFO messages 2016-10-16 08:39:23 +02:00
rpctype vm/adb: make more robust 2016-01-26 16:48:37 +01:00
symbolizer symbolizer: support discriminators in addr2line output 2016-09-05 12:49:47 +02:00
sys sys: allow to specify buffer size for strings 2016-11-11 14:34:41 -08:00
sysgen sys: allow to specify buffer size for strings 2016-11-11 14:34:41 -08:00
sysparser sys: add string flags 2016-11-11 14:33:37 -08:00
syz-extract sys: specify resources in text descriptions 2016-08-27 18:27:50 +02:00
syz-fuzzer log: add package 2016-10-09 11:27:48 +02:00
syz-gce syz-gce: fix build 2016-11-11 13:50:53 -08:00
syz-manager syz-gce, syz-manager: save image tag in syz-gce, show in syz-manager 2016-10-10 17:32:27 +02:00
tools vm/qemu: remove debug, add rodata=n to kernel cmd line 2016-10-16 08:15:24 +02:00
vm vm/adb: support separate serial console cable 2016-11-11 14:02:03 -08:00
.clang-format add a missed file 2015-10-13 15:29:07 +02:00
.gitignore sys: remove autogenerated files 2016-09-02 18:57:29 +02:00
AUTHORS CONTRIBUTORS: fix an empty 2016-09-06 22:54:43 +02:00
CONTRIBUTORS Add new collaborator to CONTRIBUTORS 2016-09-27 16:37:27 +01:00
extract.sh extract.sh: allow generating constants for Android devices. 2016-09-05 13:16:14 +02:00
LICENSE initial commit 2015-10-12 10:16:57 +02:00
Makefile Makefile: don't change source files in default action 2016-10-07 19:07:05 +02:00
README.md Update README.md 2016-11-06 11:56:08 -08:00
structure.png Update structure diagram 2016-02-17 16:49:52 +00:00

syzkaller - linux syscall fuzzer

syzkaller is an unsupervised, coverage-guided Linux syscall fuzzer. It is meant to be used with KASAN (CONFIG_KASAN=y), KTSAN (CONFIG_KTSAN=y), or KUBSAN.

Project mailing list: syzkaller@googlegroups.com, which you can subscribe to either with an google account or by sending an email to syzkaller+subscribe@googlegroups.com.

List of found bugs.

This is work-in-progress, some things may not work yet.

Usage

Various components are needed to build and run syzkaller.

  • C compiler with coverage support
  • Linux kernel with coverage additions
  • QEMU and disk image
  • The syzkaller components

Setting each of these up is discussed in the following sections.

C Compiler

Syzkaller is a coverage-guided fuzzer and so needs the kernel to be built with coverage support. Therefore, a recent upstream version of GCC is needed. Coverage support is submitted to gcc in revision 231296, released in gcc6.

Linux Kernel

As well as adding coverage support to the C compiler, the Linux kernel itself needs to be modified to:

  • add support in the build system for the coverage options (under CONFIG_KCOV)
  • add extra instrumentation on system call entry/exit (for a CONFIG_KCOV build)
  • add code to track and report per-task coverage information.

KCOV is upstreamed in linux 4.6. For older kernels you need to backport commit 5c9a8750a6409c63a0f01d51a9024861022f6593. The kernel should be configured with CONFIG_KCOV plus CONFIG_KASAN or CONFIG_KTSAN.

(Note that if the kernel under test does not include support for all namespaces, the dropprivs configuration value should be set to false.)

QEMU Setup

Syzkaller runs its fuzzer processes inside QEMU virtual machines, so a working QEMU system is needed see QEMU docs for details.

In particular:

  • The fuzzing processes communicate with the outside world, so the VM image needs to include networking support.
  • The program files for the fuzzer processes are transmitted into the VM using SSH, so the VM image needs a running SSH server.
  • The VM's SSH configuration should be set up to allow root access for the identity that is included in the syz-manager's configuration. In other words, you should be able to do ssh -i $SSHID -p $PORT root@localhost without being prompted for a password (where SSHID is the SSH identification file and PORT is the port that are specified in the syz-manager configuration file).
  • The kernel exports coverage information via a debugfs entry, so the VM image needs to mount the debugfs filesystem at /sys/kernel/debug.

create-image.sh script can be used to create a suitable Linux image.

TODO: Describe how to support other types of VM other than QEMU.

Syzkaller

The syzkaller tools are written in Go, so a Go compiler (>= 1.4) is needed to build them. Build with make, which generates compiled binaries in the bin/ folder.

Configuration

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; 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:
    • <workdir>/instance-x: per VM instance temporary files
    • <workdir>/crashes/*: crash output files (see Crash Reports)
    • <workdir>/corpus/*: corpus with interesting programs
  • 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.
  • 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).
  • 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.

Running syzkaller

Start the syz-manager process as:

./bin/syz-manager -config my.cfg

The -config command line option gives the location of the configuration file described above.

The syz-manager process will wind up qemu virtual machines and start fuzzing in them. It also reports some statistics on the HTTP address.

Process Structure

The process structure for the syzkaller system is shown in the following diagram; red labels indicate corresponding configuration options.

Process structure for syzkaller

The syz-manager process starts, monitors and restarts several VM instances (support for physical machines is not implemented yet), and starts a syz-fuzzer process inside of the VMs. It is responsible for persistent corpus and crash storage. As opposed to syz-fuzzer processes, it runs on a host with stable kernel which does not experience white-noise fuzzer load.

The syz-fuzzer process runs inside of presumably unstable VMs (or physical machines under test). The syz-fuzzer guides fuzzing process itself (input generation, mutation, minimization, etc) and sends inputs that trigger new coverage back to the syz-manager process via RPC. It also starts transient syz-executor processes.

Each syz-executor process executes a single input (a sequence of syscalls). It accepts the program to execute from the syz-fuzzer process and sends results back. It is designed to be as simple as possible (to not interfere with fuzzing process), written in C++, compiled as static binary and uses shared memory for communication.

Crash Reports

When syzkaller finds a crasher, it saves information about it into workdir/crashes directory. The directory contains one subdirectory per unique crash type. Each subdirectory contains a description file with a unique string identifying the crash (intended for bug identification and deduplication); and up to 100 logN and reportN files, one pair per test machine crash:

 - crashes/
   - 6e512290efa36515a7a27e53623304d20d1c3e
     - description
     - log0
     - report0
     - log1
     - report1
     ...
   - 77c578906abe311d06227b9dc3bffa4c52676f
     - description
     - log0
     - report0
     ...

Descriptions are extracted using a set of regular expressions. This set may need to be extended if you are using a different kernel architecture, or are just seeing a previously unseen kernel error messages.

logN files contain raw syzkaller logs and include kernel console output as well as programs executed before the crash. These logs can be fed to syz-repro tool for crash location and minimization, or to syz-execprog tool for manual localization. reportN files contain post-processed and symbolized kernel crash reports (e.g. a KASAN report). Normally you need just 1 pair of these files (i.e. log0 and report0), because they all presumably describe the same kernel bug. However, syzkaller saves up to 100 of them for the case when the crash is poorly reproducible, or if you just want to look at a set of crash reports to infer some similarities or differences.

There are 3 special types of crashes:

  • no output from test machine: the test machine produces no output whatsoever
  • lost connection to test machine: the ssh connection to the machine was unexpectedly closed
  • test machine is not executing programs: the machine looks alive, but no test programs were executed for long period of time Most likely you won't see reportN files for these crashes (e.g. if there is no output from the test machine, there is nothing to put into report). Sometimes these crashes indicate a bug in syzkaller itself (especially if you see a Go panic message in the logs). However, frequently they mean a kernel lockup or something similarly bad (here are just a few examples of bugs found this way: 1, 2, 3).

Syscall description

syzkaller uses declarative description of syscalls to generate, mutate, minimize, serialize and deserialize programs (sequences of syscalls). See details about the format and extending the descriptions in sys/README.md.

Troubleshooting

Here are some things to check if there are problems running syzkaller.

  • Check that QEMU can successfully boot the virtual machine. For example, if IMAGE is set to the VM's disk image (as per the image config value) and KERNEL is set to the test kernel (as per the kernel config value) then something like the following command should start the VM successfully:

    ```qemu-system-x86_64 -hda $IMAGE -m 256 -net nic -net user,host=10.0.2.10,hostfwd=tcp::23505-:22 -enable-kvm -kernel $KERNEL -append root=/dev/sda```
    
  • Check that inbound SSH to the running virtual machine works. For example, with a VM running and with SSHKEY set to the SSH identity (as per the sshkey config value) the following command should connect:

    ```ssh -i $SSHKEY -p 23505 root@localhost```
    
  • Check that the CONFIG_KCOV option is available inside the VM:

    • ls /sys/kernel/debug # Check debugfs mounted
    • ls /sys/kernel/debug/kcov # Check kcov enabled
    • Build the test program from Documentation/kcov.txt and run it inside the VM.
  • Check that debug information (from the CONFIG_DEBUG_INFO option) is available

    • Pass the hex output from the kcov test program to addr2line -a -i -f -e $VMLINUX (where VMLINUX is the vmlinux file, as per the vmlinux config value), to confirm that symbols for the kernel are available.
  • Use the -v N command line option to increase the amount of logging output, from both the syz-manager top-level program and the syz-fuzzer instances (which go to the output files in the crashes subdirectory of the working directory). Higher values of N give more output.

  • If logging indicates problems with the executor program (e.g. executor failure), try manually running a short sequence of system calls:

    • Build additional tools with make all-tools
    • Copy syz-executor and syz-execprog into a running VM.
    • In the VM run ./syz-execprog -executor ./syz-executor -debug sampleprog where sampleprog is a simple system call script (e.g. just containing getpid()).
    • For example, if this reports that clone has failed, this probably indicates that the test kernel does not include support for all of the required namespaces. In this case, running the syz-execprog test with the -nobody=0 option fixes the problem, so the main configuration needs to be updated to set dropprivs to false.

External Articles

Contributing

If you want to contribute to the project, you need to sign Google CLA and add yourself to AUTHORS/CONTRIBUTORS files in the first pull request. Extending/improving system call descriptions is always a good idea. If you want to work on something non-trivial, please briefly describe it on syzkaller@googlegroups.com mailing list first so that there is agreement on high level approach and no duplication of work between contributors.

Disclaimer

This is not an official Google product.