Commit Graph

621 Commits

Author SHA1 Message Date
Dmitry Vyukov
2814d6b845 sys/linux: fix perf_event_attr layout 2018-03-06 19:15:44 +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
e91c118db9 sys/linux: make ifreq template, fix some usages 2018-03-05 12:10:27 +01:00
Dmitry Vyukov
70a1ddb939 prog: harden program parsing against description changes more
Handle most of type changes, e.g. const is changed to struct,
or struct to pointers. In all these cases we create default args.
They may not give the coverage anymore, but still better than
losing them right away.
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
bd5df8f49b prog: handle excessive args and fields during program parsing
Tolerate excessive args and fields during program parsing.
This is useful after description changes to not lose corpus.
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
f027f1a3f7 sys/linux: use size attributes on structs
1. Add size attribte on sockaddr.
2. Remove sockaddr's that are larger than 16 bytes from sockaddr.
3. Add size attribute on sockaddr_storage which wasn't actually 128 bytes.
4. Add size attribute to ifreq.
5. Fix ifmap field types as uncovered by the size attributes.
6. Fix sockaddr_storage_tcp from struct to union which is should be.
7. Make sockaddr_un_file fixed size as it should be.
8. Fix some explicit paddings that were only correct for 64 bits.
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
002cecf202 pkg/compiler: allow specifying static size for filename's
Sometimes filenames are embed into structs and need to take fixed space.
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
5ef8dbdf5a pkg/compiler: support size attribute for unions 2018-03-05 12:10:27 +01:00
Dmitry Vyukov
a339951e5f pkg/compiler: add size attribute for structs
The size attribute allows to pad a struct up to the specified size.
2018-03-05 12:10:27 +01:00
Dmitry Vyukov
db01d57e91 sys/linux: a bunch of assorted improvements and fixes 2018-03-05 12:10:27 +01:00
Dmitry Vyukov
2c6f473e0f sys/linux: add remaining aux netfilter descriptions 2018-03-01 19:26:53 +01:00
Dmitry Vyukov
b370d4a70c sys/linux: few assorted additions 2018-02-26 20:37:42 +01:00
Dmitry Vyukov
6284466bc9 prog: properly squash bitfields 2018-02-26 18:21:51 +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
67f0e5ba11 sys/linux: make tcp_seq_num asymmetric
Currently it's 0x42424242 so it's not possible to understand
the value endianess in hints code.
Make it assymmetric so that endinaness is clear.
2018-02-26 15:58:19 +01:00
Dmitry Vyukov
9fe8aa42c5 prog: add arbitrary mutation of complex structs
Squash complex structs into flat byte array and mutate this array
with generic blob mutations. This allows to mutate what we currently
consider as paddings and add/remove paddings from structs, etc.
2018-02-25 18:22:02 +01:00
Dmitry Vyukov
2145057cb8 pkg/compiler: fix alignment corner case
Fix alignemnt calculation for packed structs with alignment and bitfields.
Amusingly this affected only a single real struct -- ipv6_fragment_ext_header.
2018-02-25 14:44:29 +01:00
Dmitry Vyukov
1f4ae3f413 pkg/compiler: don't assign call IDs statically
IDs change whenever a call is added or removed,
this leads to large diffs unnecessarly.
Assign IDs dynamically.
2018-02-25 14:31:40 +01:00
Dmitry Vyukov
44f66b4026 prog: return concrete arg types from Make functions
This removes a bunch of type assertions and makes code type safer.
2018-02-24 17:00:34 +01:00
Dmitry Vyukov
7a7c747c6f pkg/compiler: allow unions as syscall arguments
If all union options can be syscall arguments,
allow the union itself as syscall argument.
2018-02-23 13:50:02 +01:00
Dmitry Vyukov
e229ac7779 sys: fix descriptions for strickter return type checks
Mostly remove vma as return from some mm syscalls.
This is unnecessary and we never used these.
2018-02-23 13:42:41 +01:00
Dmitry Vyukov
3be86de046 sys/linux: prevent programs from doing arbitrary writes with ARCH_SET_FS 2018-02-23 11:55:37 +01:00
Dmitry Vyukov
8d8e249484 sys/linux: add AF_SMC sockets 2018-02-22 20:33:52 +01:00
Dmitry Vyukov
6153a72ee1 executor: bring up bond and veth devices 2018-02-22 20:16:37 +01:00
Dmitry Vyukov
907d649fc3 sys/linux: add few ip and tcp options 2018-02-22 20:14:36 +01:00
Dmitry Vyukov
c8e73b95c6 sys/linux: fix mmap call args
Also add a test for this.
2018-02-20 10:54:03 +01:00
Dmitry Vyukov
4b696a5daf sys/linux: minor fixes to bt descriptions 2018-02-19 21:48:20 +01:00
Dmitry Vyukov
a793204dd2 pkg/compiler: fix corner case in alignment calculation 2018-02-19 21:48:20 +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
85d1218f41 prog: rework foreachArg
Make Foreach* callback accept the arg and a context struct
that can contain lots of aux info.
This (1) removes lots of unuser base/parent args,
(2) provides foundation for stopping recursion,
(3) allows to merge foreachSubargOffset.
2018-02-19 21:48:20 +01:00
Dmitry Vyukov
9df1a36a98 sys/linux: add bridge netfilter support 2018-02-17 19:02:12 +01:00
Dmitry Vyukov
32aa64c5ac sys/syz-extract: run make with -j 2018-02-17 19:02:12 +01:00
Dmitry Vyukov
dd4fcef5a2 pkg/compiler: allow len of var-len arrays
All netfilter subsystems use this unfortunately,
so demote this to a warning.
2018-02-17 19:02:12 +01:00
Dmitry Vyukov
d21a39fc48 sys/linux: fixes for network descriptions
1. Fix connlimit netfilter match version.
2. Fix xt_time_info layout.
3. Introduce mac_addr_mask type.
4. Limit vlan id's for better matches between them.
2018-02-17 19:02:12 +01:00
Dmitry Vyukov
478746a50e sys/linux: fix field names in netfilter 2018-02-10 13:22:05 +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
Julia Hansbrough
a1bc9d40ad syz/syz-extract: Update Fuchsia extractor with current Fuchsia paths.
A change in Zircon a while back moved around where sysroots are located
in Fuchsia; this update will allow for proper extraction.
2018-02-04 12:21:23 +01:00
Dmitry Vyukov
826b35d667 sys/linux: describe some new 4.16 features 2018-02-01 21:27:02 +01:00
Dmitry Vyukov
e86ddaca2e sys/syz-extract: save unsupported consts to the const files
We currently print unsupported consts to console during make extract.
But this is not very useful as there are too many output now.
This also does not allow to understand what's unsupported
in newly checked-in descriptions, or what's unsupported in all current
decriptions.

