From bc1210b614287b1c035a71935fb1f791ebbbf9f6 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 4 Jul 2018 10:12:23 +0200 Subject: [PATCH] pkg/ipc: create default config based on target Pass actual target to DefaultConfig, that's what we really want, not the stray ipc flag. --- pkg/ipc/ipc.go | 15 ++------------- pkg/ipc/ipc_test.go | 2 +- syz-fuzzer/fuzzer.go | 5 +++-- tools/syz-execprog/execprog.go | 8 ++++---- tools/syz-stress/stress.go | 2 +- 5 files changed, 11 insertions(+), 21 deletions(-) diff --git a/pkg/ipc/ipc.go b/pkg/ipc/ipc.go index 72a74f16..4ad71299 100644 --- a/pkg/ipc/ipc.go +++ b/pkg/ipc/ipc.go @@ -12,7 +12,6 @@ import ( "os" "os/exec" "path/filepath" - "runtime" "strings" "sync/atomic" "time" @@ -68,7 +67,6 @@ var ( flagAbortSignal = flag.Int("abort_signal", 0, "initial signal to send to executor"+ " in error conditions; upgrades to SIGKILL if executor does not exit") flagBufferSize = flag.Uint64("buffer_size", 0, "internal buffer size (in bytes) for executor output") - flagIPC = flag.String("ipc", "", "ipc scheme (pipe/shmem)") ) type ExecOpts struct { @@ -103,7 +101,7 @@ type Config struct { BufferSize uint64 } -func DefaultConfig() (*Config, *ExecOpts, error) { +func DefaultConfig(target *prog.Target) (*Config, *ExecOpts, error) { c := &Config{ Executor: *flagExecutor, Timeout: *flagTimeout, @@ -126,22 +124,13 @@ func DefaultConfig() (*Config, *ExecOpts, error) { return nil, nil, fmt.Errorf("flag sandbox must contain one of none/setuid/namespace") } - sysTarget := targets.Get(runtime.GOOS, runtime.GOARCH) + sysTarget := targets.Get(target.OS, target.Arch) if sysTarget.ExecutorUsesShmem { c.Flags |= FlagUseShmem } if sysTarget.ExecutorUsesForkServer { c.Flags |= FlagUseForkServer } - switch *flagIPC { - case "": - case "pipe": - c.Flags &^= FlagUseShmem - case "shmem": - c.Flags |= FlagUseShmem - default: - return nil, nil, fmt.Errorf("unknown ipc scheme: %v", *flagIPC) - } opts := &ExecOpts{ Flags: FlagDedupCover, diff --git a/pkg/ipc/ipc_test.go b/pkg/ipc/ipc_test.go index cebf587d..59f9f621 100644 --- a/pkg/ipc/ipc_test.go +++ b/pkg/ipc/ipc_test.go @@ -41,7 +41,7 @@ func initTest(t *testing.T) (*prog.Target, rand.Source, int, EnvFlags) { if err != nil { t.Fatal(err) } - cfg, _, err := DefaultConfig() + cfg, _, err := DefaultConfig(target) if err != nil { t.Fatal(err) } diff --git a/syz-fuzzer/fuzzer.go b/syz-fuzzer/fuzzer.go index e4482510..b644ebb9 100644 --- a/syz-fuzzer/fuzzer.go +++ b/syz-fuzzer/fuzzer.go @@ -94,6 +94,7 @@ func main() { var ( flagName = flag.String("name", "test", "unique name for manager") + flagOS = flag.String("os", runtime.GOOS, "target OS") flagArch = flag.String("arch", runtime.GOARCH, "target arch") flagManager = flag.String("manager", "", "manager rpc address") flagProcs = flag.Int("procs", 1, "number of parallel test processes") @@ -118,12 +119,12 @@ func main() { } log.Logf(0, "fuzzer started") - target, err := prog.GetTarget(runtime.GOOS, *flagArch) + target, err := prog.GetTarget(*flagOS, *flagArch) if err != nil { log.Fatalf("%v", err) } - config, execOpts, err := ipc.DefaultConfig() + config, execOpts, err := ipc.DefaultConfig(target) if err != nil { log.Fatalf("failed to create default ipc config: %v", err) } diff --git a/tools/syz-execprog/execprog.go b/tools/syz-execprog/execprog.go index d6b9822f..9e591a8a 100644 --- a/tools/syz-execprog/execprog.go +++ b/tools/syz-execprog/execprog.go @@ -61,8 +61,7 @@ func main() { if _, err = host.Setup(features); err != nil { log.Fatalf("%v", err) } - - config, execOpts := createConfig(entries, features) + config, execOpts := createConfig(target, entries, features) var wg sync.WaitGroup wg.Add(*flagProcs) @@ -206,8 +205,9 @@ func loadPrograms(target *prog.Target, files []string) []*prog.LogEntry { return entries } -func createConfig(entries []*prog.LogEntry, features *host.Features) (*ipc.Config, *ipc.ExecOpts) { - config, execOpts, err := ipc.DefaultConfig() +func createConfig(target *prog.Target, entries []*prog.LogEntry, features *host.Features) ( + *ipc.Config, *ipc.ExecOpts) { + config, execOpts, err := ipc.DefaultConfig(target) if err != nil { log.Fatalf("%v", err) } diff --git a/tools/syz-stress/stress.go b/tools/syz-stress/stress.go index 29ab2404..03866a49 100644 --- a/tools/syz-stress/stress.go +++ b/tools/syz-stress/stress.go @@ -60,7 +60,7 @@ func main() { prios := target.CalculatePriorities(corpus) ct := target.BuildChoiceTable(prios, calls) - config, execOpts, err := ipc.DefaultConfig() + config, execOpts, err := ipc.DefaultConfig(target) if err != nil { log.Fatalf("%v", err) }