diff options
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/corpus/corpus.go | 41 | ||||
| -rw-r--r-- | pkg/corpus/prio_test.go | 3 | ||||
| -rw-r--r-- | pkg/manager/http.go | 63 |
3 files changed, 68 insertions, 39 deletions
diff --git a/pkg/corpus/corpus.go b/pkg/corpus/corpus.go index 487457376..99abd8188 100644 --- a/pkg/corpus/corpus.go +++ b/pkg/corpus/corpus.go @@ -50,6 +50,10 @@ func NewCorpus(ctx context.Context) *Corpus { } func NewMonitoredCorpus(ctx context.Context, updates chan<- NewItemEvent) *Corpus { + return NewFocusedCorpus(ctx, updates, nil) +} + +func NewFocusedCorpus(ctx context.Context, updates chan<- NewItemEvent, areas []FocusArea) *Corpus { corpus := &Corpus{ ctx: ctx, progsMap: make(map[string]*Item), @@ -62,6 +66,20 @@ func NewMonitoredCorpus(ctx context.Context, updates chan<- NewItemEvent) *Corpu stat.LenOf(&corpus.signal, &corpus.mu)) corpus.StatCover = stat.New("coverage", "Source coverage in the corpus", stat.Console, stat.Link("/cover"), stat.Prometheus("syz_corpus_cover"), stat.LenOf(&corpus.cover, &corpus.mu)) + for _, area := range areas { + obj := &ProgramsList{} + if len(areas) > 1 && area.Name != "" { + // Only show extra statistics if there's more than one area. + stat.New("corpus ["+area.Name+"]", + fmt.Sprintf("Corpus programs of the focus area %q", area.Name), + stat.Console, stat.Graph("corpus"), + stat.LenOf(&obj.progs, &corpus.mu)) + } + corpus.focusAreas = append(corpus.focusAreas, &focusAreaState{ + FocusArea: area, + ProgramsList: obj, + }) + } return corpus } @@ -106,29 +124,6 @@ type NewItemEvent struct { NewCover []uint64 } -// SetFocusAreas can only be called once on an empty corpus. -func (corpus *Corpus) SetFocusAreas(areas []FocusArea) { - corpus.mu.Lock() - defer corpus.mu.Unlock() - if len(corpus.progsMap) > 0 { - panic("SetFocusAreas() is called on a non-empty corpus") - } - for _, area := range areas { - obj := &ProgramsList{} - if len(areas) > 1 && area.Name != "" { - // Only show extra statistics if there's more than one area. - stat.New("corpus ["+area.Name+"]", - fmt.Sprintf("Corpus programs of the focus area %q", area.Name), - stat.Console, stat.Graph("corpus"), - stat.LenOf(&obj.progs, &corpus.mu)) - } - corpus.focusAreas = append(corpus.focusAreas, &focusAreaState{ - FocusArea: area, - ProgramsList: obj, - }) - } -} - func (corpus *Corpus) Save(inp NewInput) { progData := inp.Prog.Serialize() sig := hash.String(progData) diff --git a/pkg/corpus/prio_test.go b/pkg/corpus/prio_test.go index 6328ba3e5..71507c2b1 100644 --- a/pkg/corpus/prio_test.go +++ b/pkg/corpus/prio_test.go @@ -51,8 +51,7 @@ func TestChooseProgram(t *testing.T) { func TestFocusAreas(t *testing.T) { target := getTarget(t, targets.TestOS, targets.TestArch64) - corpus := NewCorpus(context.Background()) - corpus.SetFocusAreas([]FocusArea{ + corpus := NewFocusedCorpus(context.Background(), nil, []FocusArea{ { CoverPCs: map[uint64]struct{}{ 0: {}, diff --git a/pkg/manager/http.go b/pkg/manager/http.go index c94ce727f..aa54c66eb 100644 --- a/pkg/manager/http.go +++ b/pkg/manager/http.go @@ -49,11 +49,11 @@ type HTTPServer struct { // To be set once. Cfg *mgrconfig.Config StartTime time.Time - Corpus *corpus.Corpus CrashStore *CrashStore DiffStore *DiffFuzzerStore // Set dynamically. + Corpus atomic.Pointer[corpus.Corpus] Fuzzer atomic.Pointer[fuzzer.Fuzzer] Cover atomic.Pointer[CoverageInfo] ReproLoop atomic.Pointer[ReproLoop] @@ -172,10 +172,12 @@ func (serv *HTTPServer) httpExpertMode(w http.ResponseWriter, r *http.Request) { func (serv *HTTPServer) httpSyscalls(w http.ResponseWriter, r *http.Request) { var calls map[string]*corpus.CallCov - if obj := serv.EnabledSyscalls.Load(); obj != nil { - calls = serv.Corpus.CallCover() + syscallsObj := serv.EnabledSyscalls.Load() + corpusObj := serv.Corpus.Load() + if corpusObj != nil && syscallsObj != nil { + calls = corpusObj.CallCover() // Add enabled, but not yet covered calls. - for call := range obj.(map[*prog.Syscall]bool) { + for call := range syscallsObj.(map[*prog.Syscall]bool) { if calls[call.Name] == nil { calls[call.Name] = new(corpus.CallCov) } @@ -321,11 +323,16 @@ func (serv *HTTPServer) httpCrash(w http.ResponseWriter, r *http.Request) { } func (serv *HTTPServer) httpCorpus(w http.ResponseWriter, r *http.Request) { + corpus := serv.Corpus.Load() + if corpus == nil { + http.Error(w, "the corpus information is not yet available", http.StatusInternalServerError) + return + } data := UICorpus{ Call: r.FormValue("call"), RawCover: serv.Cfg.RawCover, } - for _, inp := range serv.Corpus.Items() { + for _, inp := range corpus.Items() { if data.Call != "" && data.Call != inp.StringCall() { continue } @@ -416,6 +423,12 @@ func (serv *HTTPServer) httpCoverCover(w http.ResponseWriter, r *http.Request, f return } + corpus := serv.Corpus.Load() + if corpus == nil { + http.Error(w, "the corpus information is not yet available", http.StatusInternalServerError) + return + } + rg, err := coverInfo.ReportGenerator.Get() if err != nil { http.Error(w, fmt.Sprintf("failed to generate coverage profile: %v", err), http.StatusInternalServerError) @@ -431,7 +444,7 @@ func (serv *HTTPServer) httpCoverCover(w http.ResponseWriter, r *http.Request, f var progs []cover.Prog if sig := r.FormValue("input"); sig != "" { - inp := serv.Corpus.Item(sig) + inp := corpus.Item(sig) if inp == nil { http.Error(w, "unknown input hash", http.StatusInternalServerError) return @@ -456,7 +469,7 @@ func (serv *HTTPServer) httpCoverCover(w http.ResponseWriter, r *http.Request, f } } else { call := r.FormValue("call") - for _, inp := range serv.Corpus.Items() { + for _, inp := range corpus.Items() { if call != "" && call != inp.StringCall() { continue } @@ -511,8 +524,13 @@ func (serv *HTTPServer) httpCoverCover(w http.ResponseWriter, r *http.Request, f } func (serv *HTTPServer) httpCoverFallback(w http.ResponseWriter, r *http.Request) { + corpus := serv.Corpus.Load() + if corpus == nil { + http.Error(w, "the corpus information is not yet available", http.StatusInternalServerError) + return + } calls := make(map[int][]int) - for s := range serv.Corpus.Signal() { + for s := range corpus.Signal() { id, errno := prog.DecodeFallbackSignal(uint64(s)) calls[id] = append(calls[id], errno) } @@ -548,6 +566,12 @@ func (serv *HTTPServer) httpFileCover(w http.ResponseWriter, r *http.Request) { } func (serv *HTTPServer) httpPrio(w http.ResponseWriter, r *http.Request) { + corpus := serv.Corpus.Load() + if corpus == nil { + http.Error(w, "the corpus information is not yet available", http.StatusInternalServerError) + return + } + callName := r.FormValue("call") call := serv.Cfg.Target.SyscallMap[callName] if call == nil { @@ -555,11 +579,12 @@ func (serv *HTTPServer) httpPrio(w http.ResponseWriter, r *http.Request) { return } - var corpus []*prog.Prog - for _, inp := range serv.Corpus.Items() { - corpus = append(corpus, inp.Prog) + var progs []*prog.Prog + for _, inp := range corpus.Items() { + progs = append(progs, inp.Prog) } - prios := serv.Cfg.Target.CalculatePriorities(corpus) + + prios := serv.Cfg.Target.CalculatePriorities(progs) data := &UIPrioData{Call: callName} for i, p := range prios[call.ID] { @@ -589,7 +614,12 @@ func (serv *HTTPServer) httpFile(w http.ResponseWriter, r *http.Request) { } func (serv *HTTPServer) httpInput(w http.ResponseWriter, r *http.Request) { - inp := serv.Corpus.Item(r.FormValue("sig")) + corpus := serv.Corpus.Load() + if corpus == nil { + http.Error(w, "the corpus information is not yet available", http.StatusInternalServerError) + return + } + inp := corpus.Item(r.FormValue("sig")) if inp == nil { http.Error(w, "can't find the input", http.StatusInternalServerError) return @@ -599,7 +629,12 @@ func (serv *HTTPServer) httpInput(w http.ResponseWriter, r *http.Request) { } func (serv *HTTPServer) httpDebugInput(w http.ResponseWriter, r *http.Request) { - inp := serv.Corpus.Item(r.FormValue("sig")) + corpus := serv.Corpus.Load() + if corpus == nil { + http.Error(w, "the corpus information is not yet available", http.StatusInternalServerError) + return + } + inp := corpus.Item(r.FormValue("sig")) if inp == nil { http.Error(w, "can't find the input", http.StatusInternalServerError) return |
