Commit Graph

49 Commits

Author SHA1 Message Date
Anton Lindqvist
8620c2c258 sys/openbsd: add ktrace description 2019-08-12 11:16:16 +02:00
Anton Lindqvist
e44fc68a53 sys/openbsd: add acct description 2019-08-12 11:16:16 +02:00
Anton Lindqvist
62d3ec4876 sys/openbsd: add speaker descriptions 2019-08-12 11:16:16 +02:00
Anton Lindqvist
919efc620a sys/openbsd: prevent swap partition device nodes from being created
Writing to the swap partition during fuzzing can lead to all kinds of
corruptions[1].

[1] https://syzkaller.appspot.com/bug?id=a2eca15e6e0be4be3ed1b0b2bab3332edc317b1c
2019-07-22 07:36:41 +02:00
Anton Lindqvist
ff7bf04c7c sys/openbsd: add diskmap descriptions 2019-07-10 22:37:39 +02:00
Anton Lindqvist
699d6448c8 sys/openbsd: add missing WSDISPLAYIO_SBURNER ioctl command 2019-06-30 20:34:23 +02:00
Anton Lindqvist
efb619c0e4 sys/openbsd: correct setrlimit resource detection
The sanitizer fails to sanitize programs like the following:

  setrlimit(0x10000000000002, &(0x7f0000000080))

... due to presence of the most significant bit. Therefore mask of all
bits that cannot form a valid rlimit resource.

This is one of the root causes of the high amount of reported "lost
connection to test machine".
2019-06-18 16:28:55 +02:00
Anton Lindqvist
442206d76b sys/openbsd: sanitize mlockall syscalls
Locking down future mappings will most likely cause syz-executor to run
out of memory.

This is one of the root causes of the high amount of reported "lost
connection to test machine".
2019-06-14 18:34:50 +02:00
Anton Lindqvist
998ccc760b sys/openbsd: rename test case 2019-06-13 18:51:26 +02:00
Anton Lindqvist
dad7ee745f sys/openbsd: sanitize setrlimit(RLIMIT_STACK) syscalls
Do not allow the stack to grow beyond the initial soft limit chosen by
syz-executor. Otherwise, syz-executor will most likely not be able to
perform any more heap allocations since they majoriy of memory is
reserved for the stack.

