From 2d51d57a71659b063ddcb21cc50845d05d39708b Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 1 Apr 2022 13:16:03 +0000 Subject: all: run strace on each found reproducer If `strace_bin` is specified, syzkaller will invoke a reproducer with it and save the output. This should help in debugging. If syz-manager is attached to a dashboard, upload the strace-powered output and report. --- tools/syz-crush/crush.go | 7 +++++++ tools/syz-repro/repro.go | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'tools') diff --git a/tools/syz-crush/crush.go b/tools/syz-crush/crush.go index 36424c61a..a88041a37 100644 --- a/tools/syz-crush/crush.go +++ b/tools/syz-crush/crush.go @@ -31,6 +31,7 @@ var ( flagDebug = flag.Bool("debug", false, "dump all VM output to console") flagRestartTime = flag.Duration("restart_time", 0, "how long to run the test") flagInfinite = flag.Bool("infinite", true, "by default test is run for ever, -infinite=false to stop on crash") + flagStrace = flag.Bool("strace", false, "run under strace (binary must be set in the config file") ) type FileType int @@ -59,6 +60,9 @@ func main() { } else { log.Printf("running until crash is found or till %v", *flagRestartTime) } + if *flagStrace && cfg.StraceBin == "" { + log.Fatalf("strace_bin must not be empty in order to run with -strace") + } vmPool, err := vm.Create(cfg, *flagDebug) if err != nil { @@ -160,6 +164,9 @@ func runInstance(cfg *mgrconfig.Config, reporter *report.Reporter, optArgs := &instance.OptionalConfig{ ExitCondition: vm.ExitTimeout, } + if *flagStrace { + optArgs.StraceBin = cfg.StraceBin + } var err error inst, err := instance.CreateExecProgInstance(vmPool, index, cfg, reporter, optArgs) if err != nil { diff --git a/tools/syz-repro/repro.go b/tools/syz-repro/repro.go index 6622b8203..247cc11cd 100644 --- a/tools/syz-repro/repro.go +++ b/tools/syz-repro/repro.go @@ -25,6 +25,7 @@ var ( flagDebug = flag.Bool("debug", false, "print debug output") flagOutput = flag.String("output", filepath.Join(".", "repro.txt"), "output description file (output.txt)") flagCRepro = flag.String("crepro", filepath.Join(".", "repro.c"), "output c file (repro.c)") + flagStrace = flag.String("strace", "", "output strace log (strace_bin must be set)") ) func main() { @@ -104,4 +105,21 @@ func main() { log.Logf(0, "failed to write C repro to file: %v", err) } } + if *flagStrace != "" { + result := repro.RunStrace(res, cfg, reporter, vmPool, vmIndexes[0]) + if result.Error != nil { + log.Logf(0, "failed to run strace: %v", result.Error) + } else { + if result.Report != nil { + log.Logf(0, "under strace repro crashed with title: %s", result.Report.Title) + } else { + log.Logf(0, "repro didn't crash under strace") + } + if err := osutil.WriteFile(*flagStrace, result.Output); err == nil { + fmt.Printf("C file saved to %s\n", *flagStrace) + } else { + log.Logf(0, "failed to write strace output to file: %v", err) + } + } + } } -- cgit mrf-deployment