From d94a0369a298b9dd3a9bc17d664840ea6f64401e Mon Sep 17 00:00:00 2001 From: Taras Madan Date: Tue, 1 Jul 2025 10:15:11 +0200 Subject: dashboard/app: use crash types instead, no regexps --- pkg/report/crash/types.go | 93 ++++++++++++++++++++++++++++++++++++++------- pkg/report/linux.go | 2 +- pkg/report/report.go | 4 +- pkg/report/report_test.go | 2 +- pkg/report/title_to_type.go | 28 ++++++++++++-- 5 files changed, 107 insertions(+), 22 deletions(-) (limited to 'pkg/report') diff --git a/pkg/report/crash/types.go b/pkg/report/crash/types.go index 52fba0fbc..ad550fa08 100644 --- a/pkg/report/crash/types.go +++ b/pkg/report/crash/types.go @@ -6,21 +6,28 @@ package crash type Type string const ( - UnknownType = Type("") - Hang = Type("HANG") - MemoryLeak = Type("LEAK") - DataRace = Type("DATARACE") - UnexpectedReboot = Type("REBOOT") - UBSAN = Type("UBSAN") - Bug = Type("BUG") - Warning = Type("WARNING") - KASAN = Type("KASAN") - KFENCE = Type("KFENCE") - LockdepBug = Type("LOCKDEP") - AtomicSleep = Type("ATOMIC_SLEEP") - KMSAN = Type("KMSAN") - SyzFailure = Type("SYZ_FAILURE") + UnknownType = Type("") + // keep-sorted start + AtomicSleep = Type("ATOMIC_SLEEP") + Bug = Type("BUG") + DoS = Type("DoS") + Hang = Type("HANG") + KASAN = Type("KASAN") + KCSAN = Type("KCSAN") + KCSANDataRace = Type("DATARACE") + KFENCE = Type("KFENCE") + KMSAN = Type("KMSAN") + LockdepBug = Type("LOCKDEP") + MemoryLeak = Type("LEAK") + MemorySafetyBUG = Type("MEMORY_SAFETY_BUG") + MemorySafetyUBSAN = Type("MEMORY_SAFETY_UBSAN") + MemorySafetyWARNING = Type("MEMORY_SAFETY_WARNING") + UBSAN = Type("UBSAN") + Warning = Type("WARNING") + // keep-sorted end LostConnection = Type("LOST_CONNECTION") + SyzFailure = Type("SYZ_FAILURE") + UnexpectedReboot = Type("REBOOT") ) func (t Type) String() string { @@ -29,3 +36,61 @@ func (t Type) String() string { } return string(t) } + +type TypeGroupPred func(Type) bool + +func (t Type) IsKASAN() bool { + return t == KASAN +} + +func (t Type) IsKMSAN() bool { + return t == KMSAN +} + +func (t Type) IsKCSAN() bool { + return t == KCSANDataRace || t == KCSAN +} + +func (t Type) IsUBSAN() bool { + return t == UBSAN || t == MemorySafetyUBSAN +} + +func (t Type) IsBUG() bool { + return t == Bug || t == MemorySafetyBUG +} + +func (t Type) IsWarning() bool { + return t == Warning || t == MemorySafetyWARNING +} + +func (t Type) IsBugOrWarning() bool { + return t.IsBUG() || t.IsWarning() +} + +func (t Type) IsMemSafety() bool { + return t == MemorySafetyBUG || t == MemorySafetyWARNING || t == MemorySafetyUBSAN +} + +func (t Type) IsMemoryLeak() bool { + return t == MemoryLeak +} + +func (t Type) IsLockingBug() bool { + return t.IsLockdep() || t.IsAtomicSleep() +} + +func (t Type) IsDoS() bool { + return t == Bug || t == DoS +} + +func (t Type) IsHang() bool { + return t == Hang +} + +func (t Type) IsLockdep() bool { + return t == LockdepBug +} + +func (t Type) IsAtomicSleep() bool { + return t == AtomicSleep +} diff --git a/pkg/report/linux.go b/pkg/report/linux.go index f714e55cd..ff5d6bf4e 100644 --- a/pkg/report/linux.go +++ b/pkg/report/linux.go @@ -188,7 +188,7 @@ func (ctx *linux) Parse(output []byte) *Report { } rep.reportPrefixLen = len(rep.Report) rep.Report = append(rep.Report, report...) - rep.Type = titleToCrashType(rep.Title) + rep.Type = TitleToCrashType(rep.Title) setExecutorInfo(rep) if !rep.Corrupted { rep.Corrupted, rep.CorruptedReason = isCorrupted(title, report, format) diff --git a/pkg/report/report.go b/pkg/report/report.go index 3381607ea..44d4563e2 100644 --- a/pkg/report/report.go +++ b/pkg/report/report.go @@ -800,7 +800,7 @@ func simpleLineParser(output []byte, oopses []*oops, params *stackParams, ignore rep.Report = output[rep.StartPos:] rep.Corrupted = corrupted != "" rep.CorruptedReason = corrupted - rep.Type = titleToCrashType(rep.Title) + rep.Type = TitleToCrashType(rep.Title) return rep } @@ -933,7 +933,7 @@ var groupGoRuntimeErrors = oops{ }, } -func titleToCrashType(title string) crash.Type { +func TitleToCrashType(title string) crash.Type { for _, t := range titleToType { for _, prefix := range t.includePrefixes { if strings.HasPrefix(title, prefix) { diff --git a/pkg/report/report_test.go b/pkg/report/report_test.go index 739068787..2184cd411 100644 --- a/pkg/report/report_test.go +++ b/pkg/report/report_test.go @@ -208,7 +208,7 @@ func testFromReport(rep *Report) *ParseTest { Corrupted: rep.Corrupted, corruptedReason: rep.CorruptedReason, Suppressed: rep.Suppressed, - Type: titleToCrashType(rep.Title), + Type: TitleToCrashType(rep.Title), Frame: rep.Frame, Report: rep.Report, } diff --git a/pkg/report/title_to_type.go b/pkg/report/title_to_type.go index 44f5ccaf9..61c7b6d9d 100644 --- a/pkg/report/title_to_type.go +++ b/pkg/report/title_to_type.go @@ -11,9 +11,30 @@ var titleToType = []struct { includePrefixes []string crashType crash.Type }{ + { + includePrefixes: []string{ + // keep-sorting start + "BUG: corrupted list", + "BUG: unable to handle kernel paging request", + // keep-sorting end + }, + crashType: crash.MemorySafetyBUG, + }, + { + includePrefixes: []string{ + "WARNING: refcount bug", + }, + crashType: crash.MemorySafetyWARNING, + }, + { + includePrefixes: []string{ + "UBSAN: array-index", + }, + crashType: crash.MemorySafetyUBSAN, + }, { includePrefixes: []string{"KCSAN: data-race"}, - crashType: crash.DataRace, + crashType: crash.KCSANDataRace, }, { includePrefixes: []string{ @@ -23,6 +44,7 @@ var titleToType = []struct { "BUG: rwlock", "BUG: spinlock", "BUG: still has locks held in", + "BUG: using", // BUG: using ... in preemptible ... "WARNING: bad unlock balance in", "WARNING: held lock freed in", "WARNING: lock held", @@ -53,7 +75,6 @@ var titleToType = []struct { includePrefixes: []string{ // keep-sorted start "BUG: bad usercopy in", - "BUG: corrupted list in", "kernel BUG ", // keep-sorted end }, @@ -90,7 +111,6 @@ var titleToType = []struct { // keep-sorted start "Alignment trap in", "BUG: Object already free", - "BUG: unable to handle kernel", "Internal error in", "PANIC: double fault", "Unhandled fault in", @@ -109,7 +129,7 @@ var titleToType = []struct { "unregister_netdevice: waiting for DEV to become free", // keep-sorted end }, - crashType: crash.UnknownType, + crashType: crash.DoS, }, { includePrefixes: []string{"unexpected kernel reboot"}, -- cgit mrf-deployment