syzkaller/sys/openbsd/init_test.go
Anton Lindqvist ada3c44cd1 sys/openbsd: prevent changing mutability flags on files (#1174)
This is especially problematic for file descriptors referring to tty/pty
devices since it can cause the SSH connection to the VM to die.

The ambition here is reduce the number of "lost connection/no output" failures
at the cost of limiting the coverage of chflags(2).
2019-05-13 18:14:26 -07:00

64 lines
1.2 KiB
Go

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
}{
{
`chflagsat(0x0, 0x0, 0x60004, 0x0)`,
`chflagsat(0x0, 0x0, 0x0, 0x0)`,
},
{
`fchflags(0x0, 0x60004)`,
`fchflags(0x0, 0x0)`,
},
{
// 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)`,
},
{
// major=4, minor=2
`mknod(0x0, 0x0, 0x0402)`,
`mknod(0x0, 0x0, 0x202)`,
},
}
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)
}
})
}
}