Commit Graph

72 Commits

Author SHA1 Message Date
Dmitry Vyukov
5ed76afa81 pkg/compiler: check for unused resources
If a resource is never used as an input, it is not useful.
It's effectively the same as using an integer.
Detect such cases, they are quite confusing.
Fix all existing errors in descriptions.
This uncovered some interesting bugs as well,
e.g. use of a completely unrelated fd subtype after copy-paste
(while the resource that was supposed to be used there is completely unused).
2020-08-04 16:53:16 +02:00
Ayushi Sharma
8df85ed988
sys/netbsd: Adding syscalls related to mount(2),uname(2) and sockets (#1976)
* sys/netbsd: Adding syscalls related to mount(2),uname(2) and sockets

* sys/netbsd: Adding missing flags for fstatat(2)

* sys/netbsd: reordering rlimit_type

* sys/netbsd: reordering flags for stat(2) and mount(2)
2020-07-30 14:42:32 +02:00
Ayushi Sharma
512651955a
Adding ksem family of syscalls (#1972)
* sys/netbsd: adding ksem related syscalls

* sys/netbsd: adding missing header files to lwp.txt

* sys/netbsd: updating descriptions for ksem family syscalls

* sys/netbsd: updating descriptions for ksem family syscalls
2020-07-26 10:19:16 +02:00
Ayushi Sharma
ffec44b5d1
Adding stat(2) and statfs(2) related syscalls (#1855)
* sys/netbsd: adding filesystem and communication syscalls

* sys/netbsd: add fix for struct sockaddr_storage and profil(2)

* sys/netbsd: add common ioctl(2) commands

* sys/netbsd: resolving conflicts

* sys/netbsd: adding stat() and statfs() related syscalls

* sys/netbsd: adding missing flags for getfsstat(2)

Co-authored-by: Siddharth M <siddharth.muralee@gmail.com>
2020-06-26 13:26:51 -07:00
Ayushi Sharma
eabcced432
sys/netbsd: add common ioctl() commands (#1850)
* sys/netbsd: adding filesystem and communication syscalls

* sys/netbsd: add fix for struct sockaddr_storage and profil(2)

* sys/netbsd: add common ioctl(2) commands

* sys/netbsd: resolving conflicts

Co-authored-by: Siddharth M <siddharth.muralee@gmail.com>
2020-06-21 10:00:43 -07:00
Ayushi Sharma
4f2acff939
sys/netbsd: increase syscall support (#1805)
* sys/netbsd: increase syscall support

* sys/netbsd: increase syscall support fixed

* sys/netbsd: fixed mknod issue

* sys/netbsd: add fix for getdents, futimes and setpriority
2020-06-21 01:41:23 -07:00
Ayushi Sharma
b6c46f4351
sys/netbsd: adding filesystem and communication syscalls (#1826) 2020-06-17 02:40:05 -07:00
m00nbsd
954bd312f9 sys/netbsd: improve vusb.txt 2020-05-29 21:25:38 +02:00
m00nbsd
67fa1f59b8 executor: add support for USB fuzzing on NetBSD 2020-05-19 23:07:55 +02:00
Ayushi Sharma
37bccd4ed9 sys/netbsd: increase syscall support 2020-05-15 13:43:55 -07:00
Ayushi Sharma
44aa83104c
sys/netbsd: add access(2) 2020-05-11 23:18:48 -07:00
Ayushi Sharma
3b3a2b78da
sys/netbsd: add __getcwd(2) (#1725) 2020-05-11 00:03:33 -07:00
Dmitry Vyukov
ec42220e77 Makefile: generate descriptions on-the-fly
Checking in the generated descriptions files makes few things simpler,
but causes pain for pull requests: (1) PRs that touch descriptions
_always_ conflict, (2) PRs are large and harder to review,
(3) people sometimes forget to add auto-generated files.

The proposed way does not require us to hardcode lots of dependencies
in the Makefile (which is nice) and seem to work.
Let's see how it works.

The main contributor-visible consequence is that the auto-generated
files do not need to be checked-in now.

Credit for figuring the Makefile magic goes to @melver.

Fixes #1291
2020-04-30 17:18:29 +02:00
Dmitry Vyukov
0ce7569ee7 pkg/compiler: deduplicate Types in descriptions
Add prog.Ref Type that serves as a proxy for real types
and allows to deduplicate Types in generated descriptions.
The Ref type is effectively an index in an array of types.
Just before serialization pkg/compiler replaces real types
with the Ref types and prepares corresponding array of real types.
When a Target is registered in prog package, we do the opposite
operation and replace Ref's with the corresponding real types.

This brings improvements across the board:
compiler memory consumption is reduced by 15%,
test building time by 25%, descriptions size by 33%.

Before:
$ du -h sys/linux/gen
54M	sys/linux/gen

$ time GOMAXPROCS=1 go test -p=1 -c ./prog
real	0m54.200s
real	0m53.883s

$ time GOMAXPROCS=1 go install -p=1 ./tools/syz-execprog
real	0m27.911s
real	0m27.767s

$ TIME="%e %P %M" GOMAXPROCS=1 time go tool compile ./sys/linux/gen
20.59 100% 3200016
20.97 100% 3445976
20.25 100% 3209684

After:
$ du -h sys/linux/gen
36M	sys/linux/gen

$ time GOMAXPROCS=1 go test -p=1 -c ./prog
real	0m42.290s
real	0m43.230s

$ time GOMAXPROCS=1 go install -p=1 ./tools/syz-execprog
real	0m24.337s
real	0m24.727s

$ TIME="%e %P %M" GOMAXPROCS=1 time go tool compile ./sys/linux/gen
19.11 100% 2764952
19.66 100% 2787624
19.35 100% 2749376

Update #1580
2020-04-26 05:58:31 +02:00
Ayushi Sharma
2e44d63e40
sys/netbsd: add lchmod(2) (#1687) 2020-04-21 13:22:03 +02:00
Dmitry Vyukov
0781895e0f pkg/compiler: refactor attribute handling
Introduce common infrastructure for describing and parsing attribute
instead of custom per-attribute code scattered across several locations.

Change align attribute syntax from the weird align_N to align[N].
This also allows to use literal constants as N.

Introduce notion of builtin constants.
Currently we have only PTR_SIZE, which is needed to replace
align_ptr with align[PTR_SIZE].
2020-04-19 10:26:57 +02:00
Dmitry Vyukov
365fba2440 executor: surround the data mapping with PROT_NONE pages
Surround the main data mapping with PROT_NONE pages to make virtual address layout more consistent
across different configurations (static/non-static build) and C repros.
One observed case before: executor had a mapping above the data mapping (output region),
while C repros did not have that mapping above, as the result in one case VMA had next link,
while in the other it didn't and it caused a bug to not reproduce with the C repro.

The bug that reproduces only with the mapping above:
https://lkml.org/lkml/2020/4/17/819
2020-04-18 14:43:29 +02:00
Dmitry Vyukov
67234372ef prog: refactor target.MakeMmap
Make MakeMmap return more than 1 call.
This is a preparation for future changes.
Also remove addr/size as they are effectively
always the same and can be inferred from the target
(will also conflict with the future changes).
Also rename to MakeDataMmap to better represent
the new purpose: it's just some arbitrary mmap,
but rather mapping of the data segment.
2020-04-18 14:35:45 +02:00
Dmitry Vyukov
ea36da8271 sys/linux: use PROT_EXEC for the data section mmap
Turns out the mmap protection get out of sync
between executor and C reproducers.
C reproducers missed PROT_EXEC.
Add PROT_EXEC for linux, freebsd and akaros.
2020-04-18 10:33:03 +02:00
ais2397@gmail.com
c743fcb3e0 sys/netbsd: add minherit(2) 2020-04-16 07:02:15 +02:00
ais2397@gmail.com
a517e13956 sys/netbsd: fix struct stat 2020-04-13 21:20:21 +02:00
Ayushi Sharma
d9ed075d1a
sys/netbsd: adding chflags(2) syscalls (#1661) 2020-04-04 00:07:51 +02:00
Ayushi Sharma
46105100bf
sys/netbsd: adding lwp syscalls (#1654) 2020-03-31 14:14:00 +02:00
Dmitry Vyukov
80d43738f1 prog: rename target.SanitizeCall to Neutralize
We will need a wrapper for target.SanitizeCall that will do more
than just calling the target-provided function. To avoid confusion
and potential mistakes, give the target function and prog function
different names. Prog package will continue to call this "sanitize",
which will include target's "neutralize" + more.
Also refactor API a bit: we need a helper function that sanitizes
the whole program because that's needed most of the time.

Fixes #477
Fixes #502
2020-03-17 21:19:13 +01:00
Dmitry Vyukov
1ea952c9ff pkg/compiler: calculate more precise sizes for arguments
If we have:

ioctl(fd fd, cmd int32)
ioctl$FOO(fd fd, cmd const[FOO])

Currently we assume that cmd size in ioctl$FOO is sizeof(void*).
However, we know that in ioctl it's specified as int32,
so we can infer that the actual syscall size is 4.

This massively reduces sizes of socket/setsockopt/getsockopt/ioctl
and some other syscalls, which is good because we now use physical
size in mutation/hints and some other places.

This will also enable not morphing ioctl's into other ioctl's.

Update #477
Update #502
2020-03-17 21:19:13 +01:00
Dmitry Vyukov
dd56146d26 prog: remove unused ResourceDesc.Type 2020-01-26 11:30:18 +01:00
Dmitry Vyukov
55da6462ff pkg/serializer: do not write field names if it won't save space
If we are going to write all values, don't write field names.
This only increases size of generated files.
The change reduces size of generated files by 5.8%
(62870496-59410354=3460142 bytes saved).
2020-01-26 11:07:18 +01:00
Dmitry Vyukov
22535fecd5 pkg/compiler: don't mark flags with 0 as bitmask
They can't be a bitmask. This fixes important cases
of "0, 1" and "0, 1, 2" flags. Fix some descriptions
that added 0 to bitmasks explicitly (we should do it
automatically instead).
2020-01-18 21:02:24 +01:00
Dmitry Vyukov
d412ea5e8e pkg/compiler: sort flags values
Will simplify runtime analysis of flags.
Also just no reason to make it more deterministic
and avoid unnecessary diffs in future if values are reordered.
2020-01-18 21:02:24 +01:00
Siddharth Muralee
9fd5a512f3 sys/netbsd: fix the build issues with posix_spawn 2019-12-05 10:06:13 +01:00
Siddharth M
b91ea9289b make required changes to sys/netbsd 2019-12-05 10:06:13 +01:00
R3x
a734d2a6d9 sys/netbsd: add the newer vfork syscall 2019-12-05 10:06:13 +01:00
R3x
e06d2ea701 sys/netbsd: Added posix_spawn and fork syscalls 2019-12-05 10:06:13 +01:00
Paul Chaignon
997ccc675b pkg/compiler: define fileoff template
Signed-off-by: Paul Chaignon <paul.chaignon@orange.com>
2019-11-01 19:14:49 +01:00
Siddharth M
2bbe2f0558 executor: add network packet injection for NetBSD
* Initial Commit

* working build of network packet fuzzing

* Add missed csource file

* pkg/csource: fix build

* executor/common_bsd.h: Add comment stating reason for ifconfig create
2019-07-14 17:59:29 +03:00
Siddharth M
907bf74686 sys/netbsd: Adding more syscalls
* sys/netbsd: Adding more syscalls

* Added lwp create structures

* Added a few lwp flags

* completed _lwp* syscalls

* add clone syscall

* fix errors, recheck arguments
2019-07-01 12:37:45 +02:00
R3x
c0d1d69763 sys/netbsd: Add new syscalls exit and ptrace 2019-06-26 11:18:16 +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
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
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
a320ef9292 sys/netbsd: fix socketpair usage 2018-12-09 15:31:32 +01:00
Michael Tuexen
527daf788e sys/netbsd: improve recvmsg() description 2018-12-08 14:48:53 +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
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
a4718693a3 sys/linux: add syz_execute_func
The function executes random code.

Update #310
2018-08-30 21:45:04 -07:00
Dmitry Vyukov
76e7c3dfb4 sys/netbsd: use posix helper instead of copy-pasted code
We now have this common logic in sys/targets,
so use it instread of copy-pasted code.
I missed this file during the refactoring.
2018-08-25 09:05:51 -07:00
Dmitry Vyukov
d9a893a554 Makefile: don't compile all targets into target binaries
Currently target binaries contain support for all OS/arch combinations.
However, obviously a fuchsia target binary won't test windows.
For target binaries we need support only for a single target
(with the exception of 386/arm target in amd64/arm64 binaries).
So compile in only _the_ target into target binaries.
This reduces akaros/amd64 fuzzer binary from 33 to 7 MB
and execprog from 28 to 2 MB.
2018-08-02 19:07:22 +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