This is one of the root causes of the high amount of reported "lost
connection to test machine".
2019-06-13 18:51:26 +02:00
Anton Lindqvist
794a1ad73a sys/openbsd: sanitize setrlimit(RLIMIT_DATA) syscalls (#1231)
OpenBSD performs a strict validation of the RLIMIT_DATA soft limit
during memory allocation. Lowering the same limit could cause
syz-executor to run out of memory quickly. Therefore make sure to not go
lower than the default soft limit for the staff group.

This is one of the root causes of the high amount of reported "lost
connection to test machine".
2019-06-11 16:50:14 -07:00
Anton Lindqvist
0159583c3b sys/openbsd: prevent using vio0 as a virtual multicast interface
One of the root causes to reported "lost connection to test machine" is
when the egress network interface is being used as a multicast
interface:

  setsockopt$inet6_MRT6_ADD_MIF(r0, 0x29, 0x66, &(0x7f0000000180)={0x2}, 0xc)

Prevent such syscalls from being generated by limiting the range of
allowed interface indices.
2019-06-08 10:13:59 +02:00
Anton Lindqvist
73a7d55bdf sys/openbsd: add klog descriptions 2019-06-05 19:18:58 -07:00
Anton Lindqvist
6354390a82 sys/openbsd: add missing wsmouse ioctl descriptions 2019-06-05 19:18:58 -07: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
01d1494471 .golangci.yml: add codeanalysis build tag
Using a build tag to exclude files for golangci-lint
reduces memory consumption (it does not parse them).
The naive attempt with skip-dirs did not work.
So add codeanalysis build tag and use it in auto-generated files.

Update #977
2019-05-15 11:39:31 +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
Anton Lindqvist
ada3c44cd1 sys/openbsd: prevent changing mutability flags on files (#1174)
This is especially problematic for file descriptors referring to tty/pty
devices since it can cause the SSH connection to the VM to die.

The ambition here is reduce the number of "lost connection/no output" failures
at the cost of limiting the coverage of chflags(2).
2019-05-13 18:14:26 -07:00
Anton Lindqvist
5f302c04a2 sys/openbsd: add missing padding arguments
Due to missing padding arguments, stack garbage could end up being used as
actual arguments. More reading for the curious[1].

While here, add missing descriptions for pread and pwrite.

[1] https://flak.tedunangst.com/post/syzkaller-found-a-bug
2019-05-12 14:03:04 +02:00
Anton Lindqvist
c017728b48 sys/openbsd: avoid raw root disk node creation (#1171)
Writing to the raw root disk could lead to all kinds of corruptions[1].

[1] https://flak.tedunangst.com/post/syzkaller-found-a-bug
2019-05-11 13:10:47 -07:00
Anton Lindqvist
1852eb1814 sys/openbsd: add vmm descriptions (#1152)
Most probably limited to input validation for now. In the future, it
could be extended to provide a bootable kernel during vm create (/bsd)
and turn vmid into a proper resource.

The OpenBSD VMs on GCE does support vmm(4).
2019-05-01 19:30:36 -07:00
Anton Lindqvist
5701183bd3 sys/openbsd: add pci descriptions 2019-04-05 10:22:46 +02:00
Dmitry Vyukov
162bd26be4 pkg/compiler: make buffer alias to ptr[array[int8]]
Ptr type has special handling of direction (pointers are always input).
But buffer type missed this special case all the time.
Make buffer less special by aliasing to the ptr[array[int8]] type.
As the result buffer type can't have optional trailing "opt" attribute
because we don't have such support for templates yet.
Change such cases to use ptr type directly.

Fixes #1097
2019-04-01 12:46:10 +02:00
Anton Lindqvist
3e1cf9ad8a executor: connect tun and bpf devices on OpenBSD 2019-04-01 12:39:02 +02:00
Anton Lindqvist
4ba360c5fb sys/openbsd: add common ioctl() commands 2019-04-01 12:39:02 +02:00
Anton Lindqvist
98c1bf1cfb sys/openbsd: add bpf descriptions 2019-03-29 08:51:39 +01:00
Anton Lindqvist
4656becafb sys/openbsd: add chflags descriptions 2019-03-18 08:52:35 +01:00
Anton Lindqvist
c198d5ddeb sys/openbsd: add missing wscons descriptions (#976) 2019-02-01 22:01:09 -08:00
Anton Lindqvist
c73f090a5c sys/openbsd: add wscons descriptions, limited to wsdisplay for now 2019-01-26 09:31:18 +01:00
Anton Lindqvist
fc1f188563 sys/openbsd: add openat$tty 2019-01-26 09:31:18 +01:00
Anton Lindqvist
3d7ad96eb0 sys/openbsd: add openat${null,zero} 2019-01-26 09:31:18 +01:00
Anton Lindqvist
985f75cc50 sys/openbsd: remove mincore(2) description
It was recently removed from OpenBSD[1].

[1] https://marc.info/?l=openbsd-cvs&m=154723400730318&w=2
2019-01-22 09:21:03 +01:00
Anton Lindqvist
141c212ca6 sys/openbsd: avoid /dev/fd node creation
Prevent nodes that maps to an already open kcov fd from being created since
they can corrupt the coverage buffer.

Partial revert of commit 04aed72692 with some
tweaks and testing.
2019-01-19 19:22:37 +01:00
Anton Lindqvist
04aed72692 Revert "sys/openbsd: avoid /dev/fd node creation"
This reverts commit 77c702cf1a.

A proper fix has instead been committed to OpenBSD[1].

[1] 650b9bc3ab
2019-01-17 10:41:04 +01:00
Greg Steuck
77c702cf1a sys/openbsd: avoid /dev/fd node creation
Prevents corpus explosion with corrupted coverage data.

The two parallel runs of:
`doas ./syz-execprog -cover -coverfile /tmp/{fixed,unfixed} r.syz`
show markedly different coverage pictures:

unfixed:
```
2019/01/12 13:55:38 parsed 1 programs
2019/01/12 13:55:38 executed programs: 0
2019/01/12 13:55:38 call #0: signal 821, coverage 2438
2019/01/12 13:55:38 call #1: signal 243, coverage 1363
2019/01/12 13:55:38 call #2: signal 502, coverage 1993
2019/01/12 13:55:38 call #3: signal 15, coverage 44
2019/01/12 13:55:38 call #4: signal 335, coverage 8196
```

fixed:
```
2019/01/12 13:51:57 parsed 1 programs
2019/01/12 13:51:57 executed programs: 0
2019/01/12 13:51:57 call #0: signal 837, coverage 2491
2019/01/12 13:51:57 call #1: signal 241, coverage 1341
2019/01/12 13:51:57 call #2: signal 27, coverage 61
2019/01/12 13:51:57 call #3: signal 13, coverage 44
2019/01/12 13:51:57 call #4: signal 39, coverage 299
```

The contents of `r.syz` is
```
mknod(&(0x7f0000000180)='./file0\x00', 0x2006, 0x10000016e8)
r0 = open(&(0x7f0000000100)='./file0\x00', 0x0, 0x0)
mmap(&(0x7f0000000000/0x3000)=nil, 0x3000, 0x2, 0x10, r0, 0x0, 0x0)
writev(0xffffffffffffffff, &(0x7f0000002480)=[{&(0x7f0000001480)="<junk>", 0x573}], 0x1)
lstat(&(0x7f0000000240)='./file0\x00', &(0x7f0000000000))
```

So, it's the final lstat which was getting that extra coverage.  In
particular, the end of unfixed.4 has some 4734 values
0xffffffff00000000.
2019-01-14 09:48:45 +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
083e78159d sys: consistently mark all paddings as const[0] 2018-12-10 16:37:02 +01:00
Michael Tuexen
96cc4c50c3 sys/openbsd: fix socketpair usage 2018-12-09 15:31:32 +01:00
Michael Tuexen
fabb98a11f sys/openbsd: improve recvmsg() description 2018-12-08 14:48:53 +01:00
Anton Lindqvist
8bff832f48 sys/openbsd: correct semctl syscall number 2018-12-07 09:45:14 +01:00
Michael Tüxen
6ad0ae6171 sys: remove socketpair for AF_INET and AF_INET6
* OpebBSD: remove socketpair() for AF_INET and AF_INET6.

socketpair() is only supported on AF_UNIX.

* NetBSD: remove socketpair() for AF_INET and AF_INET6.

socketpair() is only supported for AF_UNIX.

* FreeBSD: remove socketpair() for AF_INET and AF_INET6.

socketpair() only supports AF_UNIX.

* Linux: remove socketpair for AF_INET and AF_INET6.

socketpair only supports AF_UNIX.

* Autogenerated files.

These are manually generated for all platforms you are not
running on. FreeBSD in this case.

* executor: rebase.

* sys/freebsd: rebase.

* sys/linux: use AF_UNIX based socketpair for nbd.

This was suggested by Dmitry.

Fixes #845
2018-12-04 08:58:22 +00: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
Greg Steuck
2f1090dacd sys/openbsd: added minherit, extended/simplified mmap
* sys/openbsd: added minherit, extended/simplified mmap.

Added a script from anton_at_openbsd.org for regenerating syscalls.

Generated by ksh ./sys/openbsd/extract-openbsd.sh

* Undo whitespace change not passing on CI

* No need for magic script.
2018-10-29 18:59:16 +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
02d481205b Makefile: format openbsd syscall descriptions 2018-09-20 11:21:51 +02:00
Anton Lindqvist
97bc7ad1b8 sys/openbsd: make SanitizeCall() idempotent
On OpenBSD, the vnode type for a device node of type S_IFMT is interpreted as
VBAD. Such vnodes often causes assertion failures inside kernel producing noisy
crashes. The goal of the OpenBSD specific SanitizeCall() is to prevent such
device nodes from being created. The S_IFMT constant is a mask covering all
possible device types, thus covering both character and block devices. Therefore
when the fuzzer generates a mknod{,at}() syscall with the S_IFMT type we cannot
known if the intent was to create a block or character device. Therefore
simplify the code to create a character device under such circumstances.

The observed failure is caused by the interaction between the OpenBSD specific
SanitizeCall() and the Unix one. The Unix sanitizer will not modify the mode
argument if it contains the S_IFMT mask. But on the second invocation when the
mode no longer contains S_IFMT it would modify it, causing a different program
to be produced. Therefore only delegate to the Unix sanitizer if the syscall is
not equal to mknod{,at}().

Regression introduces in commit b771b17e ("Add mandatory OpenBSD bits (#689)").
2018-08-31 09:06:47 -07: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
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
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