Commit Graph

55 Commits

Author SHA1 Message Date
Dmitry Vyukov
354c324465 syz-fuzzer: don't send/check CallIndex for inputs
The call index check episodically fails:

2017/10/02 22:07:32 bad call index 1, calls 1, program:

under unknown circumstances. I've looked at the code again
and don't see where/how we can mess CallIndex.
Added a new test for minimization that especially checks resulting
CallIndex.
It would be good to understand what happens, but we don't have
any reproducers. CallIndex is actually unused at this point.
Manager only needs call name. So remove CallIndex entirely.
2017-10-10 10:41:27 +02:00
Dmitry Vyukov
52a33fd516 prog: remove default target and all global state
Now each prog function accepts the desired target explicitly.
No global, implicit state involved.
This is much cleaner and allows cross-OS/arch testing, etc.
2017-09-15 16:02:37 +02:00
Dmitry Vyukov
91def5c506 prog: remove special knowledge about "mmap" syscall
Abstract "mmap" away as it can be called differently on another OS.
2017-09-15 16:02:37 +02:00
Dmitry Vyukov
ffe7e17368 prog, sys: move types to prog
Large overhaul moves syscalls and arg types from sys to prog.
Sys package now depends on prog and contains only generated
descriptions of syscalls.
Introduce prog.Target type that encapsulates all targer properties,
like syscall list, ptr/page size, etc. Also moves OS-dependent pieces
like mmap call generation from prog to sys.

Update #191
2017-09-05 15:52:42 +02:00
Dmitry Vyukov
4fc4702694 prog: dot-import sys
In preparation for moving sys types to prog to reduce later diffs.
2017-09-05 10:46:34 +02:00
Dmitry Vyukov
399addc875 sys, pkg/compiler: move padding computation to compiler
This makes types constant during execution, everything is precomputed.
2017-09-04 20:25:23 +02:00
Dmitry Vyukov
838e336594 sys, prog: switch values to to uint64
We currently use uintptr for all values.
This won't work for 32-bit archs.
Moreover in some cases we use uintptr but assume
that it is always 64-bits (e.g. in encodingexec).
Switch everything to uint64.

Update #324
2017-08-19 10:16:23 +02:00
Alexander Potapenko
d8b0de2df3 prog: reduce the "uber-mmap" size
During minimization we create a single memory mapping that contains all
the smaller mmap() ranges, so that other mmap() calls can be dropped.
This "uber-mmap" used to start at 0x7f0000000000 regardless of where the
smaller mappings were located. Change its starting address to the
beginning of the first small mmap() range.
2017-08-08 17:57:01 +02:00
Alexander Potapenko
77825d061d prog: don't mutate mmap() calls too often
Due to https://github.com/google/syzkaller/issues/316 there're too many
mmap() calls in the programs, and syzkaller is spending quite a bit of
time mutating them. Most of the time changing mmap() calls won't give
us new coverage, so let's not do it too often.
2017-08-02 16:20:28 +02:00
Andrey Konovalov
493773c70d prog: properly remove calls when splicing progs
Use removeCall() to update use references.

Also add a test and speed up other ones.
2017-08-01 15:57:03 +02:00
Andrey Konovalov
cfc46d9d0b prog: split Arg into smaller structs
Right now Arg is a huge struct (160 bytes), which has many different fields
used for different arg kinds. Since most of the args we see in a typical
corpus are ArgConst, this results in a significant memory overuse.

This change:
- makes Arg an interface instead of a struct
- adds a SomethingArg struct for each arg kind we have
- converts all *Arg pointers into just Arg, since interface variable by
  itself contains a pointer to the actual data
- removes ArgPageSize, now ConstArg is used instead
- consolidates correspondence between arg kinds and types, see comments
  before each SomethingArg struct definition
- now LenType args that denote the length of VmaType args are serialized as
  "0x1000" instead of "(0x1000)"; to preserve backwards compatibility
  syzkaller is able to parse the old format for now
- multiple small changes all over to make the above work