Save unsupported consts to the const files instead.
This solves all of the above problems.
2018-02-01 20:18:51 +01:00
Dmitry Vyukov
08146b1a84 sys/linux: extend netfilter descriptions 2018-01-27 17:08:43 +01:00
Dmitry Vyukov
e8b4970547 pkg/compiler: allow unions with only 1 field
Unions with only 1 field are not actually unions,
and can always be replaced with the option type.
However, they are still useful when there will be
more options in future but currently only 1 is described.
Alternatives are:
 - not using union (but then all existing programs will be
   broken when union is finally introduced)
 - adding a fake field (ugly and reduces fuzzer efficiency)

Allow unions with only 1 field.
2018-01-27 17:08:43 +01:00
Dmitry Vyukov
9a6ff11ff9 sys/linux: fix devname_mask alignment
Since we use int64, it has 8-byte alignment.
It's wrong, it must have 1-byte alignment.
Use int8 instead.
2018-01-24 11:41:13 +01:00
Dmitry Vyukov
ef6d3c0e03 sys/linux: add IPPROTO_L2TP to vnet protos 2018-01-24 11:38:45 +01:00
Dmitry Vyukov
ca9c302d80 pkg/compiler, prog: fix template parent lens
It's possible that a struct can have 2+ parents,
which is the same template (differs only by arguments).
See the new test case.
Support such case.
2018-01-24 11:35:22 +01:00
Dmitry Vyukov
3d76cc40d9 pkg/compiler: fix len of parent template struct
Consider the following example:

type len_templ1[DATA1, DATA2] {
	data	DATA1
	inner	len_temp2[DATA2]
}

type len_temp2[DATA] {
	data	DATA
	len	len[len_templ1, int8]
}

Here len refers to a parent struct, but the struct is a template,
so it's actual name is something like "len_templ1[int8, int16]".
Currently this does not work as compiler barks at incorrect
len target.

