From 57a83e9453bb2d0f4c80e00df72aa4317dcac58f Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Wed, 3 Jun 2020 11:44:46 -0700 Subject: sys/fuchsia: update "make extract" support code FIDL fuzzing hasn't been working for a while, and it's further bit-rotted as upstream FIDL functionality has continued to evolve. This commit updates enough FIDL functionality to get a minimal FIDL test case to work again. --- sys/fuchsia/fidl.txt | 7 ++--- sys/fuchsia/fidlgen/main.go | 13 ++++---- sys/fuchsia/layout/fidl_mappings.go | 59 ++++++++----------------------------- sys/fuchsia/objects.txt | 3 +- sys/fuchsia/streams.txt | 8 +++++ 5 files changed, 33 insertions(+), 57 deletions(-) create mode 100644 sys/fuchsia/streams.txt (limited to 'sys/fuchsia') diff --git a/sys/fuchsia/fidl.txt b/sys/fuchsia/fidl.txt index 6c0f9a78f..8aace5d9c 100644 --- a/sys/fuchsia/fidl.txt +++ b/sys/fuchsia/fidl.txt @@ -1,7 +1,7 @@ # Copyright 2018 syzkaller project authors. All rights reserved. # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. -# See https://fuchsia.googlesource.com/fuchsia/+/master/docs/development/languages/fidl/reference/wire-format/README.md +# See https://fuchsia.dev/fuchsia-src/reference/fidl/language/wire-format include @@ -23,9 +23,8 @@ type fidl_union_member[TAG, TYPE] { type fidl_message_header[METHOD_ORDINAL] { txid const[0, int32] - reserved const[0, int32] - flags const[0, int32] -# TODO: this should be int32, but the consts passed here don't fit into 32 bits. + flags array[const[0, int8], 3] + magic_number const[1, int8] ordinal const[METHOD_ORDINAL, int64] } diff --git a/sys/fuchsia/fidlgen/main.go b/sys/fuchsia/fidlgen/main.go index 139d6461d..63f1ca120 100644 --- a/sys/fuchsia/fidlgen/main.go +++ b/sys/fuchsia/fidlgen/main.go @@ -35,7 +35,7 @@ func main() { "out", arch, "host_x64", - "fidlgen", + "fidlgen_syzkaller", ) if !osutil.IsExist(fidlgenPath) { failf("cannot find fidlgen %s", fidlgenPath) @@ -44,7 +44,7 @@ func main() { var newFiles []string for _, fidlLib := range layout.AllFidlLibraries { jsonPath := filepath.Join(sourceDir, "out", arch, fidlLib.PathToJSONIr()) - txtPathBase := strings.Replace(strings.Join(fidlLib.FqName, "_"), "^fuchsia", "fidl", 1) + txtPathBase := strings.Replace(strings.Join(fidlLib, "_"), "^fuchsia", "fidl", 1) txtPath := fidlgen( fidlgenPath, @@ -98,13 +98,14 @@ func fidlgen(fidlgenPath string, jsonPath string, txtPathBase string) string { failf("cannot find %s", jsonPath) } - _, err := osutil.RunCmd(time.Minute, "", + out, err := osutil.RunCmd(time.Minute, "", fidlgenPath, - "-generators", "syzkaller", "-json", jsonPath, - "-output-base", txtPathBase, - "-include-base", txtPathBase, + "-output-syz", txtPathBase+".syz.txt", ) + if len(out) != 0 { + fmt.Println(string(out)) + } if err != nil { failf("fidlgen failed: %v", err) diff --git a/sys/fuchsia/layout/fidl_mappings.go b/sys/fuchsia/layout/fidl_mappings.go index 837a97332..44fb308e1 100644 --- a/sys/fuchsia/layout/fidl_mappings.go +++ b/sys/fuchsia/layout/fidl_mappings.go @@ -9,50 +9,24 @@ import ( "strings" ) -// layer indicates at which layer a FidlLibrary lives in the Fuchsia build -// system. -type layer int - -const ( - _ layer = iota - zircon - garnet -) - -// FidlLibrary describes a FIDL library. It captures required details such as -// build location, header generation, etc. -type FidlLibrary struct { - layer layer - - // FqName stores the fully-qualified name of the library in parts, e.g. - // the `fuchsia.mem` library is `fuchsia`, `mem`. - FqName []string -} +// FidlLibrary is the fully-qualified name of a FIDL library. +type FidlLibrary []string // AllFidlLibraries lists all FIDL libraries. var AllFidlLibraries = []FidlLibrary{ - {zircon, []string{"fuchsia", "mem"}}, - {zircon, []string{"fuchsia", "cobalt"}}, - {zircon, []string{"fuchsia", "ldsvc"}}, - {zircon, []string{"fuchsia", "process"}}, - {zircon, []string{"fuchsia", "io"}}, - {zircon, []string{"fuchsia", "net"}}, - {zircon, []string{"fuchsia", "hardware", "ethernet"}}, - {garnet, []string{"fuchsia", "devicesettings"}}, - {garnet, []string{"fuchsia", "net", "stack"}}, - {garnet, []string{"fuchsia", "timezone"}}, - {garnet, []string{"fuchsia", "scpi"}}, + {"fuchsia", "cobalt"}, + {"fuchsia", "devicesettings"}, + {"fuchsia", "hardware", "ethernet"}, + {"fuchsia", "io"}, + {"fuchsia", "ldsvc"}, + {"fuchsia", "mem"}, + {"fuchsia", "net"}, + {"fuchsia", "process"}, + {"fuchsia", "scpi"}, } func (fidlLib FidlLibrary) dirName() string { - switch fidlLib.layer { - case zircon: - return strings.Join(fidlLib.FqName, "-") - case garnet: - return strings.Join(fidlLib.FqName, ".") - default: - panic(fmt.Sprintf("unknown layer %v", fidlLib.layer)) - } + return strings.Join(fidlLib, ".") } // PathToJSONIr provides the path to the JSON IR, relative to the out/ @@ -66,12 +40,5 @@ func (fidlLib FidlLibrary) PathToJSONIr() string { // PathToCompiledDir provides the path to compiled headers, relative to the // out/ directory. func (fidlLib FidlLibrary) PathToCompiledDir() string { - switch fidlLib.layer { - case zircon: - return filepath.Join("fidling", "gen", "zircon", "system", "fidl", fidlLib.dirName()) - case garnet: - return filepath.Join("fidling", "gen", "sdk", "fidl", fidlLib.dirName()) - default: - panic(fmt.Sprintf("unknown layer %v", fidlLib.layer)) - } + return filepath.Join("fidling", "gen", "sdk", "fidl", fidlLib.dirName()) } diff --git a/sys/fuchsia/objects.txt b/sys/fuchsia/objects.txt index 4cc7c186a..922038525 100644 --- a/sys/fuchsia/objects.txt +++ b/sys/fuchsia/objects.txt @@ -2,8 +2,9 @@ # Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. include -include include +include +include resource koid[int64]: 0 diff --git a/sys/fuchsia/streams.txt b/sys/fuchsia/streams.txt new file mode 100644 index 000000000..beb05e2d6 --- /dev/null +++ b/sys/fuchsia/streams.txt @@ -0,0 +1,8 @@ +# Copyright 2020 syzkaller project authors. All rights reserved. +# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +include + +resource zx_stream[zx_handle] + +# TODO: Add stream-related system calls. -- cgit mrf-deployment