diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-02-21 10:22:07 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-02-21 10:22:07 +0100 |
| commit | b6ed1478343c98348649330e66b021faa747b6e5 (patch) | |
| tree | 38df81e84acdb967a7dac486521f3856c598e1ca | |
| parent | bd2a74a31f07d383be203bcd77dfbecbc1205dd3 (diff) | |
prog: dump orig prog if Deserialize panics
We are seeing some one-off panics during Deserialization
and it's unclear if it's machine memory corrpution or
an actual bug in prog. I leam towards machine memory corruption
but it's impossible to prove without seeing the orig program.
Move git revision to prog and it's more base package
(sys can import prog, prog can't import sys).
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | prog/encoding.go | 6 | ||||
| -rw-r--r-- | prog/meta.go | 26 | ||||
| -rw-r--r-- | sys/sys.go | 20 | ||||
| -rw-r--r-- | syz-ci/manager.go | 9 | ||||
| -rw-r--r-- | syz-ci/updater.go | 10 | ||||
| -rw-r--r-- | syz-fuzzer/testing.go | 9 | ||||
| -rw-r--r-- | syz-manager/html.go | 3 | ||||
| -rw-r--r-- | syz-manager/manager.go | 3 | ||||
| -rw-r--r-- | syz-manager/rpc.go | 3 | ||||
| -rw-r--r-- | tools/syz-runtest/runtest.go | 4 |
11 files changed, 52 insertions, 43 deletions
@@ -58,7 +58,7 @@ GITREVDATE=$(shell git log -n 1 --format="%ad") # Reduces build time and binary sizes considerably. # That's only needed if you use gdb or nm. # If you need that, build manually without these flags. -GOFLAGS := "-ldflags=-s -w -X github.com/google/syzkaller/sys.GitRevision=$(REV) -X 'github.com/google/syzkaller/sys.gitRevisionDate=$(GITREVDATE)'" +GOFLAGS := "-ldflags=-s -w -X github.com/google/syzkaller/prog.GitRevision=$(REV) -X 'github.com/google/syzkaller/prog.gitRevisionDate=$(GITREVDATE)'" GOHOSTFLAGS := $(GOFLAGS) GOTARGETFLAGS := $(GOFLAGS) diff --git a/prog/encoding.go b/prog/encoding.go index 493edd9f4..b36bf9637 100644 --- a/prog/encoding.go +++ b/prog/encoding.go @@ -204,6 +204,12 @@ const ( ) func (target *Target) Deserialize(data []byte, mode DeserializeMode) (*Prog, error) { + defer func() { + if err := recover(); err != nil { + panic(fmt.Errorf("%v\ntarget: %v/%v, rev: %v, mode=%v, prog:\n%q", + err, target.OS, target.Arch, GitRevision, mode, data)) + } + }() p := newParser(target, data, mode == Strict) prog, err := p.parseProg() if err := p.Err(); err != nil { diff --git a/prog/meta.go b/prog/meta.go new file mode 100644 index 000000000..502309cdc --- /dev/null +++ b/prog/meta.go @@ -0,0 +1,26 @@ +// Copyright 2020 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 prog + +import ( + "strings" + "time" +) + +var ( + GitRevision string // emitted by Makefile, may contain + at the end + GitRevisionBase string // without + + gitRevisionDate string // emitted by Makefile + GitRevisionDate time.Time // parsed from gitRevisionDate +) + +func init() { + GitRevisionBase = strings.Replace(GitRevision, "+", "", -1) + if gitRevisionDate != "" { + var err error + if GitRevisionDate, err = time.Parse("Mon Jan 2 15:04:05 2006 -0700", gitRevisionDate); err != nil { + panic(err) + } + } +} diff --git a/sys/sys.go b/sys/sys.go index fa7278ab8..2c3d169d5 100644 --- a/sys/sys.go +++ b/sys/sys.go @@ -4,9 +4,6 @@ package sys import ( - "strings" - "time" - // Import all targets, so that users only need to import sys. _ "github.com/google/syzkaller/sys/akaros/gen" _ "github.com/google/syzkaller/sys/freebsd/gen" @@ -17,20 +14,3 @@ import ( _ "github.com/google/syzkaller/sys/test/gen" _ "github.com/google/syzkaller/sys/windows/gen" ) - -var ( - GitRevision string // emitted by Makefile, may contain + at the end - GitRevisionBase string // without + - gitRevisionDate string // emitted by Makefile - GitRevisionDate time.Time // parsed from gitRevisionDate -) - -func init() { - GitRevisionBase = strings.Replace(GitRevision, "+", "", -1) - if gitRevisionDate != "" { - var err error - if GitRevisionDate, err = time.Parse("Mon Jan 2 15:04:05 2006 -0700", gitRevisionDate); err != nil { - panic(err) - } - } -} diff --git a/syz-ci/manager.go b/syz-ci/manager.go index 1af16b7af..4de4913be 100644 --- a/syz-ci/manager.go +++ b/syz-ci/manager.go @@ -23,7 +23,8 @@ import ( "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/report" "github.com/google/syzkaller/pkg/vcs" - "github.com/google/syzkaller/sys" + "github.com/google/syzkaller/prog" + _ "github.com/google/syzkaller/sys" "github.com/google/syzkaller/sys/targets" "github.com/google/syzkaller/vm" ) @@ -530,7 +531,7 @@ func (mgr *Manager) createDashboardBuild(info *BuildInfo, imageDir, typ string) // Also mix in build type, so that image error builds are not merged into normal builds. var tagData []byte tagData = append(tagData, info.Tag...) - tagData = append(tagData, sys.GitRevisionBase...) + tagData = append(tagData, prog.GitRevisionBase...) tagData = append(tagData, typ...) build := &dashapi.Build{ Manager: mgr.name, @@ -538,8 +539,8 @@ func (mgr *Manager) createDashboardBuild(info *BuildInfo, imageDir, typ string) OS: mgr.managercfg.TargetOS, Arch: mgr.managercfg.TargetArch, VMArch: mgr.managercfg.TargetVMArch, - SyzkallerCommit: sys.GitRevisionBase, - SyzkallerCommitDate: sys.GitRevisionDate, + SyzkallerCommit: prog.GitRevisionBase, + SyzkallerCommitDate: prog.GitRevisionDate, CompilerID: info.CompilerID, KernelRepo: info.KernelRepo, KernelBranch: info.KernelBranch, diff --git a/syz-ci/updater.go b/syz-ci/updater.go index 17f6c42c9..f8445c303 100644 --- a/syz-ci/updater.go +++ b/syz-ci/updater.go @@ -17,7 +17,7 @@ import ( "github.com/google/syzkaller/pkg/log" "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/pkg/vcs" - "github.com/google/syzkaller/sys" + "github.com/google/syzkaller/prog" ) const ( @@ -119,7 +119,7 @@ func (upd *SyzUpdater) UpdateOnStart(autoupdate bool, shutdown chan struct{}) { if st, err := os.Stat(upd.exe); err == nil { exeMod = st.ModTime() } - uptodate := sys.GitRevisionBase == latestTag && time.Since(exeMod) < time.Minute + uptodate := prog.GitRevisionBase == latestTag && time.Since(exeMod) < time.Minute if uptodate || !autoupdate { if uptodate { // Have a fresh up-to-date build, probably just restarted. @@ -133,11 +133,11 @@ func (upd *SyzUpdater) UpdateOnStart(autoupdate bool, shutdown chan struct{}) { return } } - log.Logf(0, "current executable is on %v", sys.GitRevision) + log.Logf(0, "current executable is on %v", prog.GitRevision) log.Logf(0, "latest syzkaller build is on %v", latestTag) // No syzkaller build or executable is stale. - lastCommit := sys.GitRevisionBase + lastCommit := prog.GitRevisionBase for { lastCommit = upd.pollAndBuild(lastCommit) latestTag := upd.checkLatest() @@ -148,7 +148,7 @@ func (upd *SyzUpdater) UpdateOnStart(autoupdate bool, shutdown chan struct{}) { if err := osutil.LinkFiles(upd.latestDir, upd.currentDir, upd.syzFiles); err != nil { log.Fatal(err) } - if autoupdate && sys.GitRevisionBase != latestTag { + if autoupdate && prog.GitRevisionBase != latestTag { upd.UpdateAndRestart() } return diff --git a/syz-fuzzer/testing.go b/syz-fuzzer/testing.go index 95d9ca9c2..960a1fd23 100644 --- a/syz-fuzzer/testing.go +++ b/syz-fuzzer/testing.go @@ -17,7 +17,6 @@ import ( "github.com/google/syzkaller/pkg/rpctype" "github.com/google/syzkaller/pkg/runtest" "github.com/google/syzkaller/prog" - "github.com/google/syzkaller/sys" ) type checkArgs struct { @@ -203,13 +202,13 @@ func checkRevisions(args *checkArgs) error { if args.target.Arch != vers[1] { return fmt.Errorf("mismatching target/executor arches: %v vs %v", args.target.Arch, vers[1]) } - if sys.GitRevision != vers[3] { + if prog.GitRevision != vers[3] { return fmt.Errorf("mismatching fuzzer/executor git revisions: %v vs %v", - sys.GitRevision, vers[3]) + prog.GitRevision, vers[3]) } - if args.gitRevision != "" && args.gitRevision != sys.GitRevision { + if args.gitRevision != "" && args.gitRevision != prog.GitRevision { return fmt.Errorf("mismatching manager/fuzzer git revisions: %v vs %v", - args.gitRevision, sys.GitRevision) + args.gitRevision, prog.GitRevision) } if args.target.Revision != vers[2] { return fmt.Errorf("mismatching fuzzer/executor system call descriptions: %v vs %v", diff --git a/syz-manager/html.go b/syz-manager/html.go index 137f8f4c3..b52f50f67 100644 --- a/syz-manager/html.go +++ b/syz-manager/html.go @@ -27,7 +27,6 @@ import ( "github.com/google/syzkaller/pkg/signal" "github.com/google/syzkaller/pkg/vcs" "github.com/google/syzkaller/prog" - "github.com/google/syzkaller/sys" ) func (mgr *Manager) initHTTP() { @@ -112,7 +111,7 @@ func (mgr *Manager) collectStats() []UIStat { defer mgr.mu.Unlock() rawStats := mgr.stats.all() - head := sys.GitRevisionBase + head := prog.GitRevisionBase stats := []UIStat{ {Name: "revision", Value: fmt.Sprint(head[:8]), Link: vcs.LogLink(vcs.SyzkallerRepo, head)}, {Name: "config", Value: mgr.cfg.Name, Link: "/config"}, diff --git a/syz-manager/manager.go b/syz-manager/manager.go index 65910b6db..e64b4cd2c 100644 --- a/syz-manager/manager.go +++ b/syz-manager/manager.go @@ -33,7 +33,6 @@ import ( "github.com/google/syzkaller/pkg/rpctype" "github.com/google/syzkaller/pkg/signal" "github.com/google/syzkaller/prog" - "github.com/google/syzkaller/sys" "github.com/google/syzkaller/sys/targets" "github.com/google/syzkaller/vm" ) @@ -112,7 +111,7 @@ type Crash struct { } func main() { - if sys.GitRevision == "" { + if prog.GitRevision == "" { log.Fatalf("Bad syz-manager build. Build with make, run bin/syz-manager.") } flag.Parse() diff --git a/syz-manager/rpc.go b/syz-manager/rpc.go index d52bbcc45..c60b7a9a5 100644 --- a/syz-manager/rpc.go +++ b/syz-manager/rpc.go @@ -15,7 +15,6 @@ import ( "github.com/google/syzkaller/pkg/rpctype" "github.com/google/syzkaller/pkg/signal" "github.com/google/syzkaller/prog" - "github.com/google/syzkaller/sys" ) type RPCServer struct { @@ -97,7 +96,7 @@ func (serv *RPCServer) Connect(a *rpctype.ConnectArgs, r *rpctype.ConnectRes) er r.MemoryLeakFrames = bugFrames.memoryLeaks r.DataRaceFrames = bugFrames.dataRaces r.EnabledCalls = serv.enabledSyscalls - r.GitRevision = sys.GitRevision + r.GitRevision = prog.GitRevision r.TargetRevision = serv.target.Revision // TODO: temporary disabled b/c we suspect this negatively affects fuzzing. if false && serv.mgr.rotateCorpus() && serv.rnd.Intn(3) != 0 { diff --git a/tools/syz-runtest/runtest.go b/tools/syz-runtest/runtest.go index 2e8047660..76c120cd9 100644 --- a/tools/syz-runtest/runtest.go +++ b/tools/syz-runtest/runtest.go @@ -26,7 +26,7 @@ import ( "github.com/google/syzkaller/pkg/rpctype" "github.com/google/syzkaller/pkg/runtest" "github.com/google/syzkaller/prog" - "github.com/google/syzkaller/sys" + _ "github.com/google/syzkaller/sys" "github.com/google/syzkaller/sys/targets" "github.com/google/syzkaller/vm" ) @@ -213,7 +213,7 @@ func (mgr *Manager) finishRequest(name string, rep *report.Report) error { } func (mgr *Manager) Connect(a *rpctype.ConnectArgs, r *rpctype.ConnectRes) error { - r.GitRevision = sys.GitRevision + r.GitRevision = prog.GitRevision r.TargetRevision = mgr.target.Revision r.AllSandboxes = true select { |
