From 95fe19c19e596446412626b048d950de6ce8c886 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sun, 9 Dec 2018 17:08:14 +0100 Subject: prog: introduce strict parsing mode Over time we relaxed parsing to handle all kinds of invalid programs (excessive/missing args, wrong types, etc). This is useful when reading old programs from corpus. But this is harmful for e.g. reading test inputs as they can become arbitrary outdated. For runtests which creates additional problem of executing not what is actually written in the test (or at least what author meant). Add strict parsing mode that does not tolerate any errors. For now it just checks excessive syscall arguments. --- tools/syz-db/syz-db.go | 2 +- tools/syz-mutate/mutate.go | 2 +- tools/syz-prog2c/prog2c.go | 7 ++++++- tools/syz-stress/stress.go | 2 +- tools/syz-upgrade/upgrade.go | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/syz-db/syz-db.go b/tools/syz-db/syz-db.go index 6aa96a0c0..b2bd36bb0 100644 --- a/tools/syz-db/syz-db.go +++ b/tools/syz-db/syz-db.go @@ -76,7 +76,7 @@ func pack(dir, file string, target *prog.Target, version uint64) { } if sig := hash.String(data); key != sig { if target != nil { - p, err := target.Deserialize(data) + p, err := target.Deserialize(data, prog.NonStrict) if err != nil { failf("failed to deserialize %v: %v", file.Name(), err) } diff --git a/tools/syz-mutate/mutate.go b/tools/syz-mutate/mutate.go index c3038064f..f2403f75c 100644 --- a/tools/syz-mutate/mutate.go +++ b/tools/syz-mutate/mutate.go @@ -67,7 +67,7 @@ func main() { fmt.Fprintf(os.Stderr, "failed to read prog file: %v\n", err) os.Exit(1) } - p, err = target.Deserialize(data) + p, err = target.Deserialize(data, prog.Strict) if err != nil { fmt.Fprintf(os.Stderr, "failed to deserialize the program: %v\n", err) os.Exit(1) diff --git a/tools/syz-prog2c/prog2c.go b/tools/syz-prog2c/prog2c.go index 6abbd68b4..d45c1e5a8 100644 --- a/tools/syz-prog2c/prog2c.go +++ b/tools/syz-prog2c/prog2c.go @@ -34,6 +34,7 @@ var ( flagResetNet = flag.Bool("resetnet", false, "reset net namespace after each test") flagHandleSegv = flag.Bool("segv", false, "catch and ignore SIGSEGV") flagTrace = flag.Bool("trace", false, "trace syscall results") + flagStrict = flag.Bool("strict", false, "parse input program in strict mode") ) func main() { @@ -52,7 +53,11 @@ func main() { fmt.Fprintf(os.Stderr, "failed to read prog file: %v\n", err) os.Exit(1) } - p, err := target.Deserialize(data) + mode := prog.NonStrict + if *flagStrict { + mode = prog.Strict + } + p, err := target.Deserialize(data, mode) if err != nil { fmt.Fprintf(os.Stderr, "failed to deserialize the program: %v\n", err) os.Exit(1) diff --git a/tools/syz-stress/stress.go b/tools/syz-stress/stress.go index 9c61e8206..e5f4ff845 100644 --- a/tools/syz-stress/stress.go +++ b/tools/syz-stress/stress.go @@ -136,7 +136,7 @@ func readCorpus(target *prog.Target) []*prog.Prog { } var progs []*prog.Prog for _, rec := range db.Records { - p, err := target.Deserialize(rec.Val) + p, err := target.Deserialize(rec.Val, prog.NonStrict) if err != nil { log.Fatalf("failed to deserialize corpus program: %v", err) } diff --git a/tools/syz-upgrade/upgrade.go b/tools/syz-upgrade/upgrade.go index 0a537ac58..795d52c44 100644 --- a/tools/syz-upgrade/upgrade.go +++ b/tools/syz-upgrade/upgrade.go @@ -40,7 +40,7 @@ func main() { if err != nil { fatalf("failed to read program: %v", err) } - p, err := target.Deserialize(data) + p, err := target.Deserialize(data, prog.NonStrict) if err != nil { fatalf("failed to deserialize program: %v", err) } -- cgit mrf-deployment