aboutsummaryrefslogtreecommitdiffstats
path: root/tools/syz-testbed/instance.go
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2022-02-11 10:04:55 +0000
committerAleksandr Nogikh <wp32pw@gmail.com>2022-02-25 18:57:42 +0100
commitaba4330c5c9f0ef53b81382508da7ded88ddffc0 (patch)
tree44d2fac4c8fa2a05bb82c130b2ee14782679b995 /tools/syz-testbed/instance.go
parent2fe98689e99191e3ed22838cf26b976ea266ca8e (diff)
tools/syz-testbed: support experiments with syz-repro
Add a "syz-repro" target and 3 tables: - List of all performed (and ongoing) reproductions. - Comparison of repro rate for different bugs on different checkouts. - Comparison of the share of C reproducers.
Diffstat (limited to 'tools/syz-testbed/instance.go')
-rw-r--r--tools/syz-testbed/instance.go71
1 files changed, 68 insertions, 3 deletions
diff --git a/tools/syz-testbed/instance.go b/tools/syz-testbed/instance.go
index f34df8a98..f3a4c0bc6 100644
--- a/tools/syz-testbed/instance.go
+++ b/tools/syz-testbed/instance.go
@@ -18,6 +18,7 @@ type Instance interface {
Run() error
Stop()
FetchResult() (RunResult, error)
+ Uptime() time.Duration
}
// The essential information about an active instance.
@@ -26,6 +27,8 @@ type InstanceCommon struct {
LogFile string
ExecCommand string
ExecCommandArgs []string
+ StartedAt time.Time
+ StoppedAt time.Time
stopChannel chan bool
}
@@ -45,14 +48,15 @@ func (inst *InstanceCommon) Run() error {
}
complete := make(chan error)
+ inst.StartedAt = time.Now()
cmd.Start()
go func() {
complete <- cmd.Wait()
}()
select {
- case <-complete:
- return nil
+ case err := <-complete:
+ return err
case <-inst.stopChannel:
// TODO: handle other OSes?
cmd.Process.Signal(os.Interrupt)
@@ -65,8 +69,9 @@ func (inst *InstanceCommon) Run() error {
cmd.Process.Kill()
<-complete
}
- return nil
}
+ inst.StoppedAt = time.Now()
+ return nil
}
func (inst *InstanceCommon) Stop() {
@@ -76,6 +81,13 @@ func (inst *InstanceCommon) Stop() {
}
}
+func (inst *InstanceCommon) Uptime() time.Duration {
+ if !inst.StartedAt.IsZero() && inst.StoppedAt.IsZero() {
+ return time.Since(inst.StartedAt)
+ }
+ return inst.StoppedAt.Sub(inst.StartedAt)
+}
+
type SyzManagerInstance struct {
InstanceCommon
SyzkallerInfo
@@ -175,3 +187,56 @@ func (t *SyzManagerTarget) newSyzManagerInstance(slotName, uniqName string, chec
RunTime: t.config.RunTime.Duration,
}, nil
}
+
+type SyzReproInstance struct {
+ InstanceCommon
+ SyzkallerInfo
+ Input *SyzReproInput
+ ReproFile string
+ CReproFile string
+ // TODO: we also want to extract source and new bug titles
+}
+
+func (inst *SyzReproInstance) FetchResult() (RunResult, error) {
+ return &SyzReproResult{
+ Input: inst.Input,
+ ReproFound: osutil.IsExist(inst.ReproFile),
+ CReproFound: osutil.IsExist(inst.CReproFile),
+ Duration: inst.Uptime(),
+ }, nil
+}
+
+func (t *SyzReproTarget) newSyzReproInstance(slotName, uniqName string, input *SyzReproInput,
+ checkout *Checkout) (Instance, error) {
+ folder := filepath.Join(checkout.Path, fmt.Sprintf("run-%s", uniqName))
+ common, err := SetupSyzkallerInstance(slotName, folder, checkout)
+ if err != nil {
+ return nil, err
+ }
+
+ reproFile := filepath.Join(folder, "repro.txt")
+ cReproFile := filepath.Join(folder, "crepro.txt")
+ newExecLog := filepath.Join(folder, "execution-log.txt")
+ err = osutil.CopyFile(input.Path, newExecLog)
+ if err != nil {
+ return nil, err
+ }
+ return &SyzReproInstance{
+ InstanceCommon: InstanceCommon{
+ Name: uniqName,
+ LogFile: filepath.Join(folder, "log.txt"),
+ ExecCommand: filepath.Join(checkout.Path, "bin", "syz-repro"),
+ ExecCommandArgs: []string{
+ "-config", common.CfgFile,
+ "-output", reproFile,
+ "-crepro", cReproFile,
+ newExecLog,
+ },
+ stopChannel: make(chan bool, 1),
+ },
+ SyzkallerInfo: *common,
+ Input: input,
+ ReproFile: reproFile,
+ CReproFile: cReproFile,
+ }, nil
+}