-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
openbsd.go
189 lines (175 loc) · 4.48 KB
/
openbsd.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
// 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"
"github.com/google/syzkaller/sys/targets"
)
type openbsd struct {
kernelSrc string
kernelObj string
kernelObject string
symbols map[string][]symbolizer.Symbol
ignores []*regexp.Regexp
}
var (
openbsdSymbolizeRe = regexp.MustCompile(` at ([A-Za-z0-9_]+)\+0x([0-9a-f]+)`)
)
func ctorOpenbsd(target *targets.Target, kernelSrc, kernelObj string,
ignores []*regexp.Regexp) (Reporter, []string, error) {
var symbols map[string][]symbolizer.Symbol
kernelObject := ""
if kernelObj != "" {
kernelObject = filepath.Join(kernelObj, target.KernelObject)
var err error
symbols, err = symbolizer.ReadSymbols(kernelObject)
if err != nil {
return nil, nil, err
}
}
ctx := &openbsd{
kernelSrc: kernelSrc,
kernelObj: kernelObj,
kernelObject: kernelObject,
symbols: symbols,
ignores: ignores,
}
return ctx, nil, nil
}
func (ctx *openbsd) ContainsCrash(output []byte) bool {
return containsCrash(output, openbsdOopses, ctx.ignores)
}
func (ctx *openbsd) Parse(output []byte) *Report {
stripped := bytes.Replace(output, []byte{'\r'}, nil, -1)
rep := simpleLineParser(stripped, openbsdOopses, nil, ctx.ignores)
if rep == nil {
return nil
}
rep.Output = output
if report := ctx.shortenReport(rep.Report); len(report) != 0 {
rep.Report = report
}
return rep
}
func (ctx *openbsd) Symbolize(rep *Report) error {
symb := symbolizer.NewSymbolizer()
defer symb.Close()
var symbolized []byte
s := bufio.NewScanner(bytes.NewReader(rep.Report))
prefix := rep.reportPrefixLen
for s.Scan() {
line := append([]byte{}, s.Bytes()...)
line = append(line, '\n')
newLine := ctx.symbolizeLine(symb.Symbolize, line)
if prefix > len(symbolized) {
prefix += len(newLine) - len(line)
}
symbolized = append(symbolized, newLine...)
}
rep.Report = symbolized
rep.reportPrefixLen = prefix
return nil
}
func (ctx *openbsd) symbolizeLine(symbFunc func(bin string, pc uint64) ([]symbolizer.Frame, error),
line []byte) []byte {
match := openbsdSymbolizeRe.FindSubmatchIndex(line)
if match == nil {
return line
}
fn := line[match[2]:match[3]]
off, err := strconv.ParseUint(string(line[match[4]:match[5]]), 16, 64)
if err != nil {
return line
}
symb := ctx.symbols[string(fn)]
if len(symb) == 0 {
return line
}
fnStart := (0xffffffff << 32) | symb[0].Addr
frames, err := symbFunc(ctx.kernelObject, fnStart+off)
if err != nil || len(frames) == 0 {
return line
}
var symbolized []byte
for _, frame := range frames {
file := frame.File
file = strings.TrimPrefix(file, ctx.kernelSrc)
file = strings.TrimPrefix(file, "/")
info := fmt.Sprintf(" %v:%v", file, frame.Line)
modified := append([]byte{}, line...)
modified = replace(modified, match[5], match[5], []byte(info))
if frame.Inline {
end := match[5] + len(info)
modified = replace(modified, end, end, []byte(" [inline]"))
modified = replace(modified, match[5], match[5], []byte(" "+frame.Func))
}
symbolized = append(symbolized, modified...)
}
return symbolized
}
func (ctx *openbsd) shortenReport(report []byte) []byte {
out := new(bytes.Buffer)
for s := bufio.NewScanner(bytes.NewReader(report)); s.Scan(); {
line := s.Bytes()
out.Write(line)
// Kernel splits lines at 79 column.
if len(line) != 79 {
out.WriteByte('\n')
}
}
return out.Bytes()
}
var openbsdOopses = []*oops{
{
[]byte("cleaned vnode"),
[]oopsFormat{
{
title: compile("cleaned vnode: "),
fmt: "panic: cleaned vnode isn't",
},
},
[]*regexp.Regexp{},
},
{
[]byte("uvm_fault"),
[]oopsFormat{
{
title: compile("uvm_fault\\((?:.*\\n)+?.*Stopped at[ ]+([^\\+]+)"),
fmt: "uvm_fault: %[1]v",
},
},
[]*regexp.Regexp{},
},
{
[]byte("panic"),
[]oopsFormat{
{
title: compile("panic: kernel diagnostic assertion (.+) failed: file \".*/([^\"]+)"),
fmt: "assert %[1]v failed in %[2]v",
},
{
title: compile("panic: pool_do_put: ([^:]+): double pool_put"),
fmt: "pool: double put: %[1]v",
},
{
title: compile("panic: pool_do_get: ([^:]+) free list modified"),
fmt: "pool: free list modified: %[1]v",
},
},
[]*regexp.Regexp{},
},
{
[]byte("kernel:"),
[]oopsFormat{},
[]*regexp.Regexp{
compile("reorder_kernel"),
},
},
}