Make this work.
2018-01-23 11:38:53 +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
fbbdcd9228 sys/linux: add AF_VSOCK/vhost descriptions 2018-01-19 20:41:18 +01:00
Dmitry Vyukov
02dc66caa8 sys/linux: add AF_RDS descriptions 2018-01-19 18:06:43 +01:00
Dmitry Vyukov
161c1d640a sys/linux: resolve TODO re KCOV consts 2018-01-18 20:11:20 +01:00
Dmitry Vyukov
ff722179da sys/linux: make xattr prefix non-zero-terminated 2018-01-18 20:00:38 +01:00
Dmitry Vyukov
b7f99b54ae sys/linux: more selinux descriptions 2018-01-18 19:58:49 +01:00
Dmitry Vyukov
a84f016776 sys/linux: don't touch mknod$loop during sanitization
mknod$loop contains proc type as dev number.
Current sanitization code truncates 64-bit -1 to 32-bits
which later causes validation failure.
Don't do that, it's unnecessary for proc type.
2018-01-16 13:43:44 +01:00
Dmitry Vyukov
e17f4a5dfb sys/linux: generate GRE v0 packets even with incorrect payload 2018-01-15 20:26:04 +01:00
Dmitry Vyukov
47501d0f3b sys/linux: more NETLINK_ROUTE descriptions 2018-01-15 20:22:27 +01:00
Dmitry Vyukov
b75f5cb3cb sys/linux: add AF_PPPOX descriptions 2018-01-15 18:39:05 +01:00
Dmitry Vyukov
66d492a6c7 sys/linux: add vnet descriptions for GRE, MPLS, CAN 2018-01-14 16:23:39 +01:00
Dmitry Vyukov
33bb46947a sys/linux: more AF_NETLINK/NETLINK_ROUTE descriptions 2018-01-14 16:23:39 +01:00
Dmitry Vyukov
36e37bdf6c sys/linux: add broadcast/multicast mac addresses 2018-01-14 16:23:39 +01:00
Dmitry Vyukov
c9e7aeaef6 sys/linux: add AF_CAN descriptions 2018-01-13 12:52:09 +01:00
Dmitry Vyukov
e9aebc0683 sys/linux: add AF_NETLINK/NETLINK_ROUTE support 2018-01-13 12:52:09 +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
a94baff95e sys/syz-sysgen: don't generate syz_ syscall numbers
They don't seem to be used today.
2018-01-13 12:52:09 +01:00
Dmitry Vyukov
1623c95de1 sys/syz-extract: don't run mrproper if already clean
mrproper takes unreasonable amount of time.
2018-01-13 12:52:09 +01:00
Dmitry Vyukov
125dadd3c9 sys/linux: use type templates for netlink
-350 lines of descriptions
2018-01-13 12:52:09 +01:00
Dmitry Vyukov
5585946e22 pkg/compiler: support void type
"void": type with static size 0
	mostly useful inside of templates and varlen unions
	can't be syscall argument
2018-01-13 12:52:09 +01:00
Dmitry Vyukov
6b52293f4d pkg/compiler: support type templates
Netlink descriptions contain tons of code duplication,
and need much more for proper descriptions. Introduce
type templates to simplify writing such descriptions
and remove code duplication.

Note: type templates are experimental, have poor error handling
and are subject to change.

Type templates can be declared as follows:

```
type buffer[DIR] ptr[DIR, array[int8]]
type fileoff[BASE] BASE
type nlattr[TYPE, PAYLOAD] {
	nla_len		len[parent, int16]
	nla_type	const[TYPE, int16]
	payload		PAYLOAD
} [align_4]
```

and later used as follows:

```
syscall(a buffer[in], b fileoff[int64], c ptr[in, nlattr[FOO, int32]])
```
2018-01-13 12:52:09 +01:00
Dmitry Vyukov
a46637766b sys/linux: regenerate arm consts + small netlink fixed
Arm was broken on upstream kernel for some time
due to some assembler error. Now it seems to be fixed,
so regenerate consts.

Also fix small issues in new netlink descriptions.
2018-01-11 11:45:22 +01:00
Dmitry Vyukov
1f60c8289d sys/linux: add AF_NETLINK/NETLINK_NETFILTER descriptions 2018-01-09 21:24:30 +01:00
Dmitry Vyukov
94f8c64d03 sys/linux: add AF_NETLINK/NETLINK_GENERIC descriptions 2018-01-09 21:24:29 +01:00
Dmitry Vyukov
93bff6656f sys/linux: duplicate open/accept specializations with openat/accept4
open is not present on arm64, only openat.
accept is not present on 386, only accept4.
Duplicate all open/accept specializations with
corresponding openat/accept4 specializations
to enable testing on 386/arm64.
2018-01-09 21:24:29 +01:00
Dmitry Vyukov
0b470f2254 sys/linux: add AF_NETLINK/NETLINK_CRYPTO descriptions 2018-01-09 21:24:29 +01:00
Dmitry Vyukov
7166c86520 sys/linux: add ion and ashmem devices support
Note: ion supercedes the old android interface,
which is moved to sys/android.
2018-01-09 21:24:28 +01:00
Dmitry Vyukov
0ae499850c sys/linux: add type aliases for complex xfrm types 2018-01-08 12:52:31 +01:00
Dmitry Vyukov
95a1be6aa4 sys/linux: resolve few TODOs 2018-01-08 12:52:31 +01:00
Dmitry Vyukov
8ac12551c2 sys/linux: add type alias for socket port
type sock_port proc[20000, 4, int16be]

