From 75a7c5e2d1f09a4a58e7e1f1f4ef0b0f55a33413 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 19 Feb 2018 19:35:04 +0100 Subject: 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. --- sys/syz-sysgen/sysgen.go | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'sys/syz-sysgen') diff --git a/sys/syz-sysgen/sysgen.go b/sys/syz-sysgen/sysgen.go index aafc44feb..d91970f59 100644 --- a/sys/syz-sysgen/sysgen.go +++ b/sys/syz-sysgen/sysgen.go @@ -135,10 +135,12 @@ func generate(target *targets.Target, prg *compiler.Prog, consts map[string]uint fmt.Fprintf(out, "import . \"github.com/google/syzkaller/prog\"\n\n") fmt.Fprintf(out, "func init() {\n") - fmt.Fprintf(out, "\tRegisterTarget(&Target{OS: %q, Arch: %q, Revision: revision_%v, PtrSize: %v,"+ - "Syscalls: syscalls_%v, Resources: resources_%v, Structs: structDescs_%v, Consts: consts_%v}, "+ + fmt.Fprintf(out, "\tRegisterTarget(&Target{OS: %q, Arch: %q, Revision: revision_%v, PtrSize: %v, "+ + "PageSize: %v, NumPages: %v, DataOffset: %v, Syscalls: syscalls_%v, "+ + "Resources: resources_%v, Structs: structDescs_%v, Consts: consts_%v}, "+ "initTarget)\n", target.OS, target.Arch, target.Arch, target.PtrSize, + target.PageSize, target.NumPages, target.DataOffset, target.Arch, target.Arch, target.Arch, target.Arch) fmt.Fprintf(out, "}\n\n") @@ -174,15 +176,21 @@ func generateExecutorSyscalls(target *targets.Target, syscalls []*prog.Syscall, NeedCall bool } type ArchData struct { - Revision string - GOARCH string - CARCH []string - Calls []SyscallData + Revision string + GOARCH string + CARCH []string + PageSize uint64 + NumPages uint64 + DataOffset uint64 + Calls []SyscallData } data := ArchData{ - Revision: rev, - GOARCH: target.Arch, - CARCH: target.CArch, + Revision: rev, + GOARCH: target.Arch, + CARCH: target.CArch, + PageSize: target.PageSize, + NumPages: target.NumPages, + DataOffset: target.DataOffset, } for _, c := range syscalls { data.Calls = append(data.Calls, SyscallData{ @@ -247,6 +255,9 @@ var archTempl = template.Must(template.New("").Parse(` #if {{range $cdef := $.CARCH}}defined({{$cdef}}) || {{end}}0 #define GOARCH "{{.GOARCH}}" #define SYZ_REVISION "{{.Revision}}" +#define SYZ_PAGE_SIZE {{.PageSize}} +#define SYZ_NUM_PAGES {{.NumPages}} +#define SYZ_DATA_OFFSET {{.DataOffset}} unsigned syscall_count = {{len $.Calls}}; call_t syscalls[] = { {{range $c := $.Calls}} {"{{$c.Name}}", {{$c.NR}}{{if $c.NeedCall}}, (syscall_t){{$c.CallName}}{{end}}}, -- cgit mrf-deployment