syzkaller/sys
2017-01-19 20:46:26 +01:00
..
align.go prog, sys: fix padding varlen structs 2017-01-19 15:22:04 +01:00
bpf_amd64.const sys: add new bpf descriptions 2016-11-28 18:29:10 +01:00
bpf_arm64.const sys: add new bpf descriptions 2016-11-28 18:29:10 +01:00
bpf_ppc64le.const sys: add new bpf descriptions 2016-11-28 18:29:10 +01:00
bpf.txt sys: don't imply pointer indirection for filename type 2017-01-18 19:58:12 +01:00
decl_test.go sys: don't add clock_gettime always 2017-01-09 20:20:48 +01:00
decl.go prog, sys: fix padding varlen structs 2017-01-19 15:22:04 +01:00
dri_amd64.const sys: add missing include file for some DRI constants 2017-01-18 19:58:12 +01:00
dri_arm64.const sys: add missing include file for some DRI constants 2017-01-18 19:58:12 +01:00
dri_ppc64le.const sys: add missing include file for some DRI constants 2017-01-18 19:58:12 +01:00
dri.txt sys: add missing include file for some DRI constants 2017-01-18 19:58:12 +01:00
fuse_amd64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
fuse_arm64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
fuse_ppc64le.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
fuse.txt sys: don't imply pointer indirection for filename type 2017-01-18 19:58:12 +01:00
input_amd64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
input_arm64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
input_ppc64le.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
input.txt prog, sys: fix padding varlen structs 2017-01-19 15:22:04 +01:00
kcm_amd64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
kcm_arm64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
kcm_ppc64le.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
kcm.txt sys: refine KCM ioctl type 2016-09-28 17:22:56 +02:00
key_amd64.const sys: specify resources in text descriptions 2016-08-27 18:27:50 +02:00
key_arm64.const sys: specify resources in text descriptions 2016-08-27 18:27:50 +02:00
key_ppc64le.const sys: specify resources in text descriptions 2016-08-27 18:27:50 +02:00
key.txt sys: don't imply pointer indirection for string arguments 2016-11-11 14:33:15 -08:00
kvm_amd64.const sys: add KVM_ENABLE_CAP for vm 2017-01-18 19:58:12 +01:00
kvm_arm64.const sys: add KVM_ENABLE_CAP for vm 2017-01-18 19:58:12 +01:00
kvm_ppc64le.const sys: add KVM_ENABLE_CAP for vm 2017-01-18 19:58:12 +01:00
kvm.txt sys: add KVM_ENABLE_CAP for vm 2017-01-18 19:58:12 +01:00
netlink_amd64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
netlink_arm64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
netlink_ppc64le.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
netlink.txt sys: specify resources in text descriptions 2016-08-27 18:27:50 +02:00
netrom_amd64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
netrom_arm64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
netrom_ppc64le.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
netrom.txt sys: specify resources in text descriptions 2016-08-27 18:27:50 +02:00
perf_amd64.const sys: improve perf_event_open description 2016-11-16 13:19:33 +01:00
perf_arm64.const sys: improve perf_event_open description 2016-11-16 13:19:33 +01:00
perf_ppc64le.const sys: improve perf_event_open description 2016-11-16 13:19:33 +01:00
perf.txt sys: improve perf_event_open description 2016-11-16 13:19:33 +01:00
random_amd64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
random_arm64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
random_ppc64le.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
random.txt sys: add string flags 2016-11-11 14:33:37 -08:00
README.md sys: don't imply pointer indirection for filename type 2017-01-18 19:58:12 +01:00
sctp_amd64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
sctp_arm64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
sctp_ppc64le.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
sctp.txt sys: specify resources in text descriptions 2016-08-27 18:27:50 +02:00
sndcontrol_amd64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
sndcontrol_arm64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
sndcontrol_ppc64le.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
sndcontrol.txt sys: add string flags 2016-11-11 14:33:37 -08:00
sndseq_amd64.const sys: improve /dev/snd/seq and /dev/snd/timer descriptions 2017-01-18 19:58:12 +01:00
sndseq_arm64.const sys: improve /dev/snd/seq and /dev/snd/timer descriptions 2017-01-18 19:58:12 +01:00
sndseq_ppc64le.const sys: improve /dev/snd/seq and /dev/snd/timer descriptions 2017-01-18 19:58:12 +01:00
sndseq.txt sys: improve /dev/snd/seq and /dev/snd/timer descriptions 2017-01-18 19:58:12 +01:00
sndtimer_amd64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
sndtimer_arm64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
sndtimer_ppc64le.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
sndtimer.txt sys: improve /dev/snd/seq and /dev/snd/timer descriptions 2017-01-18 19:58:12 +01:00
socket_amd64.const sys: improve cmsghdr description 2017-01-18 20:08:41 +01:00
socket_arm64.const sys: improve cmsghdr description 2017-01-18 20:08:41 +01:00
socket_ppc64le.const sys: improve cmsghdr description 2017-01-18 20:08:41 +01:00
socket.txt sys: improve cmsghdr description 2017-01-18 20:08:41 +01:00
sys_amd64.const sys: detail kvm syscalls more 2017-01-09 20:20:48 +01:00
sys_arm64.const sys: detail kvm syscalls more 2017-01-09 20:20:48 +01:00
sys_ppc64le.const sys: detail kvm syscalls more 2017-01-09 20:20:48 +01:00
sys.txt sys: don't imply pointer indirection for filename type 2017-01-18 19:58:12 +01:00
test.txt prog: fix bytesizeN for nonarray fields 2017-01-19 20:46:26 +01:00
tlk_device_amd64.const Add the /dev/tlk_device (Open Trusted Execution device driver) description 2016-09-05 11:00:05 +02:00
tlk_device_arm64.const Add the /dev/tlk_device (Open Trusted Execution device driver) description 2016-09-05 11:00:05 +02:00
tlk_device.txt sys: add string flags 2016-11-11 14:33:37 -08:00
tty_amd64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
tty_arm64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
tty_ppc64le.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
tty.txt sys: add string flags 2016-11-11 14:33:37 -08:00
tun_amd64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
tun_arm64.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
tun_ppc64le.const overhaul syscall description generation process 2016-08-26 07:09:25 +02:00
tun.txt sys: add string flags 2016-11-11 14:33:37 -08:00
vnet_amd64.const sys: describe new pkey_* syscalls 2016-12-16 15:42:11 +01:00
vnet_arm64.const sys: describe new pkey_* syscalls 2016-12-16 15:42:11 +01:00
vnet_ppc64le.const sys: describe new pkey_* syscalls 2016-12-16 15:42:11 +01:00
vnet.txt executor: emit ethernet traffic 2016-11-29 17:39:38 +01:00

