306 Commits

Author SHA1 Message Date
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
Greg Steuck
7f125108ae More packages and fewer daemons. 2018-09-17 09:44:01 +02:00
Greg Steuck
68def56dce tools/create-openbsd-gce-ci.sh: Add VMM configuration.
Added verification of successful package install.
2018-09-17 09:44:01 +02:00
Greg Steuck
8c88323f94 tools/create-openbsd-gce-ci.sh: image for build machine
Mostly derived from Go buildlet generator with blessing from bradfitz@.

Update #712
2018-09-10 18:28:00 +02:00
Dmitry Vyukov
58f18e3f60 tools/create-gce-image.sh: disable ftrace_dump_on_oops
We don't have anything useful there.
But sometimes fuzzer somehow poppulates it with some nonsense,
and then it all dumped in crashes.
Disable it.
2018-09-10 16:19:40 +02:00
Dmitry Vyukov
6b5120a464 tools/create-gce-image.sh: auto-detect block device type
Currently we choose block device to use (nbd/loop) based on SYZ_VM_TYPE.
Strictly saying these things are orthogonal.
losetup is broken on Ubuntu. qemu-nbd is broken on Debian.
Try to auto-detect what will work based on uname.
2018-09-07 19:04:47 +02:00
Kees Cook
873745f2ff tools: update to Debian stretch
This updates the image creation tool to use Debian stretch (current stable)
instead of wheezy, which is very out of date. The only change needed here
was a hint to systemd to make the root filesystem read-write after booting.
Documentation has also been updated.
2018-09-05 19:26:06 +02:00
Dmitry Vyukov
196410e4f5 dashboard/config: re-enable selinux
Upstream "selinux: fix mounting of cgroup2 under older policies"
commit fixes mounting of cgroup2 under wheezy selinux policy.
So don't disable selinux on start.
Create separate cmdline arguments that enable selinux and apparmor.
2018-09-05 12:50:53 +02:00