github.com/google/syzkaller@v0.0.0-20240517125934-c0f1611a36d6/pkg/repro/strace.go (about) 1 // Copyright 2022 syzkaller project authors. All rights reserved. 2 // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. 3 4 package repro 5 6 import ( 7 "fmt" 8 9 "github.com/google/syzkaller/pkg/instance" 10 "github.com/google/syzkaller/pkg/log" 11 "github.com/google/syzkaller/pkg/mgrconfig" 12 "github.com/google/syzkaller/pkg/report" 13 "github.com/google/syzkaller/vm" 14 ) 15 16 type StraceResult struct { 17 Report *report.Report 18 Output []byte 19 Error error 20 } 21 22 const ( 23 straceOutputLogSize = 2048 << 10 24 ) 25 26 func RunStrace(result *Result, cfg *mgrconfig.Config, reporter *report.Reporter, 27 vmPool *vm.Pool, vmIndex int) *StraceResult { 28 if cfg.StraceBin == "" { 29 return straceFailed(fmt.Errorf("strace binary is not set in the config")) 30 } 31 inst, err := instance.CreateExecProgInstance(vmPool, vmIndex, cfg, reporter, 32 &instance.OptionalConfig{ 33 StraceBin: cfg.StraceBin, 34 BeforeContextLen: straceOutputLogSize, 35 }) 36 if err != nil { 37 return straceFailed(fmt.Errorf("failed to set up instance: %w", err)) 38 } 39 defer inst.VMInstance.Close() 40 41 var runRes *instance.RunResult 42 if result.CRepro { 43 log.Logf(1, "running C repro under strace") 44 runRes, err = inst.RunCProg(result.Prog, result.Duration, result.Opts) 45 } else { 46 log.Logf(1, "running syz repro under strace") 47 runRes, err = inst.RunSyzProg(result.Prog.Serialize(), result.Duration, result.Opts) 48 } 49 if err != nil { 50 return straceFailed(fmt.Errorf("failed to generate strace log: %w", err)) 51 } 52 return &StraceResult{ 53 Report: runRes.Report, 54 Output: runRes.Output, 55 } 56 } 57 58 func straceFailed(err error) *StraceResult { 59 return &StraceResult{Error: err} 60 } 61 62 func (strace *StraceResult) IsSameBug(repro *Result) bool { 63 if strace == nil || strace.Report == nil || repro.Report == nil { 64 return false 65 } 66 return strace.Report.Title == repro.Report.Title 67 }