diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2022-09-07 16:37:17 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2022-11-01 10:23:09 -0700 |
| commit | 75eae5a7ef67781b73f2b9038416542c7ea0612c (patch) | |
| tree | 6f4face7bb7d0343f741e759af4004129e198b92 | |
| parent | edac4fd1041732ed5d430221343f99db42a99319 (diff) | |
executor: test extension points
Test that extension points keep stable interface and work.
| -rw-r--r-- | executor/common.h | 4 | ||||
| -rw-r--r-- | executor/common_ext.h | 6 | ||||
| -rw-r--r-- | executor/common_ext_example.h | 10 | ||||
| -rw-r--r-- | executor/common_ext_test.go | 34 | ||||
| -rw-r--r-- | pkg/csource/build.go | 14 | ||||
| -rw-r--r-- | pkg/csource/generated.go | 5 |
6 files changed, 63 insertions, 10 deletions
diff --git a/executor/common.h b/executor/common.h index f4201ca45..2ee0d5bd2 100644 --- a/executor/common.h +++ b/executor/common.h @@ -507,7 +507,11 @@ static uint16 csum_inet_digest(struct csum_inet* csum) #error "unknown OS" #endif +#if SYZ_TEST_COMMON_EXT_EXAMPLE +#include "common_ext_example.h" +#else #include "common_ext.h" +#endif #if SYZ_EXECUTOR || __NR_syz_execute_func // syz_execute_func(text ptr[in, text[taget]]) diff --git a/executor/common_ext.h b/executor/common_ext.h index 6485852ef..22361649f 100644 --- a/executor/common_ext.h +++ b/executor/common_ext.h @@ -2,8 +2,10 @@ // Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. // This file is included into executor and C reproducers and can be used to add -// non-mainline pseudo-syscalls w/o changing any other files. -// These syscalls should start with syz_ext_. +// non-mainline pseudo-syscalls and to provide some other extension points +// w/o changing any other files. See common_ext_example.h for an example implementation. + +// Pseudo-syscalls defined in this file should start with syz_ext_. // This file can also define SYZ_HAVE_SETUP_EXT to 1 and provide // void setup_ext() function that will be called during VM setup. diff --git a/executor/common_ext_example.h b/executor/common_ext_example.h new file mode 100644 index 000000000..0299b6d4f --- /dev/null +++ b/executor/common_ext_example.h @@ -0,0 +1,10 @@ +// Copyright 2022 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +// An example implementation of common_ext.h used for testing. + +#define SYZ_HAVE_SETUP_EXT 1 +static void setup_ext() +{ + debug("example setup_ext called\n"); +} diff --git a/executor/common_ext_test.go b/executor/common_ext_test.go new file mode 100644 index 000000000..45ba3a3cf --- /dev/null +++ b/executor/common_ext_test.go @@ -0,0 +1,34 @@ +// Copyright 2022 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package executor + +import ( + "bytes" + "os" + "testing" + "time" + + "github.com/google/syzkaller/pkg/csource" + "github.com/google/syzkaller/pkg/osutil" + "github.com/google/syzkaller/prog" +) + +func TestCommonExt(t *testing.T) { + target, err := prog.GetTarget("test", "64_fork") + if err != nil { + t.Fatal(err) + } + bin, err := csource.BuildFile(target, "executor.cc", "-DSYZ_TEST_COMMON_EXT_EXAMPLE=1") + if err != nil { + t.Fatal(err) + } + defer os.Remove(bin) + out, err := osutil.RunCmd(time.Minute, "", bin, "setup") + if err != nil { + t.Fatal(err) + } + if !bytes.Contains(out, []byte("example setup_ext called")) { + t.Fatalf("setup_ext wasn't called:\n%s", out) + } +} diff --git a/pkg/csource/build.go b/pkg/csource/build.go index 13633382e..0855dc038 100644 --- a/pkg/csource/build.go +++ b/pkg/csource/build.go @@ -17,7 +17,7 @@ import ( // Build builds a C program from source src and returns name of the resulting binary. func Build(target *prog.Target, src []byte) (string, error) { - return build(target, src, "", true) + return build(target, src, "") } // BuildNoWarn is the same as Build, but ignores all compilation warnings. @@ -25,15 +25,15 @@ func Build(target *prog.Target, src []byte) (string, error) { // using an old repro with newer compiler, or a compiler that we never seen before. // In these cases it's more important to build successfully. func BuildNoWarn(target *prog.Target, src []byte) (string, error) { - return build(target, src, "", false) + return build(target, src, "", "-fpermissive", "-w") } // BuildFile builds a C/C++ program from file src and returns name of the resulting binary. -func BuildFile(target *prog.Target, src string) (string, error) { - return build(target, nil, src, true) +func BuildFile(target *prog.Target, src string, cflags ...string) (string, error) { + return build(target, nil, src, cflags...) } -func build(target *prog.Target, src []byte, file string, warn bool) (string, error) { +func build(target *prog.Target, src []byte, file string, cflags ...string) (string, error) { sysTarget := targets.Get(target.OS, target.Arch) compiler := sysTarget.CCompiler // We call the binary syz-executor because it sometimes shows in bug titles, @@ -59,9 +59,7 @@ func build(target *prog.Target, src []byte, file string, warn bool) (string, err // We do generate uint64's for syscall arguments that overflow longs on 32-bit archs. flags = append(flags, "-Wno-overflow") } - if !warn { - flags = append(flags, "-fpermissive", "-w") - } + flags = append(flags, cflags...) cmd := osutil.Command(compiler, flags...) if file == "" { cmd.Stdin = bytes.NewReader(src) diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index 2e213795a..711e74801 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -11220,6 +11220,11 @@ static void use_temporary_dir(void) #error "unknown OS" #endif +#if SYZ_TEST_COMMON_EXT_EXAMPLE +#include "common_ext_example.h" +#else + +#endif #if SYZ_EXECUTOR || __NR_syz_execute_func static long syz_execute_func(volatile long text) |
