aboutsummaryrefslogtreecommitdiffstats
path: root/sys/test
Commit message (Collapse)AuthorAgeFilesLines
* sys/test: fix overlay test for bigendianAlexander Egorenov2022-01-142-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | $ go test -v -short ./pkg/runtest run.go:67: overlay C : FAIL: run 0: wrong call 3 result 22, want 0 ### start ### call=0 errno=0 ### call=1 errno=0 ### call=2 errno=0 ### call=3 errno=22 ### call=4 errno=22 ### call=5 errno=22 ### call=6 errno=22 ### call=7 errno=22 ### call=8 errno=0 run.go:67: overlay /repeat C : BROKEN (non-forking loop) run.go:67: overlay /thr C : FAIL: run 0: wrong call 3 result 22, want 0 ### start ### call=0 errno=0 ### call=1 errno=0 ### call=2 errno=0 ### call=3 errno=22 ### call=4 errno=22 ### call=5 errno=22 ### call=6 errno=22 ### call=7 errno=22 ### call=8 errno=0 run.go:67: overlay /thr/repeat C : BROKEN (non-forking loop) run.go:67: overlay none : FAIL: run 0: wrong call 3 result 22, want 0 run.go:67: overlay none C : FAIL: run 0: wrong call 3 result 22, want 0 ### start ### call=0 errno=0 ### call=1 errno=0 ### call=2 errno=0 ### call=3 errno=22 ### call=4 errno=22 ### call=5 errno=22 ### call=6 errno=22 ### call=7 errno=22 ### call=8 errno=0 run.go:67: overlay none/repeat : FAIL: run 0: wrong call 3 result 22, want 0 run.go:67: overlay none/repeat C : BROKEN (non-forking loop) run.go:67: overlay none/thr : FAIL: run 0: wrong call 3 result 22, want 0 run.go:67: overlay none/thr C : FAIL: run 0: wrong call 3 result 22, want 0 ### start ### call=0 errno=0 ### call=1 errno=0 ### call=2 errno=0 ### call=3 errno=22 ### call=4 errno=22 ### call=5 errno=22 ### call=6 errno=22 ### call=7 errno=22 ### call=8 errno=0
* sys/linux: use out_overlay attributeDmitry Vyukov2022-01-111-2/+2
| | | | | | | Remove all uses of direction attributes on union fields and use out_overlay attribute instead. The attribute actually does what was the intention behind use of direction attribute on unions.
* pkg/compiler: add out_overlay field attributeDmitry Vyukov2022-01-112-35/+84
|
* pkg/compiler: optimize array[const] representationDmitry Vyukov2021-04-211-2/+3
| | | | | | | | | | | | | | Represent array[const[X, int8], N] as string["XX...X"]. This replaces potentially huge number of: NONFAILING(*(uint8_t*)0x2000126c = 0); NONFAILING(*(uint8_t*)0x2000126d = 0); NONFAILING(*(uint8_t*)0x2000126e = 0); with a single memcpy. In one reproducer we had 3991 such lines. Also replace memcpy's with memset's when possible. Update #1070
* pkg/csource: add resuling source testsDmitry Vyukov2021-04-211-0/+13
| | | | | | Add some tests that verify source we get for various programs. Update #1070
* sys: commit empty source filesDmitry Vyukov2021-04-211-0/+6
| | | | | | Commit empty files into generated packages, so that the tree is buildable even w/o generated files and Go tools continue to work.
* sys/test/test: add a hanging testDmitry Vyukov2020-09-122-0/+4
| | | | Ensure that we can handle hanging syscalls in all modes.
* prog: fix UnionType mutation for when per-field dir is specifiedNecip Fazil Yildiran2020-08-141-2/+7
| | | | prog/TestMutateRandom used to fail due to this.
* pkg/compiler: merge const files into a single fileDmitry Vyukov2020-08-135-15/+6
| | | | | | | | | | | | | | | | | | | | We now have 8 arches for Linux and .const files produce lots of noise in PRs and lots of diffs. If 3 .txt files are touched, the PR will have 24 .const files, which will be intermixed with .txt files. Frequently const values are equal across arches, and even if they don't spreading a single value across 8 files is inconvinient. Merge all 8 *_arch.const files into a single .const file. See the test for details of the new format. The old format is still parsed for now, we can't update all OSes at once. For Linux this reduces number of const files/lines from 1288/96599 to 158/11603. Fixes #1983
* pkg, prog: add per-field direction attributeNecip Fazil Yildiran2020-08-131-0/+43
|
* pkg/compiler: fix crash on fmt[flags]Dmitry Vyukov2020-07-232-0/+10
| | | | | | | Flags with only 1 value 0 are transformed to ConstType. Fmt did not expect that. Fixes #1965
* executor: wrap all syscalls into NONFAILINGDmitry Vyukov2020-07-151-0/+1
| | | | | | | | | | | | | | | Currently we sprinkle NONFAILING all over pseudo-syscall code, around all individual accesses to fuzzer-generated pointers. This is tedious manual work and subject to errors. Wrap execute_syscall invocation with NONFAILING in execute_call once instead. Then we can remove NONFAILING from all pseudo-syscalls and never get back to this. Potential downsides: (1) this is coarser-grained and we will skip whole syscall on invalid pointer, but this is how normal syscalls work as well, so should not be a problem; (2) we will skip any clean up (closing of files, etc) as well; but this may be fine as well (programs can perfectly leave open file descriptors as well). Update #1918
* executor: fix bitfields for big-endian archAlexander Egorenkov2020-07-102-0/+31
| | | | | | | | Add bitfield tests for big-endian arch Issue: #1885 Signed-off-by: Alexander Egorenkov <Alexander.Egorenkov@ibm.com>
* target: support of big-endian architecturesAlexander Egorenkov2020-06-235-3/+11
| | | | | | | | | | | | * Introduce the new target flag 'LittleEndian' which specifies of which endianness the target is. * Introduce the new requires flag 'littleendian' for tests to selectively enable/disable tests on either little-endian architectures or big-endian ones. * Disable KD unit test on s390x architecture because the test works only on little-endian architecture. Signed-off-by: Alexander Egorenkov <Alexander.Egorenkov@ibm.com>
* pkg/runtest: disable broken test combinationsDmitry Vyukov2020-05-183-1/+8
| | | | | Amusingly this was always broken but nobody was ever able to compile 32-bit binaries on Linux since the addition of the tests.
* prog: refactor hints testsDmitry Vyukov2020-05-051-0/+9
| | | | | | | The way the tests fabricate types dynamically creates problems during any non-trivial changes to prog package. Use existing types from descriptions instead.
* prog: support disabled attributeDmitry Vyukov2020-05-041-0/+8
| | | | | Update #477 Update #502
* prog: don't squash objects that contain pointersDmitry Vyukov2020-05-011-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Squashing pointers creates several problems: - we need to generate pointer types on the fly, something we don't do in any other contexts, it complicates other changes - pointers are very special as values, if we change size of the surrounding blobs, offsets changes and we will use something that's not a pointer as pointer and vise versa, boths things are most likley very bad as inputs - squashing/any implementation is just too complex This disqualifies several types for squashing: < alloc_pd_cmd < arpt_replace < array[cmsghdr_rds] < create_cq_cmd < create_flow_cmd < create_qp_cmd < create_srq_cmd < ebt_counters_info < ip6t_replace < ipt_replace < mlx5_alloc_pd_cmd < mlx5_create_dv_qp_cmd < open_xrcd_cmd < post_recv_cmd < post_send_cmd < post_srq_recv_cmd < query_qp_cmd < query_srq_cmd < reg_mr_cmd < rereg_mr_cmd < resize_cq_cmd < usbdevfs_urb < vhost_memory < vusb_connect_descriptors and adds few new: > binder_objects > query_qp_resp > resize_cq_resp > usb_bos_descriptor > usb_string_descriptor Overall this looks sane. Majority is still unchanged.
* Makefile: generate descriptions on-the-flyDmitry Vyukov2020-04-305-8380/+0
| | | | | | | | | | | | | | | | | | 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
* pkg/compiler: deduplicate Types in descriptionsDmitry Vyukov2020-04-264-3237/+5812
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* prog: add ignore_return and breaks_returns call attribtuesDmitry Vyukov2020-04-195-22/+13
| | | | | We had these hard-coded for fuchsia and linux accordingly. Replace with call attributes.
* pkg/compiler: refactor attribute handlingDmitry Vyukov2020-04-193-8/+8
| | | | | | | | | | | | 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].
* prog: refactor target.MakeMmapDmitry Vyukov2020-04-181-1/+1
| | | | | | | | | | | 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.
* pkg/compiler: check that flags values fit into base typeDmitry Vyukov2020-03-175-14/+14
| | | | | | | | flags[foo, int8] foo = 0x12345678 is always an error, detect these cases. Found some bugs in mptcp, packet sockets, kvm.
* pkg/compiler: check that const values fit into base typeDmitry Vyukov2020-03-175-9/+9
| | | | | const[0x12345678, int8] is always an error, detect these cases. Found some bugs in mptcp, socket proto and fuchsia fidl descriptions.
* pkg/compiler: calculate more precise sizes for argumentsDmitry Vyukov2020-03-174-80/+80
| | | | | | | | | | | | | | | | | | | | 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
* pkg/compiler: ensure consistency of syscall argument typesDmitry Vyukov2020-03-175-201/+249
| | | | | | | | | | | | | | | | | | Ensure that we don't have conflicting sizes for the same argument of the same syscall, e.g.: foo$1(a int16) foo$2(a int32) This is useful for several reasons: - we will be able avoid morphing syscalls into other syscalls - we will be able to figure out more precise sizes for args (lots of them are implicitly intptr, which is the largest type on most important arches) - found few bugs in linux descriptions Update #477 Update #502
* pkg/compiler: don't specify syscall consts for test OSDmitry Vyukov2020-03-174-27/+2925
| | | | This is just tedious. Fabricate them on the fly.
* prog: remove unused ResourceDesc.TypeDmitry Vyukov2020-01-261-8/+8
|
* pkg/serializer: do not write field names if it won't save spaceDmitry Vyukov2020-01-264-630/+630
| | | | | | | 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).
* pkg/compiler: don't mark flags with 0 as bitmaskDmitry Vyukov2020-01-184-12/+12
| | | | | | | 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).
* prog: don't add fallback coverage after prctlDmitry Vyukov2020-01-153-1/+5
| | | | The same reason as with seccomp.
* sys/linux: fix 2 netlink data layout bugsDmitry Vyukov2020-01-076-7/+363
| | | | | | | | | | | 1. Turns out that NLA_F_NESTED is actually used and checked (nla_parse_nested checks it, while nla_parse_nested_deprecated does not). Similarly, ipset extensively checks NLA_F_NET_BYTEORDER. So we need these bits. 2. nla_len must not account for the trailing alighnment padding. This means we set wrong len for payloads that are not multiple of 4 (int8/int16/strings/arrays/some structs/etc).
* pkg/compiler: fix another bitfield layout bugDmitry Vyukov2020-01-076-18/+92
| | | | See the added test for details.
* prog: fix tests for string enforcementDmitry Vyukov2020-01-052-4/+4
| | | | | | | | String value enforcement broke a number of tests where we use different values. Be more string as to what string values we use in tests. Required to add tmpfs descriptions to test syz_mount_image. Also special-casing AF_ALG algorithms as these are auto-generated.
* prog: don't mutate strings with enumerated valuesDmitry Vyukov2020-01-052-1/+11
| | | | | | | | | | Strings with enumerated values are frequently file names or have complete enumeration of relevant values. Mutating complete enumeration if not very profitable. Mutating file names leads to escaping paths and fuzzer messing with things it is not supposed to mess with as in: r0 = openat$apparmor_task_exec(0xffffffffffffff9c, &(0x7f0000000440)='/proc/self//exe\x00', 0x3, 0x0)
* sys/linux: fix int64 alignment on 386Dmitry Vyukov2019-12-231-12/+11
| | | | | | | | | Turns out int64 alignment is 4 on 386... But on arm it's still 8. Another amusing finding thanks to syz-check. Update #590
* prog: don't fail decoding on non-default out argsDmitry Vyukov2019-12-212-1/+5
| | | | | | | We get them in cross-compilation test where an out const arg has different values in different archs. No reason to fail deserialization in that case, replace with default arg instead.
* pkg/compiler: fix bitfield layout bugDmitry Vyukov2019-12-206-489/+391
| | | | | | Fixes #1542 Found thanks to syz-check. Update #590
* sys/test: and another set of bitfield testsDmitry Vyukov2019-12-206-14/+650
| | | | | | Just trying to get my head around it (and fix this in tests). Update #1542
* sys/test: and another bitfield testDmitry Vyukov2019-12-196-13/+70
| | | | | | Just trying to get my head around it (and fix this in tests). Update #1542
* prog: refactor bitfields representationDmitry Vyukov2019-12-194-187/+187
| | | | | | | | All callers of BitfieldMiddle just want static size (0 for middle). Make it so: Size for middle bitfields just returns 0. Removes lots of if's. Introduce Type.UnitSize, which now holds the underlying type for bitfields. This will be needed to fix #1542 b/c even if UnitSize=4 for last bitfield Size can be anywhere from 0 to 4 (not necessary equal to UnitSize due to overlapping).
* sys/test: add few other tests for tricky bitfieldsDmitry Vyukov2019-12-186-4/+243
| | | | Update #1542
* sys/test: add more tests for bitfieldsDmitry Vyukov2019-12-136-4/+355
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add tests for issue #1542 The correct results are obtained with the following program: struct foo { unsigned char f0; unsigned int f1:4; unsigned short f2:4; }; struct bar { char f0; struct foo foo; }; int main() { struct bar y; memset(&y, 0, sizeof(y)); y.f0 = 0x12; y.foo.f0 = 0x34; y.foo.f1 = 0x56; y.foo.f2 = 0x78; int i; for (i = 0; i < sizeof(y); i++) printf("%02x", ((unsigned char*)&y)[i]); printf("\n"); }
* pkg/compiler: define fileoff templatePaul Chaignon2019-11-011-17/+17
| | | | Signed-off-by: Paul Chaignon <paul.chaignon@orange.com>
* prog: mutate length of output buffersVeronica Radu2019-10-102-1/+9
| | | | Update #480
* prog: implemented argument and call prioritiesVeronica Radu2019-09-042-1/+9
|
* prog: add special mutation for binary flagsVeronica Radu2019-08-093-1/+52
|
* prog: don't minimize ProcType to 0Dmitry Vyukov2019-07-263-1/+11
| | | | | | | | Default value for ProcType is 0 (same for all PID's). Usually 0 either does not make sense at all or make different PIDs collide (since we use ProcType to separate value ranges for different PIDs). So don't change ProcType to 0 unless the type is explicitly marked as opt (in that case we will also generate 0 anyway).
* pkg/compiler: add offsetof typeDmitry Vyukov2019-05-162-1/+46
| | | | | | Similar to C offsetof gives offset of a field from the beginning of the parent struct. We have several TODOs in descriptions asking for this.