From ee541933d6cdece196c947c5aeecf496cab5e983 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 29 Apr 2024 07:55:42 +0200 Subject: prog: add raw deserialization mode Raw deserialization mode does not do any program sanitization and allows to use global file names, prohibited ioctl's, etc. This will be useful for moving syscall/feature checking code to the host, we will need to probe opening global files, etc. --- sys/linux/init_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'sys/linux/init_test.go') diff --git a/sys/linux/init_test.go b/sys/linux/init_test.go index c273a2519..7379f74c0 100644 --- a/sys/linux/init_test.go +++ b/sys/linux/init_test.go @@ -155,3 +155,31 @@ syz_open_dev$tty1(0xc, 0x4, 0x1) }, }) } + +func TestDeserializeStrictUnsafe(t *testing.T) { + t.Parallel() + target, _ := prog.GetTarget("linux", "amd64") + // Raw mode must preserve the global file name, allow to use mmap with non-fixed addr, + // and allow to use disabled syscalls. + had := `openat(0x0, &(0x7f0000000000)='/dev/foo', 0x0, 0x0) +mmap(0x0, 0x0, 0x0, 0x0, 0x0, 0x0) +clone(0x0, &(0x7f0000000000), &(0x7f0000000010), &(0x7f0000000020), &(0x7f0000000030)) +` + p, err := target.Deserialize([]byte(had), prog.StrictUnsafe) + if err != nil { + t.Fatal(err) + } + got := string(p.Serialize()) + if had != got { + t.Fatalf("program was changed:\n%s\ngot:\n%s", had, got) + } +} + +func TestDeserializeNonStrictUnsafe(t *testing.T) { + t.Parallel() + target, _ := prog.GetTarget("linux", "amd64") + _, err := target.Deserialize([]byte("clone()"), prog.NonStrictUnsafe) + if err != nil { + t.Fatal(err) + } +} -- cgit mrf-deployment