That was repeated a few times.
2018-01-08 12:52:31 +01:00
Dmitry Vyukov
f01cb93788 pkg/compiler: make signalno a type alias
We don't need compiler support for such things anymore,
now we simply can do:

type signalno int32[0:65]
2018-01-08 12:52:31 +01:00
Dmitry Vyukov
a8927abe6c prog: support opt for proc types 2018-01-06 17:40:49 +01:00
Dmitry Vyukov
8a67aa70b0 prog: add test for len mutation
Test we actually can get an unnatural len value.
2018-01-06 17:40:43 +01:00
Dmitry Vyukov
8e6b9eeb27 pkg/compiler: add bitsize type
This is need for few crypto/xfrm descriptions.
2018-01-06 17:40:36 +01:00
Dmitry Vyukov
6bfd4f1979 sys/linux: netlink xfrm support 2017-12-31 12:11:12 +01:00
Dmitry Vyukov
bb6384b81a sys/linux: add multicast and ipv4 mapped ipv6 addresses 2017-12-29 22:14:12 +01:00
Dmitry Vyukov
dde1ffd49b sys/linux: describe ipv6 tlv options 2017-12-29 18:50:08 +01:00
Dmitry Vyukov
c25d74ee51 sys/linux: improve bpf descriptions 2017-12-29 17:24:21 +01:00
Dmitry Vyukov
b888d0cf5c sys/linux: improve perf descriptions 2017-12-29 12:50:21 +01:00
Dmitry Vyukov
0cbc76dfea sys/linux: assorted improvements
Mostly extensions of API in 4.15.
2017-12-29 10:09:24 +01:00
Dmitry Vyukov
6deb615310 sys/linux: fix some copy-paste errors 2017-12-28 19:16:42 +01:00
Dmitry Vyukov
7d240098d8 sys/linux: fix splice signature
...was wrong all that time
2017-12-27 20:26:51 +01:00
Dmitry Vyukov
8ef0050706 prog: don't serialize output data args
Fixes #188

We now will write just ""/1000 to denote a 1000-byte output buffer.
Also we now don't store 1000-byte buffer in memory just to denote size.
Old format is still parsed.
2017-12-17 11:39:14 +01:00
Dmitry Vyukov
41799debdc prog: introduce more readable format for data args
Fixes #460

File names, crypto algorithm names, etc in programs are completely unreadable:

