2018-06-06 14:29:59 +00:00
|
|
|
// Copyright 2017 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-06-27 17:41:13 +00:00
|
|
|
"bufio"
|
2018-06-06 14:29:59 +00:00
|
|
|
"bytes"
|
2018-06-27 17:41:13 +00:00
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
2018-06-06 14:29:59 +00:00
|
|
|
"regexp"
|
2018-06-27 17:41:13 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/google/syzkaller/pkg/symbolizer"
|
2018-12-08 10:00:59 +00:00
|
|
|
"github.com/google/syzkaller/sys/targets"
|
2018-06-27 17:41:13 +00:00
|
|
|
"github.com/ianlancetaylor/demangle"
|
2018-06-06 14:29:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type fuchsia struct {
|
2018-06-27 17:41:13 +00:00
|
|
|
obj string
|
|
|
|
ignores []*regexp.Regexp
|
2018-06-06 14:29:59 +00:00
|
|
|
}
|
|
|
|
|
2018-06-27 17:41:13 +00:00
|
|
|
var (
|
2018-08-14 20:40:02 +00:00
|
|
|
zirconRIP = regexp.MustCompile(` RIP: (0x[0-9a-f]+) `)
|
|
|
|
zirconBT = regexp.MustCompile(`^bt#[0-9]+: (0x[0-9a-f]+)`)
|
|
|
|
zirconReportEnd = []byte("Halted")
|
|
|
|
zirconAssertFailed = []byte("ASSERT FAILED at")
|
|
|
|
zirconLinePrefix = regexp.MustCompile(`^\[\d+\.\d+\] \d+\.\d+> `)
|
|
|
|
zirconUnrelated = []*regexp.Regexp{
|
|
|
|
regexp.MustCompile(`^$`),
|
2018-06-27 17:41:13 +00:00
|
|
|
regexp.MustCompile(`stopping other cpus`),
|
|
|
|
regexp.MustCompile(`^halting cpu`),
|
|
|
|
regexp.MustCompile(`^dso: `),
|
|
|
|
regexp.MustCompile(`^UPTIME: `),
|
|
|
|
regexp.MustCompile(`^BUILDID `),
|
|
|
|
regexp.MustCompile(`^Halting\.\.\.`),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2018-12-08 10:00:59 +00:00
|
|
|
func ctorFuchsia(target *targets.Target, kernelSrc, kernelObj string,
|
|
|
|
ignores []*regexp.Regexp) (Reporter, []string, error) {
|
2018-06-06 14:29:59 +00:00
|
|
|
ctx := &fuchsia{
|
2018-06-27 17:41:13 +00:00
|
|
|
ignores: ignores,
|
2018-06-06 14:29:59 +00:00
|
|
|
}
|
2018-07-02 15:00:00 +00:00
|
|
|
if kernelObj != "" {
|
2018-12-08 10:00:59 +00:00
|
|
|
ctx.obj = filepath.Join(kernelObj, target.KernelObject)
|
2018-07-02 15:00:00 +00:00
|
|
|
}
|
2018-06-30 11:59:52 +00:00
|
|
|
suppressions := []string{
|
|
|
|
"fatal exception: process /tmp/syz-fuzzer", // OOM presumably
|
|
|
|
}
|
|
|
|
return ctx, suppressions, nil
|
2018-06-06 14:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *fuchsia) ContainsCrash(output []byte) bool {
|
2018-08-14 20:40:02 +00:00
|
|
|
return containsCrash(output, zirconOopses, ctx.ignores)
|
2018-06-06 14:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *fuchsia) Parse(output []byte) *Report {
|
2018-08-14 20:40:02 +00:00
|
|
|
// We symbolize here because zircon output does not contain even function names.
|
|
|
|
symbolized := ctx.symbolize(output)
|
|
|
|
rep := simpleLineParser(symbolized, zirconOopses, zirconStackParams, ctx.ignores)
|
|
|
|
if rep == nil {
|
2018-06-30 11:21:17 +00:00
|
|
|
return nil
|
2018-06-27 17:41:13 +00:00
|
|
|
}
|
2018-08-14 20:40:02 +00:00
|
|
|
rep.Output = output
|
2018-09-27 10:50:25 +00:00
|
|
|
if report := ctx.shortenReport(rep.Report); len(report) != 0 {
|
|
|
|
rep.Report = report
|
|
|
|
}
|
2018-08-14 20:40:02 +00:00
|
|
|
return rep
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *fuchsia) shortenReport(report []byte) []byte {
|
|
|
|
out := new(bytes.Buffer)
|
|
|
|
for s := bufio.NewScanner(bytes.NewReader(report)); s.Scan(); {
|
2018-12-20 12:21:33 +00:00
|
|
|
line := zirconLinePrefix.ReplaceAll(s.Bytes(), nil)
|
2018-08-14 20:40:02 +00:00
|
|
|
if matchesAny(line, zirconUnrelated) {
|
2018-06-27 17:41:13 +00:00
|
|
|
continue
|
|
|
|
}
|
2018-08-14 20:40:02 +00:00
|
|
|
if bytes.Contains(line, zirconReportEnd) {
|
2018-06-27 17:41:13 +00:00
|
|
|
break
|
|
|
|
}
|
2018-08-14 20:40:02 +00:00
|
|
|
out.Write(line)
|
|
|
|
out.WriteByte('\n')
|
|
|
|
}
|
|
|
|
return out.Bytes()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *fuchsia) symbolize(output []byte) []byte {
|
|
|
|
symb := symbolizer.NewSymbolizer()
|
|
|
|
defer symb.Close()
|
|
|
|
out := new(bytes.Buffer)
|
|
|
|
for s := bufio.NewScanner(bytes.NewReader(output)); s.Scan(); {
|
2018-12-20 12:21:33 +00:00
|
|
|
line := s.Bytes()
|
2018-08-14 20:40:02 +00:00
|
|
|
if bytes.Contains(line, zirconAssertFailed) && len(line) == 127 {
|
|
|
|
// This is super hacky: but zircon splits the most important information in long assert lines
|
|
|
|
// (and they are always long) into several lines in irreversible way. Try to restore full line.
|
|
|
|
line = append([]byte{}, line...)
|
|
|
|
if s.Scan() {
|
|
|
|
line = append(line, s.Bytes()...)
|
|
|
|
}
|
2018-07-06 14:35:21 +00:00
|
|
|
}
|
2018-08-14 20:40:02 +00:00
|
|
|
if ctx.obj != "" {
|
|
|
|
if match := zirconRIP.FindSubmatchIndex(line); match != nil {
|
|
|
|
if ctx.processPC(out, symb, line, match, false) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
} else if match := zirconBT.FindSubmatchIndex(line); match != nil {
|
|
|
|
if ctx.processPC(out, symb, line, match, true) {
|
|
|
|
continue
|
|
|
|
}
|
2018-06-27 17:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-14 20:40:02 +00:00
|
|
|
out.Write(line)
|
|
|
|
out.WriteByte('\n')
|
2018-06-27 17:41:13 +00:00
|
|
|
}
|
2018-08-14 20:40:02 +00:00
|
|
|
return out.Bytes()
|
2018-06-27 17:41:13 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 20:40:02 +00:00
|
|
|
func (ctx *fuchsia) processPC(out *bytes.Buffer, symb *symbolizer.Symbolizer,
|
|
|
|
line []byte, match []int, call bool) bool {
|
2018-06-27 17:41:13 +00:00
|
|
|
prefix := line[match[0]:match[1]]
|
|
|
|
pcStart := match[2] - match[0]
|
|
|
|
pcEnd := match[3] - match[0]
|
|
|
|
pcStr := prefix[pcStart:pcEnd]
|
|
|
|
pc, err := strconv.ParseUint(string(pcStr), 0, 64)
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
shortPC := pc & 0xfffffff
|
|
|
|
pc = 0xffffffff80000000 | shortPC
|
|
|
|
if call {
|
|
|
|
pc--
|
|
|
|
}
|
|
|
|
frames, err := symb.Symbolize(ctx.obj, pc)
|
|
|
|
if err != nil || len(frames) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for _, frame := range frames {
|
|
|
|
file := ctx.trimFile(frame.File)
|
|
|
|
name := demangle.Filter(frame.Func, demangle.NoParams, demangle.NoTemplateParams)
|
2018-07-05 11:17:38 +00:00
|
|
|
if strings.Contains(name, "<lambda(") {
|
|
|
|
// demangle produces super long (full) names for lambdas.
|
|
|
|
name = "lambda"
|
2018-06-27 17:41:13 +00:00
|
|
|
}
|
|
|
|
id := "[ inline ]"
|
|
|
|
if !frame.Inline {
|
|
|
|
id = fmt.Sprintf("0x%08x", shortPC)
|
|
|
|
}
|
|
|
|
start := replace(append([]byte{}, prefix...), pcStart, pcEnd, []byte(id))
|
2018-08-14 20:40:02 +00:00
|
|
|
fmt.Fprintf(out, "%s %v %v:%v\n", start, name, file, frame.Line)
|
2018-06-27 17:41:13 +00:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *fuchsia) trimFile(file string) string {
|
|
|
|
const (
|
|
|
|
prefix1 = "zircon/kernel/"
|
|
|
|
prefix2 = "zircon/"
|
|
|
|
)
|
|
|
|
if pos := strings.LastIndex(file, prefix1); pos != -1 {
|
|
|
|
return file[pos+len(prefix1):]
|
|
|
|
}
|
|
|
|
if pos := strings.LastIndex(file, prefix2); pos != -1 {
|
|
|
|
return file[pos+len(prefix2):]
|
2018-06-06 14:29:59 +00:00
|
|
|
}
|
2018-06-27 17:41:13 +00:00
|
|
|
return file
|
2018-06-06 14:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *fuchsia) Symbolize(rep *Report) error {
|
2018-08-14 20:40:02 +00:00
|
|
|
// We symbolize in Parse because zircon stacktraces don't contain even function names.
|
2018-06-06 14:29:59 +00:00
|
|
|
return nil
|
|
|
|
}
|
2018-08-14 20:40:02 +00:00
|
|
|
|
|
|
|
var zirconStackParams = &stackParams{
|
|
|
|
frameRes: []*regexp.Regexp{
|
2018-09-02 14:22:53 +00:00
|
|
|
compile(` RIP: 0x[0-9a-f]{8} +([a-zA-Z0-9_:~]+)`),
|
|
|
|
compile(` RIP: \[ inline \] +([a-zA-Z0-9_:~]+)`),
|
|
|
|
compile(`^bt#[0-9]+: 0x[0-9a-f]{8} +([a-zA-Z0-9_:~]+)`),
|
|
|
|
compile(`^bt#[0-9]+: \[ inline \] +([a-zA-Z0-9_:~]+)`),
|
2018-08-14 20:40:02 +00:00
|
|
|
},
|
|
|
|
skipPatterns: []string{
|
|
|
|
"^platform_halt$",
|
|
|
|
"^exception_die$",
|
|
|
|
"^_panic$",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var zirconOopses = []*oops{
|
|
|
|
{
|
|
|
|
[]byte("ZIRCON KERNEL PANIC"),
|
|
|
|
[]oopsFormat{
|
|
|
|
{
|
|
|
|
title: compile("ZIRCON KERNEL PANIC(?:.*\\n)+?.*ASSERT FAILED(?:.*\\n)+?.*bt#00:"),
|
|
|
|
fmt: "ASSERT FAILED in %[1]v",
|
|
|
|
stack: &stackFmt{
|
|
|
|
parts: []*regexp.Regexp{
|
|
|
|
parseStackTrace,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Some debug asserts don't contain stack trace.
|
|
|
|
title: compile("ZIRCON KERNEL PANIC(?:.*\\n)+?.*ASSERT FAILED at \\(.+?\\): (.*)"),
|
|
|
|
fmt: "ASSERT FAILED: %[1]v",
|
|
|
|
noStackTrace: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: compile("ZIRCON KERNEL PANIC(?:.*\\n)+?.*double fault, halting(?:.*\\n)+?.*bt#00:"),
|
|
|
|
fmt: "double fault in %[1]v",
|
|
|
|
stack: &stackFmt{
|
|
|
|
parts: []*regexp.Regexp{
|
|
|
|
parseStackTrace,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Some double faults don't contain stack trace.
|
|
|
|
title: compile("ZIRCON KERNEL PANIC(?:.*\\n)+?.*double fault, halting"),
|
|
|
|
fmt: "double fault",
|
|
|
|
noStackTrace: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: compile("ZIRCON KERNEL PANIC(?:.*\\n)+?.*Supervisor Page Fault exception, halting"),
|
|
|
|
fmt: "Supervisor Fault in %[1]v",
|
|
|
|
stack: &stackFmt{
|
|
|
|
parts: []*regexp.Regexp{
|
|
|
|
parseStackTrace,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: compile("ZIRCON KERNEL PANIC(?:.*\\n)+?.*recursion in interrupt handler"),
|
|
|
|
fmt: "recursion in interrupt handler in %[1]v",
|
|
|
|
stack: &stackFmt{
|
|
|
|
parts: []*regexp.Regexp{
|
|
|
|
parseStackTrace,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: compile("ZIRCON KERNEL PANIC(?:.*\\n)+?.*KVM internal error"),
|
|
|
|
fmt: "KVM internal error",
|
|
|
|
noStackTrace: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: compile("ZIRCON KERNEL PANIC"),
|
|
|
|
fmt: "KERNEL PANIC in %[1]v",
|
|
|
|
stack: &stackFmt{
|
|
|
|
parts: []*regexp.Regexp{
|
|
|
|
parseStackTrace,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]*regexp.Regexp{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]byte("recursion in interrupt handler"),
|
|
|
|
[]oopsFormat{
|
|
|
|
{
|
|
|
|
title: compile("recursion in interrupt handler(?:.*\\n)+?.*(?:bt#00:|RIP:)"),
|
|
|
|
fmt: "recursion in interrupt handler in %[1]v",
|
|
|
|
stack: &stackFmt{
|
|
|
|
parts: []*regexp.Regexp{
|
|
|
|
parseStackTrace,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: compile("recursion in interrupt handler"),
|
|
|
|
fmt: "recursion in interrupt handler",
|
|
|
|
noStackTrace: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]*regexp.Regexp{},
|
|
|
|
},
|
|
|
|
// We should detect just "stopping other cpus" as some kernel crash rather then as "lost connection",
|
|
|
|
// but if we add oops for "stopping other cpus", then it will interfere with other formats,
|
|
|
|
// because "stopping other cpus" usually goes after "ZIRCON KERNEL PANIC", but sometimes before. Mess.
|
|
|
|
//{
|
|
|
|
// []byte("stopping other cpus"),
|
|
|
|
//},
|
|
|
|
{
|
|
|
|
[]byte("welcome to Zircon"),
|
|
|
|
[]oopsFormat{
|
|
|
|
{
|
|
|
|
title: compile("welcome to Zircon"),
|
2018-12-16 15:48:05 +00:00
|
|
|
fmt: UnexpectedKernelReboot,
|
2018-08-14 20:40:02 +00:00
|
|
|
noStackTrace: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]*regexp.Regexp{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]byte("KVM internal error"),
|
|
|
|
[]oopsFormat{
|
|
|
|
{
|
|
|
|
title: compile("KVM internal error"),
|
|
|
|
fmt: "KVM internal error",
|
|
|
|
noStackTrace: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]*regexp.Regexp{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
[]byte("<== fatal exception"),
|
|
|
|
[]oopsFormat{
|
|
|
|
{
|
|
|
|
title: compile("<== fatal exception"),
|
|
|
|
report: compile("<== fatal exception: process ([a-zA-Z0-9_/-]+)"),
|
|
|
|
fmt: "fatal exception in %[1]v",
|
|
|
|
noStackTrace: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]*regexp.Regexp{
|
|
|
|
compile("<== fatal exception: process .+?syz.+?\\["),
|
|
|
|
},
|
|
|
|
},
|
2018-11-22 07:18:55 +00:00
|
|
|
{
|
|
|
|
// Panics in Go services.
|
|
|
|
[]byte("panic: "),
|
|
|
|
[]oopsFormat{
|
|
|
|
{
|
|
|
|
title: compile("panic: .*"),
|
2018-12-20 12:21:33 +00:00
|
|
|
report: compile("panic: (.*)(?:.*\\n)+?.* goroutine"),
|
2018-11-22 07:18:55 +00:00
|
|
|
fmt: "panic: %[1]v",
|
|
|
|
noStackTrace: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[]*regexp.Regexp{},
|
|
|
|
},
|
2018-08-14 20:40:02 +00:00
|
|
|
}
|