Lines Matching refs:mgr

166 	mgr := &Manager{
189 mgr.corpusDB, err = db.Open(filepath.Join(cfg.Workdir, "corpus.db"))
195 mgr.initHTTP()
196 mgr.collectUsedFiles()
199 s, err := rpctype.NewRPCServer(cfg.RPC, mgr)
204 mgr.port = s.Addr().(*net.TCPAddr).Port
208 mgr.dash = dashapi.New(cfg.DashboardClient, cfg.DashboardAddr, cfg.DashboardKey)
217 mgr.mu.Lock()
218 if mgr.firstConnect.IsZero() {
219 mgr.mu.Unlock()
222 mgr.fuzzingTime += diff * time.Duration(atomic.LoadUint32(&mgr.numFuzzing))
223 executed := mgr.stats.execTotal.get()
224 crashes := mgr.stats.crashes.get()
225 signal := mgr.corpusSignal.Len()
226 mgr.mu.Unlock()
227 numReproducing := atomic.LoadUint32(&mgr.numReproducing)
228 numFuzzing := atomic.LoadUint32(&mgr.numFuzzing)
244 mgr.mu.Lock()
245 if mgr.firstConnect.IsZero() {
246 mgr.mu.Unlock()
249 mgr.minimizeCorpus()
250 vals["corpus"] = uint64(len(mgr.corpus))
251 vals["uptime"] = uint64(time.Since(mgr.firstConnect)) / 1e9
252 vals["fuzzing"] = uint64(mgr.fuzzingTime) / 1e9
253 vals["signal"] = uint64(mgr.corpusSignal.Len())
254 vals["coverage"] = uint64(len(mgr.corpusCover))
255 for k, v := range mgr.fuzzerStats {
258 mgr.mu.Unlock()
259 for k, v := range mgr.stats.all() {
274 if mgr.dash != nil {
275 go mgr.dashboardReporter()
279 if mgr.vmPool == nil {
282 log.Logf(0, "syz-fuzzer -manager=manager.ip:%v [other flags as necessary]", mgr.port)
286 mgr.vmLoop()
306 func (mgr *Manager) vmLoop() {
310 vmCount := mgr.vmPool.Count()
327 mgr.mu.Lock()
328 phase := mgr.phase
329 mgr.mu.Unlock()
336 if !mgr.needRepro(crash) {
362 atomic.AddUint32(&mgr.numReproducing, 1)
365 res, stats, err := repro.Run(crash.Output, mgr.cfg, mgr.reporter, mgr.vmPool, vmIndexes)
375 crash, err := mgr.runInstance(idx)
383 stopRequest = mgr.vmStop
401 needRepro := mgr.saveCrash(res.crash)
408 atomic.AddUint32(&mgr.numReproducing, ^uint32(0))
425 mgr.saveFailedRepro(res.title0, res.stats)
428 mgr.saveRepro(res.res, res.stats, res.hub)
433 case crash := <-mgr.hubReproQueue:
436 case reply := <-mgr.needMoreRepros:
440 case reply := <-mgr.reproRequest:
451 func (mgr *Manager) loadCorpus() {
456 switch mgr.corpusDB.Version {
472 for _, id := range mgr.checkResult.EnabledCalls[mgr.cfg.Sandbox] {
476 for key, rec := range mgr.corpusDB.Records {
477 p, err := mgr.target.Deserialize(rec.Val)
482 mgr.corpusDB.Delete(key)
497 mgr.disabledHashes[hash.String(rec.Val)] = struct{}{}
500 mgr.candidates = append(mgr.candidates, rpctype.RPCCandidate{
506 mgr.fresh = len(mgr.corpusDB.Records) == 0
507 log.Logf(0, "%-24v: %v (%v deleted)", "corpus", len(mgr.candidates), deleted)
515 mgr.candidates = append(mgr.candidates, mgr.candidates...)
516 shuffle := mgr.candidates[len(mgr.candidates)/2:]
521 if mgr.phase != phaseInit {
522 panic(fmt.Sprintf("loadCorpus: bad phase %v", mgr.phase))
524 mgr.phase = phaseLoadedCorpus
527 func (mgr *Manager) runInstance(index int) (*Crash, error) {
528 mgr.checkUsedFiles()
529 inst, err := mgr.vmPool.Create(index)
535 fwdAddr, err := inst.Forward(mgr.port)
539 fuzzerBin, err := inst.Copy(mgr.cfg.SyzFuzzerBin)
543 executorBin, err := inst.Copy(mgr.cfg.SyzExecutorBin)
549 procs := mgr.cfg.Procs
557 atomic.AddUint32(&mgr.numFuzzing, 1)
558 defer atomic.AddUint32(&mgr.numFuzzing, ^uint32(0))
560 mgr.cfg.TargetOS, mgr.cfg.TargetArch, fwdAddr, mgr.cfg.Sandbox, procs, fuzzerV,
561 mgr.cfg.Cover, *flagDebug, false, false)
562 outc, errc, err := inst.Run(time.Hour, mgr.vmStop, cmd)
567 rep := inst.MonitorExecution(outc, errc, mgr.reporter, false)
581 func (mgr *Manager) emailCrash(crash *Crash) {
582 if len(mgr.cfg.EmailAddrs) == 0 {
586 args = append(args, mgr.cfg.EmailAddrs...)
587 log.Logf(0, "sending email to %v", mgr.cfg.EmailAddrs)
596 func (mgr *Manager) saveCrash(crash *Crash) bool {
599 mgr.stats.crashSuppressed.inc()
607 if err := mgr.reporter.Symbolize(crash.Report); err != nil {
611 mgr.stats.crashes.inc()
612 mgr.mu.Lock()
613 if !mgr.crashTypes[crash.Title] {
614 mgr.crashTypes[crash.Title] = true
615 mgr.stats.crashTypes.inc()
617 mgr.mu.Unlock()
619 if mgr.dash != nil {
621 BuildID: mgr.cfg.Tag,
628 resp, err := mgr.dash.ReportCrash(dc)
640 dir := filepath.Join(mgr.crashdir, id)
655 go mgr.emailCrash(crash)
665 if len(mgr.cfg.Tag) > 0 {
666 osutil.WriteFile(filepath.Join(dir, fmt.Sprintf("tag%v", oldestI)), []byte(mgr.cfg.Tag))
672 return mgr.needLocalRepro(crash)
677 func (mgr *Manager) needLocalRepro(crash *Crash) bool {
678 if !mgr.cfg.Reproduce || crash.Corrupted {
682 dir := filepath.Join(mgr.crashdir, sig.String())
694 func (mgr *Manager) needRepro(crash *Crash) bool {
698 if mgr.dash == nil {
699 return mgr.needLocalRepro(crash)
702 BuildID: mgr.cfg.Tag,
706 needRepro, err := mgr.dash.NeedRepro(cid)
713 func (mgr *Manager) saveFailedRepro(desc string, stats *repro.Stats) {
714 if mgr.dash != nil {
716 BuildID: mgr.cfg.Tag,
719 if err := mgr.dash.ReportFailedRepro(cid); err != nil {
725 dir := filepath.Join(mgr.crashdir, hash.String([]byte(desc)))
736 func (mgr *Manager) saveRepro(res *repro.Result, stats *repro.Stats, hub bool) {
738 if err := mgr.reporter.Symbolize(rep); err != nil {
747 res.Opts, res.Report.Title, mgr.cfg.Tag, prog))
748 mgr.mu.Lock()
749 mgr.newRepros = append(mgr.newRepros, progForHub)
750 mgr.mu.Unlock()
767 if mgr.dash != nil {
774 BuildID: mgr.cfg.Tag,
783 if _, err := mgr.dash.ReportCrash(dc); err != nil {
792 dir := filepath.Join(mgr.crashdir, hash.String([]byte(rep.Title)))
799 if len(mgr.cfg.Tag) > 0 {
800 osutil.WriteFile(filepath.Join(dir, "repro.tag"), []byte(mgr.cfg.Tag))
825 func (mgr *Manager) getMinimizedCorpus() (corpus, repros [][]byte) {
826 mgr.mu.Lock()
827 defer mgr.mu.Unlock()
828 mgr.minimizeCorpus()
829 corpus = make([][]byte, 0, len(mgr.corpus))
830 for _, inp := range mgr.corpus {
833 repros = mgr.newRepros
834 mgr.newRepros = nil
838 func (mgr *Manager) addNewCandidates(progs [][]byte) {
847 mgr.mu.Lock()
848 defer mgr.mu.Unlock()
849 mgr.candidates = append(mgr.candidates, candidates...)
850 if mgr.phase == phaseTriagedCorpus {
851 mgr.phase = phaseQueriedHub
855 func (mgr *Manager) minimizeCorpus() {
856 if mgr.phase < phaseLoadedCorpus {
859 inputs := make([]signal.Context, 0, len(mgr.corpus))
860 for _, inp := range mgr.corpus {
871 log.Logf(1, "minimized corpus: %v -> %v", len(mgr.corpus), len(newCorpus))
872 mgr.corpus = newCorpus
875 if mgr.phase < phaseTriagedCorpus {
878 for key := range mgr.corpusDB.Records {
879 _, ok1 := mgr.corpus[key]
880 _, ok2 := mgr.disabledHashes[key]
882 mgr.corpusDB.Delete(key)
885 mgr.corpusDB.BumpVersion(currentDBVersion)
888 func (mgr *Manager) Connect(a *rpctype.ConnectArgs, r *rpctype.ConnectRes) error {
890 mgr.stats.vmRestarts.inc()
891 mgr.mu.Lock()
892 defer mgr.mu.Unlock()
897 mgr.fuzzers[a.Name] = f
898 mgr.minimizeCorpus()
899 f.newMaxSignal = mgr.maxSignal.Copy()
900 f.inputs = make([]rpctype.RPCInput, 0, len(mgr.corpus))
901 for _, inp := range mgr.corpus {
904 r.EnabledCalls = mgr.enabledSyscalls
905 r.CheckResult = mgr.checkResult
907 r.TargetRevision = mgr.target.Revision
911 func (mgr *Manager) Check(a *rpctype.CheckArgs, r *int) error {
912 mgr.mu.Lock()
913 defer mgr.mu.Unlock()
915 if mgr.checkResult != nil {
918 if len(mgr.cfg.EnabledSyscalls) != 0 && len(a.DisabledCalls[mgr.cfg.Sandbox]) != 0 {
920 for _, dc := range a.DisabledCalls[mgr.cfg.Sandbox] {
921 disabled[mgr.target.Syscalls[dc.ID].Name] = dc.Reason
923 for _, id := range mgr.enabledSyscalls {
924 name := mgr.target.Syscalls[id].Name
935 len(a.EnabledCalls[mgr.cfg.Sandbox]), len(mgr.target.Syscalls))
940 mgr.checkResult = a
941 mgr.loadCorpus()
942 mgr.firstConnect = time.Now()
946 func (mgr *Manager) NewInput(a *rpctype.NewInputArgs, r *int) error {
950 mgr.mu.Lock()
951 defer mgr.mu.Unlock()
953 f := mgr.fuzzers[a.Name]
958 if _, err := mgr.target.Deserialize(a.RPCInput.Prog); err != nil {
963 if mgr.corpusSignal.Diff(inputSignal).Empty() {
966 mgr.stats.newInputs.inc()
967 mgr.corpusSignal.Merge(inputSignal)
968 mgr.corpusCover.Merge(a.Cover)
970 if inp, ok := mgr.corpus[sig]; ok {
978 mgr.corpus[sig] = inp
980 mgr.corpus[sig] = a.RPCInput
981 mgr.corpusDB.Save(sig, a.RPCInput.Prog, 0)
982 if err := mgr.corpusDB.Flush(); err != nil {
985 for _, f1 := range mgr.fuzzers {
997 func (mgr *Manager) Poll(a *rpctype.PollArgs, r *rpctype.PollRes) error {
998 mgr.mu.Lock()
999 defer mgr.mu.Unlock()
1004 mgr.stats.execTotal.add(int(v))
1006 mgr.fuzzerStats[k] += v
1010 f := mgr.fuzzers[a.Name]
1014 newMaxSignal := mgr.maxSignal.Diff(a.MaxSignal.Deserialize())
1016 mgr.maxSignal.Merge(newMaxSignal)
1017 for _, f1 := range mgr.fuzzers {
1026 if maxInputs < mgr.cfg.Procs {
1027 maxInputs = mgr.cfg.Procs
1030 for i := 0; i < maxInputs && len(mgr.candidates) > 0; i++ {
1031 last := len(mgr.candidates) - 1
1032 r.Candidates = append(r.Candidates, mgr.candidates[last])
1033 mgr.candidates[last] = rpctype.RPCCandidate{}
1034 mgr.candidates = mgr.candidates[:last]
1048 if len(mgr.candidates) == 0 {
1049 mgr.candidates = nil
1050 if mgr.phase == phaseLoadedCorpus {
1051 if mgr.cfg.HubClient != "" {
1052 mgr.phase = phaseTriagedCorpus
1053 go mgr.hubSyncLoop()
1055 mgr.phase = phaseTriagedHub
1057 } else if mgr.phase == phaseQueriedHub {
1058 mgr.phase = phaseTriagedHub
1066 func (mgr *Manager) collectUsedFiles() {
1067 if mgr.vmPool == nil {
1078 mgr.usedFiles[f] = stat.ModTime()
1080 cfg := mgr.cfg
1096 func (mgr *Manager) checkUsedFiles() {
1097 for f, mod := range mgr.usedFiles {
1112 func (mgr *Manager) dashboardReporter() {
1113 webAddr := publicWebAddr(mgr.cfg.HTTP)
1118 mgr.mu.Lock()
1119 if mgr.firstConnect.IsZero() {
1120 mgr.mu.Unlock()
1123 crashes := mgr.stats.crashes.get()
1124 execs := mgr.stats.execTotal.get()
1126 Name: mgr.cfg.Name,
1128 UpTime: time.Since(mgr.firstConnect),
1129 Corpus: uint64(len(mgr.corpus)),
1130 Cover: uint64(mgr.corpusSignal.Len()),
1131 FuzzingTime: mgr.fuzzingTime - lastFuzzingTime,
1135 mgr.mu.Unlock()
1137 if err := mgr.dash.UploadManagerStats(req); err != nil {
1141 mgr.mu.Lock()
1145 mgr.mu.Unlock()