Commit Graph

387 Commits

Author SHA1 Message Date
Greg Steuck
d8988561c0 openbsd: repair pkg/csource_test 2018-11-30 19:55:51 +00:00
Michael Tuexen
8b13c56200 executor: Use correct macros.
Suggested by Dmitry Vyukov.
2018-11-30 13:48:23 +00:00
Michael Tuexen
9656dc4c83 executor: Fix compilation on FreeBSD.
This is an autogenerated file, but it seem that changes to it
resulting from changes in executor/common_bsd.h must also be
committed.
e
2018-11-30 13:48:23 +00:00
msvoelker
0ab8db6467 executor: FreeBSD: fixed endian.h path
The include statement for endian.h failed on FreeBSD. Changed include statement to syz/endian.h for FreeBSD.
2018-11-23 11:50:41 +01:00
Marco Vanotti
d260249e70 sys/fuchsia: update VMAR syscalls
* sys/fuchsia: update vmar syscalls.

In a previous zircon commit[0], the vmar related syscalls (like
`zx_vmar_map`, `zx_vmar_protect` and `zx_vmar_allocate`) changed the
order of their parameters, making putting the flags parameter as the
second parameter, and renaming it to "options".

This commit modifies vmars.txt so that it reflects the latest state of
the syscalls in zircon. I also modified the usage in
`executor/common_fuchsia.h`

I ran make extract, make generate and compiled syzkaller to test this
change.

[0]: https://fuchsia-review.googlesource.com/c/zircon/+/168060

* sys/fuchsia run make generate

This commit is just the result of running make generate after its
parent. This regenerates the definitions for the modified VMAR syscalls.
2018-11-21 05:56:43 +01:00
Greg Steuck
538a105600 executor: OpenBSD network package injection
Squash of:

* Doc typo

* Ported some tun related functions.

* Copy vnet.txt from linux to openbsd.

* Simplified syz_emit_ethernet and stubbed out vnet.txt.

* Undo clang-format header sorting: headers are order sensitive.

* Uniquify tap devices by pid.

* clang-format off for includes

* Happier clang-format.

* Partially revert "Uniquify tap devices by pid."

Just rely on procid magic instead of getting it from a flag.
2018-11-17 15:42:37 -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
1f38e9aef7 executor: fix inclusion of kvm arch-specific code
We use GOOS now to figure out target arch
(which can be different from host arch).
2018-10-31 13:43:54 +01:00
Zach Riggle
751b7baf94 Android: Fix sandbox implementation
My test harness for this code performed some steps that are not
performed when syz-executor is invoked directy.

Specifcally, we need to operate from a directory under /data/data,
and have the correct UID/GID set as the owner of the directory.

My test harness now correctly sets these, all sandbox operations
succeed, and loop() is invoked.
2018-10-12 16:39:26 +02:00
Scott Graham
5f818b4b9f executor: Fuchsia: Use zx_task_resume_from_exception()
zx_task_resume() is deprecated; switch to using
zx_task_resume_from_exception() instead.
2018-10-10 19:45:24 +02:00
Dmitry Vyukov
adedaf77a1 executor: tune memcg container logic
The current memcg container seems to lead to lots of hangs/stalls.
Presumably the problem is with oom_score_adj and KASAN.
Executor process tree eats all memory and then the leaf process is killed
but the memory is not returned to memcg due to KASAN quarantine;
and the parent processes are protected from killing with oom_score_adj=-1000.
As the result the kernel locks up.

1. Don't use oom_score_adj=-1000. Instead bump leaf process score to 1000 (kill always).
2. Increase size of memcg to be larger than expected KASAN quarantine size.
2018-10-10 14:22:09 +02:00
Dmitry Vyukov
0c2fa87bc6 executor: fix build on newer linux distros
This sucks a lot, but ebtables.h is now broken too on Debian 4.17:

ebtables.h: In function ‘ebt_entry_target* ebt_get_target(ebt_entry*)’:
ebtables.h:197:19: error: invalid conversion from ‘void*’ to ‘ebt_entry_target*’
2018-09-27 15:34:52 +02:00
Alexander Popov
0e7547d77c executor: make the debug output useful for race condition debugging
Sometimes race conditions are reproduced by syz-execprog and are not
reproduced by the programs generated with syz-prog2c. In such cases
it's very helpful to know when exactly the fuzzing syscalls are executed.

Unfortunately, adding timestamps to the output of the original 'debug'
mode doesn't work. This mode provides very verbose output, which slows
down executor and breaks the repro.

So let's make the executor debug output less verbose and add
the timestamps.

