Commit Graph

75 Commits

Author SHA1 Message Date
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
Mark Johnston
5e1ad02b17 pkg/csource: Force promotion of 64-bit constant values
Constant 64-bit arguments to the variadic syscall(2) must have their
width specified explicitly.  In practice this is not necessary most of
the time, but on amd64/freebsd with clang the compiler can and does
store the constant 32-bit value to the stack, leaving garbage in the
upper 32 bits.

This makes C reproducers somewhat uglier, but I see no other solution.
2019-11-08 10:51:32 +01:00
Andrey Konovalov
792da3da86 executor, csource: adjust syz_open_dev$hiddev timeout
Looks like opening hiddev can take up to ~100 ms.
2019-09-24 10:45:51 +02:00
Andrey Konovalov
13c3a99962 sys/linux, executor: add syz_usb_ep_read syzkall
syz_usb_ep_read reads data from USB endpoints other than #0.
2019-07-01 17:26:35 +02:00
Andrey Konovalov
fa26c3cf35 sys/linux, executor: add basic USB HID fuzzing support
This commit adds the necessary descriptions and executor adjustments to
enable targeted fuzzing of the enumeration process of USB HID devices.
2019-06-24 17:24:44 +02:00
Andrey Konovalov
c054a92dde pkg/csource: generate timeouts for USB syzcalls
This patch only covers per call timeouts, per prog one is not adjusted yet.
2019-05-31 13:35:25 +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
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
munjinoo
001e36bc78 executor: change syscall argument type to intptr_t
The type size of long depends on compiler.
Therefore, changing to intptr_t makes it depends on architecture.
2019-05-07 08:48:35 +02:00
Mark Johnston
c08c1cd05c pkg/csource: sort sys/types.h to the top on FreeBSD
sys/types.h is a special header that is required by many other system
headers on FreeBSD.
2019-03-07 19:46:55 +01:00
Dmitry Vyukov
65a0d61939 pkg/host: don't fail if CONFIG_FAIL_FUTEX is not enabled
See #991 and added comments.

Fixes #991
2019-02-11 18:35:46 +01: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
7e81a53230 pkg/csource: write tracing output to stderr
stdout is not flushed on abnormal exit.
2019-01-31 11:35:53 +01:00
Dmitry Vyukov
af3175049a pkg/csource: split emitCall function
gometalinter points that emitCall is too complex.
Factor out call name emission.
2018-12-27 14:00:42 +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
e747ec987b pkg/csource: fix PRINTF removal
PRINTF now accepts arguments.
2018-12-26 22:06:07 +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
f3d9d5948c pkg/csource: support tun and setuid repros on {free,open}bsd
* expose procid on BSD for tun, always declare loop()
* deal with terrible bsd includes
* replicate loop() declaration
2018-12-13 09:44:24 +01:00
Dmitry Vyukov
c791837863 executor: fix handling of big-endian bitfields
Currently we apply big-endian-ness and bitfield-ness in the wrong order in copyin.
This leads to totally bogus result. Fix this.
2018-12-08 19:08:08 +01:00
Dmitry Vyukov
596466b38c pkg/runtest: fixes for fuchsia
Add simple fuchsia program, the one that is run during image testing.
Fix csource errno printing for fuchsia.
Fix creation of executable files (chmod is not implemented on fuchsia).
Check that we get signal/coverage from all syscalls.
2018-09-06 10:56:09 +02:00
Dmitry Vyukov
7067e78fd6 executor: fix gcc warnings in fuchsia generated code
gcc complains about function declarations not being prototypes,
signed/unsigned cast mismatch and casts between incompatible functions.
Fix them.
2018-08-19 01:53:59 +02:00
Dmitry Vyukov
fa9be14164 pkg/csource: fix 32-bit syscall calls
syscall accepts args as ellipsis, resources are uint64
and take 2 slots without the cast, which is wrong.
Cast resources to long when passing to syscall.
2018-08-09 16:05:46 +02:00
Dmitry Vyukov
5ff1f9faec pkg/csource: minor fixes
1. Print errno with %u instead of %d
2. Avoid unused var warning for syz_emit_ethernet
   when tracing is enabled.
2018-08-03 16:57:08 +02:00
Dmitry Vyukov
1baf121c2f pkg/csource: refactor generateCalls
Move call generation into a separate function.

Update #538
2018-08-02 16:57:32 +02:00
Dmitry Vyukov
8d7727990b pkg/csource: refactor call generation
Slightly reduce cyclomatic complexity.

Update #538
2018-07-31 17:05:09 +02:00
Dmitry Vyukov
b25fc7b831 pkg/csource: add option to trace syscall results
This will be needed for testing of generated programs.
2018-07-27 10:22:23 +02:00
Dmitry Vyukov
9d92841b4e pkg/csource: tidy generated code
1. Remove unnecessary includes.
2. Remove thunk function in threaded mode.
3. Inline syscalls into main for the simplest case.
4. Define main in common.h rather than form with printfs.
5. Fix generation for repeat mode
   (we had 2 infinite loops: in main and in loop).