After this change syzkaller uses twice less memory after deserializing a
typical corpus.
2017-07-17 14:34:09 +02:00
Andrey Konovalov
9e6516d4e9 prog: limit prog size when splicing 2017-02-01 16:47:44 +01:00
Andrey Konovalov
63b16a5d5c prog, sys: add csum type, embed checksums for ipv4 packets
This change adds a `csum[kind, type]` type.
The only available kind right now is `ipv4`.
Using `csum[ipv4, int16be]` in `ipv4_header` makes syzkaller calculate
and embed correct checksums into ipv4 packets.
2017-01-25 20:31:13 +01:00
Dmitry Vyukov
40723a067e prog: validate deserialized programs
The optimization change removed validation too aggressively.
We do need program validation during deserialization,
because we can get bad programs from corpus or hub.
Restore program validation after deserialization.
2017-01-24 10:53:21 +01:00
Andrey Konovalov
b323c5aaa9 prog: add FieldName to Type
FieldName() is the name of the struct field or union option with this type.
TypeName() is now always the name of the type.
2017-01-23 18:13:06 +01:00
Dmitry Vyukov
a7e4a49fae all: spot optimizations
A bunch of spot optmizations after cpu/memory profiling:
1. Optimize hot-path coverage comparison in fuzzer.
2. Don't allocate and copy serialized program, serialize directly into shmem.
3. Reduce allocations during parsing of output shmem (encoding/binary sucks).
4. Don't allocate and copy coverage arrays, refer directly to the shmem region
   (we are not going to mutate them).
5. Don't validate programs outside of tests, validation allocates tons of memory.
6. Replace the choose primitive with simpler switches.
   Choose allocates fullload of memory (for int, func, and everything the func refers).
7. Other minor optimizations.
2017-01-20 23:55:25 +01:00
Dmitry Vyukov
758a06c51f prog: generate larger arrays
Currently we generate arrays of size [0,5] with equal probability.
Generate [0,10] with bias towards smaller arrays. But 0 has the lowest probability.
I've benchmark a slightly different change with max array size of 20,
results are somewhat inconclusive: it was better than baseline almost all way,
but baseline suddenly caught up at the end. It also considerably reduced
executions per second (by ~20%). So increasing array size to 10 should be a win...
2017-01-20 14:56:20 +01:00
Dmitry Vyukov
c4901df5c3 prog: mutate programs more aggressively
Currently we stop mutating with 50% probability.
Stop mutating with 33% probability instead.
Benchmark shows both coverage increase and corpus reduction:

                    baseline          oneof3            diff
coverage               65467           65604             137
corpus                 35423           35354             -69
exec total           5474879         5023268         -451611
2017-01-20 14:56:20 +01:00
Dmitry Vyukov
b218a25ecb prog: mutate int arguments
Mutate int arguments instead of regenerating.
Benchmark shows strong increase of coverage:

                    baseline     mutateconst            diff
coverage               65467           65744            +277
corpus                 35423           35638            +215
exec total           5474879         5197932         -276947
2017-01-20 14:56:20 +01:00
Andrey Konovalov
109c58ef68 prog: mutate sized strings with respect to size 2017-01-18 19:16:07 +01:00
Dmitry Vyukov
bbd4840872 sys: extend kvm support
Add new pseudo syscall syz_kvm_setup_cpu that setups VCPU into
interesting states for execution. KVM is too difficult to setup otherwise.
Lots of improvements possible, but this is a starting point.
2017-01-09 20:28:10 +01:00
Andrey Konovalov
2429a7b034 sys: move sockaddr description to templates 2016-11-29 16:39:02 +01:00
Andrey Konovalov
253a40f30d sys: add proc type to denote per proccess integers 2016-11-25 17:51:41 +01:00
Andrey Konovalov
fa9c44b568 prog: minimize based on individual args 2016-11-25 17:22:42 +01:00
Andrey Konovalov
a5df734b8d fuzzer: combine progs from corpus 2016-11-25 09:58:17 +01:00
Andrey Konovalov
c1c3a73cd9 prog: fix checks for max and min len when mutating a bin blob 2016-11-22 15:56:24 +01:00
Dmitry Vyukov
3a65453870 sys: allow to specify buffer size for strings
This allows to write:
  string[salg_type, 14]
which will give a string buffer of size 14 regardless of actual string size.

Convert salg_type/salg_name to this.
2016-11-11 14:34:41 -08:00
Dmitry Vyukov
588a542b2a sys: add string flags
Allow to define string flags in txt descriptions. E.g.:

  filesystem = "ext2", "ext3", "ext4"

and then use it in string type:

  ptr[in, string[filesystem]]
