Commit Graph

513 Commits

Author SHA1 Message Date
Andrey Konovalov
d973f52833 executor: update raw gadget interface 2019-12-11 19:20:07 +01:00
Marco Vanotti
607350e438 syz/targets: add SyzExecutorCmd flag
This commit adds a new attribute to syzkaller targets that tells
syzkaller how to invoke the syz-executor command.

Some systems, like Fuchsia, are now building syz-executor as part of the
build, and there is no need to copy it over, or to run it from `/tmp`.
In fact, that might stop working at some time in the future in Fuchsia.

All places that used to copy syz-executor into the target machine will
now check for the SyzExecutorCmd flag, and won't copy it if the flag is
set.
2019-12-09 15:13:49 -08:00
Dmitry Vyukov
d20ee9bd98 tools: add fops_probe utility
fops_probe utility helps to understand what file_operations callbacks
are attached to a particular file. Requries KCOV and KALLSYMS.
Build with:
	g++ tools/fops_probe/fops_probe.cc -Wall -static -o fops_probe
Then copy the binary to target machine and run as:
	./fops_probe /dev/fb0
You should see output similar to:

	ffffffff81bcccb9 vfs_read
	................
	ffffffff83af85c3 fb_read
	ffffffff83b52af5 cirrusfb_sync

	ffffffff81bcd219 vfs_write
	................
	ffffffff83af7fe2 fb_write
	ffffffff83b52af5 cirrusfb_sync

	ffffffff81c1b745 do_vfs_ioctl
	ffffffff83af7ea9 fb_ioctl

	ffffffff81a4ea44 do_mmap
	................
	ffffffff83af716c fb_mmap

which allows to understand what callbacks are associated with /dev/fb0.
2019-12-03 18:48:14 +01:00
Matthew Dempsky
f4b7ed0781 tools/fuchsia: remove custom Go toolchain scripts
These used to be required to build Fuchsia's Go toolchain to build
syz-fuzzer to run on Fuchsia. However, Fuchsia now uses HostFuzzer
mode, so only syz-executor (written in C) needs to run on Fuchsia; all
Go code runs on the Host OS (currently Linux).
2019-11-19 17:20:14 -08:00
Dmitry Vyukov
587cec15e2 pkg/host: add Features.Supported
To reduce diff in future changes. Currently no-op.
2019-11-16 09:58:54 +01:00
Dmitry Vyukov
aa27601f9e pkg/host: rename some features
Rename some features in preparation for subsequent changes
which will align names across the code base.
2019-11-16 09:58:54 +01:00
Dmitry Vyukov
157653cfe7 pkg/csource: rename some options
Rename some options in preparation for subsequent changes
which will align names across the code base.
2019-11-16 09:58:54 +01:00
Andrey Konovalov
90f3b019e4 executor, pkg/host: update usb raw-gadget interface
The patches are being upstreamed and the interface has changed.
2019-11-15 14:53:30 +01:00
Andrey Konovalov
be7a4ab6d8 tools/syz-usbgen: update patch to dump usb ids
The patch doesn't properly work on some kernels, some ids might not be printed.
2019-11-15 14:45:46 +01:00
Dmitry Vyukov
30cb7f98cd pkg/bisect: detect wrong bisections
Detect bisection to merge commits and to commits that don't affect
kernel binary (comments, other arches, whitespaces, etc).
Such bisections are not reported in emails (but shown on web).

Update #1271
2019-11-07 11:07:03 +01:00
Andrey Konovalov
80aca15c2a executor: update the list of raw usb events
The number of reported event types changed.
2019-11-05 15:11:22 +01:00
Zubin Mithra
0a2d7d8293 pkg/bisect: modify Run() to return information about commit
* Modify Run() to return the commit object when a failure occurs on the
oldest tested release(for BisectCause) and latest tested
release(for BisectFix).
* Modify tests to check the returned commit object.
2019-11-05 09:15:56 +01:00
Andrey Konovalov
76630fc947 executor, pkg/host, dashboard/config: rename usb-fuzzer to usb raw-gadget
The interface is being upstreamed and the name has changed.
2019-11-04 15:43:43 +01:00
Dmitry Vyukov
2079602763 pkg/csource: fix lint warnings
CI failed:
https://travis-ci.org/google/syzkaller/jobs/606730911?utm_medium=notification&utm_source=github_status
2019-11-03 14:44:53 +01:00
Jiri Pirko
d40d75d2d7 executor: move fixed pci devlink handle into network namespace
In case there is a fixed pci devlink handle "pci/pci/0000:00:10.0"
on the system (initial network namespace), it is moved to a working
network namespace.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
2019-11-03 14:20:59 +01:00
Dmitry Vyukov
4ee855e7ec tools/syz-testbuild: fix too long line 2019-10-22 15:58:22 +02:00
Dmitry Vyukov
084e388155 pkg/vcs: make EnvForCommit return full compiler path
All callers of EnvForCommit need the compiler path,
so move this logic into EnvForCommit to avoid duplication.
Also simplifies tests because test impl can now return
an empty compiler (which should be unused).
2019-10-22 15:41:03 +02:00
Zubin Mithra
a2bdbd8c37 pkg/bisect: add initial testing support for cause bisection
(note: incomplete change)

Refactor existing code as follows:
* Move reusable test utility functions from git_repo_test.go to
pkg/vcs/test_util.go and make them exported.
* Split Run() into Run()+runImpl().
* Change type of bisect.go:env.inst to `instance.BuilderTester`.
Change usage inside syz-testbuild/testbuild.go accordingly.
* Move most of linux.PreviousReleaseTags() into vcs/git.go as
git.previousReleaseTags().
* Allow build.CompilerIdentity to be mocked.

Introduce the following changes:
* instance.BuilderTester is an interface with methods
	BuildSyzkaller()
	BuildKernel()
	Test()
NewEnv() now returns this interface.
* type testEnv implements instance.BuilderTester.
* type testBuilder implements builder interface. Add a entry into table
inside pkg/build/build.go:getBuilder() to return testBuilder object.
2019-10-22 10:09:57 +02:00
Andrew Turner
c59a7cd871 tools: Run 2to3 on check_links.py
The python binary may not be Python 2. Support Python 3 by running the
2to3 conversion tool on it.