6. Remove unused functions (setup/reset_loop, setup/reset_test,
   sandbox_namespace, etc).
2018-07-27 10:22:23 +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
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
574780b002 pkg/csource: prevent unused-result warnings
Warnings for write unused-result fire on travis,
somehow I don't get them locally.
Use the result in a fake way to prevent the warning.
2018-07-02 16:24:52 +02:00
Dmitry Vyukov
2960589335 pkg/csource: account for different types of syscalls on fuchsia 2018-06-30 13:40:00 +02:00
Dmitry Vyukov
7b45fa115b pkg/csource: support fuchsia
Lots of assorted heavylifting to support csource on fuchsia.
2018-06-29 10:47:42 +02:00
Dmitry Vyukov
6479ab2a75 Makefile, sys/targets: move all native compilation logic to sys/targets
We currently have native cross-compilation logic duplicated
in Makefile and in sys/targets. Some pieces are missed in one
place, some are in another. Only pkg/csource knows how to check
for -static support.

Move all CC/CFLAGS logic to sys/targets and pull results in Makefile.

This should make Makefile work on distros that have broken x86_64-linux-gnu-gcc,
now we will use just gcc. And this removes the need to define NOSTATIC,
as it's always auto-detected.

This also paves the way for making pkg/csource work on OSes other than Linux.
2018-06-06 10:02:03 +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
99e3b0a7e8 sys/linux: add support for reading partition tables 2018-04-01 18:29:56 +02:00
Dmitry Vyukov
8fbce0e442 executor: fix compilation warnings
SYS_memfd_create define produces warning in scource
if system headers already contain the definition (we strip all ifdefs!).
The same is true for CLONE_NEWCGROUP but we just never hit it yet.
Also fix format string for 32 bits.
Also fix potential uninit var in csource, and a missing new line.
2018-03-30 20:08:05 +02:00
Dmitry Vyukov
7c923cf8d4 sys/linux: add support for mounting filesystem images 2018-03-30 19:51:27 +02:00
Dmitry Vyukov
2675f92065 sys/linux: add cgroup descriptions 2018-03-25 12:46:05 +02:00
Dmitry Vyukov
1d19aa5799 executor: simplify initialize_tun
Remove executor_pid, enable_tun and setup_tun.
2018-02-26 17:43:13 +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
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
053171eaf2 pkg/csource: fix build of generated files
On another machine both clang and gcc produce:

test.c:163:32: error: invalid suffix "+procid" on integer constant
       *(uint32_t*)0x20001004 = 0x25dfdbfe+procid*4;

Not sure why this wasn't caught on buildbot.
2018-01-06 15:26:40 +01:00
Dmitry Vyukov
086787dd7e pkg/csource: tidy up generated code a bit
Remove dup newlines around includes.
Makes int values shorter if not hurting readability.
Increase line len to 80.
Remove {} when not needed during copyout.
2017-12-27 20:02:58 +01:00
Dmitry Vyukov
17f5c9e05f pkg/csource: add top-level repeat loop
Even if all 3 levels of processes in executor exit,
execprog will still recreate them.
Model the same in csource.
This matters when the inner process kills loop
and then everything stops.
2017-12-27 09:18:26 +01:00
Dmitry Vyukov
c1d8c1b352 pkg/csource: simplify generated code
We already have procid variable, no need to introduce i.
2017-12-27 09:18:26 +01:00
Dmitry Vyukov
b7b7ac19fd executor: check format strings
I see a crash which says:

	#0: too much cover 0 (errno 0)

while the code is:

	uint64_t n = ...;
	if (n >= kCoverSize)
		fail("#%d: too much cover %u", th->id, n);

It seems that the high part of n is set, but we don't see it.

Add printf format attribute to fail and friends and fix all similar cases.
Caught a bunch of similar cases and a missing argument in:

exitf("opendir(%s) failed due to NOFILE, exiting");
2017-12-27 09:18:26 +01:00
Dmitry Vyukov
8e40909025 pkg/csource: mimic the way syscalls are scheduled in executor
Currently csource uses completely different, simpler way of scheduling
syscalls onto threads (thread per call with random sleeps).
Mimic the way calls are scheduled in executor.

Fixes #312
2017-12-22 18:55:38 +01:00
Dmitry Vyukov
3645389673 pkg/csource: fix handling of proc types
Generated program always uses pid=0 even when there are multiple processes.
Make each process use own pid.

Unfortunately required to do quite significant changes to prog,
because the current format only supported fixed pid.

Fixes #490
2017-12-22 11:59:46 +01:00
Dmitry Vyukov
6f298a18e5 pkg/csource: limit thread stacks
We always set RLIMIT_AS to 128MB. I've debugged a program with 21 syscalls.
With collide it creates 42 threads. With default stack size of 8MB this
requires: 42*8 = 336MB. Thread creation fails and nothing works.
Limit thread stacks the same way executor does.

Fixes #488
2017-12-22 11:59:46 +01:00
Dmitry Vyukov
7b62abdb0a pkg/csource: fix string escaping bug 2017-12-22 11:59:46 +01:00