2016-11-11 14:33:37 -08:00
Dmitry Vyukov
f085c198ba sys: replace FileoffType with IntType{Kind: IntFileoff}
FileoffType is effectively an int, no need for a separate type.
Also remove fd option from fileoff as it is unused and use story is unclear.
2016-11-11 14:32:38 -08:00
Dmitry Vyukov
8b731ed4b7 sys: replace FilenameType with BufferType{Kind: BufferFilename}
FilenameType is effectively a buffer, there is no need for a separate type.
2016-11-11 14:32:19 -08:00
Dmitry Vyukov
b40d502736 prog: remote Type argument from Arg.Size/Value
They are not necessary since we now always have types attached to args.
Also remove sys.Type.InnerType as it is not necessary now as well.
2016-11-11 14:31:55 -08:00
Dmitry Vyukov
1a85811d68 prog: assign types to args during construction
Eliminate assignTypeAndDir function and instead assign
types to all args during construction.
This will allow considerable simplifation of assignSizes.
2016-11-11 14:29:52 -08:00
Dmitry Vyukov
d3a93e8370 sys: attach Dir to all types
Dir is a static info, so we don't need to compute, propagate and
attach it in prog whenever we generate/change programs.
Attach Dir to all types.
2016-11-11 14:27:54 -08:00
Dmitry Vyukov
959ec07095 sys: always use pointers to types
Currently we store most types by value in sys.Type.
This is somewhat counter-intuitive for C++ programmers,
because one can't easily update the type object.
Store pointers to type objects for all types.
It also makes it easier to update types, e.g. adding paddings.
2016-11-11 14:25:13 -08:00
Andrey Konovalov
78f79fee93 Refactor & improve len type handling 2016-10-11 20:09:19 +02:00
Andrey Konovalov
c99cbdbe58 Emit BufferBlob for array[int8] 2016-10-04 18:49:57 +02:00
Dmitry Vyukov
8f1cbd29ba Merge pull request #71 from xairy/blob_mutation
Better blob mutation
2016-09-19 19:43:53 +02:00
Andrey Konovalov
f41935d53f Allow range sized arrays 2016-09-19 16:16:24 +02:00
Andrey Konovalov
705a657fbe Better blob mutation 2016-09-19 15:55:28 +02:00
Dmitry Vyukov
852e3d2eae sys: support recursive structs
A struct can have a pointer to itself directly or indirectly.
Currently it leads to inifinite recursion when generating descriptions.
Fix this.
2016-09-05 12:49:47 +02:00
Dmitry Vyukov
0d0fbbe73f overhaul syscall description generation process
This splits generation process into two phases:
1. Extract values of constants from linux kernel sources.
2. Generate Go code.

Constant values are checked in.
The advantage is that the second phase is now completely independent
from linux source files, kernel version, presence of headers for
particular drivers, etc. This allows to change what Go code we generate
any time without access to all kernel headers (which in future won't be
limited to only upstream headers).

Constant extraction process does require proper kernel sources,
but this can be done only once by the person who added the driver
and has access to the required sources. Then the constant values
are checked in for others to use.
Consant extraction process is per-file/per-arch. That is,
if I am adding a driver that is not present upstream and that
works only on a single arch, I will check in constants only for
that driver and for that arch.
2016-08-26 07:09:25 +02:00
Dmitry Vyukov
8bdf62d1b7 sys: implement array byte size arguments 2016-01-23 00:37:08 +01:00
Dmitry Vyukov
4eb9d403e8 prog: implement mutation of union args 2015-12-31 16:03:01 +01:00
Dmitry Vyukov
92bcba4b0b sys: implement fixed-size arrays 2015-12-30 19:43:15 +01:00
Dmitry Vyukov
e6529b30ec sys: add union type 2015-12-29 15:00:57 +01:00
Dmitry Vyukov
28571fdc32 prog: glue mmap's together during minimization 2015-12-23 13:47:45 +01:00
Dmitry Vyukov
c4b809f85f sys: add support for PF_ALG 2015-12-17 14:38:46 +01:00
Dmitry Vyukov
6892001bbc add tty-related ioctl's 2015-11-16 19:14:05 +01:00
Dmitry Vyukov
1334407ba4 reduce number of indirections in syscall description by using consts 2015-11-06 21:51:19 +01:00
Dmitry Vyukov
e9cf3f5aa1 minor tweaks to program generation heuristics 2015-10-20 15:46:04 +02:00