-
Notifications
You must be signed in to change notification settings - Fork 2
/
akaros.go
191 lines (178 loc) · 4.43 KB
/
akaros.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// 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 (
"bufio"
"bytes"
"fmt"
"path/filepath"
"regexp"
"strconv"
"strings"
"github.com/google/syzkaller/pkg/symbolizer"
)
type akaros struct {
*config
objfile string
}
func ctorAkaros(cfg *config) (Reporter, []string, error) {
ctx := &akaros{
config: cfg,
}
if ctx.kernelObj != "" {
ctx.objfile = filepath.Join(ctx.kernelObj, ctx.target.KernelObject)
}
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 := simpleLineParser(output, akarosOopses, akarosStackParams, ctx.ignores)
if rep == nil {
return nil
}
if report := ctx.minimizeReport(rep.Report); len(report) != 0 {
rep.Report = report
}
return rep
}
func (ctx *akaros) Symbolize(rep *Report) error {
if ctx.objfile == "" {
return nil
}
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
return nil
}
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_]+)`)
akarosBacktraceRe = compile(`(?:Stack Backtrace|Backtrace of kernel context) on Core [0-9]+:`)
)
var akarosStackParams = &stackParams{
stackStartRes: []*regexp.Regexp{
akarosBacktraceRe,
},
frameRes: []*regexp.Regexp{
compile(`^#[0-9]+ {{PC}} in ([a-zA-Z0-9_]+)`),
},
skipPatterns: []string{
"backtrace",
"mon_backtrace",
"monitor",
"_panic",
"_warn",
},
}
var akarosOopses = append([]*oops{
{
[]byte("kernel panic"),
[]oopsFormat{
{
title: compile("kernel panic at {{SRC}}, from core [0-9]+: assertion failed: (.*)"),
fmt: "assertion failed: %[2]v",
stack: &stackFmt{
parts: []*regexp.Regexp{
akarosBacktraceRe,
parseStackTrace,
},
},
},
{
title: compile("kernel panic at {{SRC}}, from core [0-9]+: (.*)"),
fmt: "kernel panic: %[2]v",
stack: &stackFmt{
parts: []*regexp.Regexp{
akarosBacktraceRe,
parseStackTrace,
},
},
},
{
title: compile("kernel panic"),
fmt: "kernel panic",
noStackTrace: true,
corrupted: true,
},
},
[]*regexp.Regexp{},
},
{
[]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{},
},
}, commonOopses...)