Commit Graph

184 Commits

Author SHA1 Message Date
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