This has been tested with both Python 2 and 3.
2019-10-21 15:56:27 +02:00
Zwb
b5268b89c2 tools/create-image.sh: add a new option seek
The usage of current create-image.sh:

    ```
    ./create-image.sh -d=stretch -f=minimal --add-perf

    The options are in the following:

    -d, --distribution         Set on which debian distribution to create
    -f, --feature              Check what packages to install in the image, options are minimal, full
    -s, --seek                 Image size (MB), default 2048 (2G)
    -p, --add-perf             Add perf support with this option enabled

    The default image size may too small (2G) in some debugging scenarios, so change it to configurable.
2019-10-15 12:40:28 +02:00
Dmitry Vyukov
64612bfd3c tools/syz-reprolist: add utility to extract list of reproducers 2019-10-08 12:39:23 +02:00
Dmitry Vyukov
0f33548a39 tools/syz-trace2syz: disable golangci-lint
A new version of golangci-lint started failing trying to build syz-trace2syz
(because we already ignore some files).
Ignore the rest of files to fix the failure.
2019-10-08 12:31:54 +02:00
Marco Elver
b2f369e56e executor, host, csource: Add support to enable KCSAN
By default, the current KCSAN .config does not enable KCSAN during boot,
since we encounter races during boot which would prevent syzkaller from
ever executing.

This adds support to detect if KCSAN is available, and enables it on the
fuzzer host.
2019-10-04 13:44:09 +02:00
Veronica Radu
9d33246a91 sys/linux: add new syscall descriptions for devio and usbmon
Update #533
2019-10-01 13:55:20 +02:00
Andrey Konovalov
2b854f96b1 tools: add syz-expand
The syz-expand tools allows to parse a program and print it including all
the default values. This is mainly useful for debugging, like doing manual
program modifications while trying to come up with a reproducer for some
particular kernel behavior.
2019-09-23 17:13:23 +02:00
Veronica Radu
d2db54aab7 tools/syz-showprio: add a tool to visualize the priority table 2019-09-23 15:35:26 +02:00
Veronica Radu
5a7028d005 pkg/db: moved ReadCorpus function to avoid duplicate code 2019-09-23 15:35:26 +02:00
Andrey Konovalov
532aca508a tools/syz-usbgen: handle USB_DT_DEVICE_QUALIFIER in keyboard.c 2019-09-19 16:20:57 +02:00
Dmitry Vyukov
2dd371a3b1 tools/kcovfuzzer: add simple KCOV/libfuzzer glue 2019-09-19 15:56:24 +02:00
Andrey Konovalov
d62be7809c runtest: add a flag to specify tests to run 2019-09-17 15:58:29 +02:00
Andrey Konovalov
040fda5884 tools/syz-usbgen: ignore building keyboard.c 2019-09-04 15:59:38 +02:00
Andrey Konovalov
24cb2b46b8 docs: update USB fuzzing documentation 2019-09-04 13:53:01 +02:00
Veronica Radu
dbd627eb61 prog: add implementation for resource centric 2019-09-03 16:30:45 +02:00
Dmitry Vyukov
8d48456885 tools/syz-symbolize: fix kernel dir calculation
syz-symbolize did not use the common mgrconfig logic
to calculate kernel dirs. Thus KernelBuildSrc ended up empty,
+dirs were not extended to absolute paths.
Use the common mgrconfig logic to calculate kernel dirs.
2019-09-03 15:00:40 +02:00
Greg Steuck
1eb076e9b7
tools/create-openbsd: switch to 6.6 (#1363) 2019-08-27 18:20:23 -07:00
Andrey Konovalov
d545e945ce sys/linux: add syz_open_dev$char_usb descriptions
syz_open_dev$char_usb opens char devices with major = USB_MAJOR.
Sanitize its values to make sure it doesn't open other char/block devices.
2019-08-08 15:34:27 +02:00
Dmitry Vyukov
c85e1c5be9 pkg/cover: hierarchical coverage reports
Better coverage reports with hierarchical coverage information,
number of programs covering each line,
handling of partially covered lines,
links to programs covering lines.

Fixes #682
2019-07-26 19:32:14 +02:00
Marco Vanotti
1b0aeaa4e8 Makefile: build fuchsia go binaries using the sdk
This commit removes a dependency on fuchsia's tools/devshell/contrib/go,
which was removed recently[0].

Now to build go binaries for fuchsia we are not relying on the
fuchsia.git repo at all. The code just needs a copy of the fuchsia
//third_party/go repository, the fuchsia sdk and a copy of clang.

Users should download the sdk and clang beforehand (see documentation
for links), and then run (with the correct environment variables):

```
$ make TARGETOS=fuchsia TARGETARCH=amd64 \
    SOURCEDIR=$HOME/fuchsia \
    FX_SDK_PATH=${HOME}/sdk/fuchsia-sdk \
    CLANG_PATH=${HOME}/sdk/clang \
    fuchsia_go
```

After that, they will be able to build the syzkaller go binaries by
doing:

```
$ make TARGETOS=fuchsia TARGETARCH=amd64 \
    SOURCEDIR=$HOME/fuchsia \
    FX_SDK_PATH=${HOME}/sdk/fuchsia-sdk \
    CLANG_PATH=${HOME}/sdk/clang
