Commit Graph

343 Commits

Author SHA1 Message Date
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