bind$alg(r0, &(0x7f0000408000)={0x26, "6861736800000000000000000000",
0x0, 0x0, "6d6435000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000
00000000000"}, 0x58)

Introduce another format for printable strings.
New args are denoted by '' ("" for old args).
New format is enabled for printable chars, \x00
and \t, \r, \n.

Example:
`serialize(&(0x7f0000408000)={"6861736800000000000000000000", "4849000000"})`,
vs:
`serialize(&(0x7f0000408000)={'hash\x00', 'HI\x00'})`,
2017-12-17 11:39:14 +01:00
Dmitry Vyukov
286edfb78e prog: fix TestMutateTable
Now works fast enough even for short mode.

Fixes #208
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
Dmitry Vyukov
da131727fb sys/linux: describe PF_KEY 2017-12-11 20:12:35 +01:00
Dmitry Vyukov
4016fc5ad7 prog: fix hints of data args
Hints for data args don't work.
We do all the work, but at the final stage we patch
arg in the _old_ program, not in the _new_ one.
So programs passed to the callback are all the same
and don't contain any mutations.
Tests did not catch this because they work right before that point
(don't test the actual interface function MutateWithHints).

Fix that and add a test that catches this.
2017-12-08 10:45:11 +01:00
Dmitry Vyukov
fadd10ac05 sys/linux: add a simple description for selinux 2017-12-08 10:15:04 +01:00
Dmitry Vyukov
3a80fe350d prog: support bytesizeN for vma
I guess this is currently unused,
but ignoring bytesizeN for vma looks wrong.
If user asks for bytesizeN for vma, divide vma size by N.
2017-11-29 11:12:47 +01:00
Dmitry Vyukov
1808de66ce prog: repair arrays/buffers with incorrect size in Deserialize
For string[N] we successfully deserialize a string of any length.
Similarly for a fixed-size array[T, N] we successfully deserialize
an array of any size.
Such programs later crash in foreachSubargOffset because static size
Type.Size() does not match what we've calculated iterating over fields.
The crash happens only in SerializeForExec in syz-fuzzer,
which is especially bad.
Fix this from both sides:
1. Validate sizes of arrays/buffers in Validate.
2. Repair incorrect sizes in Deserialize.
2017-11-28 19:15:28 +01:00
Dmitry Vyukov
ac93d7e1d8 pkg/compiler: add check that len does not refer to array with varlen elements
This [almost] always means a bug in descriptions.
Fix all bugs identified by the check.
2017-11-28 14:55:21 +01:00
Dmitry Vyukov
afba0b55e6 sys/linux: add binder descriptions 2017-11-27 15:09:30 +01:00
Dmitry Vyukov
deb5f6aea2 sys/linux: assorted improvements to descriptions 2017-11-27 09:09:06 +01:00
Dmitry Vyukov
103a5b3fa4 sys/linux: add files from net dir to list of /proc files 2017-11-27 09:09:05 +01:00
Dmitry Vyukov
502d78153c sys/linux: fix control len in msghdr's
Contol len is in bytes, not array elements.
2017-11-27 09:09:03 +01:00
Dmitry Vyukov
473d90487b sys/linux: improve hash generation for KEYCTL_DH_COMPUTE
KEYCTL_DH_COMPUTE used the old fixed list of algorithm names.
Use the new code for algorithm generation.
+ it needs only SHASH algs, but we passed in all alg names.
Pass only SHASH algs.
2017-11-27 09:09:01 +01:00
Dmitry Vyukov
d695195a6b sys/linux: resolve TODO re argument truncation 2017-11-27 09:09:00 +01:00
Dmitry Vyukov
8257de047b sys/linux: open files from /proc 2017-11-27 09:08:59 +01:00
Dmitry Vyukov
bbe60f6cb6 sys/linux: improve fuse descriptions 2017-11-27 09:08:57 +01:00
Dmitry Vyukov
4bd70f886b sys/linux: remove crypto algs starting with __
These can't be created from user-space.
2017-11-24 17:50:31 +01:00
Dmitry Vyukov
3bbb8c0b30 sys/linux: prefix non-autogenerated files with init_ 2017-11-24 14:57:38 +01:00
Dmitry Vyukov
ddf7b3e065 sys/linux: improve AF_ALG alg name generation
There is effectively infinite number of possible crypto
algorithm names due to templates. Plus there is tricky
relation between algorithms and algorithm type names.

This change adds custom mutator for sockaddr_alg struct
to improve variance in generated algorithms.
2017-11-24 13:56:20 +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
ae8da4a43e executor: move arm syscall fixup to syz-extract 2017-11-22 10:34:47 +01:00
Dmitry Vyukov
f07ea3fc22 sys/linux: remove get_kernel_syms, add quotactl syscall
get_kernel_syms does not seem to be present upstream.
Describe an old quotactl syscall.
Also fix umount/umount2 names in kallsyms.
2017-11-20 17:23:24 +01:00
Dmitry Vyukov
e4f20040fb sys/syz-extract: fix compiler invocation 2017-11-20 15:41:35 +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
Tobias Klauser
784eb9c23c sys/freebsd: add POLLINIGNEOF 2017-11-08 19:30:10 +03:00
Eric Biggers
38977f0e6b sys/linux: add definition for LOOP_SET_BLOCK_SIZE
The v4.14 kernel will support a new loop ioctl, LOOP_SET_BLOCK_SIZE.
2017-11-07 12:26:11 +03:00
Eric Biggers
a6b071286e sys/linux: fix wrong ioctl numbers in loop device definitions
Fix a couple apparent copy-and-paste errors:

    - ioctl$LOOP_CHANGE_FD should use LOOP_CHANGE_FD
    - ioctl$LOOP_CTL_REMOVE should use LOOP_CTL_REMOVE
2017-11-07 12:26:11 +03:00
Eric Biggers
3f85f7fc46 syz-extract: fix printf conditional in template
commit 3520854be0 ("syz-extract: select declaring printf or not")
broke 'make extract' because it introduced invalid syntax in a text
template.  Fix it.
2017-11-07 11:21:47 +03:00
zoulasc
3520854be0 syz-extract: select declaring printf or not
Kernels are standalone implementations and can have their own
implementations of functions that have different prototypes than
the standard ones. In the NetBSD case the kernel printf returns
void, and it is declared in <sys/systm.h> so avoid re-declaring it.
Select if we are going to declare printf or not depending on the OS.
2017-11-06 11:27:45 +03:00
zoulasc
7afa56efb4 syz-extract: Add missing symlink for NetBSD and refactor symlink code. 2017-11-06 11:27:45 +03:00
Eric Biggers
7cff33f196 sys/linux: add definition for keyctl_restrict_keyring()
Add a definition for keyctl_restrict_keyring(), which was added in the
v4.12 kernel.
2017-11-03 12:33:25 +03:00
Eric Biggers
d53e548027 sys/linux: add definition for keyctl_dh_compute()
Add a definition for keyctl_dh_compute(), which was added in the v4.7
kernel, then in the v4.12 kernel extended to take in an optional
'keyctl_kdf_params' argument.  (Requires CONFIG_KEY_DH_OPERATIONS=y.)
2017-11-03 12:33:25 +03:00
Eric Biggers
494a18d9f8 sys/linux: use resource subtypes for "user" and "keyring" keys
Many functions in the keys API take in an ID parameter that is expected
to refer to a keyring, not to any key.  Therefore, define a resource
subtype 'keyring' which can be created by add_key("keyring", ...) or by
using one of the special keyring IDs.

Also define a resource subtype 'user_key', since we'll be adding a
definition for KEYCTL_DH_COMPUTE which takes in a struct containing
"user" key IDs.
2017-11-03 12:33:25 +03:00
Eric Biggers
2fb815f286 sys/linux: define all the key types
Add to key.txt all key types that currently might be present in the
kernel.  It was missing a few important ones such as "asymmetric", which
has a significant attack surface since the payloads are run through an
ASN.1 decoder.
2017-11-03 12:33:25 +03:00
Utkarsh Anand
edfd374bd6 Changing the types of members of struct stat
As defined in the header files.
2017-10-30 18:57:38 +01:00
Utkarsh Anand
4b567b4940 Added a few more syscall descriptions, consts
and other related files.
2017-10-30 18:57:38 +01:00
Utkarsh Anand
9b42a968df Add two new syscalls shmctl and msgctl 2017-10-30 18:57:38 +01:00
Utkarsh Anand
d84e0ffaec Fix the SYS_SEMCTL value issue for NetBSD 2017-10-30 18:57:38 +01:00
Dmitry Vyukov
83d9c30252 sys/netbsd: fix mmap signature
mmap syscall has 7 arguments (one unused padding)
2017-10-25 18:36:49 +02:00
Dmitry Vyukov
644a9f03f9 sys/freebsd: fix const name 2017-10-25 18:36:49 +02:00
Utkarsh Anand
3f955eba7f Lots of changes to sys/netbsd (#397)
* Lots of changes to sys/netbsd:
- Removed a few syscalls that did not have proper constants defined.
- Autogenerated *.const files.
- Removed a few types like uid and gid, that were not available.
- Ran make generate

* Few changes for NetBSD support:
- Added sys/netbsd/init.go
- Added netbsd to sys/sys.go

* Fix order in sys/sys.go

* Update documentation for NetBSD
2017-10-25 09:27:47 +02:00
Utkarsh Anand
3b95a1e305 Added 4 files containing syscall descriptions (#396)
* Added 4 files containing syscall descriptions
- Initial additions for peer review.

* Removed a flag:
- Because it was failing to compile.
2017-10-24 11:54:37 +02:00
Dmitry Vyukov
f89294761c executor: use forkserver for freebsd
Use forkserver and shmem for freebsd.
This greatly improves speed.
Also introduce fallback coverage signal based
on unique (syscall+errno) pairs.
2017-10-18 12:01:24 +02:00
Willem de Bruijn
6a3e678181 sys/linux: add MSG_ZEROCOPY 2017-10-17 15:26:15 +02:00
Dmitry Vyukov
3d5e81e280 sys/freebsd: more syscall descriptions
This is mostly copied form linux.
We probably need better support for sharing descriptions
between multiple OSes. But there are lots of differences,
so this is not trivial.
2017-10-17 13:50:05 +02:00
Dmitry Vyukov
bb146866c0 executor: improvements for akaros
1. remove workaround for pthread attrs (was fixed in akaros)
2. remove workaround for dup2 (was fixed in akaros)
3. check that we receive a program
4. implement timeout for test processes
2017-10-17 10:57:38 +02:00
Dmitry Vyukov
8793f74c6c sys/fuchsia: more descriptions 2017-10-16 19:23:13 +02:00
Dmitry Vyukov
6222b00f4b sys/fuchsia: minor improvements to syscall descriptions 2017-10-16 15:53:28 +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
2647772874 sys/akaros: add akaros support 2017-10-16 14:21:54 +02:00
Dmitry Vyukov
4a4739bd45 sys/linux: fix fcntl signature 2017-10-16 14:21:54 +02:00
Dmitry Vyukov
7553c19941 sys/syz-extract: support akaros 2017-10-16 14:21:54 +02:00
Dmitry Vyukov
81e199f719 sys/syz-extract: support freebsd 2017-10-12 18:16:25 +02:00
Dmitry Vyukov
02a7a54019 sys/syz-extract: factor out compilation function
Each arch duplicates significant portion of logic
to compile the extract source file.
Factor this logic into a separate function and reuse
it across all OSes.
2017-10-12 18:16:25 +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
1b68e030d8 sys/fuchsia: add more descriptions 2017-10-02 10:53:28 +02:00
Billy Lau
d335103a64 sys/linux: include additional header to ion.txt
This helps with resolving missing AT_FDCWD const.
2017-09-29 08:51:34 +02:00
Dmitry Vyukov
64b6c0724d sys/windows: add more descriptions 2017-09-27 20:17:09 +02:00
Dmitry Vyukov
646d96d95a Makefile, sys/syz-extract: fix android 2017-09-27 08:46:03 +02:00
Dmitry Vyukov
af442a22d9 executor, sys/windows: initial windows support 2017-09-25 15:19:06 +02:00
Dmitry Vyukov
dd56309863 sys/fuchsia: describe more syscalls 2017-09-25 08:47:48 +02:00
Dmitry Vyukov
e9c477a5b3 sys/syz-extract: support fuchsia 2017-09-25 08:47:48 +02:00
Dmitry Vyukov
913d592f97 all: more assorted fuchsia support 2017-09-22 13:10:55 +02:00
Dmitry Vyukov
653022e6a9 sys/fuchsia: fix build 2017-09-21 10:31:53 +02:00
Dmitry Vyukov
8cb7d3dcfc all: initial support for fuchsia
Nothing works, but builds.

Update #191
2017-09-20 21:19:29 +02:00
Dmitry Vyukov
4e341009db sys/linux: improve user_desc description 2017-09-20 14:01:19 +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
66393d1884 pkg/compiler: don't genererate missing syscalls
We used to generate them only because manager had no idea
what arch it is testing. So syscalls numbers had to match
between all arches.
This is not needed anymore.
Also don't generate unreferenced structs/resources.
2017-09-15 16:02:37 +02:00
Dmitry Vyukov
539e603206 syz-manager, syz-fuzzer, executor: ensure that binaries are consistent
Check that manager/fuzzer/executor are build on the same git revision,
use the same syscall descriptions and the same target arch.

Update #336
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
4503776d2b sys/syz-extract: generate build files out of tree
This does not pollute user kernel dir (we do make mrproper, though)
and enables parallel generation.
2017-09-15 16:02:37 +02:00
Dmitry Vyukov
7296cf374d sys/syz-extract: generate multiple arches at once 2017-09-15 16:02:37 +02:00
Dmitry Vyukov
f7eb58493b sys/syz-extract: use consolidated target info
Move knowledge about targets from extract.sh to syz-extract,
and make it use target into from sys.
2017-09-15 16:02:37 +02:00
Dmitry Vyukov
75ddf7ab90 sys/syz-extract: switch to consolidated target info in sys package 2017-09-15 16:02:37 +02:00
Dmitry Vyukov
487aa0d537 sys: consolidate info about various targets
Info about targets (like C arch/CFLAGS) is required in multiple places:
extract.sh
syz-extract
syz-sysgen
csource
vm/qemu
...

Consolidate it in one place and use that in syz-sysgen.
2017-09-15 16:02:37 +02:00
Dmitry Vyukov
91def5c506 prog: remove special knowledge about "mmap" syscall
Abstract "mmap" away as it can be called differently on another OS.
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
34bc139642 sys: compile all supported targets into the package
Currently we compile in only GOOS/GOARCH target.
Compile in all targets so that they can be selected at runtime.
2017-09-15 16:02:37 +02:00
Dmitry Vyukov
b16ba6390d sys/syz-extract: parallelize over files 2017-09-15 16:02:37 +02:00
Dmitry Vyukov
2119c28968 sys: move extract.sh to sys/linux 2017-09-15 16:02:37 +02:00
Dmitry Vyukov
bd13474175 sys/linux: rename package from sys to linux 2017-09-15 16:02:37 +02:00
Dmitry Vyukov
18e96021ed sys: move linux descriptions to sys/linux 2017-09-15 16:02:37 +02:00
Dmitry Vyukov
4a7f7fab1e prog: allow more than 1 target 2017-09-15 16:02:37 +02:00
Dmitry Vyukov
96b8e39972 sys: regenerate consts with tip linux 2017-09-13 15:39:34 +02:00
Dmitry Vyukov
5060392c49 sys: use correct pointer size 2017-09-05 19:02:12 +02:00
Dmitry Vyukov
19cc67af5b sys: add new perf attribute flag 2017-09-05 19:02:12 +02:00
Dmitry Vyukov
eb45aa4244 prog, sys: move dictionary of special strings to sys
It is target-specific.
2017-09-05 19:02:12 +02:00
Dmitry Vyukov
58efb7c6a5 sys: improve timespec/timeval generation 2017-09-05 19:02:12 +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
c34180fca0 pkg/compiler: assign Call.ID statically 2017-09-04 21:06:59 +02:00
Dmitry Vyukov
a27fcb3079 sys: use ptr64 type instead of ptr where necessary 2017-09-04 21:03:23 +02:00
Dmitry Vyukov
1c0d4caf7c sys: change BitfieldLast to BitfieldMiddle
That's the condition we always want.
Currently we always check:
t.BitfieldOffset() == 0 || t.BitfieldLast()
now can check just:
!t.BitfieldMiddle()
2017-09-04 20:51:56 +02:00
Dmitry Vyukov
b6e402dd48 sys: remove IntSignalno 2017-09-04 20:25:23 +02:00
Dmitry Vyukov
399addc875 sys, pkg/compiler: move padding computation to compiler
This makes types constant during execution, everything is precomputed.
2017-09-04 20:25:23 +02:00
Dmitry Vyukov
d878c4ff43 sys: minor fixes for statx and sigevent 2017-09-04 20:25:22 +02:00
Dmitry Vyukov
e707c97f9a pkg/compiler: move bitfield marking from sys 2017-09-04 20:25:22 +02:00
Dmitry Vyukov
2cf0659df1 sys: don't assume vma size is 8
Use explicit size for vma.
This is the last use of hardcoded ptrSize in sys package.
2017-09-04 20:25:22 +02:00
Dmitry Vyukov
4ee497d22e pkg/compiler: use correct arch ptr size 2017-09-04 20:25:22 +02:00
Dmitry Vyukov
8c64b078d1 pkg/compiler: detect resources without ctors
Fixes #217
2017-09-04 20:25:22 +02:00
Dmitry Vyukov
a54dce007d sys: allow custom size for PtrType
This is required to support ptr64 type.
2017-09-02 14:08:30 +02:00
Dmitry Vyukov
9c995bedad sys: improve bpf descriptions 2017-09-02 13:38:16 +02:00
Dmitry Vyukov
2c0b7b7ff3 pkg/compiler: restore generation of unsupported syscalls
Unfortunately this is sitll needed, see the added comment.

Update #191
2017-09-02 13:21:47 +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
Andrey Konovalov
76bc1b9d35 sys: add AF_PACKET sockets description 2017-09-01 17:17:33 +02:00
Dmitry Vyukov
4ccdd78294 sys: export struct/union attributes
Export struct/union attributes so that they can be filled in
by a different package.
2017-08-31 19:21:52 +02:00
Dmitry Vyukov
5a093b74f6 sys: change proc arguments to the format used by const/flags/len
All other types have optional underlying type as the last argument.
Proc have it as first. This creates very irregular syntax and
complicates parsing. Make type the last argument.

Note: this is a breaking change if you have descriptions on the side.
2017-08-31 14:31:21 +02:00
Victor Chibotaru
1336586b42 executor, fuzzer: change the way Syzkaller opens the KCOV device
We have implemented a new version of KCOV, which is able to dump
comparison operands' data, obtained from Clang's instrumentation hooks
__sanitizer_cov_trace_cmp[1248], __sanitizer_cov_trace_const_cmp[1248]
and __sanitizer_cov_trace_switch.

Current KCOV implementation can work in two modes: "Dump only the PCs"
or "Dump only comparisons' data". Mode selection is done by the
following series of calls:

fd = open(KCOV_PATH, ...); // works as previous
ioctl(fd, KCOV_INIT_TRACE, ...); // works as previous
mmap(fd, ...); // works as previous
ioctl(fd, KCOV_ENABLE, mode);
// mode = KCOV_MODE_TRACE_CMP or mode = KCOV_MODE_TRACE_PC

Note that this new interface is backwards compatible, as old KCOV
devices will just return -EINVAL for the last ioctl. This way we can
distinguish if the KCOV device is able to dump the comparisons.

Main changes in this commit:
    1. Fuzzer now checks at startup which type (new/old) of KCOV device
is running.
    2. Executor now receives an additional flag, which indicates if
executor should read the comparisons data from KCOV. The flag works on
per-call basis, so executor can collect PCs or Comps for each
individual syscall.
2017-08-30 18:40:14 +02:00
Dmitry Vyukov
be2917712f pkg/compiler: actually tolerate unsupported consts
The previous commit removes errors on unsupported structs/resources,
but their usages still error. Fix that.
2017-08-28 19:00:31 +02:00