From afa86b09bcac3bc4220aa5b71285d98ff57422a5 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Fri, 11 Oct 2024 13:41:40 +0200 Subject: tools/syz-repro: order Loop() and vmPool.Close() There used to be no strict ordering between cancelling the loop context and the actual moment the Loop() method exits. Now that we assert that all instances are freed in vmPool.Close(), we need to wait until Loop() finishes before closing the VM pool. Restructure the main() method to ensure this order. --- tools/syz-repro/repro.go | 72 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 35 deletions(-) (limited to 'tools/syz-repro') diff --git a/tools/syz-repro/repro.go b/tools/syz-repro/repro.go index c7526af3d..220170599 100644 --- a/tools/syz-repro/repro.go +++ b/tools/syz-repro/repro.go @@ -62,45 +62,47 @@ func main() { } pool := vm.NewDispatcher(vmPool, nil) pool.ReserveForRun(count) - ctx, done := context.WithCancel(context.Background()) - go pool.Loop(ctx) - defer done() - res, stats, err := repro.Run(data, cfg, flatrpc.AllFeatures, reporter, pool) - if err != nil { - log.Logf(0, "reproduction failed: %v", err) - } - if stats != nil { - fmt.Printf("extracting prog: %v\n", stats.ExtractProgTime) - fmt.Printf("minimizing prog: %v\n", stats.MinimizeProgTime) - fmt.Printf("simplifying prog options: %v\n", stats.SimplifyProgTime) - fmt.Printf("extracting C: %v\n", stats.ExtractCTime) - fmt.Printf("simplifying C: %v\n", stats.SimplifyCTime) - } - if res == nil { - return - } + ctx, done := context.WithCancel(context.Background()) + go func() { + defer done() - fmt.Printf("opts: %+v crepro: %v\n\n", res.Opts, res.CRepro) + res, stats, err := repro.Run(data, cfg, flatrpc.AllFeatures, reporter, pool) + if err != nil { + log.Logf(0, "reproduction failed: %v", err) + } + if stats != nil { + fmt.Printf("extracting prog: %v\n", stats.ExtractProgTime) + fmt.Printf("minimizing prog: %v\n", stats.MinimizeProgTime) + fmt.Printf("simplifying prog options: %v\n", stats.SimplifyProgTime) + fmt.Printf("extracting C: %v\n", stats.ExtractCTime) + fmt.Printf("simplifying C: %v\n", stats.SimplifyCTime) + } + if res == nil { + return + } - progSerialized := res.Prog.Serialize() - fmt.Printf("%s\n", progSerialized) - if err = osutil.WriteFile(*flagOutput, progSerialized); err == nil { - fmt.Printf("program saved to %s\n", *flagOutput) - } else { - log.Logf(0, "failed to write prog to file: %v", err) - } + fmt.Printf("opts: %+v crepro: %v\n\n", res.Opts, res.CRepro) + progSerialized := res.Prog.Serialize() + fmt.Printf("%s\n", progSerialized) + if err = osutil.WriteFile(*flagOutput, progSerialized); err == nil { + fmt.Printf("program saved to %s\n", *flagOutput) + } else { + log.Logf(0, "failed to write prog to file: %v", err) + } - if res.Report != nil && *flagTitle != "" { - recordTitle(res, *flagTitle) - } - if res.CRepro { - recordCRepro(res, *flagCRepro) - } - if *flagStrace != "" { - result := repro.RunStrace(res, cfg, reporter, pool) - recordStraceResult(result, *flagStrace) - } + if res.Report != nil && *flagTitle != "" { + recordTitle(res, *flagTitle) + } + if res.CRepro { + recordCRepro(res, *flagCRepro) + } + if *flagStrace != "" { + result := repro.RunStrace(res, cfg, reporter, pool) + recordStraceResult(result, *flagStrace) + } + }() + pool.Loop(ctx) } func recordTitle(res *repro.Result, fileName string) { -- cgit mrf-deployment