```

This commits adds two scripts to tools/fuchsia, one for building go in
fuchsia (just calls the ./make.all script in fuchsia's go repo), and one
that replaces the devshell/contrib/go script.

Given that go is unsupported in fuchsia, this change might break at any
point.

[0]: https://fuchsia-review.googlesource.com/c/fuchsia/+/291631
2019-07-23 08:44:20 +02:00
Andrey Konovalov
55e0c07757
sys/linux: extract USB HID ids (#1294)
* sys/linux: extract USB HID ids

As it turns out the HID kernel subsystem registers only one USB driver that
checks that the interface of the connected device has HID class and then looks
up its own list of vendor/device ids to find a matching driver. This means
that we currently don't generate proper vendor/device ids for USB HID devices.

This patch updates the syz-usbgen tool to also extract USB HID vendor/device
ids from a running kernel and makes the generated descriptions for HID devices
to be patched using the extracted ids.

This patch also contains some minor improvements to USB descriptions
(better HID descriptions and more replies for some USB classes/drivers).

* sys/linux: run make generate
2019-07-22 19:25:54 +02:00
Greg Steuck
b3c615f51b tools/syz-execprog: remove unused parameter 2019-07-22 07:37:09 +02:00
Dmitry Vyukov
8304907db0 tools/syz-env: restrict Makefile parallelism based on RAM
Ensure that we have at least 1GB per Makefile job.
Go compiler/linker can consume significant amount of memory
(observed to consume at least 600MB). See #1276 for context.
Update #1276
2019-07-19 09:51:07 +02:00
Dmitry Vyukov
06616a2715 tools/syz-cover: skip empty lines in coverage file
If it's constructed manually, it's easy to add an empty line at the end.
2019-07-18 09:36:03 +02:00
Siddharth M
f613a7c41d pkg/cover: fix prefix computation
* pkg/cover: Modify parsing logic
1. Remove prefix computation
2. Add a mgrconfig for kernel build directory

* pkg/report: shorten reports with kernelBuildSrc instead of kernelSrc

* pkg/report: Fix failing tests

* pkg/report: fix formating issues

* tools/syz-cover: Fix unintended redefinition

* make changes to fix failing ci build

* pkg/report: fix issues
2019-07-17 11:58:23 +02:00
Dmitry Vyukov
a963689197 pkg/log: rename -v to -vv
To avoid conflicts with programs that import both syzkaller packages
and github.com/golang/glog which also defines -v flag.
2019-07-16 11:18:12 +02:00
Dmitry Vyukov
1dcdf7ef37 tools/syz-stress: fix syscall list parsing
If -syscalls flag is empty (default),
strings.Split produces an empty string which
is then not parsed as valid syscall name.
2019-06-14 12:19:25 +02:00
Andrew Turner
ea2f400664 tools/kcovtrace: Fix the format of kcovtrace.c 2019-06-11 15:25:32 +02:00
Andrew Turner
28a6eb7203 tools/kcovtrace: Fix cover type on FreeBSD and NetBSD
It should be uint64_t as a 32 bit tool may be tracing a 64 bit kernel.
2019-06-11 12:31:30 +02:00
Andrey Konovalov
142ce68175 pkg/runtest: add simple USB runtest 2019-05-31 13:35:25 +02:00
R3x
9809825e48 make changes to prevent failing build 2019-05-21 13:56:38 +02:00
Dmitry Vyukov
8285069f89 executor: implement support for leak checking
Leak checking support was half done and did not really work.
This is heavy-lifting to make it work.

1. Move leak/fault setup into executor.
pkg/host was a wrong place for them because we need then in C repros too.
The pkg/host periodic callback functionality did not work too,
we need it in executor so that we can reuse it in C repros too.
Remove setup/callback functions in pkg/host entirely.

2. Do leak setup/checking in C repros.
The way leak checking is invoked is slightly different from fuzzer,
but much better then no support at all.
At least the checking code is shared.

3. Add Leak option to pkg/csource and -leak flag to syz-prog2c.

4. Don't enalbe leak checking in fuzzer while we are triaging initial corpus.
It's toooo slow.

5. Fix pkg/repro to do something more sane for leak bugs.

Few other minor fixes here and there.
2019-05-20 19:40:20 +02:00
Greg Steuck
051c49fe0d
tools/create-openbsd: valid URIs must use a single slash (#1184)
Triggered by OpenBSD ftp upgrade which isn't looking kindly
at double slahses: https://marc.info/?t=155794126200001&r=1&w=2
2019-05-15 12:08:03 -07:00
Dmitry Vyukov
01d1494471 .golangci.yml: add codeanalysis build tag
Using a build tag to exclude files for golangci-lint
reduces memory consumption (it does not parse them).
The naive attempt with skip-dirs did not work.
So add codeanalysis build tag and use it in auto-generated files.

Update #977
2019-05-15 11:39:31 +02:00
Dmitry Vyukov
92d5fb8ed3 tools/syz-bisect: add usage docs 2019-05-13 13:04:01 +02:00
Dmitry Vyukov
39449875b6 syz-ci: don't assume kernel config is called .config
.config is linux-ism. We have a convention that kernel config
is copied to kernel.config file. Use it.
2019-05-12 11:38:18 +02:00
Greg Steuck
018207ef2f
tools/create-openbsd-vmm-worker.sh: set location to cd0 for consistency (and speed) (#1168) 2019-05-09 12:46:24 -07:00
Greg Steuck
a7aeccd44b
tools/create-openbsd-gce-ci.sh: explicitly specify sets location (#1167)
The previous default must have changed resulting in apparent failure
to install siteXX.tgz. The observable symptom was:
`Package installation failed. Inspect install_log.`
2019-05-09 10:40:00 -07:00
Andrew Donnellan
bfc19a4b19 tools/create-gce-image.sh: Generate ppc64le pseries disk images
Add support for generating ppc64le pseries disk images. This will create a
disk image with a PowerPC PReP boot partition at the start, and install
the IEEE1275/OpenFirmware version of GRUB.

If we ever support the powernv platform in the future we're going to have
to do something different here.

Add a command line argument to specify architecture, defaulting to amd64.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
2019-05-03 10:00:16 +02:00
Andrey Konovalov
10e721ba92 sys: add USB descriptions
This commit adds syzkaller descriptions for USB fuzzing. The descriptions in
vusb.txt are written manually and cover different kinds of USB descriptors.
The descriptions in init_vusb_ids.go are generated automanitally by the
syz-usbgen tool and contain the vendor, device and some other IDs that
map to different USB drivers.
2019-04-11 16:24:45 +02:00
Andrey Konovalov
5c51045d28 all: add optional close_fds feature to reproducers
Instead of always closing open fds (number 3 to 30) after each program,
add an options called EnableCloseFds. It can be passed to syz-execprog,
syz-prog2c and syz-stress via the -enable and -disable flags. Set the
default value to true. Also minimize C repros over it, except for when
repeat is enabled.
2019-04-09 10:53:11 +02:00
Dmitry Vyukov
0dfb045226 tools/syz-benchcmp: update name of coverage stat 2019-04-08 15:10:07 +02:00
Shankara Pailoor
acbc5b7d05 sys/linux: move openat to dev_rtc.txt
move openat$rtc to rtc_dev and change return type to fd_rtc
2019-03-24 09:28:43 +01:00
Dongliang Mu
a2cef203ff tools/syz-execprog: remove dead code 2019-03-23 09:54:12 +01:00
Dmitry Vyukov
93e723abbc tools/syz-testbuild: add utility for kernel build testing
syz-testbuild tests kernel build/boot on releases as it will be done by pkg/bisect.
This allows to ensure that, for example, a change to kernel config won't break
build/boot on older releases and consequently won't break bisection process.
The binary needs to run under root because it creates images.
The kernel checkout given to the tool will be cleaned and used for in-tree builds.
Example invocation:

sudo syz-testbuild -kernel_src $LINUX_CHECKOUT \
	-config dashboard/config/upstream-kasan.config \
	-sysctl dashboard/config/upstream.sysctl \
	-cmdline dashboard/config/upstream-apparmor.cmdline \
	-userspace $WHEEZY_USERSPACE \
	-bisect_bin $BISECT_BIN

A suitable wheezy userspace can be downloaded from:
https://storage.googleapis.com/syzkaller/wheezy.tar.gz
A set of binaries required for bisection (older compilers) can be downloaded from:
https://storage.googleapis.com/syzkaller/bisect_bin.tar.gz
2019-03-17 18:06:44 +01:00
Dmitry Vyukov
b3ed01507f pkg/bisect: various improvements
A bunch of improvements after more wide bisection testing.
Improve logging.
Support returning several commits for inconclusive bisection.
Return Report with the final crash.
Remove code that was moved to pkg/vcs.

Update #501
2019-03-17 18:06:44 +01:00
Dongliang Mu
2881fc25a8 tools/create-image.sh: fix two issues
allow user to provide ADD_PACKAGE and double check if KERNEL is set when perf is enabled
2019-03-12 18:33:29 +01:00
Kees Cook
18215b8d64 create-image.sh: Fix "full" package list
The list of packages to install is comma-separated, not space. This
fixes the "-f full" argument to actually install the expected packages.
2019-03-06 18:44:30 +01:00
Andrey Konovalov
eb9e33b10f execprog: fix executing with fault injection
If the fault injection flags are not provided, but the log contains a
fault injection like this:

2017/08/12 17:16:04 executing program 5 (fault-call:4 fault-nth:5):

we fail to enable fault injection in ipc.Config. Fix it.
2019-03-05 16:05:02 +01:00
Andrey Konovalov
dfd609eca1 execprog, stress, prog2c: unify flags to enable additional features
This change makes all syz-execprog, syz-prog2c and syz-stress accept
-enable and -disable flags to enable or disable additional features
(tun, net_dev, net_reset, cgroups and binfmt_misc) instead of having
a separate flag for each of them.

The default (without any flags) behavior isn't changed: syz-execprog
and syz-stress enabled all the features (provided the runtime supports
them) and syz-prog2c disables all of them.
2019-03-05 14:30:10 +01:00
Greg Steuck
1c0e457aaa tools/*openbsd*: switch to 6.5 now that it's in -beta 2019-03-01 19:09:16 +01:00
Andrey Konovalov
68d9e495c3 check_links: ignore mailto:* links 2019-03-01 13:19:42 +01:00
Dongliang Mu
8a4b3a6b65 tweak create-image.sh script and modify document about its deployment (#1022) 2019-03-01 06:29:44 +01:00
Dongliang Mu
f6f233c07e tools/create-image.sh: make more flexible
The usage of current create-image.sh:

```
./create-image.sh -d=stretch -f=minimal --add-perf

