From 1fd901159188a5e0c2b3559ae7ec7deff7c4e7a2 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 29 Nov 2020 10:40:36 +0100 Subject: pkg/mgrconfig: add prog&sys.targets targets to Config These are widely used with the config as the refactoring shows. This removes a bunch of unnecessary code. Also fixes a number of bugs where we confused Arch with VMArch. --- tools/syz-bisect/bisect.go | 4 ++-- tools/syz-crush/crush.go | 12 +++--------- tools/syz-repro/repro.go | 4 ---- tools/syz-runtest/runtest.go | 17 +++++------------ tools/syz-testbuild/testbuild.go | 2 +- 5 files changed, 11 insertions(+), 28 deletions(-) (limited to 'tools') diff --git a/tools/syz-bisect/bisect.go b/tools/syz-bisect/bisect.go index f50b29095..a7f3ca180 100644 --- a/tools/syz-bisect/bisect.go +++ b/tools/syz-bisect/bisect.go @@ -70,7 +70,7 @@ func main() { fmt.Fprintln(os.Stderr, err) os.Exit(1) } - mgrcfg, err := mgrconfig.LoadPartialData(mycfg.Manager) + mgrcfg, err := mgrconfig.LoadData(mycfg.Manager) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) @@ -99,7 +99,7 @@ func main() { Syzkaller: bisect.SyzkallerConfig{ Repo: mycfg.SyzkallerRepo, }, - Manager: *mgrcfg, + Manager: mgrcfg, } loadString("syzkaller.commit", &cfg.Syzkaller.Commit) loadString("kernel.commit", &cfg.Kernel.Commit) diff --git a/tools/syz-crush/crush.go b/tools/syz-crush/crush.go index 164e46da6..778f17b10 100644 --- a/tools/syz-crush/crush.go +++ b/tools/syz-crush/crush.go @@ -24,7 +24,6 @@ import ( "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/report" "github.com/google/syzkaller/prog" - "github.com/google/syzkaller/sys/targets" "github.com/google/syzkaller/vm" ) @@ -60,11 +59,6 @@ func main() { log.Printf("running until crash is found or till %v", *flagRestartTime) } - target, err := prog.GetTarget(cfg.TargetOS, cfg.TargetArch) - if err != nil { - log.Fatalf("%v", err) - } - vmPool, err := vm.Create(cfg, *flagDebug) if err != nil { log.Fatalf("%v", err) @@ -90,7 +84,7 @@ func main() { log.Fatalf("error reading source file from '%s'", reproduceMe) } - cfg.SyzExecprogBin, err = csource.BuildNoWarn(target, execprog) + cfg.SyzExecprogBin, err = csource.BuildNoWarn(cfg.Target, execprog) if err != nil { log.Fatalf("failed to build source file: %v", err) } @@ -107,7 +101,7 @@ func main() { for i := 0; i < vmPool.Count(); i++ { go func(index int) { for { - runDone <- runInstance(target, cfg, reporter, vmPool, index, *flagRestartTime, runType) + runDone <- runInstance(cfg.Target, cfg, reporter, vmPool, index, *flagRestartTime, runType) if atomic.LoadUint32(&shutdown) != 0 || !*flagInfinite { // If this is the last worker then we can close the channel. if atomic.AddUint32(&stoppedWorkers, 1) == uint32(vmPool.Count()) { @@ -181,7 +175,7 @@ func runInstance(target *prog.Target, cfg *mgrconfig.Config, reporter report.Rep if runType == LogFile { // If SyzExecutorCmd is provided, it means that syz-executor is already in // the image, so no need to copy it. - executorCmd := targets.Get(cfg.TargetOS, cfg.TargetArch).SyzExecutorCmd + executorCmd := cfg.SysTarget.SyzExecutorCmd if executorCmd == "" { executorCmd, err = inst.Copy(cfg.SyzExecutorBin) if err != nil { diff --git a/tools/syz-repro/repro.go b/tools/syz-repro/repro.go index b73b3db20..b46952931 100644 --- a/tools/syz-repro/repro.go +++ b/tools/syz-repro/repro.go @@ -15,7 +15,6 @@ import ( "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/report" "github.com/google/syzkaller/pkg/repro" - "github.com/google/syzkaller/prog" "github.com/google/syzkaller/vm" ) @@ -40,9 +39,6 @@ func main() { if err != nil { log.Fatalf("failed to open log file %v: %v", logFile, err) } - if _, err := prog.GetTarget(cfg.TargetOS, cfg.TargetArch); err != nil { - log.Fatalf("%v", err) - } vmPool, err := vm.Create(cfg, *flagDebug) if err != nil { log.Fatalf("%v", err) diff --git a/tools/syz-runtest/runtest.go b/tools/syz-runtest/runtest.go index b6f25d784..1780c6892 100644 --- a/tools/syz-runtest/runtest.go +++ b/tools/syz-runtest/runtest.go @@ -26,7 +26,6 @@ import ( "github.com/google/syzkaller/pkg/runtest" "github.com/google/syzkaller/prog" _ "github.com/google/syzkaller/sys" - "github.com/google/syzkaller/sys/targets" "github.com/google/syzkaller/vm" ) @@ -42,10 +41,6 @@ func main() { if err != nil { log.Fatal(err) } - target, err := prog.GetTarget(cfg.TargetOS, cfg.TargetArch) - if err != nil { - log.Fatal(err) - } vmPool, err := vm.Create(cfg, *flagDebug) if err != nil { log.Fatal(err) @@ -57,7 +52,6 @@ func main() { osutil.MkdirAll(cfg.Workdir) mgr := &Manager{ cfg: cfg, - target: target, vmPool: vmPool, reporter: reporter, debug: *flagDebug, @@ -102,7 +96,7 @@ func main() { for sandbox, ids := range mgr.checkResult.EnabledCalls { calls := make(map[*prog.Syscall]bool) for _, id := range ids { - calls[target.Syscalls[id]] = true + calls[cfg.Target.Syscalls[id]] = true } enabledCalls[sandbox] = calls } @@ -116,8 +110,8 @@ func main() { fmt.Printf("%-24v: %v calls enabled\n", sandbox+" sandbox", len(calls)) } ctx := &runtest.Context{ - Dir: filepath.Join(cfg.Syzkaller, "sys", target.OS, targets.TestOS), - Target: target, + Dir: filepath.Join(cfg.Syzkaller, "sys", cfg.Target.OS, "test"), + Target: cfg.Target, Features: mgr.checkResult.Features, EnabledCalls: enabledCalls, Requests: mgr.requests, @@ -137,7 +131,6 @@ func main() { type Manager struct { cfg *mgrconfig.Config - target *prog.Target vmPool *vm.Pool reporter report.Reporter requests chan *runtest.RunRequest @@ -173,7 +166,7 @@ func (mgr *Manager) boot(name string, index int) (*report.Report, error) { // If SyzExecutorCmd is provided, it means that syz-executor is already in // the image, so no need to copy it. - executorCmd := targets.Get(mgr.cfg.TargetOS, mgr.cfg.TargetArch).SyzExecutorCmd + executorCmd := mgr.cfg.SysTarget.SyzExecutorCmd if executorCmd == "" { executorCmd, err = inst.Copy(mgr.cfg.SyzExecutorBin) if err != nil { @@ -212,7 +205,7 @@ func (mgr *Manager) finishRequest(name string, rep *report.Report) error { func (mgr *Manager) Connect(a *rpctype.ConnectArgs, r *rpctype.ConnectRes) error { r.GitRevision = prog.GitRevision - r.TargetRevision = mgr.target.Revision + r.TargetRevision = mgr.cfg.Target.Revision r.AllSandboxes = true select { case <-mgr.checkResultReady: diff --git a/tools/syz-testbuild/testbuild.go b/tools/syz-testbuild/testbuild.go index eae70e2ae..69f2c67db 100644 --- a/tools/syz-testbuild/testbuild.go +++ b/tools/syz-testbuild/testbuild.go @@ -67,7 +67,7 @@ func main() { } defer os.RemoveAll(dir) cfg := &mgrconfig.Config{ - Target: *flagOS + "/" + *flagArch, + RawTarget: *flagOS + "/" + *flagArch, HTTP: ":0", Workdir: dir, KernelSrc: *flagKernelSrc, -- cgit mrf-deployment