From 28bd3e371b1f31cb243f0df56b9c7720971a89db Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 10 Dec 2018 15:49:04 +0100 Subject: prog: support AUTO args in programs AUTO arguments can be used for: - consts - lens - pointers For const's and len's AUTO is replaced with the natural value, addresses for AUTO pointers are allocated linearly. This greatly simplifies writing test programs by hand as most of the time we want these natural values. Update tests to use AUTO. --- sys/linux/test/binfmt | 20 ++++++++++---------- sys/linux/test/cgroup | 16 ++++++++-------- sys/linux/test/file_immutable | 10 +++++----- sys/linux/test/fuse_deadlock | 16 ++++++++-------- sys/linux/test/vnet_tun | 4 ++-- sys/test/gen/64.go | 13 ++++++++++++- sys/test/test.txt | 10 ++++++++++ sys/test/test/align0 | 6 +++--- sys/test/test/bf | 8 +++----- 9 files changed, 61 insertions(+), 42 deletions(-) (limited to 'sys') diff --git a/sys/linux/test/binfmt b/sys/linux/test/binfmt index 9ab905824..8998c6226 100644 --- a/sys/linux/test/binfmt +++ b/sys/linux/test/binfmt @@ -1,16 +1,16 @@ # Tests for binfmt_misc. # Executor setups binfmt_misc with ./file0 interpreter for files with byte 0x01 at offset 0. -execveat(0xffffffffffffff9c, &(0x7f0000000000)='./file1\x00', &(0x7f0000000100)=[0x0], &(0x7f0000000200)=[0x0], 0x0) # ENOENT -r0 = openat(0xffffffffffffff9c, &(0x7f0000000000)='./file1\x00', 0x42, 0x1ff) +execveat(0xffffffffffffff9c, &AUTO='./file1\x00', &AUTO=[0x0], &AUTO=[0x0], 0x0) # ENOENT +r0 = openat(0xffffffffffffff9c, &AUTO='./file1\x00', 0x42, 0x1ff) close(r0) -execveat(0xffffffffffffff9c, &(0x7f0000000000)='./file1\x00', &(0x7f0000000100)=[0x0], &(0x7f0000000200)=[0x0], 0x0) # ENOEXEC -r1 = openat(0xffffffffffffff9c, &(0x7f0000000000)='./file1\x00', 0x2, 0x0) -write(r1, &(0x7f0000000300)="01010101", 0x4) +execveat(0xffffffffffffff9c, &AUTO='./file1\x00', &AUTO=[0x0], &AUTO=[0x0], 0x0) # ENOEXEC +r1 = openat(0xffffffffffffff9c, &AUTO='./file1\x00', 0x2, 0x0) +write(r1, &AUTO="01010101", 0x4) close(r1) -execveat(0xffffffffffffff9c, &(0x7f0000000000)='./file1\x00', &(0x7f0000000100)=[0x0], &(0x7f0000000200)=[0x0], 0x0) # ENOENT -r2 = openat(0xffffffffffffff9c, &(0x7f0000000000)='./file0\x00', 0x42, 0x0) +execveat(0xffffffffffffff9c, &AUTO='./file1\x00', &AUTO=[0x0], &AUTO=[0x0], 0x0) # ENOENT +r2 = openat(0xffffffffffffff9c, &AUTO='./file0\x00', 0x42, 0x0) close(r2) -execveat(0xffffffffffffff9c, &(0x7f0000000000)='./file1\x00', &(0x7f0000000100)=[0x0], &(0x7f0000000200)=[0x0], 0x0) # EACCES -fchmodat(0xffffffffffffff9c, &(0x7f0000000000)='./file0\x00', 0x1ff) -execveat(0xffffffffffffff9c, &(0x7f0000000000)='./file1\x00', &(0x7f0000000100)=[0x0], &(0x7f0000000200)=[0x0], 0x0) # ENOEXEC +execveat(0xffffffffffffff9c, &AUTO='./file1\x00', &AUTO=[0x0], &AUTO=[0x0], 0x0) # EACCES +fchmodat(0xffffffffffffff9c, &AUTO='./file0\x00', 0x1ff) +execveat(0xffffffffffffff9c, &AUTO='./file1\x00', &AUTO=[0x0], &AUTO=[0x0], 0x0) # ENOEXEC diff --git a/sys/linux/test/cgroup b/sys/linux/test/cgroup index db6fb7317..f06d87ac8 100644 --- a/sys/linux/test/cgroup +++ b/sys/linux/test/cgroup @@ -4,12 +4,12 @@ # requires: -sandbox= -sandbox=setuid -C,norepeat r0 = getpid() -r1 = openat(0xffffffffffffff9c, &(0x7f0000000000)='./cgroup/cgroup.procs\x00', 0x2, 0x0) -read(r1, &(0x7f0000000100)="00", 0x1) -write$cgroup_pid(r1, &(0x7f0000000100)=r0, 0x12) +r1 = openat(0xffffffffffffff9c, &AUTO='./cgroup/cgroup.procs\x00', 0x2, 0x0) +read(r1, &AUTO="00", AUTO) +write$cgroup_pid(r1, &AUTO=r0, AUTO) close(r1) -openat(0xffffffffffffff9c, &(0x7f0000000000)='./cgroup/pids.max\x00', 0x2, 0x0) -openat(0xffffffffffffff9c, &(0x7f0000000000)='./cgroup.cpu/cgroup.procs\x00', 0x2, 0x0) -openat(0xffffffffffffff9c, &(0x7f0000000000)='./cgroup.cpu/cpuset.cpus\x00', 0x2, 0x0) -openat(0xffffffffffffff9c, &(0x7f0000000000)='./cgroup.net/cgroup.procs\x00', 0x2, 0x0) -openat(0xffffffffffffff9c, &(0x7f0000000000)='./cgroup.net/devices.allow\x00', 0x1, 0x0) +openat(0xffffffffffffff9c, &AUTO='./cgroup/pids.max\x00', 0x2, 0x0) +openat(0xffffffffffffff9c, &AUTO='./cgroup.cpu/cgroup.procs\x00', 0x2, 0x0) +openat(0xffffffffffffff9c, &AUTO='./cgroup.cpu/cpuset.cpus\x00', 0x2, 0x0) +openat(0xffffffffffffff9c, &AUTO='./cgroup.net/cgroup.procs\x00', 0x2, 0x0) +openat(0xffffffffffffff9c, &AUTO='./cgroup.net/devices.allow\x00', 0x1, 0x0) diff --git a/sys/linux/test/file_immutable b/sys/linux/test/file_immutable index e6a18240b..61ad6b36a 100644 --- a/sys/linux/test/file_immutable +++ b/sys/linux/test/file_immutable @@ -3,8 +3,8 @@ # It also requires root, so will fail with setuid. # requires: -sandbox=namespace -sandbox=setuid -r0 = openat(0xffffffffffffff9c, &(0x7f0000000000)='./file0\x00', 0x26e1, 0x0) -ioctl$FS_IOC_FSSETXATTR(r0, 0x40086602, &(0x7f0000000100)={0x17e}) -mkdirat(0xffffffffffffff9c, &(0x7f0000000200)='./file1\x00', 0x1ff) -r1 = openat(0xffffffffffffff9c, &(0x7f0000000300)='./file1\x00', 0x0, 0x0) -ioctl$FS_IOC_FSSETXATTR(r1, 0x40086602, &(0x7f0000000100)={0x17e}) +r0 = openat(0xffffffffffffff9c, &AUTO='./file0\x00', 0x26e1, 0x0) +ioctl$FS_IOC_FSSETXATTR(r0, 0x40086602, &AUTO={0x17e, 0x0, 0x0, 0x0, 0x0, 0x0}) +mkdirat(0xffffffffffffff9c, &AUTO='./file1\x00', 0x1ff) +r1 = openat(0xffffffffffffff9c, &AUTO='./file1\x00', 0x0, 0x0) +ioctl$FS_IOC_FSSETXATTR(r1, 0x40086602, &AUTO={0x17e, 0x0, 0x0, 0x0, 0x0, 0x0}) diff --git a/sys/linux/test/fuse_deadlock b/sys/linux/test/fuse_deadlock index 844bfe701..897977fb3 100644 --- a/sys/linux/test/fuse_deadlock +++ b/sys/linux/test/fuse_deadlock @@ -1,11 +1,11 @@ # Test how we avoid fuse deadlocks in kill_and_wait. # requires: threaded -sandbox= -C,norepeat -mkdirat(0xffffffffffffff9c, &(0x7f0000000000)='./file0\x00', 0x0) -r0 = openat$fuse(0xffffffffffffff9c, &(0x7f0000000640)='/dev/fuse\x00', 0x2, 0x0) -mount$fuse(0x0, &(0x7f0000000200)='./file0\x00', &(0x7f0000000300)='fuse\x00', 0x0, &(0x7f0000000400)={{'fd', 0x3d, r0}, 0x2c, {'rootmode', 0x3d, 0x4000}, 0x2c, {'user_id', 0x3d}, 0x2c, {'group_id', 0x3d}, 0x2c}) -read$FUSE(r0, &(0x7f0000002000), 0x1000) -pread64(r0, &(0x7f0000000540)=""/236, 0xec, 0x0) # blocked -write$FUSE_INIT(r0, &(0x7f0000000100)={0x50, 0x0, 0x1, {0x7, 0x1b}}, 0x50) -mkdirat(0xffffffffffffff9c, &(0x7f0000000500)='./file0/file0\x00', 0x0) # unfinished -write$FUSE_NOTIFY_INVAL_ENTRY(r0, &(0x7f00000000c0)={0x29, 0x3, 0x0, {0x1, 0x8, 0x0, 'group_id'}}, 0x29) # unfinished +mkdirat(0xffffffffffffff9c, &AUTO='./file0\x00', 0x0) +r0 = openat$fuse(0xffffffffffffff9c, &AUTO='/dev/fuse\x00', 0x2, 0x0) +mount$fuse(0x0, &AUTO='./file0\x00', &AUTO='fuse\x00', 0x0, &AUTO={{'fd', 0x3d, r0}, 0x2c, {'rootmode', 0x3d, 0x4000}, 0x2c, {'user_id', 0x3d, 0x0}, 0x2c, {'group_id', 0x3d, 0x0}, 0x2c, {[], [], 0x0}}) +read$FUSE(r0, &AUTO=""/4096, AUTO) +pread64(r0, &AUTO=""/236, AUTO, 0x0) # blocked +write$FUSE_INIT(r0, &AUTO={AUTO, 0x0, 0x1, {AUTO, AUTO, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]}}, AUTO) +mkdirat(0xffffffffffffff9c, &AUTO='./file0/file0\x00', 0x0) # unfinished +write$FUSE_NOTIFY_INVAL_ENTRY(r0, &AUTO={AUTO, 0x3, 0x0, {0x1, AUTO, 0x0, 'group_id', 0x0}}, AUTO) # unfinished diff --git a/sys/linux/test/vnet_tun b/sys/linux/test/vnet_tun index bb88fc9d6..c1b08e695 100644 --- a/sys/linux/test/vnet_tun +++ b/sys/linux/test/vnet_tun @@ -1,2 +1,2 @@ -syz_emit_ethernet() -syz_emit_ethernet() +syz_emit_ethernet(0x0, 0x0, 0x0) +syz_emit_ethernet(0x0, 0x0, 0x0) diff --git a/sys/test/gen/64.go b/sys/test/gen/64.go index 1abe96317..d3c24241d 100644 --- a/sys/test/gen/64.go +++ b/sys/test/gen/64.go @@ -65,6 +65,11 @@ var structDescs_64 = []*KeyedStruct{ &IntType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "int8", FldName: "i8", TypeSize: 1}}}, &IntType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "int32", FldName: "i32", TypeSize: 4}}}, }}}, + {Key: StructKey{Name: "auto_struct0"}, Desc: &StructDesc{TypeCommon: TypeCommon{TypeName: "auto_struct0", TypeSize: 12}, Fields: []Type{ + &LenType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "len", FldName: "f0", TypeSize: 4}}, Buf: "parent"}, + &ConstType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "const", FldName: "f1", TypeSize: 4}}, Val: 67}, + &IntType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "int32", FldName: "f2", TypeSize: 4}}}, + }}}, {Key: StructKey{Name: "compare_data"}, Desc: &StructDesc{TypeCommon: TypeCommon{TypeName: "compare_data", IsVarlen: true}, Fields: []Type{ &StructType{Key: StructKey{Name: "align0"}, FldName: "align0"}, &StructType{Key: StructKey{Name: "syz_bf_struct0"}, FldName: "bf0"}, @@ -660,6 +665,12 @@ var syscalls_64 = []*Syscall{ {Name: "test$array2", CallName: "test", Args: []Type{ &PtrType{TypeCommon: TypeCommon{TypeName: "ptr", FldName: "a0", TypeSize: 8}, Type: &StructType{Key: StructKey{Name: "syz_array_blob"}}}, }}, + {Name: "test$auto0", CallName: "test", Args: []Type{ + &ConstType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "const", FldName: "a", TypeSize: 8}}, Val: 66}, + &PtrType{TypeCommon: TypeCommon{TypeName: "ptr", FldName: "b", TypeSize: 8}, Type: &StructType{Key: StructKey{Name: "auto_struct0"}}}, + &LenType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "len", FldName: "c", TypeSize: 8}}, Buf: "b"}, + &IntType{IntTypeCommon: IntTypeCommon{TypeCommon: TypeCommon{TypeName: "int32", FldName: "d", TypeSize: 4}}}, + }}, {Name: "test$bf0", CallName: "test", Args: []Type{ &PtrType{TypeCommon: TypeCommon{TypeName: "ptr", FldName: "a0", TypeSize: 8}, Type: &StructType{Key: StructKey{Name: "syz_bf_struct0"}}}, }}, @@ -929,4 +940,4 @@ var consts_64 = []ConstValue{ {Name: "SYS_unsupported"}, } -const revision_64 = "82736d421a5d52db6df0775561f1e59cc6cb9014" +const revision_64 = "ece48c7de48771745acdea340f4c52c47e058e65" diff --git a/sys/test/test.txt b/sys/test/test.txt index aadf704b4..214c42c6c 100644 --- a/sys/test/test.txt +++ b/sys/test/test.txt @@ -703,3 +703,13 @@ unsupported$1(a unsupported) unsupported fallback$0() fd fallback$1(a fd) seccomp() + +# AUTO + +test$auto0(a const[0x42], b ptr[in, auto_struct0], c len[b], d int32) + +auto_struct0 { + f0 len[parent, int32] + f1 const[0x43, int32] + f2 int32 +} diff --git a/sys/test/test/align0 b/sys/test/test/align0 index e2e5b9275..426b6e2de 100644 --- a/sys/test/test/align0 +++ b/sys/test/test/align0 @@ -1,3 +1,3 @@ -syz_compare(&(0x7f0000000000)="010000000200000003000400000000000500000000000000", 0x18, &(0x7f0000001000)=@align0={0x1, 0x2, 0x3, 0x4, 0x5}, 0x18) -syz_compare(&(0x7f0000000000)="", 0x18, &(0x7f0000001000)=@align0={0x0, 0x0, 0x0, 0x0, 0x0}, 0x17) # EBADF -syz_compare(&(0x7f0000000000)="", 0x18, &(0x7f0000001000)=@align0={0x1, 0x0, 0x0, 0x0, 0x0}, 0x18) # EINVAL +syz_compare(&AUTO="010000000200000003000400000000000500000000000000", 0x18, &AUTO=@align0={0x1, 0x2, 0x3, 0x4, 0x5}, AUTO) +syz_compare(&AUTO="", 0x18, &AUTO=@align0={0x0, 0x0, 0x0, 0x0, 0x0}, 0x17) # EBADF +syz_compare(&AUTO="", 0x18, &AUTO=@align0={0x1, 0x0, 0x0, 0x0, 0x0}, AUTO) # EINVAL diff --git a/sys/test/test/bf b/sys/test/test/bf index bc43b1fb4..4e43b989b 100644 --- a/sys/test/test/bf +++ b/sys/test/test/bf @@ -1,5 +1,3 @@ -syz_compare(&(0x7f0000000000)="ab03000000000000cdcdcdcdcdcdcdcdeb070000ff7f0000ab0303abaa000000", 0x20, &(0x7f0000001000)=@bf0={0xabab, 0xcdcdcdcdcdcdcdcd, 0xabab, 0xffff, 0xffffff, 0xabab, 0xabab, 0xaaa}, 0x20) - -syz_compare(&(0x7f0000002000)="dcfcde563422f10e", 0x8, &(0x7f0000003000)=@bf2={0x0abc, 0x0bcd, 0xcdef, 0x123456, 0x78ef12}, 0x8) - -syz_compare(&(0x7f0000004000)="0ef1223456defcdc", 0x8, &(0x7f0000005000)=@bf3={0x0abc, 0x0bcd, 0xcdef, 0x123456, 0x78ef12}, 0x8) +syz_compare(&AUTO="ab03000000000000cdcdcdcdcdcdcdcdeb070000ff7f0000ab0303abaa000000", 0x20, &AUTO=@bf0={0xabab, 0xcdcdcdcdcdcdcdcd, 0xabab, 0xffff, 0xffffff, 0xabab, 0xabab, 0xaaa}, AUTO) +syz_compare(&AUTO="dcfcde563422f10e", 0x8, &AUTO=@bf2={0x0abc, 0x0bcd, 0xcdef, 0x123456, 0x78ef12}, AUTO) +syz_compare(&AUTO="0ef1223456defcdc", 0x8, &AUTO=@bf3={0x0abc, 0x0bcd, 0xcdef, 0x123456, 0x78ef12}, AUTO) -- cgit mrf-deployment