Signed-off-by: Alexander Popov <alex.popov@linux.com>
2018-09-24 14:55:35 +02:00
Dmitry Vyukov
6c662d569b executor: fix build
Move debug_dump_data back to executor.cc.
debug_dump_data in common_linux.h does not play well
with pkg/csource debug stripping logic. It strips a large
random piece of code since it thinks debug_dump_data
definition is actually debug_dump_data call site.
2018-09-20 14:46:58 +02:00
Anton Lindqvist
5f78ab4b81 executor: move debug_dump_data() into common_linux.h
Compiling the executor on OpenBSD currently fails:

  executor/executor.cc:1316:6: error: unused function 'debug_dump_data'
2018-09-20 11:17:14 +02:00
Dmitry Vyukov
98f4a9612d executor: make sandboxes more modular
Currently we have a global fixed set of sandboxes,
which makes it hard to add new OS-specific ones
(all OSes need to updated to say that they don't
support this sandbox).
Let it each OS say what sandboxes it supports instead.
2018-09-17 11:39:04 +02:00
Zach Riggle
0eca949a6c RFC: android: Add support for untrusted_app sandboxing (#697)
executor: add support for android_untrusted_app sandbox

This adds a new sandbox type, 'android_untrusted_app', which restricts
syz-executor to the privileges which are available to third-party applications,
e.g. those installed from the Google Play store.

In particular, this uses the UID space reserved for applications (instead of
the 'setuid' sandbox, which uses the traditional 'nobody' user / 65534)
as well as a set of groups which the Android-specific kernels are aware of,
and finally ensures that the SELinux context is set appropriately.

Dependencies on libselinux are avoided by manually implementing the few
functions that are needed to change the context of the current process,
and arbitrary files.  The underlying mechanisms are relatively simple.

Fixes google/syzkaller#643

Test: make presubmit
Bug: http://b/112900774
2018-09-17 11:33:11 +02:00
Dmitry Vyukov
fd85ed4885 pkg/runtest, pkg/csource: don't run tests on openbsd
The tests are currently broken on openbsd.
2018-09-17 10:59:06 +02:00
Dmitry Vyukov
e3d1d545d3 executor: reset oom_score_adj for test process
oom_score_adj is inherited, so we need to reset it to 0.
2018-09-11 12:39:25 +02:00
Dmitry Vyukov
f167cb6b09 executor: sandbox with memory/pid cgroups
Set limit of 32 pids and 200MB per test process.
This should prevent things like fork bombs and frequent OOMs.

Fixes #589
2018-09-10 16:19:47 +02: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
a4718693a3 sys/linux: add syz_execute_func
The function executes random code.

Update #310
2018-08-30 21:45:04 -07:00
Anton Lindqvist
b771b17ec9 Add mandatory OpenBSD bits (#689)
all: add openbsd support

squash of the following commits:

* openbsd: add mandatory bits
* report: add OpenBSD support
* executor: skip building kvm on OpenBSD
* executor: add OpenBSD support
Linking against libutil is necessary due to usage of openpty(3).
* executor: fix typo in fail() message
* fixup! report: add OpenBSD support
* fixup! openbsd: add mandatory bits
* fixup! openbsd: add mandatory bits
* fixup! openbsd: add mandatory bits
* fixup! report: add OpenBSD support
* gometalinter: skip sys/openbsd
2018-08-28 10:07:26 -07: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
1fb62d5815 executor: fix FS_XFLAG_IMMUTABLE for 32-bit mode
FS_IOC_FSSETXATTR is not supported in compat mode, use FS_IOC_SETFLAGS instead.
2018-08-09 16:05:46 +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
3a2fe60529 executor: fix cgroups
1. Create per-proc cgroup in executor.
2. Setup cgroups after chdir into test dir
   (it assumes relative paths against test dir).
3. Add test.
2018-08-09 16:05:46 +02:00
Dmitry Vyukov
922e8e2734 executor: mount binfmt_mist
We forgot to mount binfmt_misc. Mount it. Add a test.
Increase per-call timeout, otherwise last execve timesout.
Fix csource waiting for call completion at the end of program.
2018-08-09 16:05:46 +02:00
Dmitry Vyukov
acf31536e9 executor: clean up immutable dirs
Turns out dirs can be immutable too.

Update #650
2018-08-09 16:05:46 +02:00
Dmitry Vyukov
23b45a7525 executor: remove unnecessary hooks on fuchsia
These are not needed now.
2018-08-09 16:05:46 +02:00
Dokyung Song
2eeda842c8 sys/fuchsia: add syscall description for binding channels to Launcher 2018-08-08 19:31:56 +02:00
Dmitry Vyukov
17a0470620 executor: manually define struct fsxattr
It should be in <linux/fs.h> but is not there on some distros/arches as expected.

Travis build fails with:

      		<stdin>: In function ‘remove_dir’:
        		<stdin>:152:13: error: variable ‘attr’ has initializer but incomplete type
        		<stdin>:152:13: error: excess elements in struct initializer [-Werror]
        		<stdin>:152:13: error: (near initialization for ‘attr’) [-Werror]
        		<stdin>:152:21: error: storage size of ‘attr’ isn’t known
        		<stdin>:153:20: error: ‘FS_IOC_FSSETXATTR’ undeclared (first use in this function)
        		<stdin>:153:20: note: each undeclared identifier is reported only once for each function it appears in
        		<stdin>:152:21: error: unused variable ‘attr’ [-Werror=unused-variable]
        		cc1: all warnings being treated as errors

https://travis-ci.org/google/syzkaller/jobs/413574080
2018-08-08 17:04:50 +02:00
Dmitry Vyukov
d46deef51c executor: clean up immutable files
Fixes #650
2018-08-08 15:06:29 +02:00
Dmitry Vyukov
91e4f273d6 pkg/csource: don't do checkpoint/reset net with setuid sandbox
Missing part of
"executor: don't checkpoint/reset net namespace with setuid sandbox"
2018-08-08 15:02:25 +02:00
Dmitry Vyukov
ddeb9f8d88 executor: don't checkpoint/reset net namespace with setuid sandbox
After setuid the process won't have rights to reset net namespace,
but it should not be able to change it during fuzzing too.
So just skip that part.
2018-08-08 11:16:54 +02:00
Dan Austin
14f8a76fe7 executor: checkpoint net namespace in the right namespace
With checkpoint_net_namespace moved to setup_common,
and Android fuzzing session terminates prematurely due to
ipv4_tables not being initialized at this time.
Moving the call back to loop fixes this behavior.
2018-08-08 11:03:33 +02:00
Dmitry Vyukov
1beb81367c executor: check write return value
gcc complains:

error: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Werror=unused-result]

Also fix includes.
2018-08-05 13:05:47 +02:00
Dmitry Vyukov
3a7200e49b executor: abort fuse connection
If the test process is not dying after 100ms,
abort all fuse connections in the system.
This gets rid at least of simple fuse deadlocks,
let's see how well this works in all cases.
2018-08-04 17:50:58 +02:00
Dmitry Vyukov
78e3ad98f6 sys/test: add more tests
Add syz_errno syscall which sets errno to the argument,
and add a test with different errno values.
This mostly tests the testing infrastructure itself.

Add syz_compare syscall which compare two blobs,
this can be used for testing of argument memory layout.

Implement syz_mmap and fix Makefile to allow building syz-execprog for test OS.
Useful for debugging.

Update #603
2018-08-03 19:53:14 +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
41beddb6da executor: extend logging in netfilter code
We see some failures there, extend logging so that it's least
possible to understand what exactly call has failed.
2018-08-02 19:45:31 +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
3c5c9177b5 pkg/csource: refactor defineList
Make it simpler and shorter.

Update #538
2018-08-02 16:57:32 +02:00
Dmitry Vyukov
fbedd425b5 pkg/mgrconfig: move from syz-manager/mgrconfig
mgrconfig was used only by syz-manager initially,
but now it's used by a dozen of packages and it's
weird to import from under a binary dir.
pkg/ is much more reasonable dir for a widely used
helper package.
2018-08-02 16:57:32 +02:00
Dmitry Vyukov
efc2683657 pkg/csource: rafactor option checking
Update #538
2018-07-31 18:43:45 +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
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
b8bd991ee2 executor: make current_time_ms/sleep_ms
Fix conditions for when current_time_ms/sleep_ms are used
and make them static.
2018-07-30 11:17:44 +02:00
Dmitry Vyukov
a43c5ed638 pkg/csource: turn off 32-bit tests
Test OS fails the same was as linux on travis.
2018-07-27 13:48:44 +02:00
Dmitry Vyukov
9faf980ad5 executor: disable clang-format for some parts
clang-format badly mishandles this part,
moreover different versions mishandle it differently.
2018-07-27 13:48:44 +02:00
Dmitry Vyukov
788351b1b0 pkg/csource: rewrite gen.sh in Go
Shell files cause portability problems.
On Linux it's hard to install /bin/sh,
/bin/bash is not present on *BSD.
Any solution is hard to test on Darwin.
Don't even want to mention Windows.

Just do it in Go.
2018-07-27 10:22:23 +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
c3da5dc5e0 executor: simplify event_timedwait
We always have current_time_ms in event_timedwait
so use it instead of manual clock_gettime calls
which tend to be bulkier.
2018-07-27 10:22:23 +02:00
Dmitry Vyukov
22105302cc executor: ignore unshare errors in setuid sandbox
We already do this in sandbox=none, but forgot about setuid.
2018-07-27 10:22:23 +02:00
Dmitry Vyukov
ad155aa428 pkg/csource: say what compiler is missing 2018-07-25 10:44:45 +02:00
Dmitry Vyukov
3cbc0ac516 pkg/csource: tun/cgroups are linux-specific 2018-07-25 10:39:29 +02:00
Anton Lindqvist
9182049979 pkg/csource: remove /bin/bash assumption
OpenBSD and probably other BSDs does not ship with /bin/bash. This particular
script runs fine with regular /bin/sh.
2018-07-25 08:30:07 +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
92a4950507 pkg/host: add "network devices" feature
Linux executor sets up some network devices for testing,
detect when that's supported on the machine and don't
do it if it's not supported.
2018-07-13 12:46:32 +02:00
Dmitry Vyukov
95e7a88b97 sys/linux: implement fuse as normal syscalls
Remove syz_fuse* and implement them as normal syscalls.
We not have enough expressive power to form mount options.
2018-07-10 16:18:45 +02:00
Dmitry Vyukov
7004c9c8a8 executor: tweaks for better 9p testing
See the added comments.
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
c9a7a4dccd executor: executor fix fuchsia build 2018-07-07 19:08:38 +02:00
Dmitry Vyukov
3e6e034413 executor: repair akaros support 2018-07-05 10:44:34 +02:00
Dmitry Vyukov
c32749f1e8 pkg/csource: disable most features on akaros
Akaros does not support tun, fault injections, sandboxes, etc.
2018-07-05 10:44:34 +02:00
Dmitry Vyukov
0dee9249b7 executor: remove unnecessary parens 2018-07-05 10:44:34 +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
b7d8ccf74f executor: include more headers on fuchsia
Since we are taking address of functions in syscall table,
we need all headers even if we don't use them directly.
2018-06-30 17:28:48 +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
65c456e595 pkg/csource: don't use pthread_cond_timedwait for fuchsia
We removed it in executor, do the same in csource.
2018-06-30 13:32:05 +02:00
Dmitry Vyukov
9dd8cf63e0 executor, pkg/ipc: support output over pipes 2018-06-29 16:33:07 +02:00
Dmitry Vyukov
346edcb763 executor: fix pid check after fork 2018-06-29 11:45:59 +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
3f9c293199 executor: don't crash during tun setup if ipv6 is not enabled
Some options that tun initialization sets up are optional.
Don't fail if they are missing in kernel.
2018-06-26 13:47:21 +02:00
Dmitry Vyukov
c31f96a8c6 executor: rework fallback coverage
We have fallback coverage implmentation for freebsd.
1. It's broken after some recent changes.
2. We need it for fuchsia, windows, akaros, linux too.
3. It's painful to work with C code.

Move fallback coverage to ipc package,
fix it and provide for all OSes.
2018-06-22 16:40:45 +02:00
Dmitry Vyukov
ef9ddfbe36 executor: handle case when AF_INET is not enabled
No AF_INET is somewhat crazy, but why not.
2018-06-22 16:40:45 +02:00
Dmitry Vyukov
deb0e69e10 executor: always use errors=continue when mounting ext2/3/4
For ext2/3/4 we have to have errors=continue because the image
can contain errors=panic flag and can legally crash kernel.

Fixes #599
2018-06-11 12:12:01 +03:00
Dmitry Vyukov
645e75f803 executor: make syscall table and number constant
We see some crashes that suggest corruption of the syscall number:

invalid command number 1296 (errno 11)
invalid command number 107 (errno 110)

Make the table and the number constant to prevent corruption.
2018-06-07 15:32:30 +02:00
Dmitry Vyukov
606f9a96d8 pkg/csource: allow to build source fom memory
In most cases we have source in memory,
so provide a function to build right from memory
without creating temp files.
2018-06-06 10:30:54 +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
738d58ade0 pkg/csource: minimize netdevices and net reset
Add separate options to minimize netdevices setup and net namespace reset.

Fixes #581
2018-05-17 19:57:54 +02:00
Dmitry Vyukov
3717901c10 pkg/csource: serialize options into json
Current format is painful to parse after changes.
Switch to json.
2018-05-17 19:07:46 +02:00
Dmitry Vyukov
9fb3ae4dfd pkg/osutil: introduce TempFile helper
Introduce TempFile helper and use it in several packages.
2018-05-14 11:17:23 +02:00
Ioana Ciornei
481f030ccd executor: fix strncpy compile error
gcc8 is stricter when dealing with strings and strncpy and demands that
the size of the actual string to be copied to be explicitly smaller than
the size of the destination, just to make sure the NULL terminator is
taken into considerantion. This patch fixes the issue.

Signed-off-by: Ioana Ciornei <ciorneiioana@gmail.com>
2018-05-13 16:27:22 +02:00
Dmitry Vyukov
045bbd4afb pkg/csource: fix test exit code 2018-05-07 20:40:44 +02:00
Dmitry Vyukov
02e3401638 pkg/csource: skip tests under race detector
csource tests consume too much memory under race detector (>1GB),
and periodically timeout on Travis. So we skip them.
2018-05-07 20:27:06 +02:00
Dmitry Vyukov
bdff58b1a1 pkg/csource: reduce test size
The test times out on travis:

https://travis-ci.org/google/syzkaller/jobs/375965899
https://travis-ci.org/google/syzkaller/jobs/375965900
2018-05-07 19:24: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
4c24e4a467 gometalinter: enable package comment checking
Update #538
2018-05-03 13:53:01 +02:00
Dmitry Vyukov
37e76fe20b pkg/scource: rename compiled binary to syz-executor
We call the binary syz-executor because it sometimes shows in bug titles,
and we don't want 2 different bugs for when a crash is triggered during
fuzzing and during repro.
2018-04-24 19:17:07 +02:00
Dmitry Vyukov
bf2018dd07 executor: don't fail when ipv6 is not enabled
Check in checkpoint_iptables is not enough as
reset_iptables will fail even if no tables enabled.
Add similar check to reset_iptables.
2018-04-20 20:14:10 +02:00
Dmitry Vyukov
e5453dd396 executor: increase max image size to 128MB
Images of some filesystems need to be that large (xfs, btrfs, f2fs).
2018-04-19 16:59:49 +02:00
Dmitry Vyukov
f24e540fe5 executor: don't fail if IPv6 is not enabled 2018-04-16 21:11:10 +02:00
Hangbin Liu
0a0c5db668 executor: add two slave interfaces for bridge,bond,team
Bridge device is used for forwarding. Bond/team device is used for
load balance and fail over. So it would make more sense to add two
slave interfaces for these devices.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2018-04-13 09:38:31 +02:00
Dmitry Vyukov
9cd56d71a8 sys/linux: add veth devices to devnames
Also comment new veth code for future me.
2018-04-11 11:36:25 +02:00
Hangbin Liu
a9b12a986c executor: add salve interface for bond0/team0
Add a veth pair with name bond/team_slave and set their master
to bond0/team0.

Remove veth from devtypes because the cmd `ip link add veth0 type veth`
will actually failed with "RTNETLINK answers: File exists" and no veth
interface created. When create veth device, kernel will create a
pair of veth, so no need to create them one by one.

Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
2018-04-11 11:18:45 +02:00
Dmitry Vyukov
8e4c2e24cb executor: create team device 2018-04-06 17:28:33 +02:00
Dmitry Vyukov
676bd07e7e sys/linux: test various binfmt's in execve 2018-04-02 20:10:48 +02:00
Dmitry Vyukov
dc88925771 executor: fix unchecked result warning 2018-04-01 18:49:53 +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
bf5e585c5e executor: rework cgroups support
Turns out creating a cgroup per test is too expensive.
Moreover, it leads to hanged tasks as cgroup destruction
is asynchronous and overloads kernel work queues.

Create only a single cgroup per proc, but restrict
descriptions to mess with that single group,
instead test processes create own nested cgroups for messing.
2018-03-27 11:39:58 +02:00
Dmitry Vyukov
60d6f956a2 executor: fix reset of bridge netfilter
We left entries non-zero, so memcmp always failed.
2018-03-25 12:46:05 +02:00
Dmitry Vyukov
2675f92065 sys/linux: add cgroup descriptions 2018-03-25 12:46:05 +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
11cf581658 executor: fix ifdef's for csource
There is test failure on travis:
https://travis-ci.org/google/syzkaller/jobs/349948391
I can't reproduce it locally, and it only happened on 1.8, but not on 1.9?
But this seems to be what could have provoked such failure.
2018-03-07 10:50:09 +01:00
Dmitry Vyukov
bbd5104f06 executor: fix includes
We use errno, vaargs, printf in all of fail/error/exitf,
but we include the corresponding headers only when SYZ_USE_TMP_DIR.
Include them whenever fail/error/exitf are used.
2018-03-05 12:59:12 +01:00
Dmitry Vyukov
42467f5b7b sys/linux: add syz_init_net_socket syscall
The new pseudo syscall allows opening sockets that can only
be created in init net namespace (BLUETOOTH, NFC, LLC).
Use it to open these sockets.

Unfortunately this only works with sandbox none at the moment.
The problem is that setns of a network namespace requires CAP_SYS_ADMIN
in the target namespace, and we've lost all privs in the init namespace
during creation of a user namespace.
2018-03-05 12:10:27 +01: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
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
66cf309385 executor, pkg/csource: make fd numbers consistent
Currently when executor creates fd's it gets: 0, 3, 4.
When tun is enabled: 3, 4, 5.
For C programs: 3, 4, 5.
When run is enabled: 4, 5, 6.

Theoretically it should not matter,
but these fd numbers are probably sometimes are used as data.
So make them consistent in all these cases (3, 4, 5).
2018-02-26 15:54:02 +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
6153a72ee1 executor: bring up bond and veth devices 2018-02-22 20:16:37 +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
6051a5b552 prog: combine RequiresBitmasks and RequiresChecksums into RequiredFeatures 2018-02-19 21:48:20 +01:00
Dmitry Vyukov
833f78c7b0 executor: fix build
Older versions of linux require an additional header.
2018-02-17 19:11:57 +01:00
Dmitry Vyukov
9df1a36a98 sys/linux: add bridge netfilter support 2018-02-17 19:02:12 +01:00
Dmitry Vyukov
e67d44e011 executor: compile with -O2
We don't frequently debug it and it does some intensive computations
on coverage, so no reason to not compile with -O2.
2018-02-10 12:14:13 +01:00
Dmitry Vyukov
2b6b214cf2 pkg/csource: fix debug calls
debug calls are only properly stripped if they are on a single line.
2018-02-09 20:31:41 +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
Dmitry Vyukov
08d47756d0 executor: fix 32-bit support
ipt_get_entries.entrytable must be pointer aligned,
so in 32-bit build there is no padding before it.
2018-01-28 09:17:03 +01:00
Dmitry Vyukov
08146b1a84 sys/linux: extend netfilter descriptions 2018-01-27 17:08:43 +01:00
Dmitry Vyukov
a5b7566c4a executor: handle old and new selinux mount points 2018-01-23 12:56:00 +01:00
Dmitry Vyukov
40a6602675 sys/linux: add netfilter descriptions
Lots of TODOs and only ipv4, but some start.
2018-01-22 12:19:33 +01:00
Dmitry Vyukov
b7f99b54ae sys/linux: more selinux descriptions 2018-01-18 19:58:49 +01:00
Dmitry Vyukov
b705c02263 executor: fix tun/device setup for sandbox=namespace
For sandbox=namespace we first create network devices
and then do CLONE_NEWNS, which brings us into a new
namespace which actually does not have any of these devices.
Tun mostly worked, because we hold fd to the tun device.
However, even for tun we could not see the "syz0" device.
2018-01-15 19:09:16 +01:00
Dmitry Vyukov
212f927d3c executor: setup network devices
We test in a new network namespace, which does not have any
devices set up (even lo). Create/up as many devices as possible.
Give them some addresses and use these addresses in descriptions.
2018-01-13 12:52:09 +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
fd3e9f2b97 executor: introduce uint64/32/16/8 types
The "define uint64_t unsigned long long" were too good to work.
With a different toolchain I am getting:

cstdint:69:11: error: expected unqualified-id
  using ::uint64_t;
          ^
executor/common.h:34:18: note: expanded from macro 'uint64_t'

Do it the proper way: introduce uint64/32/16/8 types and use them.

pkg/csource then does s/uint64/uint64_t/ to not clutter code with
additional typedefs.
2017-12-27 11:15:04 +01:00
Dmitry Vyukov
34c18f5f43 executor: fix another format bug
Detected only by clang.
2017-12-27 10:21:12 +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
26cd53f078 executor: remove dead code
doexit already contains an infinite loop.
2017-12-22 13:42:27 +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
Dmitry Vyukov
d5beb42ace pkg/csource: make strings more readable
If string contains a file name or a crypto alg name,
don't escape it all to hex.
2017-12-17 11:39:14 +01:00
Dmitry Vyukov
a33677f8bf prog: use dense indexes for copyout instructions
Fixes #174
2017-12-17 11:39:14 +01:00
Dmitry Vyukov
fea5478f46 prog: add DeserializeExec
Factor out program parsing from pkg/csource.
csource code that parses program and at the same time
formats output is very messy and complex.
New aproach also allows to understand e.g.
when a call has copyout instructions which is
useful for better C source output.
2017-12-17 11:39:14 +01:00
Dmitry Vyukov
431d3c90b1 pkg/csource: refactor
csource.go is too large and messy.
Move Build/Format into buid.go.
Move generation of common header into common.go.
Split generation of common header into smaller managable functions.
2017-12-17 11:39:14 +01:00
Dmitry Vyukov
019cf5f235 sys: move test syscalls to a separate target
We have them in linux solely for historical reasons.

Fixes #462
2017-12-17 11:39:14 +01:00
Andrey Konovalov
ea8dc17ee9 executor: fix macros in common.h 2017-12-14 08:54:55 +01:00
Dmitry Vyukov
71ac44a0c2 executor: fix build
exitf function was not defined with some combinations of options in csource.
Fix defines and switch exitf back to fail, fail already checks ENOMEM/EAGAIN,
so there is no reason to use exitf in this particular case.
2017-12-06 10:34:58 +01:00
Dmitry Vyukov
8257de047b sys/linux: open files from /proc 2017-11-27 09:08:59 +01:00
Dmitry Vyukov
7061d1973b sys/syz-extract: fix mmap on arm
__NR_mmap is missing on arm entirely,
so we disable mmap during generate.
Patch mmap to mmap2 right in syz-extract,
so that mmap is never missing.
2017-11-23 08:51:04 +01:00
Dmitry Vyukov
fba338cd51 pkg/csource: add function to parse serialized options
Also move options and options tests into a separate file,
add serialization function.
2017-11-17 17:57:51 +01:00
Dmitry Vyukov
c4d43f4773 pkg/osutil: don't leace runaway processes
When manager is stopped there are sometimes runaway qemu
processes still running. Set PDEATHSIG for all subprocesses.
We never need child processes outliving parents.
2017-11-16 12:48:02 +01:00
Andrey Konovalov
dd1609f876 executor: proceed even if /dev/net/tun is not available
For some racy bugs syzkaller can generate a C reproducer with tun
enabled, when it's not actuallly required to trigger the bug.
Some kernel developers (that don't have CONFIG_TUN=y on their setups)
complain about such C repros.
When tun is not available, instead of exiting, print a message that tun
initialization failed and proceed.
2017-11-08 17:43:40 +01:00
zoulasc
0460a8dda0 csource: Fix sed(1) invocation
There is no need to specify '-' as the filename for sed(1):
- The default behavior is to read stdin
- It was not done in all places
- It breaks on NetBSD sed(1) (although I am tempted to fix it now :-)
  and it does not work
2017-11-06 11:27:45 +03:00
Dmitry Vyukov
636a4dbf38 pkg/csource: add freebsd/netbsd support 2017-10-26 15:31:23 +02:00
Dmitry Vyukov
3704c60135 executor: fix build breakages due to doexit
Some standard libraries contain "using ::exit;",
which breaks with the current redefinition of exit.
2017-10-19 11:06:05 +02:00
Dmitry Vyukov
c2337c94bf executor: fix akaros nonfailing mode 2017-10-16 14:21:54 +02:00
Dmitry Vyukov
85b1f93f8d executor, pkg/ipc: unify ipc protocol between linux and other OSes
We currently use more complex and functional protocol on linux,
and a simple ad-hoc protocol on other OSes.
This leads to code duplication in both ipc and executor.
Linux supports coverage, shared memory communication and fork server,
which would also be useful for most other OSes.

Unify communication protocol and parametrize it by
(1) use of shmem or only pipes, (2) use of fork server.

This reduces duplication in ipc and executor and will
allow to support the useful features for other OSes easily.

Finally, this fixes akaros support as it currently uses
syz-stress running on host (linux) and executor running on akaros.
2017-10-16 14:21:54 +02:00
Dmitry Vyukov
f78642861b pkg/csource: support akaros 2017-10-16 14:21:54 +02:00
Dmitry Vyukov
f0565e6231 executor: write debug output to stderr
We print all other output to stderr, write debug output to stderr as well.
This does not matter for the main use case of running syz-execprog -debug,
but can is helpful if we want to communicate with syz-executor via stdin/stdout.
2017-10-16 14:21:54 +02:00
Dmitry Vyukov
66aeb467de pkg/ipc: don't send program padding to executor
Currently we always send 2MB of data to executor in ipc_simple.go.
Send only what's consumed by the program, and don't send the trailing zeros.
Serialized programs usually take only few KBs.
2017-10-12 19:08:18 +02:00
Dmitry Vyukov
c2aee24101 executor: include missing header
writev requires <sys/uio.h>. Include it.
2017-10-10 19:03:04 +02:00
Dmitry Vyukov
179a860885 all: basic freebsd support
For now we just make Go part build for freebsd.
2017-10-02 14:17:32 +02:00
Dmitry Vyukov
eb97aa0610 executor: support fragmentation in syz_emit_ethernet
A recent linux commit "tun: enable napi_gro_frags() for TUN/TAP driver"
added support for fragmentation when emitting packets via tun.
Support this feature in syz_emit_ethernet.
2017-10-02 13:56:36 +02:00
Dmitry Vyukov
bdffe2484c executor: fix execution of windows syscalls
First, they must be called with stdcall convention.
Second, wrap them in __try/__except because they can crash.
2017-09-27 18:59:50 +02:00
Dmitry Vyukov
af442a22d9 executor, sys/windows: initial windows support 2017-09-25 15:19:06 +02:00
Dmitry Vyukov
0a5156336e pkg/csource: disable linux/386 tests
Another attempt to fix travis build.
2017-09-22 13:18:28 +02:00
Dmitry Vyukov
913d592f97 all: more assorted fuchsia support 2017-09-22 13:10:55 +02:00
Dmitry Vyukov
da1873aadd sys/targets: move targets from sys package
This breaks circular dependency between:
sysgen -> sys/linux -> sys -> sysgen
With this circular dependency it is very difficult to
update format of generated descriptions because sysgen does not build.
2017-09-15 16:02:37 +02:00
Dmitry Vyukov
19f9bc13d3 pkg/csource: support archs other than x86_64 2017-09-15 16:02:37 +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
f7b1163afb syz-manager/mgrconfig: explicitly specify target in config
Add target config parameter (e.g. linux/amd64) which controls target OS/arch.
No more explicit assumptions about target.
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
5db39ab953 sys: rename Call to Syscall
In preparation for moving sys types to prog
to avoid confusion between sys.Call and prog.Call.
2017-09-05 10:38:22 +02:00
Dmitry Vyukov
a7206b24ca pkg/compiler: check and generate types
Move most of the logic from sysgen to pkg/compiler.

Update #217
2017-09-02 13:06:53 +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
Dmitry Vyukov
32e29dda2c pkg/repro: fix invalid options minimization
Repro can generate Sandbox="namespace"/UseTmpDir=false.
This combination is broken for two reasons:
 - on second and subsequent executions of the program,
   it fails to create syz-tmp dir
 - with Procs>1, it fails right away, because all procs
   try to create syz-tmp dir

Don't generate such combination.
2017-08-09 15:41:52 +02:00
Dmitry Vyukov
8b78527436 pkg/csource, pkg/repro: filter out invalid options combinations
We currently have 2 invalid options combinations:
 - collide without threads
 - procs>1 without repeat
They are invalid in the sense that result of csource.Write
is the same for them. Filter out these combinations.
This cuts csource testing time in half and reduces repro minimization time.
2017-08-09 15:41:52 +02:00
Dmitry Vyukov
a3c5751de3 executor: sandbox with RLIMIT_MEMLOCK
Locking memory is a reasonably legitimate local DoS vector.
E.g. bpf maps allow allocation of large chunks of kernel memory
without RLIMIT_MEMLOCK, which leads to hangups.
Set RLIMIT_MEMLOCK=8MB in executor.
2017-08-08 13:24:46 +02:00
Andrey Konovalov
e83310d8a2 pkg/csource: make all usleeps random
We can't know the exact values of those sleeps in advance, they can be
different for different bugs. Making them random increases the chance that
the C repro executes with the right timings at some point.
2017-07-24 14:22:54 +02:00
Dmitry Vyukov
6231964849 pkg/csource: reformat 2017-07-05 19:45:25 +02:00
Andrey Konovalov
d50208f93e pkg/csourse: don't generate __NR_X defines for old syscalls 2017-07-05 15:46:38 +02:00
Dmitry Vyukov
a7b199253f all: use consistent file permissions
Currently we have unix permissions for new files/dirs
hardcoded throughout the code base. Some places use 0644,
some - 0640, some - 0600 and a variety of other constants.

Introduce osutil.MkdirAll/WriteFile that use the default
permissions and use them throughout the code base.

This makes permissions consistent and also allows to easily
change the permissions later if we change our minds.

Also merge pkg/fileutil into pkg/osutil as they become
dependent on each other. The line between them was poorly
defined anyway as both operate on files.
2017-07-03 14:00:47 +02:00
Dmitry Vyukov
d8daf57eca pkg/csource: regenerate 2017-06-26 15:34:54 +02:00
Dmitry Vyukov
baad3b4b02 pkg/csource: move from csource 2017-06-17 14:41:15 +02:00