The options are in the following:

-d, --distribution         Set on which debian distribution to create
-f, --feature              Check what packages to install in the image, options are minimal, full
-p, --add-perf             Add perf support with this option enabled

The default image is stretch with minimal feature, without perf.
2019-02-15 10:54:18 +01:00
Dmitry Vyukov
6193630786 pkg/runtest: don't print skipped/broken tests by default
SKIP/BROKEN distract too much attention from FAIL tests
and are not usually interesting. Add Verbose flag that
controls printing of SKIP/BROKEN tests. Enable it in
pkf/runtest/run_test.go by default and disable in tools/syz-runtest.
2019-02-13 15:58:42 +01:00
Dmitry Vyukov
be0e89ec44 tools/syz-stress: add flag to select subset of syscalls
Add -enable flag similar to syz-mutate flag.
The flag allows to select a subset of syscalls that will be tested
(e.g. -enable=open,read,write,close).
2019-02-12 18:34:25 +01:00
Greg Steuck
b4f792e401
tools/openbsd: use fully resolved gcc package name (#988) 2019-02-09 10:11:37 -08:00
Anton Lindqvist
c69659e352 openbsd: remove shorten report logic (#986)
A line length of 79 in the ddb output does not necessarily imply that the
following line is a continuation of the current line. Since there's no way
to distinguish between ordinary and continuation lines, it could end up
corrupting the report by joining two lines that are disjoint[1].

Instead, disable line wrapping in ddb. If we want some kind of wrapping in
the future it's easier done by pkg/report.

[1] https://syzkaller.appspot.com/bug?extid=03f7377a9848d7d008c9
2019-02-09 08:23:53 -08:00
Dmitry Vyukov
25e10a0434 executor: remove ability to detect kernel bugs
This ability was never used but we maintain a bunch of code for it.
syzkaller also recently learned to spoof this error code
with some ptrace magic (probably intercepted control flow again
and exploited executor binary).
Drop all of it.
2019-01-31 11:35:53 +01:00
Dmitry Vyukov
fa3d6b0b21 Makefile: don't cross-compile executor if cross-compiler is missing
We started building netbsd executor on linux.
This fails on CI since cross-compiler is missing.
But we don't want to exclude netbsd from presubmit entirely.
So check if cross-compiler is missing and just produce a warning.
This should unbreak CI and humans will see the warning.
2019-01-24 11:28:55 +01:00
Shankara Pailoor
769e75ed8e tools/syz-trace2syz/proggen: add support to generate structs like sockaddr_storage_in6
trace2syz has trouble generating structs like sockaddr_storage_in6 which are
wrappers around other structs like sockaddr_in6 because strace just decodes the
wrapped struct (sockaddr_in6). This causes trace2syz to generate the addr field
of sockaddr_storage_in6 from the af_family field of sockaddr_in6 which triggers
an error. We now try and detect these cases and recursively generate the struct.
2019-01-17 13:44:43 +01:00
Andrey Konovalov
c2faf9b2d5 all: detect extra coverage support
Based on whether the kernel supports KCOV_REMOTE_ENABLE ioctl.
2019-01-16 19:19:53 +01:00
Andrey Konovalov
b5df78dc5d all: support extra coverage
Right now syzkaller only supports coverage collected from the threads that
execute syscalls. However some useful things happen in background threads,
and it would be nice to collect coverage from those threads as well.

This change adds extra coverage support to syzkaller. This coverage is not
associated with a particular syscall, but rather with the whole program.
Executor passes extra coverage over the same ipc mechanism to syz-fuzzer
with syscall number set to -1. syz-fuzzer then passes this coverage to
syz-manager with the call name "extra".

This change requires the following kcov patch:
https://github.com/xairy/linux/pull/2
2019-01-16 19:19:53 +01:00
Shankara Pailoor
505b1767d0 tools/syz-trace2syz/proggen: add support for open, openat, syz_open_dev variants
Add support to accurately select variants for open and openat system calls.
This is needed because in order to accurately select ioctl variants we need
to use device resource types. The device resource types can only be created
by syz_open_dev and openat variants.
2019-01-16 16:34:17 +01:00
Shankara Pailoor
31648909f9 tools/syz-trace2syz/proggen: deleting unnecessary code in genSockaddrStorage()
genSockaddrStorage() determines the correct sockaddr_storage union option when we
cannot identify the system call variant. We used to have custom logic per system
call which was not tested and is actually unnecessary. This patch deletes that
code and adds a test to make sure there are no regressions.
2019-01-14 17:47:18 +01:00
Michael Tuexen
95f1d718cf tools/kcovtrace: add FreeBSD support
KCOV support has been committed to FreeBSD in r342962. Therefore,
allow this program to be run on FreeBSD.
2019-01-14 09:50:07 +01:00
Shankara Pailoor
80dde1721e tools/syz-trace2syz/proggen.go: delete reorderStructFields()
strace incorrectly printed sin6_addr before sin6_flowinfo. To fix this,
trace2syz added reorderStructFields() which swapped back the order. Incorrect
orderings of structs is a bug in strace or in our descriptions so we should
fix the source rather than work around. We have submitted a patch to fix the
sockaddr_in6 decoding in strace so we can safely delete this function.
2019-01-10 17:24:09 +01:00
Shankara Pailoor
db9b657915 tools/syz-trace2syz/proggen/proggen_test.go: test ipv6 address conversion 2019-01-10 12:34:28 +01:00
Shankara Pailoor
f9ccea26eb tools/syz-trace2syz/proggen: convert strace byte arrays to int args
strace decodes certain arguments like sockaddr_in.sin_port or sin_addr
as hex strings under -Xraw. This is because the arguments are in network byte
order. This patch supports converting those hex strings to int args if the size
of the string is 1, 2, 4, or 8.
2019-01-10 12:34:28 +01:00
Shankara Pailoor
8ca2b64365 tools/syz-trace2syz/proggen: append 0 to string buffers
String buffers get the null byte added during generation.
This means we need to add the null byte explicitly in trace2syz.
2018-12-29 07:45:10 +01:00
Shankara Pailoor
e33ad0f187 tools/syz-trace2syz: only add null-byte for prog.BufferFilename
trace2syz used to always add a null byte to strings.
This isn't correct behavior since we may end up writing null bytes to files.
The extra byte can affect system calls like ioctl FS_IOC_ENABLE_VERITY.
We now only add the byte for filenames.
2018-12-28 15:18:24 +01:00
Shankara Pailoor
6a33670d2f tools/syz-trace2syz/parser: parse octal numbers
We don't properly parse octal numbers which is an issue because that's how strace decodes file permissions even under -Xraw.
We used to do so but we didn't have a test for it so as when we added support for negative numbers we broke how we parse octals.
This commit fixes how we parse octals and includes a test to catch future regressions.
2018-12-28 13:57:14 +01:00
Dmitry Vyukov
85d28281fb syz-manager: factor out rpc serving part
Update #605
2018-12-26 10:58:23 +01:00
Shankara Pailoor
dd2986b43b tools/syz-trace2syz/parser: parse strace bitsets
Strace decodes bitsets like fd_set or sa_mask into the following structure: [a b c d e].
Before we couldn't parse these structures, but now parse them into the Group IR Type
2018-12-24 10:05:32 +01:00
Dmitry Vyukov
88f5934633 vm: allow fine-grained control over program exit conditions
Currently we only support canExit flag.
However there are actually 3 separate conditions:
 - program can exit normally
 - program can timeout (e.g. fuzzer test or runtest can't)
 - program can exit with error (e.g. C test can)
Allow to specify these 3 conditions separately.
2018-12-24 09:59:56 +01:00
Greg Steuck
02e6905247 tools/create-openbsd-gce-ci.sh: raise memory limit for openbsd 2018-12-19 20:17:05 +01:00
Dmitry Vyukov
a9cc88c19f pkg/osutil: provide better Rename
os.Rename fails for cross-device renaming (e.g. to/from tmpfs).
This is quite unpleasant. Provide own version that falls back to copying.
2018-12-17 19:09:10 +01:00
Dmitry Vyukov
b38da77e00 pkg/bisect: check existence of input files
It's better to fail early then to wait for kernel build.

Update #501
2018-12-17 19:09:03 +01:00
Dmitry Vyukov
def91db3fe prog, pkg/csource: more readable serialization for strings
Always serialize strings in readable format (non-hex).
Serialize binary data in readable format in more cases.

Fixes #792
2018-12-15 15:17:13 +01:00
Dmitry Vyukov
c7ba317e9b tools/syz-runtest: test program parsing before booting VMs
It sucks to wait for VMs to boot just to discover that programs don't parse.
2018-12-10 16:37:02 +01:00
Dmitry Vyukov
95fe19c19e prog: introduce strict parsing mode
Over time we relaxed parsing to handle all kinds of invalid programs
(excessive/missing args, wrong types, etc).
This is useful when reading old programs from corpus.
But this is harmful for e.g. reading test inputs as they can become arbitrary outdated.
For runtests which creates additional problem of executing not
what is actually written in the test (or at least what author meant).
Add strict parsing mode that does not tolerate any errors.
For now it just checks excessive syscall arguments.
2018-12-10 16:37:01 +01:00
Dmitry Vyukov
ceeb374637 tools/syz-cover: add utility for generation of coverage reports
syz-cover generates coverage HTML report from raw coverage files.
Raw coverage files are text files with one PC in hex form per line, e.g.:

	0xffffffff8398658d
	0xffffffff839862fc
	0xffffffff8398633f

Raw coverage files can be obtained either from /rawcover manager HTTP handler,
or from syz-execprog with -coverfile flag.

Usage:
	syz-cover [-os=OS -arch=ARCH -kernel_src=. -kernel_obj=.] rawcover.file*
2018-12-10 16:37:01 +01:00
Greg Steuck
979179d6d6 tools/*openbsd*: use nc from base instead of curl from package
This worked fine for ci machine but gce workers have no packages.
2018-12-09 08:55:19 +01:00
Anton Lindqvist
977de94f01 tools/syz-symbolize: add optional arch flag with sensible default
The manager config passed to NewReporter() must include a valid arch by now.
2018-12-08 18:59:10 +01:00
Dmitry Vyukov
6ae0ca72a1 tools/syz-trace2syz/proggen: fix name shadowing 2018-12-08 09:01:54 +01:00
Dmitry Vyukov
fa1f41078a tools/syz-trace2syz/proggen: comment blank import
golint suggests to comment all blank imports.
But actually we don't need whole sys, we can import only sys/linux.

Also rename target var to prevent name shadowing.
2018-12-08 08:59:52 +01:00
Dmitry Vyukov
b80cc86486 prog: rename ProgGen to Builder
golint suggests that "prog.Prog" is a bad naming
because everything in prog package is ProgSomething.
Rename to Builder, "prog.Builder" sounds right.
2018-12-08 08:40:03 +01:00
Dmitry Vyukov
65ed24721e tools/syz-trace2syz/proggen: reduce nesting depth in context.genResult 2018-12-07 14:32:44 +01:00
Dmitry Vyukov
c138f09215 tools/syz-trace2syz/proggen: remove currentStraceArg
It's used only by 2 functions: genSockaddrNetlink and genIfrIfru.
Majority of functions just accept the straceType as argument,
which looks like a much more appropriate way to pass an argument to a function.
Amusingly, both functions already accept and use the straceType as argument.
2018-12-07 14:28:12 +01:00
Dmitry Vyukov
276faf74b2 tools/syz-trace2syz/proggen: unexport and refactor Context
1. Unexport Context, it's not meant for callers.
2. Unexport all Context fields.
3. Make all function Context methods.
2018-12-07 14:23:58 +01:00
Dmitry Vyukov
c9f43ce698 tools/syz-trace2syz/proggen: tidy up shouldSkip 2018-12-07 14:08:56 +01:00
Dmitry Vyukov
4f39cef6c2 tools/syz-trace2syz/proggen: convert tests to table format
This has number of advantages:
1. Tests are readable and writable.
   The current checks [1] are neither.
2. Tests are much more compact.
3. Tests verify all aspects rather than just
   1 aspect of the resulting program.
4. Tests are much less fragile.
5. Any diffs in the results will be more clearly visible.

[1]
switch a := p.Calls[1].Args[0].(type) {
case *prog.ResultArg:
	if a.Res != p.Calls[0].Ret {

switch a := p.Calls[1].Args[0].(type) {
case *prog.ResultArg:
	pipeSecondFd := p.Calls[0].Args[0].(*prog.PointerArg).Res.(*prog.GroupArg).Inner[1]
	if a.Res != pipeSecondFd {

write := p.Calls[len(p.Calls)-2]
inotifyRmWatch := p.Calls[len(p.Calls)-1]
switch a := write.Args[0].Type().(type) {
case *prog.ResourceType:
	if a.TypeName != "fd" {
		t.Fatalf("expected first argument of write to have type fd, got: %s", a.TypeName)
	}
default:
	t.Fatalf("first argument of write is not resource type: %s", a.Name())
}
switch a := inotifyRmWatch.Args[1].(type) {
case *prog.ResultArg:
	b := a.Type().(*prog.ResourceType)
	if b.TypeName != "inotifydesc" {
		t.Fatalf("expected second argument of inotify_rm_watch to have type inoitfydesc, got: %s", b.TypeName)
	}
	if a.Res != p.Calls[2].Ret {
		t.Fatalf("inotify_rm_watch's second argument should match the result of inotify_add_watch.")
	}
}

sockaddr, ok := a.(*prog.PointerArg).Res.(*prog.GroupArg)
if !ok {
	t.Fatalf("%s", a.Type().Name())
}
ipv4Addr, ok := sockaddr.Inner[2].(*prog.UnionArg)
if !ok {
	t.Fatalf("expected 3rd argument to be unionArg, got %s", sockaddr.Inner[2].Type().Name())
}
optName := ipv4Addr.Option.Type().FieldName()
if !strings.Contains(optName, "rand") {
	t.Fatalf("expected ip option to be random opt, got: %s", optName)
}
ip, ok := ipv4Addr.Option.(*prog.ConstArg)
if !ok {
	t.Fatalf("ipv4Addr option is not IntType")
}
if ip.Val != expectedIp {
	t.Fatalf("parsed != expected, %d != %d", ip.Val, expectedIp)
}
2018-12-07 14:01:26 +01:00
Dmitry Vyukov
eada53b810 tools/syz-trace2syz/proggen: fix vma allocation
There are 2 bugs:
1. We always allocate 1 page, even if use more.
2. VMA addresses are not aligned, so most mmap-like functions fail with EINVAL.
The added test currently panics with "unaligned vma address".
2018-12-07 12:56:38 +01:00
Dmitry Vyukov
9e8a45fe27 tools/syz-trace2syz/proggen: replace memoryTracker with prog.memAlloc 2018-12-07 12:44:45 +01:00
Dmitry Vyukov
413e414738 tools/syz-trace2syz: add go-fuzz fuzzer
Inputs like "2__R" or "3_F	T.3.3l" make
traze2syz hang infinitely consuming all machine memory.
Need to fix all crashes over time.
2018-12-07 12:12:27 +01:00
Dmitry Vyukov
742f85bb22 tools/syz-trace2syz: start adding proper error handling
log.Fatal is not the proper way to handle errors.
It does not allow to write good tests, fuzzers
and utilities that crash all the time.
2018-12-07 12:05:43 +01:00
Dmitry Vyukov
8056889866 tools/syz-trace2syz/proggen: add ParseFile function
Current code structuring has 2 problems:

1. parsing anything with proggen requires complex multistep dance including
 - parsing data with parser
 - walking the resulting tree manually and calling proggen on each
 - then for each context
   - calling FillOutMemory (unclear why it's not part of parsing)
   - calling prog.Finalize
   - checking is the program is not too large
All of this duplicated across trace2syz and tests.
And any new tests or fuzzers we will write will need to duplicate
all of this logic too.

2. As the result of this structuring, lots of proggen guts
and implementation details are exposed.
While none of the callers are actually intersted in Context details,
they are not interested in Context itself whatsoever.

What every caller wants is "here is data to parse, give me programs".
Add such function.
2018-12-07 11:30:13 +01:00
Dmitry Vyukov
840b5cc058 tools/syz-trace2syz/parser: remove Filename from TraceTree
We already printed file name of the trace in parseTraces,
no need to print it again and again.
Consequently we don't need Filename in TraceTree.
If needed, caller can always log it before parsing,
or pass along with the TraceTree.
2018-12-07 10:43:27 +01:00
Dmitry Vyukov
5cdc1f5f6d tools/syz-trace2syz: use short variable declaration syntax
Use short variable declaration syntax where possible.
Move declarations closer to usages.
2018-12-07 10:35:42 +01:00
Dmitry Vyukov
ae17c862c9 tools/syz-trace2syz/parser: use []byte instead of string for file contents
If we are handling whole files, it's more efficient to use []byte.
string is not really meant to hold large amounts of data.
2018-12-07 10:24:24 +01:00
Shankara Pailoor
1eb6a7e433 tools/syz-trace2syz: adding missing copyright headers
Adding missing copyright headers to return_cache.go and context.go
2018-12-07 09:50:45 +01:00
Greg Steuck
dcf836b12d tools/syz-trace2syz/proggen/return_cache.go: format string mismatch 2018-12-06 20:33:02 +01:00
Dmitry Vyukov
ab4b148b34 prog: add Prog.Finalize
Prog.Finalize combines assignSizesCall, SanitizeCall and validate.
Intended for users who build own programs,
so that we don't need to expose all individual methods.
2018-12-06 18:56:08 +01:00
Dmitry Vyukov
ceaec61a83 prog: export Type.DefaultArg
It's effectively exported anyway.
So export it the proper way.
2018-12-06 18:55:46 +01:00
Dmitry Vyukov
f40330afce tools/syz-trace2syz: skip 2 more syscalls
These set_robust_list and set_tid_address are issued by glibc
for every process/thread start.
Normal programs don't use them and it's unlikely we build
something interesting with them (e.g. we won't get real robust list in memory).
Skip them.
2018-12-06 17:33:05 +01:00
Dmitry Vyukov
df8657a90f tools/syz-trace2syz: tidy up code
Lots of assorted changes mainly converting code to idiomatic Go
and replacing code with equivalent, but shorter code.
2018-12-06 17:28:09 +01:00
Dmitry Vyukov
c1641491e4 pkg/db: provide helper function for database creation
This is needed for both tools/syz-db and tools/syz-trace2syz.
Also, remove code to resolve SHA1 collisions.
Also, don't set db version as we actually want to minimize
and smash these programs like anything else
(not minimizing nor smashing them is only useful during tool testing).
2018-12-06 16:49:37 +01:00
Dmitry Vyukov
d68400a8d1 tools/syz-trace2syz: merge config package into proggen
Since we now have only single variable there,
it does not seem to deserve a separate package.
2018-12-06 16:30:14 +01:00
shankarapailoor
6a60a19530 tools/syz-trace2syz: add tool to convert strace output to programs
* fixing weird merge error

* fixing presubmit

* fixing presubmit

* removing parsing code because of -Xraw option

* fix presubmit

* update

* deleting vma_call_handlers as we are currently skipping most vma calls. This simplifies memory_tracker as we don't need to keep track of vma allocations

* removing custom handling of bpf_instruction union

* removing ifconf parsing

* update

* removed all expression types and replaced them with constant types. removing ipv6_addr parsing while -Xraw is getting fixed. Removing constants.go

* removing ipv6 parsing

* presubmit

* moving direction check from ipv4_addr out to genUnion

* removing code that parses kcov

* removing redundant test

* removing custom code in generate unions to fill ipv4_addr

* proggen: changing order of imports to make external packages import first

fixing presubmit

* changing log messages to lower case to be consistent with other packages.

* removing pointer type and simplifying memory_tracker

removing comment

* moving context and return_cache to seaparate files

* deleting default argument generation when we should probably throw an error
2018-12-06 16:25:37 +01:00
Greg Steuck
49e1764c75 tools/create-openbsd-vmm-worker.sh: shut off pagination in ddb 2018-12-04 08:55:04 +00:00
Greg Steuck
e0d8c853f6 tools: set openbsd hostname to instance name for serviceability
* openbsd images: set hostname to instance name for serviceability

* openbsd startup scripts insist on EOL characters
2018-12-02 09:53:06 +00:00
Greg Steuck
4b6d14f266 tools/create-openbsd-gce-ci.sh: simplification due to workers on GCE 2018-11-27 13:16:46 +01:00
Greg Steuck
6419afbb77 openbsd: run on gce
* build/openbsd: minor cleanup (use tuples instead of maps)

* Grammar nits in comments.

* Simplify openbsd.Create, will defer when there's more than one error exit.

* pkg/build: Support copying kernel into GCE image

* Simple test for openbsd image copy build.

* Cleanup in case something failed before.

* Support multi-processor VMs on GCE.

* More debug

* Reformat

* OpenBSD gce image needs to be raw.

* GC

* Force format to GNU directly on Go 1.10 or newer.

* Use vmType passed as a parameter inside openbsd.go

* gofmt

* more fmt

* Can't use GENERIC.mp just yet.

* capitalize

* Copyright
2018-11-27 13:14:06 +01:00
Andrey Konovalov
2b0dc848a0 ipc: fix ProgInfo usage better
Fix a bad fix for ProgInfo usage.
2018-11-23 07:17:29 +01:00
Andrey Konovalov
87815d9d32 ipc: fix ProgInfo usage
We used to use len([]CallInfo) to check both, whether the slice is nil or
whether its length is zero. Since ProgInfo is not a slice, we need a
separate check for nil.
2018-11-22 19:30:04 +01:00
Andrey Konovalov
582e1f0d1d ipc: add ProgInfo struct
This patch add a new struct ProgInfo that for now holds info about each
call in a program []CallInfo, but in the future will be expanded with remote
coverage info. Update all the callers to use the new interface as well.
2018-11-22 13:49:50 +01:00
Greg Steuck
16ba540df4 Review 2018-11-21 07:27:04 +01:00
Greg Steuck
5cdd8fe0e0 syz-repro: minor UX improvements. 2018-11-21 07:27:04 +01:00
Dmitry Vyukov
adf636a83b tools/syz-fmt: allow to reformat all OSes at once
We forgot trusty in Makefile.
Fix this once and for all by formatting all known targets.
2018-11-17 11:46:48 -08:00
Dmitry Vyukov
d1a8851085 sys/targest: introduce target.BuildOS
We can't cross-compile native binaries from just any OS to any other.
For most OSes we can do only native compilation.
Some can only be compiled from linux.
To date we avoided this problem completely (mostly assumed linux build OS).
Make this notion of what can build what explicit.
2018-11-17 11:42:22 -08:00
Anton Lindqvist
1508cc9c44 pkg/csource: add support for creating reproducers on OpenBSD 2018-11-17 10:32:19 -08:00
Dmitry Vyukov
4744d8ccac pkg/report: fix guilty file extraction
reportPrefixLen can become wrong after symbolization
if we symbolize any lines in the prefix.
Adjust reportPrefixLen during symbolization.

Automatic testing of this is problematic
because we would need to symbolize which requires
the object file with debug info.
Tested manually with syz-symbolize.
2018-10-28 19:07:22 +01:00
Greg Steuck
24808096ca tools/create-openbsd*sh: use cdn.openbsd.org not cloudflare, install vmm-firmware
* Use cdn.openbsd.org not cloudflare. Install vmm-firmware explicitly.

* Use cdn.openbsd.org not cloudflare. Install vmm-firmware explicitly.

* set hw.smt=1: the underlying hw on VM is unknown so don't waste SMT.
2018-10-28 10:18:59 +01:00
Dmitry Vyukov
8cd30605ce tools/create-gce-image.sh: create ext4 image without journalling
We don't need consistent image after reboot since we always reimage.
We know of some use cases that don't use journalling, but don't know
of any that use journalling.
2018-10-15 18:56:55 +02:00
Zach Riggle
caf1290068 Android: Add simple test harness for Sandbox 2018-10-12 16:39:26 +02:00
Greg Steuck
42c78641f5 tools/create-openbsd*: Support post-version flip snapshots.
* Fixed pkg_add status checking
  * Switched to qcow2 test image
  * Minor GC
2018-10-11 19:44:34 +02:00
Dmitry Vyukov
fefd83bf0b tools/syz-execprog: show host features
syz-execprog -output is handy way to check what features host.Check detects.
2018-10-10 15:36:57 +02:00
Greg Steuck
0b624c8069 tools/create-openbsd-*: fully functional images from scratch
* tools/create-openbsd-gce-ci: use config from /syzkaller

* Use syzkaller copy of src instead of a separate one.

* Using /dev/null disk in vm.conf

* Use KVM, enable doas, no longer symlink.

* Use a dummmy.img

* Revert "Use a dummmy.img"

This reverts commit 656b24d5e4573dde5e95c6158852001c7241e65a.
2018-09-28 11:13:51 +02:00
Dmitry Vyukov
8899d58437 tools/create-gce-image.sh: mount securityfs and configfs 2018-09-26 14:06:11 +02:00
Greg Steuck
455b6354e8 tools/create-openbsd-gce-ci auto-start syz-ci, redirect 8080 to 80 2018-09-26 09:41:21 +02:00
Greg Steuck
370797126e tools/create-openbsd-gce-ci.sh mount 10G ramdisk for worker images 2018-09-20 20:46:45 +02:00
Greg Steuck
b117b6ed3d tools/*openbsd*: smaller VMM images and tweaks. 2018-09-20 11:03:43 +02:00