aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/csource
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2021-02-08 08:47:37 +0100
committerDmitry Vyukov <dvyukov@google.com>2021-02-12 18:09:14 +0100
commit98682e5e2aefc9aad61354f4f3ac93be96002a2a (patch)
tree04d0977ddcf677cc32fe7c8376e79765058406be /pkg/csource
parent394d4bf77bc71747a74968f49ef153a8c9ff0cd4 (diff)
sys/linux: add ieee802154 descriptions
Diffstat (limited to 'pkg/csource')
-rw-r--r--pkg/csource/common.go1
-rw-r--r--pkg/csource/generated.go89
-rw-r--r--pkg/csource/options.go4
-rw-r--r--pkg/csource/options_test.go4
4 files changed, 82 insertions, 16 deletions
diff --git a/pkg/csource/common.go b/pkg/csource/common.go
index 74f12485c..fe1655c13 100644
--- a/pkg/csource/common.go
+++ b/pkg/csource/common.go
@@ -121,6 +121,7 @@ func commonDefines(p *prog.Prog, opts Options) map[string]bool {
"SYZ_REPRO": opts.Repro,
"SYZ_TRACE": opts.Trace,
"SYZ_WIFI": opts.Wifi,
+ "SYZ_802154": opts.IEEE802154,
"SYZ_SYSCTL": opts.Sysctl,
"SYZ_EXECUTOR_USES_SHMEM": sysTarget.ExecutorUsesShmem,
"SYZ_EXECUTOR_USES_FORK_SERVER": sysTarget.ExecutorUsesForkServer,
diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go
index 91c69e5d4..b5ebc7a7e 100644
--- a/pkg/csource/generated.go
+++ b/pkg/csource/generated.go
@@ -2359,7 +2359,7 @@ static bool write_file(const char* file, const char* what, ...)
}
#endif
-#if SYZ_EXECUTOR || SYZ_NET_DEVICES || SYZ_NET_INJECTION || SYZ_DEVLINK_PCI || SYZ_WIFI || \
+#if SYZ_EXECUTOR || SYZ_NET_DEVICES || SYZ_NET_INJECTION || SYZ_DEVLINK_PCI || SYZ_WIFI || SYZ_802154 || \
__NR_syz_genetlink_get_family_id || __NR_syz_80211_inject_frame || __NR_syz_80211_join_ibss
#include <arpa/inet.h>
#include <net/if.h>
@@ -2407,7 +2407,7 @@ static void netlink_attr(struct nlmsg* nlmsg, int typ,
nlmsg->pos += NLMSG_ALIGN(attr->nla_len);
}
-#if SYZ_EXECUTOR || SYZ_NET_DEVICES
+#if SYZ_EXECUTOR || SYZ_NET_DEVICES || SYZ_802154
static void netlink_nest(struct nlmsg* nlmsg, int typ)
{
struct nlattr* attr = (struct nlattr*)nlmsg->pos;
@@ -2454,7 +2454,7 @@ static int netlink_send_ext(struct nlmsg* nlmsg, int sock,
return ((struct nlmsgerr*)(hdr + 1))->error;
}
-#if SYZ_EXECUTOR || SYZ_NET_DEVICES || SYZ_NET_INJECTION || SYZ_DEVLINK_PCI || SYZ_WIFI || \
+#if SYZ_EXECUTOR || SYZ_NET_DEVICES || SYZ_NET_INJECTION || SYZ_DEVLINK_PCI || SYZ_WIFI || SYZ_802154 || \
__NR_syz_80211_join_ibss || __NR_syz_80211_inject_frame
static int netlink_send(struct nlmsg* nlmsg, int sock)
{
@@ -2504,7 +2504,7 @@ static int netlink_next_msg(struct nlmsg* nlmsg, unsigned int offset,
}
#endif
-#if SYZ_EXECUTOR || SYZ_NET_DEVICES
+#if SYZ_EXECUTOR || SYZ_NET_DEVICES || SYZ_802154
static void netlink_add_device_impl(struct nlmsg* nlmsg, const char* type,
const char* name)
{
@@ -2516,7 +2516,9 @@ static void netlink_add_device_impl(struct nlmsg* nlmsg, const char* type,
netlink_nest(nlmsg, IFLA_LINKINFO);
netlink_attr(nlmsg, IFLA_INFO_KIND, type, strlen(type));
}
+#endif
+#if SYZ_EXECUTOR || SYZ_NET_DEVICES
static void netlink_add_device(struct nlmsg* nlmsg, int sock, const char* type,
const char* name)
{
@@ -2643,7 +2645,7 @@ static void netlink_add_ipvlan(struct nlmsg* nlmsg, int sock, const char* name,
}
#endif
-#if SYZ_EXECUTOR || SYZ_NET_DEVICES || SYZ_NET_INJECTION || SYZ_DEVLINK_PCI
+#if SYZ_EXECUTOR || SYZ_NET_DEVICES || SYZ_NET_INJECTION || SYZ_DEVLINK_PCI || SYZ_802154
static void netlink_device_change(struct nlmsg* nlmsg, int sock, const char* name, bool up,
const char* master, const void* mac, int macsize,
const char* new_name)
@@ -2725,7 +2727,7 @@ static void netlink_add_neigh(struct nlmsg* nlmsg, int sock, const char* name,
#endif
#endif
-#if SYZ_EXECUTOR || SYZ_NET_DEVICES || SYZ_NET_INJECTION || SYZ_DEVLINK_PCI || SYZ_WIFI
+#if SYZ_EXECUTOR || SYZ_NET_DEVICES || SYZ_NET_INJECTION || SYZ_DEVLINK_PCI || SYZ_WIFI || SYZ_802154
static struct nlmsg nlmsg;
#endif
@@ -6007,19 +6009,21 @@ static long syz_emit_vhci(volatile long a0, volatile long a1)
#include <errno.h>
#include <sys/socket.h>
-static long syz_genetlink_get_family_id(volatile long name)
+static long syz_genetlink_get_family_id(volatile long name, volatile long sock_arg)
{
- struct nlmsg nlmsg_tmp;
-
- debug("syz_genetlink_get_family_id(%s)\n", (char*)name);
- int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
- if (fd == -1) {
- debug("syz_genetlink_get_family_id: socket failed: %d\n", errno);
- return -1;
+ debug("syz_genetlink_get_family_id(%s, %d)\n", (char*)name, (int)sock_arg);
+ int fd = sock_arg;
+ if (fd < 0) {
+ fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
+ if (fd == -1) {
+ debug("syz_genetlink_get_family_id: socket failed: %d\n", errno);
+ return -1;
+ }
}
-
+ struct nlmsg nlmsg_tmp;
int ret = netlink_query_family_id(&nlmsg_tmp, fd, (char*)name);
- close(fd);
+ if ((int)sock_arg >= 0)
+ close(fd);
if (ret < 0) {
debug("syz_genetlink_get_family_id: netlink_query_family_id failed: %d\n", ret);
return -1;
@@ -9404,6 +9408,56 @@ static void setup_sysctl()
}
#endif
+#if SYZ_EXECUTOR || SYZ_802154
+#include <net/if.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#define NL802154_CMD_SET_SHORT_ADDR 11
+#define NL802154_ATTR_IFINDEX 3
+#define NL802154_ATTR_SHORT_ADDR 10
+
+static void setup_802154()
+{
+ int sock_route = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ if (sock_route == -1)
+ fail("socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE) failed");
+ int sock_generic = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC);
+ if (sock_generic < 0)
+ fail("socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC) failed");
+ int nl802154_family_id = netlink_query_family_id(&nlmsg, sock_generic, "nl802154");
+ for (int i = 0; i < 2; i++) {
+ char devname[] = "wpan0";
+ devname[strlen(devname) - 1] += i;
+ uint64 hwaddr = 0xaaaaaaaaaaaa0002 + (i << 8);
+ uint16 shortaddr = 0xaaa0 + i;
+ int ifindex = if_nametoindex(devname);
+ struct genlmsghdr genlhdr;
+ memset(&genlhdr, 0, sizeof(genlhdr));
+ genlhdr.cmd = NL802154_CMD_SET_SHORT_ADDR;
+ netlink_init(&nlmsg, nl802154_family_id, 0, &genlhdr, sizeof(genlhdr));
+ netlink_attr(&nlmsg, NL802154_ATTR_IFINDEX, &ifindex, sizeof(ifindex));
+ netlink_attr(&nlmsg, NL802154_ATTR_SHORT_ADDR, &shortaddr, sizeof(shortaddr));
+ int err = netlink_send(&nlmsg, sock_generic);
+ if (err < 0) {
+ debug("NL802154_CMD_SET_SHORT_ADDR failed: %s\n", strerror(-err));
+ }
+ netlink_device_change(&nlmsg, sock_route, devname, true, 0, &hwaddr, sizeof(hwaddr), 0);
+ if (i == 0) {
+ netlink_add_device_impl(&nlmsg, "lowpan", "lowpan0");
+ netlink_done(&nlmsg);
+ netlink_attr(&nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex));
+ int err = netlink_send(&nlmsg, sock_route);
+ debug("netlink: adding device lowpan0 type lowpan link wpan0: %s\n", strerror(-err));
+ (void)err;
+ }
+ }
+ close(sock_route);
+ close(sock_generic);
+}
+#endif
+
#if GOARCH_s390x
#include <sys/mman.h>
#define CAST(f) ({void* p = (void*)f; p; })
@@ -10308,6 +10362,9 @@ int main(void)
#if SYZ_USB
setup_usb();
#endif
+#if SYZ_802154
+ setup_802154();
+#endif
#if SYZ_HANDLE_SEGV
install_segv_handler();
diff --git a/pkg/csource/options.go b/pkg/csource/options.go
index df8811559..a0e1fe7ac 100644
--- a/pkg/csource/options.go
+++ b/pkg/csource/options.go
@@ -44,6 +44,7 @@ type Options struct {
USB bool `json:"usb,omitempty"`
VhciInjection bool `json:"vhci,omitempty"`
Wifi bool `json:"wifi,omitempty"`
+ IEEE802154 bool `json:"ieee802154,omitempty"`
Sysctl bool `json:"sysctl,omitempty"`
UseTmpDir bool `json:"tmpdir,omitempty"`
@@ -138,6 +139,7 @@ func (opts Options) checkLinuxOnly(OS string) error {
"USB": &opts.USB,
"VhciInjection": &opts.VhciInjection,
"Wifi": &opts.Wifi,
+ "ieee802154": &opts.IEEE802154,
"Fault": &opts.Fault,
"Leak": &opts.Leak,
"Sysctl": &opts.Sysctl,
@@ -172,6 +174,7 @@ func DefaultOpts(cfg *mgrconfig.Config) Options {
opts.USB = true
opts.VhciInjection = true
opts.Wifi = true
+ opts.IEEE802154 = true
opts.Sysctl = true
}
if cfg.Sandbox == "" || cfg.Sandbox == "setuid" {
@@ -257,6 +260,7 @@ func defaultFeatures(value bool) Features {
"usb": {"setup and use /dev/raw-gadget for USB emulation", value},
"vhci": {"setup and use /dev/vhci for hci packet injection", value},
"wifi": {"setup and use mac80211_hwsim for wifi emulation", value},
+ "ieee802154": {"setup and use mac802154_hwsim for emulation", value},
"sysctl": {"setup sysctl's for fuzzing", value},
}
}
diff --git a/pkg/csource/options_test.go b/pkg/csource/options_test.go
index cd247fada..758e91ea1 100644
--- a/pkg/csource/options_test.go
+++ b/pkg/csource/options_test.go
@@ -250,6 +250,7 @@ func TestParseFeaturesFlags(t *testing.T) {
"usb": true,
"vhci": true,
"wifi": true,
+ "ieee802154": true,
"sysctl": true,
}},
{"none", "none", false, map[string]bool{}},
@@ -264,6 +265,7 @@ func TestParseFeaturesFlags(t *testing.T) {
"usb": true,
"vhci": true,
"wifi": true,
+ "ieee802154": true,
"sysctl": true,
}},
{"", "none", true, map[string]bool{}},
@@ -279,6 +281,7 @@ func TestParseFeaturesFlags(t *testing.T) {
"usb": true,
"vhci": true,
"wifi": true,
+ "ieee802154": true,
"sysctl": true,
}},
{"tun,net_dev", "none", true, map[string]bool{
@@ -294,6 +297,7 @@ func TestParseFeaturesFlags(t *testing.T) {
"usb": true,
"vhci": true,
"wifi": true,
+ "ieee802154": true,
"sysctl": true,
}},
{"close_fds", "none", true, map[string]bool{