2018-07-04 07:57:55 +00:00
|
|
|
// Copyright 2018 syzkaller project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package report
|
|
|
|
|
|
|
|
import (
|
2018-07-16 15:03:14 +00:00
|
|
|
"bufio"
|
2018-07-04 07:57:55 +00:00
|
|
|
"bytes"
|
2018-07-16 15:03:14 +00:00
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2018-07-04 07:57:55 +00:00
|
|
|
"regexp"
|
2018-07-16 15:03:14 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/syzkaller/pkg/symbolizer"
|
2018-07-04 07:57:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type akaros struct {
|
|
|
|
ignores []*regexp.Regexp
|
2018-07-16 15:03:14 +00:00
|
|
|
objfile string
|
2018-07-04 07:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ctorAkaros(kernelSrc, kernelObj string, ignores []*regexp.Regexp) (Reporter, []string, error) {
|
|
|
|
ctx := &akaros{
|
|
|
|
ignores: ignores,
|
2018-07-16 15:03:14 +00:00
|
|
|
objfile: filepath.Join(kernelObj, "akaros-kernel-64b"),
|
2018-07-04 07:57:55 +00:00
|
|
|
}
|
|
|
|
return ctx, nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *akaros) ContainsCrash(output []byte) bool {
|
|
|
|
return containsCrash(output, akarosOopses, ctx.ignores)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *akaros) Parse(output []byte) *Report {
|
|
|
|
rep := &Report{
|
|
|
|
Output: output,
|
|
|
|
}
|
|
|
|
var oops *oops
|
|
|
|
for pos := 0; pos < len(output); {
|
|
|
|
next := bytes.IndexByte(output[pos:], '\n')
|
|
|
|
if next != -1 {
|
|
|
|
next += pos
|
|
|
|
} else {
|
|
|
|
next = len(output)
|
|
|
|
}
|
|
|
|
line := output[pos:next]
|
|
|
|
for _, oops1 := range akarosOopses {
|
|
|
|
match := matchOops(line, oops1, ctx.ignores)
|
|
|
|
if match != -1 {
|
|
|
|
oops = oops1
|
|
|
|
rep.StartPos = pos
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if oops != nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
pos = next + 1
|
|
|
|
}
|
|
|
|
if oops == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2018-07-16 15:03:14 +00:00
|
|
|
title, corrupted, _ := extractDescription(output[rep.StartPos:], oops, akarosStackParams)
|
2018-07-04 07:57:55 +00:00
|
|
|
rep.Title = title
|
2018-07-16 15:03:14 +00:00
|
|
|
rep.Report = ctx.minimizeReport(output[rep.StartPos:])
|
2018-07-04 07:57:55 +00:00
|
|
|
rep.Corrupted = corrupted != ""
|
2018-07-16 15:03:14 +00:00
|
|
|
rep.CorruptedReason = corrupted
|
2018-07-04 07:57:55 +00:00
|
|
|
return rep
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *akaros) Symbolize(rep *Report) error {
|
2018-07-16 15:03:14 +00:00
|
|
|
symb := symbolizer.NewSymbolizer()
|
|
|
|
defer symb.Close()
|
|
|
|
var symbolized []byte
|
|
|
|
s := bufio.NewScanner(bytes.NewReader(rep.Report))
|
|
|
|
for s.Scan() {
|
|
|
|
line := bytes.Trim(s.Bytes(), "\r")
|
|
|
|
line = ctx.symbolizeLine(symb.Symbolize, ctx.objfile, line)
|
|
|
|
symbolized = append(symbolized, line...)
|
|
|
|
symbolized = append(symbolized, '\n')
|
|
|
|
}
|
|
|
|
rep.Report = symbolized
|
2018-07-04 07:57:55 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-07-16 15:03:14 +00:00
|
|
|
func (ctx *akaros) symbolizeLine(symbFunc func(bin string, pc uint64) ([]symbolizer.Frame, error),
|
|
|
|
objfile string, line []byte) []byte {
|
|
|
|
match := akarosSymbolizeRe.FindSubmatchIndex(line)
|
|
|
|
if match == nil {
|
|
|
|
return line
|
|
|
|
}
|
|
|
|
addr, err := strconv.ParseUint(string(line[match[2]:match[3]]), 0, 64)
|
|
|
|
if err != nil {
|
|
|
|
return line
|
|
|
|
}
|
|
|
|
frames, err := symbFunc(objfile, addr-1)
|
|
|
|
if err != nil || len(frames) == 0 {
|
|
|
|
return line
|
|
|
|
}
|
|
|
|
var symbolized []byte
|
|
|
|
for i, frame := range frames {
|
|
|
|
if i != 0 {
|
|
|
|
symbolized = append(symbolized, '\n')
|
|
|
|
}
|
|
|
|
file := frame.File
|
|
|
|
if pos := strings.LastIndex(file, "/kern/"); pos != -1 {
|
|
|
|
file = file[pos+6:]
|
|
|
|
}
|
|
|
|
modified := append([]byte{}, line...)
|
|
|
|
modified = append(modified, fmt.Sprintf(" at %v:%v", file, frame.Line)...)
|
|
|
|
if frame.Inline {
|
|
|
|
modified = replace(modified, match[4], match[5], []byte(frame.Func))
|
|
|
|
modified = replace(modified, match[2], match[3], []byte(" [inline] "))
|
|
|
|
}
|
|
|
|
symbolized = append(symbolized, modified...)
|
|
|
|
}
|
|
|
|
return symbolized
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *akaros) minimizeReport(report []byte) []byte {
|
|
|
|
out := new(bytes.Buffer)
|
|
|
|
for s := bufio.NewScanner(bytes.NewReader(report)); s.Scan(); {
|
|
|
|
line := bytes.Trim(s.Bytes(), "\r")
|
|
|
|
if len(line) == 0 ||
|
|
|
|
bytes.Contains(line, []byte("Entering Nanwan's Dungeon")) ||
|
|
|
|
bytes.Contains(line, []byte("Type 'help' for a list of commands")) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
out.Write(line)
|
|
|
|
out.WriteByte('\n')
|
|
|
|
}
|
|
|
|
return out.Bytes()
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
akarosSymbolizeRe = compile(`^#[0-9]+ \[\<(0x[0-9a-f]+)\>\] in ([a-zA-Z0-9_]+)`)
|
2018-07-18 15:34:19 +00:00
|
|
|
akarosBacktraceRe = compile(`(?:Stack Backtrace|Backtrace of kernel context) on Core [0-9]+:`)
|
2018-07-16 15:03:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var akarosStackParams = &stackParams{
|
|
|
|
stackStartRes: []*regexp.Regexp{
|
2018-07-18 15:34:19 +00:00
|
|
|
akarosBacktraceRe,
|
2018-07-16 15:03:14 +00:00
|
|
|
},
|
|
|
|
frameRes: []*regexp.Regexp{
|
|
|
|
compile(`^#[0-9]+ {{PC}} in ([a-zA-Z0-9_]+)`),
|
|
|
|
},
|
|
|
|
skipPatterns: []string{
|
|
|
|
"backtrace",
|
|
|
|
"mon_backtrace",
|
|
|
|
"monitor",
|
|
|
|
"_panic",
|
2018-07-23 18:37:19 +00:00
|
|
|
"_warn",
|
2018-07-16 15:03:14 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-07-04 07:57:55 +00:00
|
|
|
var akarosOopses = []*oops{
|
|
|
|
&oops{
|
|
|
|
[]byte("kernel panic"),
|
|
|
|
[]oopsFormat{
|
|
|
|
{
|
2018-07-16 15:03:14 +00:00
|
|
|
title: compile("kernel panic at {{SRC}}, from core [0-9]+: assertion failed: (.*)"),
|
|
|
|
fmt: "assertion failed: %[2]v",
|
|
|
|
stack: &stackFmt{
|
|
|
|
parts: []*regexp.Regexp{
|
2018-07-18 15:34:19 +00:00
|
|
|
akarosBacktraceRe,
|
2018-07-16 15:03:14 +00:00
|
|
|
parseStackTrace,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: compile("kernel panic at {{SRC}}, from core [0-9]+: (.*)"),
|
|
|
|
fmt: "kernel panic: %[2]v",
|
|
|
|
stack: &stackFmt{
|
|
|
|
parts: []*regexp.Regexp{
|
2018-07-18 15:34:19 +00:00
|
|
|
akarosBacktraceRe,
|
2018-07-16 15:03:14 +00:00
|
|
|
parseStackTrace,
|
|
|
|
},
|
|
|
|
},
|
2018-07-04 07:57:55 +00:00
|
|
|
},
|
|
|
|
{
|
2018-07-16 15:03:14 +00:00
|
|
|
title: compile("kernel panic"),
|
|
|
|
fmt: "kernel panic",
|
2018-07-04 07:57:55 +00:00
|
|
|
noStackTrace: true,
|
2018-07-16 15:03:14 +00:00
|
|
|
corrupted: true,
|
2018-07-04 07:57:55 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
[]*regexp.Regexp{},
|
|
|
|
},
|
2018-07-23 18:37:19 +00:00
|
|
|
&oops{
|
|
|
|
[]byte("kernel warning"),
|
|
|
|
[]oopsFormat{
|
|
|
|
{
|
|
|
|
title: compile("kernel warning at {{SRC}}, from core [0-9]+"),
|
|
|
|
fmt: "kernel warning in %[2]v",
|
|
|
|
stack: &stackFmt{
|
|
|
|
parts: []*regexp.Regexp{
|
|
|
|
akarosBacktraceRe,
|
|
|
|
parseStackTrace,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: compile("kernel warning"),
|
|
|
|
fmt: "kernel warning",
|
|
|
|
noStackTrace: true,
|
|
|
|
corrupted: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]*regexp.Regexp{},
|
|
|
|
},
|
2018-07-04 07:57:55 +00:00
|
|
|
}
|