aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Steuck <gnezdo@google.com>2018-12-11 14:30:49 -0800
committerDmitry Vyukov <dvyukov@google.com>2018-12-13 09:44:24 +0100
commitf3d9d5948cad441ab08e763c8ed86efe79f4198b (patch)
tree6e1c38fcb434a2aa74928a1a9871a77e406c273f
parentec0147d47fb25d0efdc677000312db1919ea0086 (diff)
pkg/csource: support tun and setuid repros on {free,open}bsd
* expose procid on BSD for tun, always declare loop() * deal with terrible bsd includes * replicate loop() declaration
-rw-r--r--executor/common.h3
-rw-r--r--executor/common_bsd.h7
-rw-r--r--pkg/csource/csource.go12
-rw-r--r--pkg/csource/generated.go7
-rw-r--r--pkg/csource/options.go6
5 files changed, 25 insertions, 10 deletions
diff --git a/executor/common.h b/executor/common.h
index 7e855b91c..6823c6ba4 100644
--- a/executor/common.h
+++ b/executor/common.h
@@ -40,7 +40,8 @@ NORETURN void doexit(int status)
#endif
#if SYZ_EXECUTOR || SYZ_PROCS || SYZ_REPEAT && SYZ_ENABLE_CGROUPS || \
- __NR_syz_mount_image || __NR_syz_read_part_table
+ __NR_syz_mount_image || __NR_syz_read_part_table || \
+ (GOOS_openbsd || GOOS_freebsd) && SYZ_TUN_ENABLE
unsigned long long procid;
#endif
diff --git a/executor/common_bsd.h b/executor/common_bsd.h
index 53ffc8668..0dcf6ff5f 100644
--- a/executor/common_bsd.h
+++ b/executor/common_bsd.h
@@ -211,7 +211,8 @@ struct tcp_resources {
#include <netinet/ip6.h>
#include <netinet/tcp.h>
-// Include order matters, empty line prevent re-sorting.
+// Include order matters, empty line prevent re-sorting. See a workaround in
+// pkg/csource hoistIncludes.
#include <netinet/if_ether.h>
static long syz_extract_tcp_res(long a0, long a1, long a2)
@@ -299,7 +300,9 @@ static void sandbox_common()
#endif // SYZ_EXECUTOR || SYZ_SANDBOX_SETUID || SYZ_SANDBOX_NONE
#if SYZ_EXECUTOR || SYZ_SANDBOX_NONE
+
static void loop();
+
static int do_sandbox_none(void)
{
sandbox_common();
@@ -317,6 +320,8 @@ static int do_sandbox_none(void)
#include <sys/wait.h>
#include <unistd.h>
+static void loop();
+
static int wait_for_loop(int pid)
{
if (pid < 0)
diff --git a/pkg/csource/csource.go b/pkg/csource/csource.go
index aa5f615e1..91e66e1cd 100644
--- a/pkg/csource/csource.go
+++ b/pkg/csource/csource.go
@@ -430,21 +430,23 @@ func (ctx *context) hoistIncludes(result []byte) []byte {
includes[string(match)] = true
}
result = includeRe.ReplaceAll(result, nil)
- // Linux headers are broken, so we have to move all linux includes to the bottom.
- var sorted, sortedLinux []string
+ // Certain linux and bsd headers are broken and go to the bottom.
+ var sorted, sortedBottom []string
for include := range includes {
if strings.Contains(include, "<linux/") {
- sortedLinux = append(sortedLinux, include)
+ sortedBottom = append(sortedBottom, include)
+ } else if strings.Contains(include, "<netinet/if_ether.h>") {
+ sortedBottom = append(sortedBottom, include)
} else {
sorted = append(sorted, include)
}
}
sort.Strings(sorted)
- sort.Strings(sortedLinux)
+ sort.Strings(sortedBottom)
newResult := append([]byte{}, result[:includesStart]...)
newResult = append(newResult, strings.Join(sorted, "")...)
newResult = append(newResult, '\n')
- newResult = append(newResult, strings.Join(sortedLinux, "")...)
+ newResult = append(newResult, strings.Join(sortedBottom, "")...)
newResult = append(newResult, result[includesStart:]...)
return newResult
}
diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go
index 73b050355..7881199f7 100644
--- a/pkg/csource/generated.go
+++ b/pkg/csource/generated.go
@@ -34,7 +34,8 @@ NORETURN void doexit(int status)
#endif
#if SYZ_EXECUTOR || SYZ_PROCS || SYZ_REPEAT && SYZ_ENABLE_CGROUPS || \
- __NR_syz_mount_image || __NR_syz_read_part_table
+ __NR_syz_mount_image || __NR_syz_read_part_table || \
+ (GOOS_openbsd || GOOS_freebsd) && SYZ_TUN_ENABLE
unsigned long long procid;
#endif
@@ -664,7 +665,9 @@ static void sandbox_common()
#endif
#if SYZ_EXECUTOR || SYZ_SANDBOX_NONE
+
static void loop();
+
static int do_sandbox_none(void)
{
sandbox_common();
@@ -682,6 +685,8 @@ static int do_sandbox_none(void)
#include <sys/wait.h>
#include <unistd.h>
+static void loop();
+
static int wait_for_loop(int pid)
{
if (pid < 0)
diff --git a/pkg/csource/options.go b/pkg/csource/options.go
index 6dc3a249e..4a0cc9fbc 100644
--- a/pkg/csource/options.go
+++ b/pkg/csource/options.go
@@ -95,7 +95,7 @@ func (opts Options) checkLinuxOnly(OS string) error {
if OS == linux {
return nil
}
- if opts.EnableTun {
+ if opts.EnableTun && !(OS == "openbsd" || OS == "freebsd") {
return fmt.Errorf("EnableTun is not supported on %v", OS)
}
if opts.EnableCgroups {
@@ -107,7 +107,9 @@ func (opts Options) checkLinuxOnly(OS string) error {
if opts.ResetNet {
return fmt.Errorf("ResetNet is not supported on %v", OS)
}
- if opts.Sandbox == sandboxNamespace || opts.Sandbox == sandboxSetuid || opts.Sandbox == sandboxAndroidUntrustedApp {
+ if opts.Sandbox == sandboxNamespace ||
+ (opts.Sandbox == sandboxSetuid && !(OS == "openbsd" || OS == "freebsd")) ||
+ opts.Sandbox == sandboxAndroidUntrustedApp {
return fmt.Errorf("Sandbox=%v is not supported on %v", opts.Sandbox, OS)
}
if opts.Fault {