diff options
Diffstat (limited to 'executor')
| -rw-r--r-- | executor/common.h | 3 | ||||
| -rw-r--r-- | executor/common_ext.h | 3 | ||||
| -rw-r--r-- | executor/common_ext_example.h | 7 | ||||
| -rw-r--r-- | executor/common_ext_test.go | 29 |
4 files changed, 42 insertions, 0 deletions
diff --git a/executor/common.h b/executor/common.h index 2ee0d5bd2..fb7b04f4a 100644 --- a/executor/common.h +++ b/executor/common.h @@ -668,6 +668,9 @@ static void loop(void) #if SYZ_HAVE_SETUP_TEST setup_test(); #endif +#if SYZ_HAVE_SETUP_EXT_TEST + setup_ext_test(); +#endif #if GOOS_akaros #if SYZ_EXECUTOR dup2(child_pipe[0], kInPipeFd); diff --git a/executor/common_ext.h b/executor/common_ext.h index 22361649f..edbfcac0b 100644 --- a/executor/common_ext.h +++ b/executor/common_ext.h @@ -9,3 +9,6 @@ // This file can also define SYZ_HAVE_SETUP_EXT to 1 and provide // void setup_ext() function that will be called during VM setup. + +// This file can also define SYZ_HAVE_SETUP_EXT_TEST to 1 and provide +// void setup_ext_test() function that will be called during setup of each test process. diff --git a/executor/common_ext_example.h b/executor/common_ext_example.h index 0299b6d4f..0cabcb75c 100644 --- a/executor/common_ext_example.h +++ b/executor/common_ext_example.h @@ -8,3 +8,10 @@ static void setup_ext() { debug("example setup_ext called\n"); } + +#define SYZ_HAVE_SETUP_EXT_TEST 1 +static void setup_ext_test() +{ + // See TestCommonExt. + *(uint64*)(SYZ_DATA_OFFSET + 0x1234) = 0xbadc0ffee; +} diff --git a/executor/common_ext_test.go b/executor/common_ext_test.go index 45ba3a3cf..2815b095a 100644 --- a/executor/common_ext_test.go +++ b/executor/common_ext_test.go @@ -10,6 +10,8 @@ import ( "time" "github.com/google/syzkaller/pkg/csource" + "github.com/google/syzkaller/pkg/ipc" + "github.com/google/syzkaller/pkg/ipc/ipcconfig" "github.com/google/syzkaller/pkg/osutil" "github.com/google/syzkaller/prog" ) @@ -31,4 +33,31 @@ func TestCommonExt(t *testing.T) { if !bytes.Contains(out, []byte("example setup_ext called")) { t.Fatalf("setup_ext wasn't called:\n%s", out) } + + // The example setup_ext_test does: + // *(uint64*)(SYZ_DATA_OFFSET + 0x1234) = 0xbadc0ffee; + // The following program tests that that value is present at 0x1234. + test := `syz_compare(&(0x7f0000001234)="", 0x8, &(0x7f0000000000)=@blob="eeffc0ad0b000000", AUTO)` + p, err := target.Deserialize([]byte(test), prog.Strict) + if err != nil { + t.Fatal(err) + } + cfg, opts, err := ipcconfig.Default(target) + if err != nil { + t.Fatal(err) + } + cfg.Executor = bin + cfg.Flags |= ipc.FlagDebug + env, err := ipc.MakeEnv(cfg, 0) + if err != nil { + t.Fatalf("failed to create env: %v", err) + } + defer env.Close() + _, info, _, err := env.Exec(opts, p) + if err != nil { + t.Fatal(err) + } + if call := info.Calls[0]; (call.Flags&ipc.CallFinished) == 0 || call.Errno != 0 { + t.Fatalf("bad call result: flags=%x errno=%v", call.Flags, call.Errno) + } } |
