From 141c212ca6fdc95f4017af0c856768337242bb2e Mon Sep 17 00:00:00 2001 From: Anton Lindqvist Date: Sat, 19 Jan 2019 18:30:04 +0100 Subject: sys/openbsd: avoid /dev/fd node creation Prevent nodes that maps to an already open kcov fd from being created since they can corrupt the coverage buffer. Partial revert of commit 04aed72692137822b809098c55401dd3493dd0f6 with some tweaks and testing. --- sys/openbsd/init_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 sys/openbsd/init_test.go (limited to 'sys/openbsd/init_test.go') diff --git a/sys/openbsd/init_test.go b/sys/openbsd/init_test.go new file mode 100644 index 000000000..780fe3efb --- /dev/null +++ b/sys/openbsd/init_test.go @@ -0,0 +1,50 @@ +package openbsd_test + +import ( + "fmt" + "strings" + "testing" + + "github.com/google/syzkaller/prog" + _ "github.com/google/syzkaller/sys/openbsd/gen" +) + +func TestSanitizeMknodCall(t *testing.T) { + target, err := prog.GetTarget("openbsd", "amd64") + if err != nil { + t.Fatal(err) + } + tests := []struct { + input string + output string + }{ + { + // major=22, minor=232 + `mknodat(0x0, 0x0, 0x0, 0x16e8)`, + `mknodat(0x0, 0x0, 0x0, 0x202)`, + }, + { + // major=22, minor=232 + `mknod(0x0, 0x0, 0x16e8)`, + `mknod(0x0, 0x0, 0x202)`, + }, + { + // major=22, minor=0 + `mknod(0x0, 0x0, 0x1600)`, + `mknod(0x0, 0x0, 0x1600)`, + }, + } + for i, test := range tests { + t.Run(fmt.Sprint(i), func(t *testing.T) { + p, err := target.Deserialize([]byte(test.input), prog.Strict) + if err != nil { + t.Fatal(err) + } + got := strings.TrimSpace(string(p.Serialize())) + want := strings.TrimSpace(test.output) + if got != want { + t.Fatalf("input:\n%v\ngot:\n%v\nwant:\n%s", test.input, got, want) + } + }) + } +} -- cgit mrf-deployment