diff options
| -rw-r--r-- | pkg/instance/instance.go | 2 | ||||
| -rw-r--r-- | syz-fuzzer/fuzzer.go | 40 | ||||
| -rw-r--r-- | syz-manager/manager.go | 1 | ||||
| -rw-r--r-- | vm/gvisor/gvisor.go | 8 | ||||
| -rw-r--r-- | vm/vm.go | 7 | ||||
| -rw-r--r-- | vm/vmimpl/vmimpl.go | 5 |
6 files changed, 46 insertions, 17 deletions
diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go index 7696a945d..2f48cdbc7 100644 --- a/pkg/instance/instance.go +++ b/pkg/instance/instance.go @@ -459,6 +459,7 @@ type OptionalFuzzerArgs struct { Slowdown int RawCover bool SandboxArg int + PprofPort int } type FuzzerCmdArgs struct { @@ -500,6 +501,7 @@ func FuzzerCmd(args *FuzzerCmdArgs) string { {Name: "slowdown", Value: fmt.Sprint(args.Optional.Slowdown)}, {Name: "raw_cover", Value: fmt.Sprint(args.Optional.RawCover)}, {Name: "sandbox_arg", Value: fmt.Sprint(args.Optional.SandboxArg)}, + {Name: "pprof_port", Value: fmt.Sprint(args.Optional.PprofPort)}, } optionalArg = " " + tool.OptionalFlags(flags) } diff --git a/syz-fuzzer/fuzzer.go b/syz-fuzzer/fuzzer.go index 99d04f57f..ed22edde2 100644 --- a/syz-fuzzer/fuzzer.go +++ b/syz-fuzzer/fuzzer.go @@ -30,7 +30,6 @@ import ( "github.com/google/syzkaller/prog" _ "github.com/google/syzkaller/sys" "github.com/google/syzkaller/sys/targets" - "github.com/google/syzkaller/vm/vmimpl" ) type Fuzzer struct { @@ -160,15 +159,16 @@ func main() { debug.SetGCPercent(50) var ( - flagName = flag.String("name", "test", "unique name for manager") - flagOS = flag.String("os", runtime.GOOS, "target OS") - flagArch = flag.String("arch", runtime.GOARCH, "target arch") - flagManager = flag.String("manager", "", "manager rpc address") - flagProcs = flag.Int("procs", 1, "number of parallel test processes") - flagOutput = flag.String("output", "stdout", "write programs to none/stdout/dmesg/file") - flagTest = flag.Bool("test", false, "enable image testing mode") // used by syz-ci - flagRunTest = flag.Bool("runtest", false, "enable program testing mode") // used by pkg/runtest - flagRawCover = flag.Bool("raw_cover", false, "fetch raw coverage") + flagName = flag.String("name", "test", "unique name for manager") + flagOS = flag.String("os", runtime.GOOS, "target OS") + flagArch = flag.String("arch", runtime.GOARCH, "target arch") + flagManager = flag.String("manager", "", "manager rpc address") + flagProcs = flag.Int("procs", 1, "number of parallel test processes") + flagOutput = flag.String("output", "stdout", "write programs to none/stdout/dmesg/file") + flagTest = flag.Bool("test", false, "enable image testing mode") // used by syz-ci + flagRunTest = flag.Bool("runtest", false, "enable program testing mode") // used by pkg/runtest + flagRawCover = flag.Bool("raw_cover", false, "fetch raw coverage") + flagPprofPort = flag.Int("pprof_port", 0, "HTTP port for the pprof endpoint (disabled if 0)") ) defer tool.Init()() outputType := parseOutputType(*flagOutput) @@ -197,13 +197,9 @@ func main() { os.Exit(1) }() - // Necessary for pprof handlers. - go func() { - err := http.ListenAndServe(fmt.Sprintf("0.0.0.0:%v", vmimpl.PprofPort), nil) - if err != nil { - log.SyzFatalf("failed to setup a server: %v", err) - } - }() + if *flagPprofPort != 0 { + setupPprofHandler(*flagPprofPort) + } checkArgs := &checkArgs{ target: target, @@ -629,6 +625,16 @@ func (fuzzer *Fuzzer) checkNewCallSignal(p *prog.Prog, info *ipc.CallInfo, call return true } +func setupPprofHandler(port int) { + // Necessary for pprof handlers. + go func() { + err := http.ListenAndServe(fmt.Sprintf("0.0.0.0:%v", port), nil) + if err != nil { + log.SyzFatalf("failed to setup a server: %v", err) + } + }() +} + func signalPrio(p *prog.Prog, info *ipc.CallInfo, call int) (prio uint8) { if call == -1 { return 0 diff --git a/syz-manager/manager.go b/syz-manager/manager.go index 77efb32d2..3efee4f0e 100644 --- a/syz-manager/manager.go +++ b/syz-manager/manager.go @@ -827,6 +827,7 @@ func (mgr *Manager) runInstanceInner(index int, instanceName string) (*report.Re Slowdown: mgr.cfg.Timeouts.Slowdown, RawCover: mgr.cfg.RawCover, SandboxArg: mgr.cfg.SandboxArg, + PprofPort: inst.PprofPort(), }, } cmd := instance.FuzzerCmd(args) diff --git a/vm/gvisor/gvisor.go b/vm/gvisor/gvisor.go index 5ca3e0971..45c076b23 100644 --- a/vm/gvisor/gvisor.go +++ b/vm/gvisor/gvisor.go @@ -243,6 +243,14 @@ func (inst *instance) Info() ([]byte, error) { return []byte(info), nil } +func (inst *instance) PprofPort() int { + // Some of the gVisor instances use the host's network namespace, which + // results in conflicting bind operations on the same HTTP port. + // Until there's an actual need to debug gVisor VMs with pprof, let's + // just disable it. + return 0 +} + func (inst *instance) runscCmd(add ...string) *exec.Cmd { cmd := osutil.Command(inst.image, append(inst.args(), add...)...) cmd.Env = []string{ @@ -187,6 +187,13 @@ func (inst *Instance) Info() ([]byte, error) { return nil, nil } +func (inst *Instance) PprofPort() int { + if ii, ok := inst.impl.(vmimpl.PprofPortProvider); ok { + return ii.PprofPort() + } + return vmimpl.PprofPort +} + func (inst *Instance) diagnose(rep *report.Report) ([]byte, bool) { if rep == nil { panic("rep is nil") diff --git a/vm/vmimpl/vmimpl.go b/vm/vmimpl/vmimpl.go index 8b63ca77e..a9afdc1f1 100644 --- a/vm/vmimpl/vmimpl.go +++ b/vm/vmimpl/vmimpl.go @@ -67,6 +67,11 @@ type Infoer interface { Info() ([]byte, error) } +// PprofPortProvider is used when the instance wants to define a custom pprof port. +type PprofPortProvider interface { + PprofPort() int +} + // Env contains global constant parameters for a pool of VMs. type Env struct { // Unique name |