Syscall Description

syzkaller uses declarative description of syscalls to generate, mutate, minimize, serialize and deserialize programs (sequences of syscalls). Below you can see (hopefully self-explanatory) excerpt from the description:

open(file filename, flags flags[open_flags], mode flags[open_mode]) fd
read(fd fd, buf buffer[out], count len[buf]) len[buf]
close(fd fd)
open_mode = S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP, S_IXGRP, S_IROTH, S_IWOTH, S_IXOTH

The description is contained in sys/*.txt files. See for example sys/sys.txt file.

Syntax

Pseudo-formal grammar of syscall description:

	syscallname "(" [arg ["," arg]*] ")" [type]
	arg = argname type
	argname = identifier
	type = typename [ "[" type-options "]" ]
	typename = "const" | "intN" | "intptr" | "flags" | "array" | "ptr" |
			"buffer" | "string" | "strconst" | "filename" |
			"len" | "bytesize" | "vma" | "proc"
	type-options = [type-opt ["," type-opt]]

common type-options include:

	"opt" - the argument is optional (like mmap fd argument, or accept peer argument)

rest of the type-options are type-specific:

	"const": integer constant, type-options:
		value, underlying type (one if "intN", "intptr")
	"intN"/"intptr": an integer without a particular meaning, type-options:
		optional range of values (e.g. "5:10", or "-100:200")
	"flags": a set of flags, type-options:
		reference to flags description (see below)
	"array": a variable/fixed-length array, type-options:
		type of elements, optional size (fixed "5", or ranged "5:10", boundaries inclusive)
	"ptr": a pointer to an object, type-options:
		type of the object; direction (in/out/inout)
	"buffer": a pointer to a memory buffer (like read/write buffer argument), type-options:
		direction (in/out/inout)
	"string": a zero-terminated memory buffer (no pointer indirection implied), type-options:
		either a string value in quotes for constant strings (e.g. "foo"),
		or a reference to string flags,
		optionally followed by a buffer size (string values will be padded with \x00 to that size)
	"filename": a file/link/dir name, no pointer indirection implied, in most cases you want `ptr[in, filename]`
	"fileoff": offset within a file
	"len": length of another field (for array it is number of elements), type-options:
		argname of the object
	"bytesize": similar to "len", but always denotes the size in bytes, type-options:
		argname of the object
	"vma": a pointer to a set of pages (used as input for mmap/munmap/mremap/madvise), type-options:
		optional number of pages (e.g. vma[7]), or a range of pages (e.g. vma[2-4])
	"proc": per process int (see description below), type-options:
		underlying type, value range start, how many values per process
	"text16", "text32", "text64": machine code of the specified bitness

flags/len/flags also have trailing underlying type type-option when used in structs/unions/pointers.

Flags are described as:

	flagname = const ["," const]*

or for string flags as:

	flagname = "\"" literal "\"" ["," "\"" literal "\""]*

Ints

You can use int8, int16, int32, int64 and int64 to denote an integer of the corresponding size.

By appending be suffix (like int16be) integers become big-endian.

It's possible to specify range of values for an integer in the format of int32[0:100].

To denote a bitfield of size N use int64:N.

It's possible to use these various kinds of ints as base types for const, flags, len and proc.

example_struct {
	f0	int8			# random 1-byte integer
	f1	const[0x42, int16be]	# const 2-byte integer with value 0x4200 (big-endian 0x42)
	f2	int32[0:100]		# random 4-byte integer with values from 0 to 100 inclusive
	f3	int64:20		# random 20-bit bitfield
}

Structs

Structs are described as:

	structname "{" "\n"
		(fieldname type "\n")+
	"}"

Structs can have trailing attributes "packed" and "align_N", they are specified in square brackets after the struct.

Unions

Unions are described as:

	unionname "[" "\n"
		(fieldname type "\n")+
	"]"

Unions can have a trailing "varlen" attribute (specified in square brackets after the union), which means that union length is not maximum of all option lengths, but rather length of a particular chosen option.

Resources

Custom resources are described as:

	resource identifier "[" underlying_type "]" [ ":" const ("," const)* ]

underlying_type is either one of int8, int16, int32, int64, intptr or another resource. Resources can then be used as types. For example:

resource fd[int32]: 0xffffffffffffffff, AT_FDCWD, 1000000
resource sock[fd]
resource sock_unix[sock]

socket(...) sock
accept(fd sock, ...) sock
listen(fd sock, backlog int32)

Proc

The proc type can be used to denote per process integers. The idea is to have a separate range of values for each executor, so they don't interfere.

The simplest example is a port number. The proc[int16be, 20000, 4] type means that we want to generate an int16be integer starting from 20000 and assign no more than 4 integers for each process. As a result the executor number n will get values in the [20000 + n * 4, 20000 + (n + 1) * 4) range.

Misc

Description files also contain include directives that refer to Linux kernel header files and define directives that define symbolic constant values. See the following section for details.

Code generation

Textual syscall descriptions are translated into code used by syzkaller. This process consists of 2 steps. The first step is extraction of values of symbolic constants from Linux sources using syz-extract utility. syz-extract generates a small C program that includes kernel headers referenced by include directives, defines macros as specified by define directives and prints values of symbolic constants. Results are stored in .const files, one per arch. For example, sys/tty.txt is translated into sys/tty_amd64.const.

The second step is generation of Go code for syzkaller. This step uses syscall descriptions and the const files generated during the first step. You can see a result in sys/sys_amd64.go and in executor/syscalls.h.

Describing new system calls

This section describes how to extend syzkaller to allow fuzz testing of a new system call; this is particularly useful for kernel developers who are proposing new system calls.

First, add a declarative description of the new system call to the appropriate file:

  • Various sys/<subsystem>.txt files hold system calls for particular kernel subsystems, for example bpf or socket.
  • sys/sys.txt holds descriptions for more general system calls.
  • An entirely new subsystem can be added as a new sys/<new>.txt file.

The description format is described above.

If the subsystem is present in the mainline kernel, add the new txt file to extract.sh file and run make extract LINUX=$KSRC with KSRC set to the location of a kernel source tree. This will generate const files.

If the subsystem is not present in the mainline kernel, then you need to manually run syz-extract binary:

make bin/syz-extract
bin/syz-extract -arch $ARCH -linux "$LINUX" -linuxbld "$LINUXBLD" sys/<new>.txt

$ARCH is one of amd64, arm64, ppc64le. If the subsystem is supported on several architectures, then run syz-exctact for each arch. $LINUX should point to kernel source checkout, which is configured for the corresponding arch (i.e. you need to run make someconfig && make there first). If the kernel was built into a separate directory (with make O=...) then also set $LINUXBLD to the location of the build directory.

Then, run make generate which will update generated code.

Rebuild syzkaller (make clean all) to force use of the new system call definitions.

Optionally, adjust the enable_syscalls configuration value for syzkaller to specifically target the new system calls.