Commit Graph

498 Commits

Author SHA1 Message Date
Veronica Radu
aff9e255cd prog: add special mutation for binary flags 2019-08-09 15:02:02 +02:00
Dmitry Vyukov
7c7ded697e prog: fix out-of-bounds access
ParseLog can access data out-of-bounds.
Fix that and fix regression fuzz tests to catch this.
2019-07-30 19:33:02 +02:00
Dmitry Vyukov
3e5d1beb82 prog: fix crash in blob mutation
If we deserialized a huge blob (larger than max blob size),
then we can get a negative size in the "Insert random bytes" case at:

		if r := int(maxLen) - len(data); n > r {
			n = r
		}

Don't insert bytes if data is already larger than maxLen.
2019-07-26 10:43:08 +02:00
Dmitry Vyukov
cf49ed5769 prog: don't minimize ProcType to 0
Default value for ProcType is 0 (same for all PID's).
Usually 0 either does not make sense at all or make different PIDs collide
(since we use ProcType to separate value ranges for different PIDs).
So don't change ProcType to 0 unless the type is explicitly marked as opt
(in that case we will also generate 0 anyway).
2019-07-26 10:29:36 +02:00
Andrey Konovalov
9ba1e9ae4b prog: fix updating triedPaths when minimizing resources 2019-07-16 15:20:33 +02:00
Dmitry Vyukov
55565fa037 prog: fix minimization bugs
Fix several nasty bugs in minimization that could lead
to almost arbitrary results. These bugs affected both
crash minimization and corpus population.
Extend the randomized test to catch these bugs.
Add additional asserts to code to catch similar bugs in future.

Reported-by @xairy
2019-07-02 14:49:44 +02:00
Marco Elver
ce9107d086 prog/mutation: Add internal comments 2019-06-07 14:03:39 +02:00
Anton Lindqvist
85c573157d pkg/csource: add ability to annotate syscalls using comments in C reproducers
Providing additional info, especially regarding syscall arguments, in reproducers
can be helpful. An example is device numbers passed to mknod(2).

This commit introduces an optional annotate function on a per target basis.

Example for the OpenBSD target:

  $ cat prog.in
  mknod(0x0, 0x0, 0x4503)
  getpid()
  $ syz-prog2c -prog prog.in
  int main(void)
  {
    syscall(SYS_mmap, 0x20000000, 0x1000000, 3, 0x1012, -1, 0, 0);
    syscall(SYS_mknod, 0, 0, 0x4503); /* major = 69, minor = 3 */
    syscall(SYS_getpid);
    return 0;
  }
2019-05-24 22:33:56 +02:00
Dmitry Vyukov
76fc461b55 pkg/compiler: add offsetof type
Similar to C offsetof gives offset of a field
from the beginning of the parent struct.
We have several TODOs in descriptions asking for this.
2019-05-16 18:05:05 +02:00
Dmitry Vyukov
bd4e3ac77b prog: fix crash in assignSize on optional pointer 2019-05-14 20:58:33 +02:00
Dmitry Vyukov
2376f0f937 pkg/compiler: allow to refer to syscall arguments in len paths
This allows to use len[syscall:arg] expressions.
2019-05-14 19:28:01 +02:00
Dmitry Vyukov
9a4969814e pkg/compiler: refactor len target checking
Create named const for "parent" and move some code into a helper function.
2019-05-14 19:28:01 +02:00
Dmitry Vyukov
93dcf0adc8 prog: implement complex len target support
This actually implements support for complex len targets
during program generation and mutation.
2019-05-14 19:28:01 +02:00
Dmitry Vyukov
16c881ad85 pkg/compiler: generate complex len targets
Change the generated format for len type to support multiple path elements.
2019-05-14 19:28:01 +02:00
Dmitry Vyukov
da22883527 prog: fix TestTransitivelyEnabledCalls
We now have io_uring on all arches so remove the hack.
2019-05-10 13:04:27 +02:00
Kaipeng Zeng
c2aed7c7e3 sys/linux: update descriptions of sendmsg/sendmmsg
Fix the descriptions of cmsghdr.
Add sendmsg$sock and sendmmsg$sock for __sock_cmsg_send.
2019-05-10 13:00:44 +02:00
Dmitry Vyukov
335cf4f4fd prog: fix crash in createResource
We may be in createResource but have no resources at all because of ANYRES
that are not in target.Resources.
This is actually the case for some test targets. We have resources there,
but syscalls that create them are disabled.
In such case we crash in Intn(0).
Check that we have some resources before calling Intn.
2019-04-23 18:59:49 +03:00
Dmitry Vyukov
8095117313 all: fix some static analysis warnings
Fix warnings produced by golangci-lint.

Update #977
2019-04-23 17:58:54 +03:00
Dmitry Vyukov
4f421599f9 sys/linux: add simple io_uring descriptions
We don't actually communicate with the uring yet,
but this already finds a bunch of bugs.
2019-04-12 16:19:23 +02:00
Dmitry Vyukov
44fe9159be prog/test: rename prog/fuzz to prog/test
gometalinter complained about fuzz.FuzzFoo names,
but go-fuzz now requires all fuzz functions to start with Fuzz.
So move the package to prog/test.
2019-04-01 12:20:19 +02:00
Dmitry Vyukov
c35ee0ea6d prog, pkg/compiler: fix warnings
gometalinter says:

pkg/compiler/consts.go:192:⚠️ internal error: no range for "n" (vetshadow)
pkg/compiler/consts.go:197:⚠️ internal error: no range for "n" (vetshadow)
prog/encoding.go:862:⚠️ declaration of "v" shadows declaration at prog/encoding.go:852 (vetshadow)

This somehow happens only with Go1.11 but not 1.12 so wasn't detected locally.
The prog warnings looks legit.
The pkg/compiler warning was amusingly introduced to please golangci-lint checker,
revert that fix for now.
2019-03-29 19:04:30 +01:00
Dmitry Vyukov
c84501fe70 prog: fix a bunch of bugs in parsing
Add fuzzer for Deserialize and fix 5 or so bugs it found.

Fixes #1086
2019-03-29 08:56:02 +01:00
Dmitry Vyukov
4a9fce1952 all: fix warnings pointed to by golangci-lint
Update #977
2019-03-28 15:30:18 +01:00
Dmitry Vyukov
d23e90a7b4 all: switch to Go 1.12
Differences in code formatting between Go versions cause constant
problems for us (https://github.com/golang/go/issues/25161).
Currently we support 1.9 and 1.10. Switch to newer 1.11 and 1.12.

Fixes #1013
2019-03-14 14:55:59 +01:00
Dmitry Vyukov
0278574b21 prog: add a test for ChoiceTable 2019-02-21 10:08:34 +01:00
Dmitry Vyukov
a39e52b1cd all: reformat with Go 1.10 2019-02-11 18:13:34 +01:00
Dan Robertson
13f1d0047a sys/linux: add NDISC packet formats to vnet.txt
Add the basic NDISC (RFC 4861) packet formats to sys/linux/vnet.txt.
2019-02-11 18:10:35 +01:00
Dmitry Vyukov
fa6c7b7080 sys/linux: prohibit opening /proc/self/exe
Fuzzer manages to open it and do bad things with it.
Prevent it from doing so.
2019-02-08 16:30:44 +01:00
Andrey Konovalov
ceb907750f prog: fix checksum dependencies
Make pseudo checksums depend (via csumUses) on the arg it requires for
calculation. Otherwise we fail to assign addrs to those args during encoding
for execution. Also add a test.
2019-02-01 16:52:54 +01:00
Dmitry Vyukov
8e579f27d6 prog: fix escaping of C strings
C's \xHH hex constants in strings accept any number of hex digits
(not just 2 or 4). So later non-hex escaped chars glue to the \x construct.
Use \OOO instead as it accepts at most 3 octal digits.
2019-01-31 11:35:53 +01:00
houjingyi
69d69aa92d Update hints_test.go 2019-01-07 10:01:28 +01:00
Dmitry Vyukov
709e893d24 prog: don't produce the same program when mutating with hints
No point in producing the same program as result of mutation with hints.
So don't do it.
2019-01-03 13:39:30 +01:00
Dmitry Vyukov
adddc5fd46 prog: remove several sources of non-determinism
Non-determinism is bad:
 - it leads to flaky coverage reports
 - it makes test failures non-reproducible

Remove 4 sources of non-determinism related to maps:
 - file name generation
 - string generation
 - resource generation
 - hints generation

All a test that ensures all main operations are fully deterministic.
2019-01-03 12:23:57 +01:00
Dmitry Vyukov
06a2b89fc3 prog, pkg/{csource,ifuzz,ipc,repro}: make tests deterministic on travis
Don't use random seed on travis as it produces flaky coverage reports,
and probably generally better for CI setting.
2019-01-02 11:57:53 +01:00
Dmitry Vyukov
c5499485c2 prog: speed up TestResourceCtors
We check each resource multiple times. Check each resource once.
2018-12-31 12:32:14 +01:00
Dmitry Vyukov
2b084c9886 pkg/csource: use 0 for missing syscall args
We don't specify trailing unused args for some syscalls
(e.g. ioctl that does not use its arg).
Executor always filled tailing unsed args with 0's
but pkg/csource didn't. Some such syscalls actually
check that the unsed arg is 0 and as the result failed with C repro.

We could statically check and eliminate all such cases,
but it turns out the warning fires in 1500+ cases:
a3ace5a63f/gistfile1.txt

So instead fill such args with 0's in pkg/csource too.
2018-12-27 13:11:57 +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
Greg Steuck
7795ae03c0 prog: detect invalid target.Syscalls in BuildChoiceTable
Without this check programs may end up panicing in places far away
from the real cause. E.g.

worker# ./syz-fuzzer -executor=./syz-executor -name=vm-0 -arch=amd64 -manager=10.128.0.101:21386 -sandbox=setuid -procs=2 -v=0 -cover=true -debug=false -test=false
2004/02/03 12:11:11 fuzzer started
2004/02/03 12:11:11 dialing manager at 10.128.0.101:21386
2004/02/03 12:11:12 syscalls: 1
2004/02/03 12:11:12 code coverage: enabled
2004/02/03 12:11:12 comparison tracing: support is not implemented in syzkaller
2004/02/03 12:11:12 setuid sandbox: support is not implemented in syzkaller
2004/02/03 12:11:12 namespace sandbox: support is not implemented in syzkaller
2004/02/03 12:11:12 Android sandbox: support is not implemented in syzkaller
2004/02/03 12:11:12 fault injection: support is not implemented in syzkaller
2004/02/03 12:11:12 leak checking: support is not implemented in syzkaller
2004/02/03 12:11:12 net packet injection: enabled
2004/02/03 12:11:12 net device setup: support is not implemented in syzkaller
panic: invalid argument to Intn

goroutine 27 [running]:
math/rand.(*Rand).Intn(0xc000dff530, 0x0, 0x40)
        /usr/local/go/src/math/rand/rand.go:169 +0x9c
github.com/google/syzkaller/prog.(*ChoiceTable).Choose(0xc000d92ec0, 0xc000dff530, 0xffffffffffffffff, 0xc000dff650)
        /syzkaller/gopath/src/github.com/google/syzkaller/prog/prio.go:241 +0x1a0
github.com/google/syzkaller/prog.(*randGen).generateCall(0xc000e145a0, 0xc000c2a200, 0xc000ce7f80, 0x2348f1940, 0xc000ce3440, 0xc000e6ee01)
        /syzkaller/gopath/src/github.com/google/syzkaller/prog/rand.go:451 +0x69
github.com/google/syzkaller/prog.(*Target).Generate(0xc00007f1e0, 0x8f8680, 0xc000ce3440, 0x1e, 0xc000d92ec0, 0x0)
        /syzkaller/gopath/src/github.com/google/syzkaller/prog/generation.go:19 +0x2b2
main.(*Proc).loop(0xc000d92f40)
        /syzkaller/gopath/src/github.com/google/syzkaller/syz-fuzzer/proc.go:93 +0x2a1
created by main.main
        /syzkaller/gopath/src/github.com/google/syzkaller/syz-fuzzer/fuzzer.go:236 +0xfe2
2018-12-11 11:14:20 +01:00
Dmitry Vyukov
28bd3e371b prog: support AUTO args in programs
AUTO arguments can be used for:
 - consts
 - lens
 - pointers

For const's and len's AUTO is replaced with the natural value,
addresses for AUTO pointers are allocated linearly.

This greatly simplifies writing test programs by hand
as most of the time we want these natural values.

Update tests to use AUTO.
2018-12-10 16:37:02 +01:00
Dmitry Vyukov
ba64d006de prog: implement strict parsing mode
Add bulk of checks for strict parsing mode.
Probably not complete, but we can extend then in future as needed.
Turns out we can't easily use it for serialized programs
as they omit default args and during deserialization it looks like missing args.
2018-12-10 16:37:01 +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
a5efea3ec3 prog: refactor deserialization code
Move target and vars into parser and make all
parsing functions methods of the parser.
This reduces number of args that we need to pass around
and eases adding more state that needs to be passed around.
2018-12-10 16:37:01 +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
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
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
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
0b29b7f952 prog: prevent sandbox escaping files from entering s.files 2018-11-27 13:16:05 +01:00
Andrey Konovalov
5a0d6e039d prog: try to nullify pointers when minimizing
This patch changes minimization routines to try assigning a.Res to nil
for each pointer arg.
2018-11-21 05:30:44 +01:00
Dmitry Vyukov
8bd6bd6365 prog: allow escaping paths but don't generate them
Filename generated escaping paths in the past.
The reason for the check during validation is to
wipe old program from corpuses. Now that they are
hopefully wiped everywhere, we can relax the check
to restrict only filename to not produce escaping paths,
but allow existing programs with escaping paths.
This is useful in particular if we generate syzkaller
programs from strace output.
2018-11-02 17:31:59 +01:00
Dmitry Vyukov
ecb386fe6f sys: check that target consts are defined
Currently when we get target consts with target.ConstMap["name"]
during target initialization, we just get 0 for missing consts.
This is error-prone as we can mis-type a const, or a const may
be undefined only on some archs (as we have common unix code
shared between several OSes).
Check that all the consts are actually defined.
The check detects several violations, to fix them:
1. move mremap to linux as it's only defined on linux
2. move S_IFMT to openbsd, as it's only defined and used on openbsd
3. define missing MAP_ANONYMOUS for freebsd and netbsd
4. fix extract for netbsd
2018-10-19 19:11:22 +01:00
Dmitry Vyukov
1ba7fd7e65 all: fix code formatting
Reformat, remove debug leftovers, fix comment style.
2018-10-16 13:57:24 +02:00
Zach Riggle
f37861df63 targets: Use OS=linux when GOOS=android
This avoids the issue of "android" not having any registered configurations
or syscalls / ioctls / etc, when built with GOOS=android.

This occurs when building in Google3, since --config=android_arm64 selects
the Android toolchain.
2018-10-10 11:54:53 +02:00
Dmitry Vyukov
a4718693a3 sys/linux: add syz_execute_func
The function executes random code.

Update #310
2018-08-30 21:45:04 -07:00
Dmitry Vyukov
e8dd2c6713 prog: add concept of "special pointers"
Currently we only generate either valid user-space pointers or NULL.
Extend NULL to a set of special pointers that we will use in programs.
All targets now contain 3 special values:
 - NULL
 - 0xfffffffffffffff (invalid kernel pointer)
 - 0x999999999999999 (non-canonical address)
Each target can add additional special pointers on top of this.

Also generate NULL/special pointers for non-opt ptr's.
This restriction was always too restrictive. We may want to generate
them with very low probability, but we do want to generate them.

Also change pointers to NULL/special during mutation
(but still not in the opposite direction).
2018-08-30 21:45:03 -07:00
Dmitry Vyukov
6ba5fe3e62 sys/openbsd: disable mknod sanitization as tests fail
TestSerializeDeserializeRandom fails from time to time
because program is different after we serialize/deserialize it.
Turns out openbsd SanitizeCall is not idempotent.
Add a test for this and disable the logic for now.
2018-08-30 21:44:56 -07:00
Dmitry Vyukov
ee42876f95 prog: fix corner case in normalizePrio
Based on twitter bug report:
https://twitter.com/panicaII/status/1035058001269248000
2018-08-30 21:44:00 -07:00
Dmitry Vyukov
2dc4378f02 prog: don't add fallback signal after seccomp
seccomp filter can produce arbitrary errno values for subsequent syscalls.
Don't trust anything afterwards.
2018-08-19 00:13:24 -07:00
Dmitry Vyukov
c00da3df66 prog: collect all prog comments
Parse and collect and prog comments.
Will be needed for runtest annotations
(e.g. "requires threaded mode", etc).
2018-08-08 13:07:49 +02:00
Dmitry Vyukov
95a080a682 prog: strenghten type checking during validation
Check that argument types match expected static types.
I.e. detect when, say, syscall argument is a resource,
but actual generated argument is a pointer.
2018-08-02 16:57:31 +02:00
Dmitry Vyukov
ae2f24aa70 prog: refactor calcStaticPriorities
Factor out several helper functions.

Update #538
2018-08-02 16:57:31 +02:00
Dmitry Vyukov
c56465d568 prog: split and simplify Mutate
Update #538
2018-08-02 16:57:31 +02:00
Dmitry Vyukov
1da82ae0f0 prog: introduce debugValidate
Move debug validation into a separate function.

Update #538
2018-08-02 16:57:31 +02:00
Dmitry Vyukov
c8643744fe prog: refactor defaultArg/isDefaultArg
Refactor from single-big-switch to type methods.

Update #538
2018-08-02 16:57:31 +02:00
Dmitry Vyukov
e002278dfb prog: refactor SerializeForExec
Factor copyin, copyout and checksums into separate functions.
Also slightly tidy csum analysis.

Update #538
2018-08-02 16:57:31 +02:00
Dmitry Vyukov
97bce4e2ce prog: refactor program serialization
Make argument serialization Arg method.
This eliminates a very long function
that serializes all arguments.

Update #538
2018-07-31 18:43:50 +02:00
Dmitry Vyukov
46b824df22 prog: refactor SerializeForExec
Reduce cyclomatic complexity.

Update #538
2018-07-31 18:38:54 +02:00
Dmitry Vyukov
0e9b376bc3 prog: refactor Minimize
Reduce cyclomatic complexity of argument minimization
by moving type-specific logic into separate functions.
Fix few bugs along the way.

Update #538
2018-07-31 16:06:21 +02:00
Dmitry Vyukov
f5d67fbd9c .gometalinter.json: enable gofmt
The part that we want from gofmt is simplify (-s).
Fix all code that needs fixing.

Update #538
2018-07-31 12:16:54 +02:00
Dmitry Vyukov
1a381291a3 executor: collect coverage from unfinished syscalls
Write coverage from unfinished syscalls.
Also detect when a syscall was blocked during execution,
even if it finished. Helpful for fallback coverage.

Fixes #580
2018-07-29 19:46:05 +02:00
Dmitry Vyukov
68faa52582 prog: parse comments in serialized programs
Remember per-call comments, will be useful for annotating tests.
Also support this form:
call() # comment
2018-07-27 10:22:23 +02:00
Dmitry Vyukov
e0c1bcbabc prog: move MaxPids const to prog
The const may be needed by other packages.
E.g. when checking manager config.
2018-07-25 10:39:29 +02:00
Dmitry Vyukov
9fe4bdc5f1 executor: overhaul
Make as much code as possible shared between all OSes.
In particular main is now common across all OSes.
Make more code shared between executor and csource
(in particular, loop function and threaded execution logic).
Also make loop and threaded logic shared across all OSes.
Make more posix/unix code shared across OSes
(e.g. signal handling, pthread creation, etc).
Plus other changes along similar lines.
Also support test OS in executor (based on portable posix)
and add 4 arches that cover all execution modes
(fork server/no fork server, shmem/no shmem).

This change paves way for testing of executor code
and allows to preserve consistency across OSes and executor/csource.
2018-07-24 12:04:27 +02:00
Anton Lindqvist
54bb6b9222 prog: add missing Default() implementation for ConstType 2018-07-23 11:11:32 +02:00
Dmitry Vyukov
06c33b3af0 prog: sanitize calls after hints mutation
Hints mutation could produce unsanitized calls.
Sanitize calls after hints mutation.
Also sanitize on load (in validate), because bad programs
can already be in corpuses. And it's just the right thing
to do because sanitization rules can change over time.
2018-07-12 12:40:30 +02:00
Dmitry Vyukov
fb2fc0f4dc prog: fix pointer validation
Query size after validating the object itself,
otherwise size can panic on corrupted object.
2018-07-08 22:52:24 +02:00
Dmitry Vyukov
1c667063a8 prog: don't generate filenames that escape sandbox
All files that fuzzer works with must be in the working dir.
Using "/" is known to cause problems when fuzzer
removes files there or mounts something.
2018-07-08 22:52:24 +02:00
Dmitry Vyukov
306ca0571c prog, pkg/compiler: support fmt type
fmt type allows to convert intergers and resources
to string representation.
2018-07-08 22:52:24 +02:00
Dmitry Vyukov
57799a834f prog: fix and improve fallback coverage
First we emitted fallbackSignalFlags inside of the loop,
while we need to this outside of the loop.
Second, make flags signal weaker otherwise we get all 256
signals for open, chmod, etc.
Third, simplify and speedup code.
2018-06-30 13:28:11 +02:00
Dmitry Vyukov
5012ddc8eb prog: detect when flags are a bitmask 2018-06-30 13:27:24 +02:00
Dmitry Vyukov
f7498af7af prog: add stronger fallback signal
Also mixin resource constructors and some signature
of flags values for successful calls into fallback coverage.
2018-06-29 20:34:43 +02:00
Dmitry Vyukov
dcb1eebb7f prog: more precise constructor calculation
Currently a call that both accepts and creates a resource
self-justifies itself and thus is always enabled.
A good example is accept call. Accepts are always self-enable
and thus enable all other syscalls that work with the socket.

Calculate TransitivelyEnabledCalls in the opposite direction
to resolve this. Start with empty set of enable syscalls,
then enable syscalls that don't accept any resources,
then enable syscalls that accept resources created by the
previous batch of syscalls, and so on.

This prevents self-enablement of accept.
2018-06-18 19:45:48 +02:00
Dmitry Vyukov
2dcee3b338 prog: use all resource special values for opt args 2018-06-18 19:45:46 +02:00
Dmitry Vyukov
598eb19243 prog: mutate fixed-size strings more
Allow removing/inserting ranges of bytes from fixed-size strings,
provided we truncate/extend resulting string to keep original size.
2018-06-12 19:09:26 +02:00
Dmitry Vyukov
9e0846e8a4 all: get rid of underscores in identifiers
Underscores are against Go coding style.

Update #538
2018-05-07 17:59:06 +02:00
Dmitry Vyukov
97d2b0e4c4 prog: refactor mutateArg from a big huge function
Update #538
2018-05-07 16:24:03 +02:00
Dmitry Vyukov
55a5e98a0a pkg/ifuzz: move generated code to a separate package
This helps to ignore generated code with gometalinter.
There is currently no other way:
https://github.com/alecthomas/gometalinter/issues/270

Update #538
2018-05-07 15:42:28 +02:00
Dmitry Vyukov
df6e2fb6df prog: deduplicate minimization test
Update #538
2018-05-07 14:55:53 +02:00
Dmitry Vyukov
8041642739 prog: dedup checksumming code
Update #538
2018-05-07 14:51:28 +02:00
Dmitry Vyukov
23b5913da9 prog: reorder checksum functions
Put the most important function at the top.
2018-05-07 14:46:17 +02:00
Dmitry Vyukov
068da17e1f prog: dedup mutation code
Update #538
2018-05-07 14:42:22 +02:00
Dmitry Vyukov
cda1fcb742 sys: dedup mmap code across OSes
Update #538
2018-05-06 16:58:38 +02:00
Dmitry Vyukov
6a0382b543 prog: rework validation code
The current code is total, unstructured mess.
Since we now have 1:1 type -> arg correspondence,
rework validation around args. This makes code
much cleaner and 30% shorter.
2018-05-05 11:43:00 +02:00
Dmitry Vyukov
afe402d20a prog: make c.Ret optional
No reason to allocate return value if there is no return type.
c.Ret == nil is the reasonable indication that this is a "void" call.
2018-05-05 10:25:45 +02:00
Dmitry Vyukov
9dfb5efa91 prog: simplify code
Now that we don't have ReturnArg and only ResultArg's refer
to other ResultArg's we can remove ArgUser/ArgUsed and
devirtualize lots of code.
2018-05-05 10:13:04 +02:00
Dmitry Vyukov
5ca897bd50 prog: remove ReturnArg
It's not all that needed.
2018-05-05 09:08:48 +02:00
Dmitry Vyukov
9846445c8e prog: parallelize tests
Parallelize more tests and reduce number of iterations
in random tests under race detector.
2018-05-04 20:07:32 +02:00
Dmitry Vyukov
2c7e14a847 gometalinter: enable cyclomatic complexity checking
Refactor some functions to be simpler.

Update #538
2018-05-04 18:03:46 +02:00
Dmitry Vyukov
08141db61a gometalinter: enable line length checking
120 columns looks like a reasonable limit
and requires few changes to existing code.

Update #538
2018-05-04 14:24:51 +02:00
Dmitry Vyukov
a630fd8b41 gometalinter: some fixes for unparam
But we still can't enable it as there are more [uninteresting] warnings.

Update #538
2018-05-03 15:48:26 +02:00
Dmitry Vyukov
39302300d9 gometalinter: check unkeyed composite literals
Update #538
2018-05-03 14:01:48 +02:00
Dmitry Vyukov
d169e0f3c4 prog: test TransitivelyEnabledCalls on all targets
Fixes #585
2018-05-03 13:40:21 +02:00
Julia Hansbrough
9ce14f4b01 prog: Fix page fault for syz-stress users.
In resources.go, haveGettime is False when SyscallMap["clock_gettime"]
is nil.

In this code, there's a branch that's entered only if Gettime is False,
which appends SyscallMap["clock_gettime"] to resourceCtors.  That is, it
appends nil to resourceCtors, then iterates through resourceCtors and
tries to dereference the .Name of each time, in this case, nil.Name.

This was causing a page fault on Fuchsia.

I'm not certain how the "standard" flow is supposed to work, since it
seems like any code that enters the `if cantCreate == "" && !haveGettime`
should fail... but, removing that section causes test failures, so let's
just enforce that SyscallMap["clock_gettime"] is non-nil.

If there's a better way to solve this, I'm open to suggestions.
2018-05-03 07:50:03 +02:00
Dmitry Vyukov
02bbd80e7c prog: fix gometalinter warnings 2018-04-24 13:23:01 +02:00
Dmitry Vyukov
2a9c3edcda pkg/prog: explain why syscalls are transitively disabled 2018-04-06 19:43:06 +02:00
Dmitry Vyukov
3e679c51c0 pkg/compiler: support non-zero terminated filenames
Now file names become:

string[filename]

with a possibility of using other string features:

stringnoz[filename]
string[filename, CONST_SIZE]

and filename is left as type alias as it is commonly used:

type filename string[filename]
2018-04-02 20:10:07 +02:00
Dmitry Vyukov
185ac3525e prog: support big-endian during hints matching
Use big-endian match/replace for both blobs and ints.
Sometimes we have unmarked blobs (no little/big-endian info);
for ANYBLOBs we intentionally lose all marking;
but even for marked ints we may need this too.
Consider that kernel code does not convert the data
(i.e. not ntohs(pkt->proto) == ETH_P_BATMAN),
but instead converts the constant (i.e. pkt->proto == htons(ETH_P_BATMAN)).
In such case we will see dynamic operand that does not
match what we have in the program.
2018-04-01 15:28:01 +02:00
Dmitry Vyukov
0174c6c8f7 prog: reduce nesting level in shrinkExpand 2018-03-31 18:55:59 +02:00
Dmitry Vyukov
7c923cf8d4 sys/linux: add support for mounting filesystem images 2018-03-30 19:51:27 +02:00
Dmitry Vyukov
7c62f71804 sys/linux: add netlink fou descriptions 2018-03-21 12:18:36 +01:00
Dmitry Vyukov
36d1c4540a all: fix gometalinter warnings
Fix typos, non-canonical code, remove dead code, etc.
2018-03-08 18:48:26 +01:00
Dmitry Vyukov
d0790618dc prog: fix isDefaultArg
Test that isDefaultArg returns true for result of DefaultArg.
Fix few bugs uncovered by this test.
2018-03-08 12:02:17 +01:00
Dmitry Vyukov
4bad061006 prog: extend some error messages 2018-03-05 12:58:29 +01:00
Dmitry Vyukov
bc09be4253 prog: fix 32-bit build
Currently fails with:
prog/mutation.go:442:24: constant 4294967296 overflows int
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
70a1ddb939 prog: harden program parsing against description changes more
Handle most of type changes, e.g. const is changed to struct,
or struct to pointers. In all these cases we create default args.
They may not give the coverage anymore, but still better than
losing them right away.
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
b99c76c405 prog: recover after type changes during program deserialization
Make program deserialization handle and recover after type changes
in descriptions.
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
bd5df8f49b prog: handle excessive args and fields during program parsing
Tolerate excessive args and fields during program parsing.
This is useful after description changes to not lose corpus.
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
002cecf202 pkg/compiler: allow specifying static size for filename's
Sometimes filenames are embed into structs and need to take fixed space.
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
5ef8dbdf5a pkg/compiler: support size attribute for unions 2018-03-05 12:10:27 +01:00
Dmitry Vyukov
a339951e5f pkg/compiler: add size attribute for structs
The size attribute allows to pad a struct up to the specified size.
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
e28ba02d9d prog: harden program parsing
This fixes crash during parsing of existing programs in corpus
after vma<->ptr type change in descriptions.
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
6ceee05ad9 prog: extend a TODO about big-endian hints 2018-02-27 12:06:28 +01:00
Dmitry Vyukov
6284466bc9 prog: properly squash bitfields 2018-02-26 18:21:51 +01:00
Dmitry Vyukov
d1322dff4c prog: remove stale TODOs 2018-02-26 17:46:44 +01:00
Dmitry Vyukov
b37b65b0e6 sys/linux: remove proc type from network descriptions
We now always create net namespace for testing,
so socket ports and other IDs do not overlap between
different test processes.
Proc types play badly with squashing packets to ANYBLOB.
To squash into a block we need concrete value, but it depends
on process id.
Removing proc also makes tun setup and address descriptions simpler.
2018-02-26 16:48:31 +01:00
Dmitry Vyukov
14dae29c2a executor: use proper default values for resources
We currently use -1 as default value for resources
when the actual value is not available.
-1 is good for fd's, but is not the right default
value for pointers/keys/etc.
Pass from prog and use in executor proper default
value for resources.
2018-02-26 15:00:46 +01:00
Dmitry Vyukov
41f6f2579b prog: fix address analysis
Even during mutation of a call we want to analyze whole program
to find all used addresses (rather then stop on the selected call).
Also update address during ANY mutation if size has increased.
2018-02-26 13:33:11 +01:00
Dmitry Vyukov
17ad67b472 prog: better error message when failed to create a resource 2018-02-26 12:15:08 +01:00
Dmitry Vyukov
9fe8aa42c5 prog: add arbitrary mutation of complex structs
Squash complex structs into flat byte array and mutate this array
with generic blob mutations. This allows to mutate what we currently
consider as paddings and add/remove paddings from structs, etc.
2018-02-25 18:22:02 +01:00
Dmitry Vyukov
2145057cb8 pkg/compiler: fix alignment corner case
Fix alignemnt calculation for packed structs with alignment and bitfields.
Amusingly this affected only a single real struct -- ipv6_fragment_ext_header.
2018-02-25 14:44:29 +01:00
Dmitry Vyukov
1f4ae3f413 pkg/compiler: don't assign call IDs statically
IDs change whenever a call is added or removed,
this leads to large diffs unnecessarly.
Assign IDs dynamically.
2018-02-25 14:31:40 +01:00
Dmitry Vyukov
44f66b4026 prog: return concrete arg types from Make functions
This removes a bunch of type assertions and makes code type safer.
2018-02-24 17:00:34 +01:00
Dmitry Vyukov
7a7c747c6f pkg/compiler: allow unions as syscall arguments
If all union options can be syscall arguments,
allow the union itself as syscall argument.
2018-02-23 13:50:02 +01:00
Dmitry Vyukov
3be86de046 sys/linux: prevent programs from doing arbitrary writes with ARCH_SET_FS 2018-02-23 11:55:37 +01:00
Dmitry Vyukov
c1f526e3e5 prog: mutate len fields based on hints
With the new address allocation logic,
the reason to not touch len has gone.
2018-02-19 21:48:20 +01:00
Dmitry Vyukov
a793204dd2 pkg/compiler: fix corner case in alignment calculation 2018-02-19 21:48:20 +01:00
Dmitry Vyukov
75a7c5e2d1 prog: rework address allocation
1. mmap all memory always, without explicit mmap calls in the program.
This makes lots of things much easier and removes lots of code.
Makes mmap not a special syscall and allows to fuzz without mmap enabled.

2. Change address assignment algorithm.
Current algorithm allocates unmapped addresses too frequently
and allows collisions between arguments of a single syscall.
The new algorithm analyzes actual allocations in the program
and places new arguments at unused locations.
2018-02-19 21:48:20 +01:00
Dmitry Vyukov
90fd650313 prog: fix PhysicalAddr for NULL addresses
Turns out we never produced NULL pointers because
what's meant to be NULL pointer was actually encoded
as pointer to beginning of the data region.
2018-02-19 21:48:20 +01:00
Dmitry Vyukov
6e89f94756 prog: fix mutationArgs for special types
There are 2 bugs currently:
1. mutationArgs recurses into special types,
even though they must be mutated as the whole only.
2. When mutationArgs is called from Gen.MutateArg,
it included the top special type as well,
it must not because at this point only the subargs
must be mutated.

Fix both problems.
2018-02-19 21:48:20 +01:00
Dmitry Vyukov
6051a5b552 prog: combine RequiresBitmasks and RequiresChecksums into RequiredFeatures 2018-02-19 21:48:20 +01:00
Dmitry Vyukov
4eef71bb2d prog: merge foreachSubargOffset into foreachArgImpl 2018-02-19 21:48:20 +01:00
Dmitry Vyukov
85d1218f41 prog: rework foreachArg
Make Foreach* callback accept the arg and a context struct
that can contain lots of aux info.
This (1) removes lots of unuser base/parent args,
(2) provides foundation for stopping recursion,
(3) allows to merge foreachSubargOffset.
2018-02-19 21:48:20 +01:00
Dmitry Vyukov
76ab9250a7 prog: move Minimize tests to an own file 2018-02-19 21:48:20 +01:00
Dmitry Vyukov
dd768bf1c6 prog: reorder Minimize arguments
Make the predicate the last argument.
It's more common and convenient (arguments are not separated by multiple lines).
2018-02-19 21:48:20 +01:00
Dmitry Vyukov
4f4f70406c prog: unexport Args and PyPhysicalAddr 2018-02-17 19:02:12 +01:00
Dmitry Vyukov
a08436c973 prog: give special type generators access to target 2018-02-17 19:02:12 +01:00
Dmitry Vyukov
5204f75a58 prog: fix test output
Print programs as strings, rather than byte sequences.
2018-02-17 19:02:12 +01:00
Dmitry Vyukov
dd4fcef5a2 pkg/compiler: allow len of var-len arrays
All netfilter subsystems use this unfortunately,
so demote this to a warning.
2018-02-17 19:02:12 +01:00
Dmitry Vyukov
033b610ec9 sys/linux: improve netfilter descriptions
Put the underflow entry at the end.
Entries must end on an unconditional, non-goto entry,
otherwise fallthrough from the last entry is invalid.

Add arp tables support.

Split unspec matches/targets to unspec and inet.

Reset ipv6 and arp tables in executor.

Fix number of counters in tables.

Plus a bunch of assorted fixes for matches/targets.
2018-02-09 20:14:33 +01:00