From 2bbe2f05585bb06f9c417ee8437a8077c97b0de2 Mon Sep 17 00:00:00 2001 From: Siddharth M Date: Sun, 14 Jul 2019 20:29:29 +0530 Subject: executor: add network packet injection for NetBSD * Initial Commit * working build of network packet fuzzing * Add missed csource file * pkg/csource: fix build * executor/common_bsd.h: Add comment stating reason for ifconfig create --- pkg/csource/generated.go | 24 ++++++++++++++---------- pkg/host/host_netbsd.go | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'pkg') diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index 766ab6e28..3db1ee059 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -430,7 +430,7 @@ static uintptr_t syz_open_pts(void) #endif -#if GOOS_freebsd || GOOS_openbsd +#if GOOS_freebsd || GOOS_openbsd || GOOS_netbsd #if SYZ_EXECUTOR || SYZ_TUN_ENABLE @@ -506,7 +506,16 @@ static void initialize_tun(int tun_id) char tun_device[sizeof(TUN_DEVICE)]; snprintf_check(tun_device, sizeof(tun_device), TUN_DEVICE, tun_id); + + char tun_iface[sizeof(TUN_IFACE)]; + snprintf_check(tun_iface, sizeof(tun_iface), TUN_IFACE, tun_id); + +#if GOOS_netbsd + execute_command(0, "ifconfig %s destroy", tun_iface); + execute_command(0, "ifconfig %s create", tun_iface); +#else execute_command(0, "ifconfig %s destroy", tun_device); +#endif tunfd = open(tun_device, O_RDWR | O_NONBLOCK); #if GOOS_freebsd @@ -529,31 +538,26 @@ static void initialize_tun(int tun_id) close(tunfd); tunfd = kTunFd; - char tun_iface[sizeof(TUN_IFACE)]; - snprintf_check(tun_iface, sizeof(tun_iface), TUN_IFACE, tun_id); - char local_mac[sizeof(LOCAL_MAC)]; snprintf_check(local_mac, sizeof(local_mac), LOCAL_MAC); #if GOOS_openbsd execute_command(1, "ifconfig %s lladdr %s", tun_iface, local_mac); +#elif GOOS_netbsd + execute_command(1, "ifconfig %s link %s", tun_iface, local_mac); #else execute_command(1, "ifconfig %s ether %s", tun_iface, local_mac); #endif - char local_ipv4[sizeof(LOCAL_IPV4)]; snprintf_check(local_ipv4, sizeof(local_ipv4), LOCAL_IPV4, tun_id); execute_command(1, "ifconfig %s inet %s netmask 255.255.255.0", tun_iface, local_ipv4); - char remote_mac[sizeof(REMOTE_MAC)]; char remote_ipv4[sizeof(REMOTE_IPV4)]; snprintf_check(remote_mac, sizeof(remote_mac), REMOTE_MAC); snprintf_check(remote_ipv4, sizeof(remote_ipv4), REMOTE_IPV4, tun_id); execute_command(0, "arp -s %s %s", remote_ipv4, remote_mac); - char local_ipv6[sizeof(LOCAL_IPV6)]; snprintf_check(local_ipv6, sizeof(local_ipv6), LOCAL_IPV6, tun_id); execute_command(1, "ifconfig %s inet6 %s", tun_iface, local_ipv6); - char remote_ipv6[sizeof(REMOTE_IPV6)]; snprintf_check(remote_ipv6, sizeof(remote_ipv6), REMOTE_IPV6, tun_id); execute_command(0, "ndp -s %s%%%s %s", remote_ipv6, tun_iface, remote_mac); @@ -701,7 +705,7 @@ static void loop(); static int do_sandbox_none(void) { sandbox_common(); -#if (GOOS_freebsd || GOOS_openbsd) && (SYZ_EXECUTOR || SYZ_TUN_ENABLE) +#if (GOOS_freebsd || GOOS_openbsd || GOOS_netbsd) && (SYZ_EXECUTOR || SYZ_TUN_ENABLE) initialize_tun(procid); #endif loop(); @@ -736,7 +740,7 @@ static int do_sandbox_setuid(void) return wait_for_loop(pid); sandbox_common(); -#if (GOOS_freebsd || GOOS_openbsd) && (SYZ_EXECUTOR || SYZ_TUN_ENABLE) +#if (GOOS_freebsd || GOOS_openbsd || GOOS_netbsd) && (SYZ_EXECUTOR || SYZ_TUN_ENABLE) initialize_tun(procid); #endif diff --git a/pkg/host/host_netbsd.go b/pkg/host/host_netbsd.go index 2ba822c36..609db091c 100644 --- a/pkg/host/host_netbsd.go +++ b/pkg/host/host_netbsd.go @@ -13,4 +13,5 @@ func isSupported(c *prog.Syscall, target *prog.Target, sandbox string) (bool, st func init() { checkFeature[FeatureCoverage] = unconditionallyEnabled + checkFeature[FeatureNetworkInjection] = unconditionallyEnabled } -- cgit mrf-deployment