pkg/report: fix corrupted stack trace checking

We started detecting all kernel reboots as corrupted,
because we considered that after any "Allocated" line
a stack trace should follow.
Kernel boot output now contains:
ima: Allocated hash algorithm: sha256
and there is no stack trace after that.

1. Refine stack trace regexps (we actually want to look for
"Allocated by task PID:" lines).
2. Don't check stacks if report format says that it
does not contain stacks.
This commit is contained in:
Dmitry Vyukov 2018-11-22 07:40:50 +01:00
parent 76b59936da
commit 6839de7050
2 changed files with 1151 additions and 7 deletions

View File

@ -464,17 +464,20 @@ func (ctx *linux) extractFiles(report []byte) []string {
}
func (ctx *linux) isCorrupted(title string, report []byte, format oopsFormat) (bool, string) {
// Check if the report contains stack trace.
if !format.noStackTrace && !bytes.Contains(report, []byte("Call Trace")) &&
!bytes.Contains(report, []byte("backtrace")) {
return true, "no stack trace in report"
}
// Check for common title corruptions.
for _, re := range linuxCorruptedTitles {
if re.MatchString(title) {
return true, "title matches corrupted regexp"
}
}
// Check if the report contains stack trace.
if !format.noStackTrace && !bytes.Contains(report, []byte("Call Trace")) &&
!bytes.Contains(report, []byte("backtrace")) {
return true, "no stack trace in report"
}
if format.noStackTrace {
return false, ""
}
// When a report contains 'Call Trace', 'backtrace', 'Allocated' or 'Freed' keywords,
// it must also contain at least a single stack frame after each of them.
for _, key := range linuxStackKeywords {
@ -621,8 +624,10 @@ var linuxCorruptedTitles = []*regexp.Regexp{
var linuxStackKeywords = []*regexp.Regexp{
regexp.MustCompile(`Call Trace`),
regexp.MustCompile(`Allocated`),
regexp.MustCompile(`Freed`),
regexp.MustCompile(`Allocated:`),
regexp.MustCompile(`Allocated by task [0-9]+:`),
regexp.MustCompile(`Freed:`),
regexp.MustCompile(`Freed by task [0-9]+:`),
// Match 'backtrace:', but exclude 'stack backtrace:'
regexp.MustCompile(`[^k] backtrace:`),
}

1139
pkg/report/testdata/linux/report/317 vendored Normal file

File diff suppressed because it is too large Load Diff