aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--executor/common_bsd.h8
-rw-r--r--executor/common_linux.h24
-rw-r--r--pkg/csource/common.go31
-rw-r--r--pkg/csource/csource_test.go21
-rw-r--r--pkg/csource/generated.go24
5 files changed, 62 insertions, 46 deletions
diff --git a/executor/common_bsd.h b/executor/common_bsd.h
index 80e3fbf3e..7cc55820d 100644
--- a/executor/common_bsd.h
+++ b/executor/common_bsd.h
@@ -45,10 +45,6 @@ static uintptr_t syz_open_pts(void)
static int tunfd = -1;
-// We just need this to be large enough to hold headers that we parse (ethernet/ip/tcp).
-// Rest of the packet (if any) will be silently truncated which is fine.
-#define SYZ_TUN_MAX_PACKET_SIZE 1000
-
#if GOOS_netbsd
// Increased number of tap and tun devices if image script is used
#define MAX_TUN 64
@@ -266,7 +262,9 @@ static long syz_extract_tcp_res(volatile long a0, volatile long a1, volatile lon
if (tunfd < 0)
return (uintptr_t)-1;
- char data[SYZ_TUN_MAX_PACKET_SIZE];
+ // We just need this to be large enough to hold headers that we parse (ethernet/ip/tcp).
+ // Rest of the packet (if any) will be silently truncated which is fine.
+ char data[1000];
int rv = read_tun(&data[0], sizeof(data));
if (rv == -1)
return (uintptr_t)-1;
diff --git a/executor/common_linux.h b/executor/common_linux.h
index e2d0a4f17..34f600313 100644
--- a/executor/common_linux.h
+++ b/executor/common_linux.h
@@ -375,10 +375,6 @@ static void netlink_add_neigh(struct nlmsg* nlmsg, int sock, const char* name,
static int tunfd = -1;
static int tun_frags_enabled;
-// We just need this to be large enough to hold headers that we parse (ethernet/ip/tcp).
-// Rest of the packet (if any) will be silently truncated which is fine.
-#define SYZ_TUN_MAX_PACKET_SIZE 1000
-
#define TUN_IFACE "syz_tun"
#define LOCAL_MAC 0xaaaaaaaaaaaa
@@ -936,7 +932,7 @@ static void flush_tun()
if (!flag_net_injection)
return;
#endif
- char data[SYZ_TUN_MAX_PACKET_SIZE];
+ char data[1000];
while (read_tun(&data[0], sizeof(data)) != -1) {
}
}
@@ -972,7 +968,9 @@ static long syz_extract_tcp_res(volatile long a0, volatile long a1, volatile lon
if (tunfd < 0)
return (uintptr_t)-1;
- char data[SYZ_TUN_MAX_PACKET_SIZE];
+ // We just need this to be large enough to hold headers that we parse (ethernet/ip/tcp).
+ // Rest of the packet (if any) will be silently truncated which is fine.
+ char data[1000];
int rv = read_tun(&data[0], sizeof(data));
if (rv == -1)
return (uintptr_t)-1;
@@ -1214,15 +1212,15 @@ struct fs_image_segment {
#define IMAGE_MAX_SIZE (129 << 20)
#if GOARCH_386
-#define SYZ_memfd_create 356
+#define sys_memfd_create 356
#elif GOARCH_amd64
-#define SYZ_memfd_create 319
+#define sys_memfd_create 319
#elif GOARCH_arm
-#define SYZ_memfd_create 385
+#define sys_memfd_create 385
#elif GOARCH_arm64
-#define SYZ_memfd_create 279
+#define sys_memfd_create 279
#elif GOARCH_ppc64le
-#define SYZ_memfd_create 360
+#define sys_memfd_create 360
#endif
#endif
@@ -1249,7 +1247,7 @@ static long syz_read_part_table(volatile unsigned long size, volatile unsigned l
}
if (size > IMAGE_MAX_SIZE)
size = IMAGE_MAX_SIZE;
- int memfd = syscall(SYZ_memfd_create, "syz_read_part_table", 0);
+ int memfd = syscall(sys_memfd_create, "syz_read_part_table", 0);
if (memfd == -1) {
err = errno;
goto error;
@@ -1352,7 +1350,7 @@ static long syz_mount_image(volatile long fsarg, volatile long dir, volatile uns
}
if (size > IMAGE_MAX_SIZE)
size = IMAGE_MAX_SIZE;
- int memfd = syscall(SYZ_memfd_create, "syz_mount_image", 0);
+ int memfd = syscall(sys_memfd_create, "syz_mount_image", 0);
if (memfd == -1) {
err = errno;
goto error;
diff --git a/pkg/csource/common.go b/pkg/csource/common.go
index 67d31ad81..49c3096de 100644
--- a/pkg/csource/common.go
+++ b/pkg/csource/common.go
@@ -69,9 +69,25 @@ func createCommonHeader(p, mmapProg *prog.Prog, replacements map[string]string,
}
func defineList(p, mmapProg *prog.Prog, opts Options) (defines []string) {
+ for def, ok := range commonDefines(p, opts) {
+ if ok {
+ defines = append(defines, def)
+ }
+ }
+ for _, c := range p.Calls {
+ defines = append(defines, "__NR_"+c.Meta.CallName)
+ }
+ for _, c := range mmapProg.Calls {
+ defines = append(defines, "__NR_"+c.Meta.CallName)
+ }
+ sort.Strings(defines)
+ return
+}
+
+func commonDefines(p *prog.Prog, opts Options) map[string]bool {
sysTarget := targets.Get(p.Target.OS, p.Target.Arch)
bitmasks, csums := prog.RequiredFeatures(p)
- enabled := map[string]bool{
+ return map[string]bool{
"GOOS_" + p.Target.OS: true,
"GOARCH_" + p.Target.Arch: true,
"HOSTGOOS_" + runtime.GOOS: true,
@@ -103,19 +119,6 @@ func defineList(p, mmapProg *prog.Prog, opts Options) (defines []string) {
"SYZ_EXECUTOR_USES_SHMEM": sysTarget.ExecutorUsesShmem,
"SYZ_EXECUTOR_USES_FORK_SERVER": sysTarget.ExecutorUsesForkServer,
}
- for def, ok := range enabled {
- if ok {
- defines = append(defines, def)
- }
- }
- for _, c := range p.Calls {
- defines = append(defines, "__NR_"+c.Meta.CallName)
- }
- for _, c := range mmapProg.Calls {
- defines = append(defines, "__NR_"+c.Meta.CallName)
- }
- sort.Strings(defines)
- return
}
func removeSystemDefines(src []byte, defines []string) ([]byte, error) {
diff --git a/pkg/csource/csource_test.go b/pkg/csource/csource_test.go
index 64fd1e936..914ecaa71 100644
--- a/pkg/csource/csource_test.go
+++ b/pkg/csource/csource_test.go
@@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "regexp"
"runtime"
"strings"
"testing"
@@ -160,3 +161,23 @@ func TestSysTests(t *testing.T) {
})
}
}
+
+func TestExecutorMacros(t *testing.T) {
+ // Ensure that executor does not mis-spell any of the SYZ_* macros.
+ target, _ := prog.GetTarget("test", "64")
+ p := target.Generate(rand.NewSource(0), 1, nil)
+ expected := commonDefines(p, Options{})
+ expected["SYZ_EXECUTOR"] = true
+ expected["SYZ_HAVE_SETUP_LOOP"] = true
+ expected["SYZ_HAVE_RESET_LOOP"] = true
+ expected["SYZ_HAVE_SETUP_TEST"] = true
+ macros := regexp.MustCompile("SYZ_[A-Za-z0-9_]+").FindAllString(commonHeader, -1)
+ for _, macro := range macros {
+ if strings.HasPrefix(macro, "SYZ_HAVE_") {
+ continue
+ }
+ if _, ok := expected[macro]; !ok {
+ t.Errorf("unexpected macro: %v", macro)
+ }
+ }
+}
diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go
index e3903830f..3ad192f28 100644
--- a/pkg/csource/generated.go
+++ b/pkg/csource/generated.go
@@ -439,7 +439,6 @@ static uintptr_t syz_open_pts(void)
#include <sys/types.h>
static int tunfd = -1;
-#define SYZ_TUN_MAX_PACKET_SIZE 1000
#if GOOS_netbsd
#define MAX_TUN 64
@@ -631,8 +630,7 @@ static long syz_extract_tcp_res(volatile long a0, volatile long a1, volatile lon
if (tunfd < 0)
return (uintptr_t)-1;
-
- char data[SYZ_TUN_MAX_PACKET_SIZE];
+ char data[1000];
int rv = read_tun(&data[0], sizeof(data));
if (rv == -1)
return (uintptr_t)-1;
@@ -1412,7 +1410,6 @@ static void netlink_add_neigh(struct nlmsg* nlmsg, int sock, const char* name,
static int tunfd = -1;
static int tun_frags_enabled;
-#define SYZ_TUN_MAX_PACKET_SIZE 1000
#define TUN_IFACE "syz_tun"
@@ -1905,7 +1902,7 @@ static void flush_tun()
if (!flag_net_injection)
return;
#endif
- char data[SYZ_TUN_MAX_PACKET_SIZE];
+ char data[1000];
while (read_tun(&data[0], sizeof(data)) != -1) {
}
}
@@ -1937,8 +1934,7 @@ static long syz_extract_tcp_res(volatile long a0, volatile long a1, volatile lon
if (tunfd < 0)
return (uintptr_t)-1;
-
- char data[SYZ_TUN_MAX_PACKET_SIZE];
+ char data[1000];
int rv = read_tun(&data[0], sizeof(data));
if (rv == -1)
return (uintptr_t)-1;
@@ -2985,15 +2981,15 @@ struct fs_image_segment {
#define IMAGE_MAX_SIZE (129 << 20)
#if GOARCH_386
-#define SYZ_memfd_create 356
+#define sys_memfd_create 356
#elif GOARCH_amd64
-#define SYZ_memfd_create 319
+#define sys_memfd_create 319
#elif GOARCH_arm
-#define SYZ_memfd_create 385
+#define sys_memfd_create 385
#elif GOARCH_arm64
-#define SYZ_memfd_create 279
+#define sys_memfd_create 279
#elif GOARCH_ppc64le
-#define SYZ_memfd_create 360
+#define sys_memfd_create 360
#endif
#endif
@@ -3018,7 +3014,7 @@ static long syz_read_part_table(volatile unsigned long size, volatile unsigned l
}
if (size > IMAGE_MAX_SIZE)
size = IMAGE_MAX_SIZE;
- int memfd = syscall(SYZ_memfd_create, "syz_read_part_table", 0);
+ int memfd = syscall(sys_memfd_create, "syz_read_part_table", 0);
if (memfd == -1) {
err = errno;
goto error;
@@ -3109,7 +3105,7 @@ static long syz_mount_image(volatile long fsarg, volatile long dir, volatile uns
}
if (size > IMAGE_MAX_SIZE)
size = IMAGE_MAX_SIZE;
- int memfd = syscall(SYZ_memfd_create, "syz_mount_image", 0);
+ int memfd = syscall(sys_memfd_create, "syz_mount_image", 0);
if (memfd == -1) {
err = errno;
goto error;