From f38211dffe4374a9e09d966b021c00da9d1300c5 Mon Sep 17 00:00:00 2001 From: Aleksandr Nogikh Date: Wed, 14 Dec 2022 19:09:08 +0100 Subject: dashboard: extract subsystems for saved crashes Invoke the extractor code at pkg/subsystem and store the result into the Bug entity. Augment the Maintainers content by per-subsystem emails. --- pkg/subsystem/extract.go | 31 ++++++++++++++++++++++--------- pkg/subsystem/extract_test.go | 5 +++-- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'pkg/subsystem') diff --git a/pkg/subsystem/extract.go b/pkg/subsystem/extract.go index caf80636e..181c15835 100644 --- a/pkg/subsystem/extract.go +++ b/pkg/subsystem/extract.go @@ -7,11 +7,11 @@ import ( "regexp" "github.com/google/syzkaller/prog" - "github.com/google/syzkaller/sys/targets" ) type SubsystemExtractor struct { - CallToSubsystems func(call string) []string + pathToSubsystems func(path string) []string + callToSubsystems func(call string) []string } // Crash contains the subset of Crash fields relevant for subsystem extraction. @@ -21,21 +21,26 @@ type Crash struct { SyzRepro string } +func MakeLinuxSubsystemExtractor() *SubsystemExtractor { + return &SubsystemExtractor{ + pathToSubsystems: linuxPathToSubsystems, + } +} + func (se *SubsystemExtractor) Extract(crash *Crash) []string { retMap := map[string]bool{} // Currently we only have the dumbest possible implementation of subsystem detection. - if crash.OS == targets.Linux { - for _, guiltyPath := range crash.GuiltyFiles { - if vfsPathRegexp.MatchString(guiltyPath) { - retMap["vfs"] = true - break + if se.pathToSubsystems != nil { + for _, path := range crash.GuiltyFiles { + for _, value := range se.pathToSubsystems(path) { + retMap[value] = true } } } - if se.CallToSubsystems != nil { + if se.callToSubsystems != nil { callSet, _, _ := prog.CallSet([]byte(crash.SyzRepro)) for call := range callSet { - for _, subsystem := range se.CallToSubsystems(call) { + for _, subsystem := range se.callToSubsystems(call) { retMap[subsystem] = true } } @@ -47,6 +52,14 @@ func (se *SubsystemExtractor) Extract(crash *Crash) []string { return retSlice } +func linuxPathToSubsystems(path string) []string { + ret := []string{} + if vfsPathRegexp.MatchString(path) { + ret = append(ret, "vfs") + } + return ret +} + var ( vfsPathRegexp = regexp.MustCompile(`^fs/[^/]+\.c`) ) diff --git a/pkg/subsystem/extract_test.go b/pkg/subsystem/extract_test.go index 936f4fa8e..29512f460 100644 --- a/pkg/subsystem/extract_test.go +++ b/pkg/subsystem/extract_test.go @@ -12,7 +12,7 @@ import ( ) func TestSimpleLinuxExtract(t *testing.T) { - se := &SubsystemExtractor{} + se := MakeLinuxSubsystemExtractor() ret := se.Extract(&Crash{ OS: targets.Linux, @@ -34,7 +34,8 @@ func TestSimpleLinuxExtract(t *testing.T) { func TestProgCallRules(t *testing.T) { se := &SubsystemExtractor{ - CallToSubsystems: func(call string) []string { + pathToSubsystems: linuxPathToSubsystems, + callToSubsystems: func(call string) []string { ret := map[string][]string{ // Intentionally add some that are not present in the test below. "test": {"test"}, -- cgit mrf-deployment