diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2021-02-08 08:47:37 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2021-02-12 18:09:14 +0100 |
| commit | 98682e5e2aefc9aad61354f4f3ac93be96002a2a (patch) | |
| tree | 04d0977ddcf677cc32fe7c8376e79765058406be /pkg | |
| parent | 394d4bf77bc71747a74968f49ef153a8c9ff0cd4 (diff) | |
sys/linux: add ieee802154 descriptions
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/csource/common.go | 1 | ||||
| -rw-r--r-- | pkg/csource/generated.go | 89 | ||||
| -rw-r--r-- | pkg/csource/options.go | 4 | ||||
| -rw-r--r-- | pkg/csource/options_test.go | 4 | ||||
| -rw-r--r-- | pkg/host/features.go | 5 | ||||
| -rw-r--r-- | pkg/host/features_linux.go | 8 | ||||
| -rw-r--r-- | pkg/host/syscalls_linux.go | 2 | ||||
| -rw-r--r-- | pkg/repro/repro.go | 10 | ||||
| -rw-r--r-- | pkg/runtest/run.go | 3 |
9 files changed, 110 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{ diff --git a/pkg/host/features.go b/pkg/host/features.go index 14d4f5c89..d7012e918 100644 --- a/pkg/host/features.go +++ b/pkg/host/features.go @@ -29,6 +29,7 @@ const ( FeatureUSBEmulation FeatureVhciInjection FeatureWifiEmulation + Feature802154Emulation numFeatures ) @@ -69,6 +70,7 @@ func Check(target *prog.Target) (*Features, error) { FeatureUSBEmulation: {Name: "USB emulation", Reason: unsupported}, FeatureVhciInjection: {Name: "hci packet injection", Reason: unsupported}, FeatureWifiEmulation: {Name: "wifi device emulation", Reason: unsupported}, + Feature802154Emulation: {Name: "802.15.4 emulation", Reason: unsupported}, } if noHostChecks(target) { return res, nil @@ -111,6 +113,9 @@ func Setup(target *prog.Target, features *Features, featureFlags csource.Feature if features[FeatureUSBEmulation].Enabled { args = append(args, "usb") } + if featureFlags["ieee802154"].Enabled && features[Feature802154Emulation].Enabled { + args = append(args, "802154") + } _, err := osutil.RunCmd(5*time.Minute, "", executor, args...) return err } diff --git a/pkg/host/features_linux.go b/pkg/host/features_linux.go index fc925c00c..5c45bdcc1 100644 --- a/pkg/host/features_linux.go +++ b/pkg/host/features_linux.go @@ -33,6 +33,7 @@ func init() { checkFeature[FeatureUSBEmulation] = checkUSBEmulation checkFeature[FeatureVhciInjection] = checkVhciInjection checkFeature[FeatureWifiEmulation] = checkWifiEmulation + checkFeature[Feature802154Emulation] = check802154Emulation } func checkCoverage() string { @@ -233,6 +234,13 @@ func checkWifiEmulation() string { return requireKernel(4, 17) } +func check802154Emulation() string { + if err := osutil.IsAccessible("/sys/bus/platform/devices/mac802154_hwsim"); err != nil { + return err.Error() + } + return "" +} + func requireKernel(x, y int) string { info := new(unix.Utsname) if err := unix.Uname(info); err != nil { diff --git a/pkg/host/syscalls_linux.go b/pkg/host/syscalls_linux.go index e31e0dc24..a13af0caa 100644 --- a/pkg/host/syscalls_linux.go +++ b/pkg/host/syscalls_linux.go @@ -223,9 +223,11 @@ func isSyzGenetlinkGetFamilyIDSupported(c *prog.Syscall, target *prog.Target, sa if fd == -1 { return false, fmt.Sprintf("socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC) failed: %v", err) } + // TODO: try to obtain actual family ID here. It will disable whole sets of sendmsg syscalls. syscall.Close(fd) return true, "" } + func isSyzMountImageSupported(c *prog.Syscall, target *prog.Target, sandbox string) (bool, string) { if ok, reason := onlySandboxNone(sandbox); !ok { return ok, reason diff --git a/pkg/repro/repro.go b/pkg/repro/repro.go index aca892cb9..4433c84a9 100644 --- a/pkg/repro/repro.go +++ b/pkg/repro/repro.go @@ -204,6 +204,9 @@ func createStartOptions(cfg *mgrconfig.Config, features *host.Features, crashTyp if !features[host.FeatureWifiEmulation].Enabled { opts.Wifi = false } + if !features[host.Feature802154Emulation].Enabled { + opts.IEEE802154 = false + } } return opts } @@ -969,6 +972,13 @@ var cSimplifies = append(progSimplifies, []Simplify{ return true }, func(opts *csource.Options) bool { + if !opts.IEEE802154 { + return false + } + opts.IEEE802154 = false + return true + }, + func(opts *csource.Options) bool { if !opts.UseTmpDir || opts.Sandbox == "namespace" || opts.Cgroups { return false } diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go index 437970768..5a071676a 100644 --- a/pkg/runtest/run.go +++ b/pkg/runtest/run.go @@ -468,6 +468,9 @@ func (ctx *Context) createCTest(p *prog.Prog, sandbox string, threaded bool, tim if ctx.Features[host.FeatureWifiEmulation].Enabled { opts.Wifi = true } + if ctx.Features[host.Feature802154Emulation].Enabled { + opts.IEEE802154 = true + } } src, err := csource.Write(p, opts) if err != nil { |
