// https://syzkaller.appspot.com/bug?id=82ee167a55d45618bcbf303528c26d3c44b06559 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef __NR_mmap #define __NR_mmap 222 #endif static unsigned long long procid; static __thread int clone_ongoing; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { if (__atomic_load_n(&clone_ongoing, __ATOMIC_RELAXED) != 0) { exit(sig); } uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0; int valid = addr < prog_start || addr > prog_end; if (skip && valid) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ ({ \ int ok = 1; \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } else \ ok = 0; \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ ok; \ }) static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } struct nlmsg { char* pos; int nesting; struct nlattr* nested[8]; char buf[4096]; }; static void netlink_init(struct nlmsg* nlmsg, int typ, int flags, const void* data, int size) { memset(nlmsg, 0, sizeof(*nlmsg)); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf; hdr->nlmsg_type = typ; hdr->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | flags; memcpy(hdr + 1, data, size); nlmsg->pos = (char*)(hdr + 1) + NLMSG_ALIGN(size); } static void netlink_attr(struct nlmsg* nlmsg, int typ, const void* data, int size) { struct nlattr* attr = (struct nlattr*)nlmsg->pos; attr->nla_len = sizeof(*attr) + size; attr->nla_type = typ; if (size > 0) memcpy(attr + 1, data, size); nlmsg->pos += NLMSG_ALIGN(attr->nla_len); } static void netlink_nest(struct nlmsg* nlmsg, int typ) { struct nlattr* attr = (struct nlattr*)nlmsg->pos; attr->nla_type = typ; nlmsg->pos += sizeof(*attr); nlmsg->nested[nlmsg->nesting++] = attr; } static void netlink_done(struct nlmsg* nlmsg) { struct nlattr* attr = nlmsg->nested[--nlmsg->nesting]; attr->nla_len = nlmsg->pos - (char*)attr; } static int netlink_send_ext(struct nlmsg* nlmsg, int sock, uint16_t reply_type, int* reply_len, bool dofail) { if (nlmsg->pos > nlmsg->buf + sizeof(nlmsg->buf) || nlmsg->nesting) exit(1); struct nlmsghdr* hdr = (struct nlmsghdr*)nlmsg->buf; hdr->nlmsg_len = nlmsg->pos - nlmsg->buf; struct sockaddr_nl addr; memset(&addr, 0, sizeof(addr)); addr.nl_family = AF_NETLINK; ssize_t n = sendto(sock, nlmsg->buf, hdr->nlmsg_len, 0, (struct sockaddr*)&addr, sizeof(addr)); if (n != (ssize_t)hdr->nlmsg_len) { if (dofail) exit(1); return -1; } n = recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); if (reply_len) *reply_len = 0; if (n < 0) { if (dofail) exit(1); return -1; } if (n < (ssize_t)sizeof(struct nlmsghdr)) { errno = EINVAL; if (dofail) exit(1); return -1; } if (hdr->nlmsg_type == NLMSG_DONE) return 0; if (reply_len && hdr->nlmsg_type == reply_type) { *reply_len = n; return 0; } if (n < (ssize_t)(sizeof(struct nlmsghdr) + sizeof(struct nlmsgerr))) { errno = EINVAL; if (dofail) exit(1); return -1; } if (hdr->nlmsg_type != NLMSG_ERROR) { errno = EINVAL; if (dofail) exit(1); return -1; } errno = -((struct nlmsgerr*)(hdr + 1))->error; return -errno; } static int netlink_send(struct nlmsg* nlmsg, int sock) { return netlink_send_ext(nlmsg, sock, 0, NULL, true); } static int netlink_query_family_id(struct nlmsg* nlmsg, int sock, const char* family_name, bool dofail) { struct genlmsghdr genlhdr; memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = CTRL_CMD_GETFAMILY; netlink_init(nlmsg, GENL_ID_CTRL, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(nlmsg, CTRL_ATTR_FAMILY_NAME, family_name, strnlen(family_name, GENL_NAMSIZ - 1) + 1); int n = 0; int err = netlink_send_ext(nlmsg, sock, GENL_ID_CTRL, &n, dofail); if (err < 0) { return -1; } uint16_t id = 0; struct nlattr* attr = (struct nlattr*)(nlmsg->buf + NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(genlhdr))); for (; (char*)attr < nlmsg->buf + n; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { if (attr->nla_type == CTRL_ATTR_FAMILY_ID) { id = *(uint16_t*)(attr + 1); break; } } if (!id) { errno = EINVAL; return -1; } recv(sock, nlmsg->buf, sizeof(nlmsg->buf), 0); return id; } static int netlink_next_msg(struct nlmsg* nlmsg, unsigned int offset, unsigned int total_len) { struct nlmsghdr* hdr = (struct nlmsghdr*)(nlmsg->buf + offset); if (offset == total_len || offset + hdr->nlmsg_len > total_len) return -1; return hdr->nlmsg_len; } static void netlink_add_device_impl(struct nlmsg* nlmsg, const char* type, const char* name, bool up) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); if (up) hdr.ifi_flags = hdr.ifi_change = IFF_UP; netlink_init(nlmsg, RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); if (name) netlink_attr(nlmsg, IFLA_IFNAME, name, strlen(name)); netlink_nest(nlmsg, IFLA_LINKINFO); netlink_attr(nlmsg, IFLA_INFO_KIND, type, strlen(type)); } static void netlink_add_device(struct nlmsg* nlmsg, int sock, const char* type, const char* name) { netlink_add_device_impl(nlmsg, type, name, false); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); if (err < 0) { } } static void netlink_add_veth(struct nlmsg* nlmsg, int sock, const char* name, const char* peer) { netlink_add_device_impl(nlmsg, "veth", name, false); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_nest(nlmsg, VETH_INFO_PEER); nlmsg->pos += sizeof(struct ifinfomsg); netlink_attr(nlmsg, IFLA_IFNAME, peer, strlen(peer)); netlink_done(nlmsg); netlink_done(nlmsg); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); if (err < 0) { } } static void netlink_add_xfrm(struct nlmsg* nlmsg, int sock, const char* name) { netlink_add_device_impl(nlmsg, "xfrm", name, true); netlink_nest(nlmsg, IFLA_INFO_DATA); int if_id = 1; netlink_attr(nlmsg, 2, &if_id, sizeof(if_id)); netlink_done(nlmsg); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); if (err < 0) { } } static void netlink_add_hsr(struct nlmsg* nlmsg, int sock, const char* name, const char* slave1, const char* slave2) { netlink_add_device_impl(nlmsg, "hsr", name, false); netlink_nest(nlmsg, IFLA_INFO_DATA); int ifindex1 = if_nametoindex(slave1); netlink_attr(nlmsg, IFLA_HSR_SLAVE1, &ifindex1, sizeof(ifindex1)); int ifindex2 = if_nametoindex(slave2); netlink_attr(nlmsg, IFLA_HSR_SLAVE2, &ifindex2, sizeof(ifindex2)); netlink_done(nlmsg); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); if (err < 0) { } } static void netlink_add_linked(struct nlmsg* nlmsg, int sock, const char* type, const char* name, const char* link) { netlink_add_device_impl(nlmsg, type, name, false); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); if (err < 0) { } } static void netlink_add_vlan(struct nlmsg* nlmsg, int sock, const char* name, const char* link, uint16_t id, uint16_t proto) { netlink_add_device_impl(nlmsg, "vlan", name, false); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_attr(nlmsg, IFLA_VLAN_ID, &id, sizeof(id)); netlink_attr(nlmsg, IFLA_VLAN_PROTOCOL, &proto, sizeof(proto)); netlink_done(nlmsg); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); if (err < 0) { } } static void netlink_add_macvlan(struct nlmsg* nlmsg, int sock, const char* name, const char* link) { netlink_add_device_impl(nlmsg, "macvlan", name, false); netlink_nest(nlmsg, IFLA_INFO_DATA); uint32_t mode = MACVLAN_MODE_BRIDGE; netlink_attr(nlmsg, IFLA_MACVLAN_MODE, &mode, sizeof(mode)); netlink_done(nlmsg); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); if (err < 0) { } } static void netlink_add_geneve(struct nlmsg* nlmsg, int sock, const char* name, uint32_t vni, struct in_addr* addr4, struct in6_addr* addr6) { netlink_add_device_impl(nlmsg, "geneve", name, false); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_attr(nlmsg, IFLA_GENEVE_ID, &vni, sizeof(vni)); if (addr4) netlink_attr(nlmsg, IFLA_GENEVE_REMOTE, addr4, sizeof(*addr4)); if (addr6) netlink_attr(nlmsg, IFLA_GENEVE_REMOTE6, addr6, sizeof(*addr6)); netlink_done(nlmsg); netlink_done(nlmsg); int err = netlink_send(nlmsg, sock); if (err < 0) { } } #define IFLA_IPVLAN_FLAGS 2 #define IPVLAN_MODE_L3S 2 #undef IPVLAN_F_VEPA #define IPVLAN_F_VEPA 2 static void netlink_add_ipvlan(struct nlmsg* nlmsg, int sock, const char* name, const char* link, uint16_t mode, uint16_t flags) { netlink_add_device_impl(nlmsg, "ipvlan", name, false); netlink_nest(nlmsg, IFLA_INFO_DATA); netlink_attr(nlmsg, IFLA_IPVLAN_MODE, &mode, sizeof(mode)); netlink_attr(nlmsg, IFLA_IPVLAN_FLAGS, &flags, sizeof(flags)); netlink_done(nlmsg); netlink_done(nlmsg); int ifindex = if_nametoindex(link); netlink_attr(nlmsg, IFLA_LINK, &ifindex, sizeof(ifindex)); int err = netlink_send(nlmsg, sock); if (err < 0) { } } 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) { struct ifinfomsg hdr; memset(&hdr, 0, sizeof(hdr)); if (up) hdr.ifi_flags = hdr.ifi_change = IFF_UP; hdr.ifi_index = if_nametoindex(name); netlink_init(nlmsg, RTM_NEWLINK, 0, &hdr, sizeof(hdr)); if (new_name) netlink_attr(nlmsg, IFLA_IFNAME, new_name, strlen(new_name)); if (master) { int ifindex = if_nametoindex(master); netlink_attr(nlmsg, IFLA_MASTER, &ifindex, sizeof(ifindex)); } if (macsize) netlink_attr(nlmsg, IFLA_ADDRESS, mac, macsize); int err = netlink_send(nlmsg, sock); if (err < 0) { } } static int netlink_add_addr(struct nlmsg* nlmsg, int sock, const char* dev, const void* addr, int addrsize) { struct ifaddrmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ifa_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ifa_prefixlen = addrsize == 4 ? 24 : 120; hdr.ifa_scope = RT_SCOPE_UNIVERSE; hdr.ifa_index = if_nametoindex(dev); netlink_init(nlmsg, RTM_NEWADDR, NLM_F_CREATE | NLM_F_REPLACE, &hdr, sizeof(hdr)); netlink_attr(nlmsg, IFA_LOCAL, addr, addrsize); netlink_attr(nlmsg, IFA_ADDRESS, addr, addrsize); return netlink_send(nlmsg, sock); } static void netlink_add_addr4(struct nlmsg* nlmsg, int sock, const char* dev, const char* addr) { struct in_addr in_addr; inet_pton(AF_INET, addr, &in_addr); int err = netlink_add_addr(nlmsg, sock, dev, &in_addr, sizeof(in_addr)); if (err < 0) { } } static void netlink_add_addr6(struct nlmsg* nlmsg, int sock, const char* dev, const char* addr) { struct in6_addr in6_addr; inet_pton(AF_INET6, addr, &in6_addr); int err = netlink_add_addr(nlmsg, sock, dev, &in6_addr, sizeof(in6_addr)); if (err < 0) { } } static void netlink_add_neigh(struct nlmsg* nlmsg, int sock, const char* name, const void* addr, int addrsize, const void* mac, int macsize) { struct ndmsg hdr; memset(&hdr, 0, sizeof(hdr)); hdr.ndm_family = addrsize == 4 ? AF_INET : AF_INET6; hdr.ndm_ifindex = if_nametoindex(name); hdr.ndm_state = NUD_PERMANENT; netlink_init(nlmsg, RTM_NEWNEIGH, NLM_F_EXCL | NLM_F_CREATE, &hdr, sizeof(hdr)); netlink_attr(nlmsg, NDA_DST, addr, addrsize); netlink_attr(nlmsg, NDA_LLADDR, mac, macsize); int err = netlink_send(nlmsg, sock); if (err < 0) { } } static struct nlmsg nlmsg; static int tunfd = -1; #define TUN_IFACE "syz_tun" #define LOCAL_MAC 0xaaaaaaaaaaaa #define REMOTE_MAC 0xaaaaaaaaaabb #define LOCAL_IPV4 "172.20.20.170" #define REMOTE_IPV4 "172.20.20.187" #define LOCAL_IPV6 "fe80::aa" #define REMOTE_IPV6 "fe80::bb" #define IFF_NAPI 0x0010 static void initialize_tun(void) { tunfd = open("/dev/net/tun", O_RDWR | O_NONBLOCK); if (tunfd == -1) { printf("tun: can't open /dev/net/tun: please enable CONFIG_TUN=y\n"); printf("otherwise fuzzing or reproducing might not work as intended\n"); return; } const int kTunFd = 200; if (dup2(tunfd, kTunFd) < 0) exit(1); close(tunfd); tunfd = kTunFd; struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, TUN_IFACE, IFNAMSIZ); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; if (ioctl(tunfd, TUNSETIFF, (void*)&ifr) < 0) { exit(1); } char sysctl[64]; sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/accept_dad", TUN_IFACE); write_file(sysctl, "0"); sprintf(sysctl, "/proc/sys/net/ipv6/conf/%s/router_solicitations", TUN_IFACE); write_file(sysctl, "0"); int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); netlink_add_addr4(&nlmsg, sock, TUN_IFACE, LOCAL_IPV4); netlink_add_addr6(&nlmsg, sock, TUN_IFACE, LOCAL_IPV6); uint64_t macaddr = REMOTE_MAC; struct in_addr in_addr; inet_pton(AF_INET, REMOTE_IPV4, &in_addr); netlink_add_neigh(&nlmsg, sock, TUN_IFACE, &in_addr, sizeof(in_addr), &macaddr, ETH_ALEN); struct in6_addr in6_addr; inet_pton(AF_INET6, REMOTE_IPV6, &in6_addr); netlink_add_neigh(&nlmsg, sock, TUN_IFACE, &in6_addr, sizeof(in6_addr), &macaddr, ETH_ALEN); macaddr = LOCAL_MAC; netlink_device_change(&nlmsg, sock, TUN_IFACE, true, 0, &macaddr, ETH_ALEN, NULL); close(sock); } #define DEVLINK_FAMILY_NAME "devlink" #define DEVLINK_CMD_PORT_GET 5 #define DEVLINK_ATTR_BUS_NAME 1 #define DEVLINK_ATTR_DEV_NAME 2 #define DEVLINK_ATTR_NETDEV_NAME 7 static struct nlmsg nlmsg2; static void initialize_devlink_ports(const char* bus_name, const char* dev_name, const char* netdev_prefix) { struct genlmsghdr genlhdr; int len, total_len, id, err, offset; uint16_t netdev_index; int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (sock == -1) exit(1); int rtsock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (rtsock == -1) exit(1); id = netlink_query_family_id(&nlmsg, sock, DEVLINK_FAMILY_NAME, true); if (id == -1) goto error; memset(&genlhdr, 0, sizeof(genlhdr)); genlhdr.cmd = DEVLINK_CMD_PORT_GET; netlink_init(&nlmsg, id, NLM_F_DUMP, &genlhdr, sizeof(genlhdr)); netlink_attr(&nlmsg, DEVLINK_ATTR_BUS_NAME, bus_name, strlen(bus_name) + 1); netlink_attr(&nlmsg, DEVLINK_ATTR_DEV_NAME, dev_name, strlen(dev_name) + 1); err = netlink_send_ext(&nlmsg, sock, id, &total_len, true); if (err < 0) { goto error; } offset = 0; netdev_index = 0; while ((len = netlink_next_msg(&nlmsg, offset, total_len)) != -1) { struct nlattr* attr = (struct nlattr*)(nlmsg.buf + offset + NLMSG_HDRLEN + NLMSG_ALIGN(sizeof(genlhdr))); for (; (char*)attr < nlmsg.buf + offset + len; attr = (struct nlattr*)((char*)attr + NLMSG_ALIGN(attr->nla_len))) { if (attr->nla_type == DEVLINK_ATTR_NETDEV_NAME) { char* port_name; char netdev_name[IFNAMSIZ]; port_name = (char*)(attr + 1); snprintf(netdev_name, sizeof(netdev_name), "%s%d", netdev_prefix, netdev_index); netlink_device_change(&nlmsg2, rtsock, port_name, true, 0, 0, 0, netdev_name); break; } } offset += len; netdev_index++; } error: close(rtsock); close(sock); } static int runcmdline(char* cmdline) { int ret = system(cmdline); if (ret) { } return ret; } #define DEV_IPV4 "172.20.20.%d" #define DEV_IPV6 "fe80::%02x" #define DEV_MAC 0x00aaaaaaaaaa static void netdevsim_add(unsigned int addr, unsigned int port_count) { write_file("/sys/bus/netdevsim/del_device", "%u", addr); if (write_file("/sys/bus/netdevsim/new_device", "%u %u", addr, port_count)) { char buf[32]; snprintf(buf, sizeof(buf), "netdevsim%d", addr); initialize_devlink_ports("netdevsim", buf, "netdevsim"); } } #define WG_GENL_NAME "wireguard" enum wg_cmd { WG_CMD_GET_DEVICE, WG_CMD_SET_DEVICE, }; enum wgdevice_attribute { WGDEVICE_A_UNSPEC, WGDEVICE_A_IFINDEX, WGDEVICE_A_IFNAME, WGDEVICE_A_PRIVATE_KEY, WGDEVICE_A_PUBLIC_KEY, WGDEVICE_A_FLAGS, WGDEVICE_A_LISTEN_PORT, WGDEVICE_A_FWMARK, WGDEVICE_A_PEERS, }; enum wgpeer_attribute { WGPEER_A_UNSPEC, WGPEER_A_PUBLIC_KEY, WGPEER_A_PRESHARED_KEY, WGPEER_A_FLAGS, WGPEER_A_ENDPOINT, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, WGPEER_A_LAST_HANDSHAKE_TIME, WGPEER_A_RX_BYTES, WGPEER_A_TX_BYTES, WGPEER_A_ALLOWEDIPS, WGPEER_A_PROTOCOL_VERSION, }; enum wgallowedip_attribute { WGALLOWEDIP_A_UNSPEC, WGALLOWEDIP_A_FAMILY, WGALLOWEDIP_A_IPADDR, WGALLOWEDIP_A_CIDR_MASK, }; static void netlink_wireguard_setup(void) { const char ifname_a[] = "wg0"; const char ifname_b[] = "wg1"; const char ifname_c[] = "wg2"; const char private_a[] = "\xa0\x5c\xa8\x4f\x6c\x9c\x8e\x38\x53\xe2\xfd\x7a\x70\xae\x0f\xb2\x0f\xa1" "\x52\x60\x0c\xb0\x08\x45\x17\x4f\x08\x07\x6f\x8d\x78\x43"; const char private_b[] = "\xb0\x80\x73\xe8\xd4\x4e\x91\xe3\xda\x92\x2c\x22\x43\x82\x44\xbb\x88\x5c" "\x69\xe2\x69\xc8\xe9\xd8\x35\xb1\x14\x29\x3a\x4d\xdc\x6e"; const char private_c[] = "\xa0\xcb\x87\x9a\x47\xf5\xbc\x64\x4c\x0e\x69\x3f\xa6\xd0\x31\xc7\x4a\x15" "\x53\xb6\xe9\x01\xb9\xff\x2f\x51\x8c\x78\x04\x2f\xb5\x42"; const char public_a[] = "\x97\x5c\x9d\x81\xc9\x83\xc8\x20\x9e\xe7\x81\x25\x4b\x89\x9f\x8e\xd9\x25" "\xae\x9f\x09\x23\xc2\x3c\x62\xf5\x3c\x57\xcd\xbf\x69\x1c"; const char public_b[] = "\xd1\x73\x28\x99\xf6\x11\xcd\x89\x94\x03\x4d\x7f\x41\x3d\xc9\x57\x63\x0e" "\x54\x93\xc2\x85\xac\xa4\x00\x65\xcb\x63\x11\xbe\x69\x6b"; const char public_c[] = "\xf4\x4d\xa3\x67\xa8\x8e\xe6\x56\x4f\x02\x02\x11\x45\x67\x27\x08\x2f\x5c" "\xeb\xee\x8b\x1b\xf5\xeb\x73\x37\x34\x1b\x45\x9b\x39\x22"; const uint16_t listen_a = 20001; const uint16_t listen_b = 20002; const uint16_t listen_c = 20003; const uint16_t af_inet = AF_INET; const uint16_t af_inet6 = AF_INET6; const struct sockaddr_in endpoint_b_v4 = { .sin_family = AF_INET, .sin_port = htons(listen_b), .sin_addr = {htonl(INADDR_LOOPBACK)}}; const struct sockaddr_in endpoint_c_v4 = { .sin_family = AF_INET, .sin_port = htons(listen_c), .sin_addr = {htonl(INADDR_LOOPBACK)}}; struct sockaddr_in6 endpoint_a_v6 = {.sin6_family = AF_INET6, .sin6_port = htons(listen_a)}; endpoint_a_v6.sin6_addr = in6addr_loopback; struct sockaddr_in6 endpoint_c_v6 = {.sin6_family = AF_INET6, .sin6_port = htons(listen_c)}; endpoint_c_v6.sin6_addr = in6addr_loopback; const struct in_addr first_half_v4 = {0}; const struct in_addr second_half_v4 = {(uint32_t)htonl(128 << 24)}; const struct in6_addr first_half_v6 = {{{0}}}; const struct in6_addr second_half_v6 = {{{0x80}}}; const uint8_t half_cidr = 1; const uint16_t persistent_keepalives[] = {1, 3, 7, 9, 14, 19}; struct genlmsghdr genlhdr = {.cmd = WG_CMD_SET_DEVICE, .version = 1}; int sock; int id, err; sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (sock == -1) { return; } id = netlink_query_family_id(&nlmsg, sock, WG_GENL_NAME, true); if (id == -1) goto error; netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_a, strlen(ifname_a) + 1); netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_a, 32); netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_a, 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4, sizeof(endpoint_b_v4)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[0], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4, sizeof(first_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6, sizeof(first_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v6, sizeof(endpoint_c_v6)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[1], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4, sizeof(second_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6, sizeof(second_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); err = netlink_send(&nlmsg, sock); if (err < 0) { } netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_b, strlen(ifname_b) + 1); netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_b, 32); netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_b, 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6, sizeof(endpoint_a_v6)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[2], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4, sizeof(first_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6, sizeof(first_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_c, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_c_v4, sizeof(endpoint_c_v4)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[3], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4, sizeof(second_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6, sizeof(second_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); err = netlink_send(&nlmsg, sock); if (err < 0) { } netlink_init(&nlmsg, id, 0, &genlhdr, sizeof(genlhdr)); netlink_attr(&nlmsg, WGDEVICE_A_IFNAME, ifname_c, strlen(ifname_c) + 1); netlink_attr(&nlmsg, WGDEVICE_A_PRIVATE_KEY, private_c, 32); netlink_attr(&nlmsg, WGDEVICE_A_LISTEN_PORT, &listen_c, 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGDEVICE_A_PEERS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_a, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_a_v6, sizeof(endpoint_a_v6)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[4], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v4, sizeof(first_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &first_half_v6, sizeof(first_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGPEER_A_PUBLIC_KEY, public_b, 32); netlink_attr(&nlmsg, WGPEER_A_ENDPOINT, &endpoint_b_v4, sizeof(endpoint_b_v4)); netlink_attr(&nlmsg, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL, &persistent_keepalives[5], 2); netlink_nest(&nlmsg, NLA_F_NESTED | WGPEER_A_ALLOWEDIPS); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v4, sizeof(second_half_v4)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_nest(&nlmsg, NLA_F_NESTED | 0); netlink_attr(&nlmsg, WGALLOWEDIP_A_FAMILY, &af_inet6, 2); netlink_attr(&nlmsg, WGALLOWEDIP_A_IPADDR, &second_half_v6, sizeof(second_half_v6)); netlink_attr(&nlmsg, WGALLOWEDIP_A_CIDR_MASK, &half_cidr, 1); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); netlink_done(&nlmsg); err = netlink_send(&nlmsg, sock); if (err < 0) { } error: close(sock); } static void initialize_netdevices(void) { char netdevsim[16]; sprintf(netdevsim, "netdevsim%d", (int)procid); struct { const char* type; const char* dev; } devtypes[] = { {"ip6gretap", "ip6gretap0"}, {"bridge", "bridge0"}, {"vcan", "vcan0"}, {"bond", "bond0"}, {"team", "team0"}, {"dummy", "dummy0"}, {"nlmon", "nlmon0"}, {"caif", "caif0"}, {"batadv", "batadv0"}, {"vxcan", "vxcan1"}, {"veth", 0}, {"wireguard", "wg0"}, {"wireguard", "wg1"}, {"wireguard", "wg2"}, }; const char* devmasters[] = {"bridge", "bond", "team", "batadv"}; struct { const char* name; int macsize; bool noipv6; } devices[] = { {"lo", ETH_ALEN}, {"sit0", 0}, {"bridge0", ETH_ALEN}, {"vcan0", 0, true}, {"tunl0", 0}, {"gre0", 0}, {"gretap0", ETH_ALEN}, {"ip_vti0", 0}, {"ip6_vti0", 0}, {"ip6tnl0", 0}, {"ip6gre0", 0}, {"ip6gretap0", ETH_ALEN}, {"erspan0", ETH_ALEN}, {"bond0", ETH_ALEN}, {"veth0", ETH_ALEN}, {"veth1", ETH_ALEN}, {"team0", ETH_ALEN}, {"veth0_to_bridge", ETH_ALEN}, {"veth1_to_bridge", ETH_ALEN}, {"veth0_to_bond", ETH_ALEN}, {"veth1_to_bond", ETH_ALEN}, {"veth0_to_team", ETH_ALEN}, {"veth1_to_team", ETH_ALEN}, {"veth0_to_hsr", ETH_ALEN}, {"veth1_to_hsr", ETH_ALEN}, {"hsr0", 0}, {"dummy0", ETH_ALEN}, {"nlmon0", 0}, {"vxcan0", 0, true}, {"vxcan1", 0, true}, {"caif0", ETH_ALEN}, {"batadv0", ETH_ALEN}, {netdevsim, ETH_ALEN}, {"xfrm0", ETH_ALEN}, {"veth0_virt_wifi", ETH_ALEN}, {"veth1_virt_wifi", ETH_ALEN}, {"virt_wifi0", ETH_ALEN}, {"veth0_vlan", ETH_ALEN}, {"veth1_vlan", ETH_ALEN}, {"vlan0", ETH_ALEN}, {"vlan1", ETH_ALEN}, {"macvlan0", ETH_ALEN}, {"macvlan1", ETH_ALEN}, {"ipvlan0", ETH_ALEN}, {"ipvlan1", ETH_ALEN}, {"veth0_macvtap", ETH_ALEN}, {"veth1_macvtap", ETH_ALEN}, {"macvtap0", ETH_ALEN}, {"macsec0", ETH_ALEN}, {"veth0_to_batadv", ETH_ALEN}, {"veth1_to_batadv", ETH_ALEN}, {"batadv_slave_0", ETH_ALEN}, {"batadv_slave_1", ETH_ALEN}, {"geneve0", ETH_ALEN}, {"geneve1", ETH_ALEN}, {"wg0", 0}, {"wg1", 0}, {"wg2", 0}, }; int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) netlink_add_device(&nlmsg, sock, devtypes[i].type, devtypes[i].dev); for (i = 0; i < sizeof(devmasters) / (sizeof(devmasters[0])); i++) { char master[32], slave0[32], veth0[32], slave1[32], veth1[32]; sprintf(slave0, "%s_slave_0", devmasters[i]); sprintf(veth0, "veth0_to_%s", devmasters[i]); netlink_add_veth(&nlmsg, sock, slave0, veth0); sprintf(slave1, "%s_slave_1", devmasters[i]); sprintf(veth1, "veth1_to_%s", devmasters[i]); netlink_add_veth(&nlmsg, sock, slave1, veth1); sprintf(master, "%s0", devmasters[i]); netlink_device_change(&nlmsg, sock, slave0, false, master, 0, 0, NULL); netlink_device_change(&nlmsg, sock, slave1, false, master, 0, 0, NULL); } netlink_add_xfrm(&nlmsg, sock, "xfrm0"); netlink_device_change(&nlmsg, sock, "bridge_slave_0", true, 0, 0, 0, NULL); netlink_device_change(&nlmsg, sock, "bridge_slave_1", true, 0, 0, 0, NULL); netlink_add_veth(&nlmsg, sock, "hsr_slave_0", "veth0_to_hsr"); netlink_add_veth(&nlmsg, sock, "hsr_slave_1", "veth1_to_hsr"); netlink_add_hsr(&nlmsg, sock, "hsr0", "hsr_slave_0", "hsr_slave_1"); netlink_device_change(&nlmsg, sock, "hsr_slave_0", true, 0, 0, 0, NULL); netlink_device_change(&nlmsg, sock, "hsr_slave_1", true, 0, 0, 0, NULL); netlink_add_veth(&nlmsg, sock, "veth0_virt_wifi", "veth1_virt_wifi"); netlink_add_linked(&nlmsg, sock, "virt_wifi", "virt_wifi0", "veth1_virt_wifi"); netlink_add_veth(&nlmsg, sock, "veth0_vlan", "veth1_vlan"); netlink_add_vlan(&nlmsg, sock, "vlan0", "veth0_vlan", 0, htons(ETH_P_8021Q)); netlink_add_vlan(&nlmsg, sock, "vlan1", "veth0_vlan", 1, htons(ETH_P_8021AD)); netlink_add_macvlan(&nlmsg, sock, "macvlan0", "veth1_vlan"); netlink_add_macvlan(&nlmsg, sock, "macvlan1", "veth1_vlan"); netlink_add_ipvlan(&nlmsg, sock, "ipvlan0", "veth0_vlan", IPVLAN_MODE_L2, 0); netlink_add_ipvlan(&nlmsg, sock, "ipvlan1", "veth0_vlan", IPVLAN_MODE_L3S, IPVLAN_F_VEPA); netlink_add_veth(&nlmsg, sock, "veth0_macvtap", "veth1_macvtap"); netlink_add_linked(&nlmsg, sock, "macvtap", "macvtap0", "veth0_macvtap"); netlink_add_linked(&nlmsg, sock, "macsec", "macsec0", "veth1_macvtap"); char addr[32]; sprintf(addr, DEV_IPV4, 14 + 10); struct in_addr geneve_addr4; if (inet_pton(AF_INET, addr, &geneve_addr4) <= 0) exit(1); struct in6_addr geneve_addr6; if (inet_pton(AF_INET6, "fc00::01", &geneve_addr6) <= 0) exit(1); netlink_add_geneve(&nlmsg, sock, "geneve0", 0, &geneve_addr4, 0); netlink_add_geneve(&nlmsg, sock, "geneve1", 1, 0, &geneve_addr6); netdevsim_add((int)procid, 4); netlink_wireguard_setup(); for (i = 0; i < sizeof(devices) / (sizeof(devices[0])); i++) { char addr[32]; sprintf(addr, DEV_IPV4, i + 10); netlink_add_addr4(&nlmsg, sock, devices[i].name, addr); if (!devices[i].noipv6) { sprintf(addr, DEV_IPV6, i + 10); netlink_add_addr6(&nlmsg, sock, devices[i].name, addr); } uint64_t macaddr = DEV_MAC + ((i + 10ull) << 40); netlink_device_change(&nlmsg, sock, devices[i].name, true, 0, &macaddr, devices[i].macsize, NULL); } close(sock); } static void initialize_netdevices_init(void) { int sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (sock == -1) exit(1); struct { const char* type; int macsize; bool noipv6; bool noup; } devtypes[] = { {"nr", 7, true}, {"rose", 5, true, true}, }; unsigned i; for (i = 0; i < sizeof(devtypes) / sizeof(devtypes[0]); i++) { char dev[32], addr[32]; sprintf(dev, "%s%d", devtypes[i].type, (int)procid); sprintf(addr, "172.30.%d.%d", i, (int)procid + 1); netlink_add_addr4(&nlmsg, sock, dev, addr); if (!devtypes[i].noipv6) { sprintf(addr, "fe88::%02x:%02x", i, (int)procid + 1); netlink_add_addr6(&nlmsg, sock, dev, addr); } int macsize = devtypes[i].macsize; uint64_t macaddr = 0xbbbbbb + ((unsigned long long)i << (8 * (macsize - 2))) + (procid << (8 * (macsize - 1))); netlink_device_change(&nlmsg, sock, dev, !devtypes[i].noup, 0, &macaddr, macsize, NULL); } close(sock); } static int read_tun(char* data, int size) { if (tunfd < 0) return -1; int rv = read(tunfd, data, size); if (rv < 0) { if (errno == EAGAIN || errno == EBADF || errno == EBADFD) return -1; exit(1); } return rv; } static void flush_tun() { char data[1000]; while (read_tun(&data[0], sizeof(data)) != -1) { } } #define MAX_FDS 30 #define USB_MAX_IFACE_NUM 4 #define USB_MAX_EP_NUM 32 #define USB_MAX_FDS 6 struct usb_endpoint_index { struct usb_endpoint_descriptor desc; int handle; }; struct usb_iface_index { struct usb_interface_descriptor* iface; uint8_t bInterfaceNumber; uint8_t bAlternateSetting; uint8_t bInterfaceClass; struct usb_endpoint_index eps[USB_MAX_EP_NUM]; int eps_num; }; struct usb_device_index { struct usb_device_descriptor* dev; struct usb_config_descriptor* config; uint8_t bDeviceClass; uint8_t bMaxPower; int config_length; struct usb_iface_index ifaces[USB_MAX_IFACE_NUM]; int ifaces_num; int iface_cur; }; struct usb_info { int fd; struct usb_device_index index; }; static struct usb_info usb_devices[USB_MAX_FDS]; static struct usb_device_index* lookup_usb_index(int fd) { for (int i = 0; i < USB_MAX_FDS; i++) { if (__atomic_load_n(&usb_devices[i].fd, __ATOMIC_ACQUIRE) == fd) return &usb_devices[i].index; } return NULL; } static int usb_devices_num; static bool parse_usb_descriptor(const char* buffer, size_t length, struct usb_device_index* index) { if (length < sizeof(*index->dev) + sizeof(*index->config)) return false; memset(index, 0, sizeof(*index)); index->dev = (struct usb_device_descriptor*)buffer; index->config = (struct usb_config_descriptor*)(buffer + sizeof(*index->dev)); index->bDeviceClass = index->dev->bDeviceClass; index->bMaxPower = index->config->bMaxPower; index->config_length = length - sizeof(*index->dev); index->iface_cur = -1; size_t offset = 0; while (true) { if (offset + 1 >= length) break; uint8_t desc_length = buffer[offset]; uint8_t desc_type = buffer[offset + 1]; if (desc_length <= 2) break; if (offset + desc_length > length) break; if (desc_type == USB_DT_INTERFACE && index->ifaces_num < USB_MAX_IFACE_NUM) { struct usb_interface_descriptor* iface = (struct usb_interface_descriptor*)(buffer + offset); index->ifaces[index->ifaces_num].iface = iface; index->ifaces[index->ifaces_num].bInterfaceNumber = iface->bInterfaceNumber; index->ifaces[index->ifaces_num].bAlternateSetting = iface->bAlternateSetting; index->ifaces[index->ifaces_num].bInterfaceClass = iface->bInterfaceClass; index->ifaces_num++; } if (desc_type == USB_DT_ENDPOINT && index->ifaces_num > 0) { struct usb_iface_index* iface = &index->ifaces[index->ifaces_num - 1]; if (iface->eps_num < USB_MAX_EP_NUM) { memcpy(&iface->eps[iface->eps_num].desc, buffer + offset, sizeof(iface->eps[iface->eps_num].desc)); iface->eps_num++; } } offset += desc_length; } return true; } static struct usb_device_index* add_usb_index(int fd, const char* dev, size_t dev_len) { int i = __atomic_fetch_add(&usb_devices_num, 1, __ATOMIC_RELAXED); if (i >= USB_MAX_FDS) return NULL; if (!parse_usb_descriptor(dev, dev_len, &usb_devices[i].index)) return NULL; __atomic_store_n(&usb_devices[i].fd, fd, __ATOMIC_RELEASE); return &usb_devices[i].index; } struct vusb_connect_string_descriptor { uint32_t len; char* str; } __attribute__((packed)); struct vusb_connect_descriptors { uint32_t qual_len; char* qual; uint32_t bos_len; char* bos; uint32_t strs_len; struct vusb_connect_string_descriptor strs[0]; } __attribute__((packed)); static const char default_string[] = {8, USB_DT_STRING, 's', 0, 'y', 0, 'z', 0}; static const char default_lang_id[] = {4, USB_DT_STRING, 0x09, 0x04}; static bool lookup_connect_response_in(int fd, const struct vusb_connect_descriptors* descs, const struct usb_ctrlrequest* ctrl, struct usb_qualifier_descriptor* qual, char** response_data, uint32_t* response_length) { struct usb_device_index* index = lookup_usb_index(fd); uint8_t str_idx; if (!index) return false; switch (ctrl->bRequestType & USB_TYPE_MASK) { case USB_TYPE_STANDARD: switch (ctrl->bRequest) { case USB_REQ_GET_DESCRIPTOR: switch (ctrl->wValue >> 8) { case USB_DT_DEVICE: *response_data = (char*)index->dev; *response_length = sizeof(*index->dev); return true; case USB_DT_CONFIG: *response_data = (char*)index->config; *response_length = index->config_length; return true; case USB_DT_STRING: str_idx = (uint8_t)ctrl->wValue; if (descs && str_idx < descs->strs_len) { *response_data = descs->strs[str_idx].str; *response_length = descs->strs[str_idx].len; return true; } if (str_idx == 0) { *response_data = (char*)&default_lang_id[0]; *response_length = default_lang_id[0]; return true; } *response_data = (char*)&default_string[0]; *response_length = default_string[0]; return true; case USB_DT_BOS: *response_data = descs->bos; *response_length = descs->bos_len; return true; case USB_DT_DEVICE_QUALIFIER: if (!descs->qual) { qual->bLength = sizeof(*qual); qual->bDescriptorType = USB_DT_DEVICE_QUALIFIER; qual->bcdUSB = index->dev->bcdUSB; qual->bDeviceClass = index->dev->bDeviceClass; qual->bDeviceSubClass = index->dev->bDeviceSubClass; qual->bDeviceProtocol = index->dev->bDeviceProtocol; qual->bMaxPacketSize0 = index->dev->bMaxPacketSize0; qual->bNumConfigurations = index->dev->bNumConfigurations; qual->bRESERVED = 0; *response_data = (char*)qual; *response_length = sizeof(*qual); return true; } *response_data = descs->qual; *response_length = descs->qual_len; return true; default: break; } break; default: break; } break; default: break; } return false; } typedef bool (*lookup_connect_out_response_t)( int fd, const struct vusb_connect_descriptors* descs, const struct usb_ctrlrequest* ctrl, bool* done); static bool lookup_connect_response_out_generic( int fd, const struct vusb_connect_descriptors* descs, const struct usb_ctrlrequest* ctrl, bool* done) { switch (ctrl->bRequestType & USB_TYPE_MASK) { case USB_TYPE_STANDARD: switch (ctrl->bRequest) { case USB_REQ_SET_CONFIGURATION: *done = true; return true; default: break; } break; } return false; } struct vusb_descriptor { uint8_t req_type; uint8_t desc_type; uint32_t len; char data[0]; } __attribute__((packed)); struct vusb_descriptors { uint32_t len; struct vusb_descriptor* generic; struct vusb_descriptor* descs[0]; } __attribute__((packed)); struct vusb_response { uint8_t type; uint8_t req; uint32_t len; char data[0]; } __attribute__((packed)); struct vusb_responses { uint32_t len; struct vusb_response* generic; struct vusb_response* resps[0]; } __attribute__((packed)); static bool lookup_control_response(const struct vusb_descriptors* descs, const struct vusb_responses* resps, struct usb_ctrlrequest* ctrl, char** response_data, uint32_t* response_length) { int descs_num = 0; int resps_num = 0; if (descs) descs_num = (descs->len - offsetof(struct vusb_descriptors, descs)) / sizeof(descs->descs[0]); if (resps) resps_num = (resps->len - offsetof(struct vusb_responses, resps)) / sizeof(resps->resps[0]); uint8_t req = ctrl->bRequest; uint8_t req_type = ctrl->bRequestType & USB_TYPE_MASK; uint8_t desc_type = ctrl->wValue >> 8; if (req == USB_REQ_GET_DESCRIPTOR) { int i; for (i = 0; i < descs_num; i++) { struct vusb_descriptor* desc = descs->descs[i]; if (!desc) continue; if (desc->req_type == req_type && desc->desc_type == desc_type) { *response_length = desc->len; if (*response_length != 0) *response_data = &desc->data[0]; else *response_data = NULL; return true; } } if (descs && descs->generic) { *response_data = &descs->generic->data[0]; *response_length = descs->generic->len; return true; } } else { int i; for (i = 0; i < resps_num; i++) { struct vusb_response* resp = resps->resps[i]; if (!resp) continue; if (resp->type == req_type && resp->req == req) { *response_length = resp->len; if (*response_length != 0) *response_data = &resp->data[0]; else *response_data = NULL; return true; } } if (resps && resps->generic) { *response_data = &resps->generic->data[0]; *response_length = resps->generic->len; return true; } } return false; } #define UDC_NAME_LENGTH_MAX 128 struct usb_raw_init { __u8 driver_name[UDC_NAME_LENGTH_MAX]; __u8 device_name[UDC_NAME_LENGTH_MAX]; __u8 speed; }; enum usb_raw_event_type { USB_RAW_EVENT_INVALID = 0, USB_RAW_EVENT_CONNECT = 1, USB_RAW_EVENT_CONTROL = 2, }; struct usb_raw_event { __u32 type; __u32 length; __u8 data[0]; }; struct usb_raw_ep_io { __u16 ep; __u16 flags; __u32 length; __u8 data[0]; }; #define USB_RAW_EPS_NUM_MAX 30 #define USB_RAW_EP_NAME_MAX 16 #define USB_RAW_EP_ADDR_ANY 0xff struct usb_raw_ep_caps { __u32 type_control : 1; __u32 type_iso : 1; __u32 type_bulk : 1; __u32 type_int : 1; __u32 dir_in : 1; __u32 dir_out : 1; }; struct usb_raw_ep_limits { __u16 maxpacket_limit; __u16 max_streams; __u32 reserved; }; struct usb_raw_ep_info { __u8 name[USB_RAW_EP_NAME_MAX]; __u32 addr; struct usb_raw_ep_caps caps; struct usb_raw_ep_limits limits; }; struct usb_raw_eps_info { struct usb_raw_ep_info eps[USB_RAW_EPS_NUM_MAX]; }; #define USB_RAW_IOCTL_INIT _IOW('U', 0, struct usb_raw_init) #define USB_RAW_IOCTL_RUN _IO('U', 1) #define USB_RAW_IOCTL_EVENT_FETCH _IOR('U', 2, struct usb_raw_event) #define USB_RAW_IOCTL_EP0_WRITE _IOW('U', 3, struct usb_raw_ep_io) #define USB_RAW_IOCTL_EP0_READ _IOWR('U', 4, struct usb_raw_ep_io) #define USB_RAW_IOCTL_EP_ENABLE _IOW('U', 5, struct usb_endpoint_descriptor) #define USB_RAW_IOCTL_EP_DISABLE _IOW('U', 6, __u32) #define USB_RAW_IOCTL_EP_WRITE _IOW('U', 7, struct usb_raw_ep_io) #define USB_RAW_IOCTL_EP_READ _IOWR('U', 8, struct usb_raw_ep_io) #define USB_RAW_IOCTL_CONFIGURE _IO('U', 9) #define USB_RAW_IOCTL_VBUS_DRAW _IOW('U', 10, __u32) #define USB_RAW_IOCTL_EPS_INFO _IOR('U', 11, struct usb_raw_eps_info) #define USB_RAW_IOCTL_EP0_STALL _IO('U', 12) #define USB_RAW_IOCTL_EP_SET_HALT _IOW('U', 13, __u32) #define USB_RAW_IOCTL_EP_CLEAR_HALT _IOW('U', 14, __u32) #define USB_RAW_IOCTL_EP_SET_WEDGE _IOW('U', 15, __u32) static int usb_raw_open() { return open("/dev/raw-gadget", O_RDWR); } static int usb_raw_init(int fd, uint32_t speed, const char* driver, const char* device) { struct usb_raw_init arg; strncpy((char*)&arg.driver_name[0], driver, sizeof(arg.driver_name)); strncpy((char*)&arg.device_name[0], device, sizeof(arg.device_name)); arg.speed = speed; return ioctl(fd, USB_RAW_IOCTL_INIT, &arg); } static int usb_raw_run(int fd) { return ioctl(fd, USB_RAW_IOCTL_RUN, 0); } static int usb_raw_ep_write(int fd, struct usb_raw_ep_io* io) { return ioctl(fd, USB_RAW_IOCTL_EP_WRITE, io); } static int usb_raw_configure(int fd) { return ioctl(fd, USB_RAW_IOCTL_CONFIGURE, 0); } static int usb_raw_vbus_draw(int fd, uint32_t power) { return ioctl(fd, USB_RAW_IOCTL_VBUS_DRAW, power); } static int usb_raw_ep0_write(int fd, struct usb_raw_ep_io* io) { return ioctl(fd, USB_RAW_IOCTL_EP0_WRITE, io); } static int usb_raw_ep0_read(int fd, struct usb_raw_ep_io* io) { return ioctl(fd, USB_RAW_IOCTL_EP0_READ, io); } static int usb_raw_event_fetch(int fd, struct usb_raw_event* event) { return ioctl(fd, USB_RAW_IOCTL_EVENT_FETCH, event); } static int usb_raw_ep_enable(int fd, struct usb_endpoint_descriptor* desc) { return ioctl(fd, USB_RAW_IOCTL_EP_ENABLE, desc); } static int usb_raw_ep_disable(int fd, int ep) { return ioctl(fd, USB_RAW_IOCTL_EP_DISABLE, ep); } static int usb_raw_ep0_stall(int fd) { return ioctl(fd, USB_RAW_IOCTL_EP0_STALL, 0); } static int lookup_interface(int fd, uint8_t bInterfaceNumber, uint8_t bAlternateSetting) { struct usb_device_index* index = lookup_usb_index(fd); if (!index) return -1; for (int i = 0; i < index->ifaces_num; i++) { if (index->ifaces[i].bInterfaceNumber == bInterfaceNumber && index->ifaces[i].bAlternateSetting == bAlternateSetting) return i; } return -1; } static int lookup_endpoint(int fd, uint8_t bEndpointAddress) { struct usb_device_index* index = lookup_usb_index(fd); if (!index) return -1; if (index->iface_cur < 0) return -1; for (int ep = 0; ep < index->ifaces[index->iface_cur].eps_num; ep++) if (index->ifaces[index->iface_cur].eps[ep].desc.bEndpointAddress == bEndpointAddress) return index->ifaces[index->iface_cur].eps[ep].handle; return -1; } #define USB_MAX_PACKET_SIZE 4096 struct usb_raw_control_event { struct usb_raw_event inner; struct usb_ctrlrequest ctrl; char data[USB_MAX_PACKET_SIZE]; }; struct usb_raw_ep_io_data { struct usb_raw_ep_io inner; char data[USB_MAX_PACKET_SIZE]; }; static void set_interface(int fd, int n) { struct usb_device_index* index = lookup_usb_index(fd); if (!index) return; if (index->iface_cur >= 0 && index->iface_cur < index->ifaces_num) { for (int ep = 0; ep < index->ifaces[index->iface_cur].eps_num; ep++) { int rv = usb_raw_ep_disable( fd, index->ifaces[index->iface_cur].eps[ep].handle); if (rv < 0) { } else { } } } if (n >= 0 && n < index->ifaces_num) { for (int ep = 0; ep < index->ifaces[n].eps_num; ep++) { int rv = usb_raw_ep_enable(fd, &index->ifaces[n].eps[ep].desc); if (rv < 0) { } else { index->ifaces[n].eps[ep].handle = rv; } } index->iface_cur = n; } } static int configure_device(int fd) { struct usb_device_index* index = lookup_usb_index(fd); if (!index) return -1; int rv = usb_raw_vbus_draw(fd, index->bMaxPower); if (rv < 0) { return rv; } rv = usb_raw_configure(fd); if (rv < 0) { return rv; } set_interface(fd, 0); return 0; } static volatile long syz_usb_connect_impl(uint64_t speed, uint64_t dev_len, const char* dev, const struct vusb_connect_descriptors* descs, lookup_connect_out_response_t lookup_connect_response_out) { if (!dev) { return -1; } int fd = usb_raw_open(); if (fd < 0) { return fd; } if (fd >= MAX_FDS) { close(fd); return -1; } struct usb_device_index* index = add_usb_index(fd, dev, dev_len); if (!index) { return -1; } char device[32]; sprintf(&device[0], "dummy_udc.%llu", procid); int rv = usb_raw_init(fd, speed, "dummy_udc", &device[0]); if (rv < 0) { return rv; } rv = usb_raw_run(fd); if (rv < 0) { return rv; } bool done = false; while (!done) { struct usb_raw_control_event event; event.inner.type = 0; event.inner.length = sizeof(event.ctrl); rv = usb_raw_event_fetch(fd, (struct usb_raw_event*)&event); if (rv < 0) { return rv; } if (event.inner.type != USB_RAW_EVENT_CONTROL) continue; char* response_data = NULL; uint32_t response_length = 0; struct usb_qualifier_descriptor qual; if (event.ctrl.bRequestType & USB_DIR_IN) { if (!lookup_connect_response_in(fd, descs, &event.ctrl, &qual, &response_data, &response_length)) { usb_raw_ep0_stall(fd); continue; } } else { if (!lookup_connect_response_out(fd, descs, &event.ctrl, &done)) { usb_raw_ep0_stall(fd); continue; } response_data = NULL; response_length = event.ctrl.wLength; } if ((event.ctrl.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD && event.ctrl.bRequest == USB_REQ_SET_CONFIGURATION) { rv = configure_device(fd); if (rv < 0) { return rv; } } struct usb_raw_ep_io_data response; response.inner.ep = 0; response.inner.flags = 0; if (response_length > sizeof(response.data)) response_length = 0; if (event.ctrl.wLength < response_length) response_length = event.ctrl.wLength; response.inner.length = response_length; if (response_data) memcpy(&response.data[0], response_data, response_length); else memset(&response.data[0], 0, response_length); if (event.ctrl.bRequestType & USB_DIR_IN) { rv = usb_raw_ep0_write(fd, (struct usb_raw_ep_io*)&response); } else { rv = usb_raw_ep0_read(fd, (struct usb_raw_ep_io*)&response); } if (rv < 0) { return rv; } } sleep_ms(200); return fd; } static volatile long syz_usb_connect(volatile long a0, volatile long a1, volatile long a2, volatile long a3) { uint64_t speed = a0; uint64_t dev_len = a1; const char* dev = (const char*)a2; const struct vusb_connect_descriptors* descs = (const struct vusb_connect_descriptors*)a3; return syz_usb_connect_impl(speed, dev_len, dev, descs, &lookup_connect_response_out_generic); } static volatile long syz_usb_control_io(volatile long a0, volatile long a1, volatile long a2) { int fd = a0; const struct vusb_descriptors* descs = (const struct vusb_descriptors*)a1; const struct vusb_responses* resps = (const struct vusb_responses*)a2; struct usb_raw_control_event event; event.inner.type = 0; event.inner.length = USB_MAX_PACKET_SIZE; int rv = usb_raw_event_fetch(fd, (struct usb_raw_event*)&event); if (rv < 0) { return rv; } if (event.inner.type != USB_RAW_EVENT_CONTROL) { return -1; } char* response_data = NULL; uint32_t response_length = 0; if ((event.ctrl.bRequestType & USB_DIR_IN) && event.ctrl.wLength) { if (!lookup_control_response(descs, resps, &event.ctrl, &response_data, &response_length)) { usb_raw_ep0_stall(fd); return -1; } } else { if ((event.ctrl.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD || event.ctrl.bRequest == USB_REQ_SET_INTERFACE) { int iface_num = event.ctrl.wIndex; int alt_set = event.ctrl.wValue; int iface_index = lookup_interface(fd, iface_num, alt_set); if (iface_index < 0) { } else { set_interface(fd, iface_index); } } response_length = event.ctrl.wLength; } struct usb_raw_ep_io_data response; response.inner.ep = 0; response.inner.flags = 0; if (response_length > sizeof(response.data)) response_length = 0; if (event.ctrl.wLength < response_length) response_length = event.ctrl.wLength; if ((event.ctrl.bRequestType & USB_DIR_IN) && !event.ctrl.wLength) { response_length = USB_MAX_PACKET_SIZE; } response.inner.length = response_length; if (response_data) memcpy(&response.data[0], response_data, response_length); else memset(&response.data[0], 0, response_length); if ((event.ctrl.bRequestType & USB_DIR_IN) && event.ctrl.wLength) { rv = usb_raw_ep0_write(fd, (struct usb_raw_ep_io*)&response); } else { rv = usb_raw_ep0_read(fd, (struct usb_raw_ep_io*)&response); } if (rv < 0) { return rv; } sleep_ms(200); return 0; } static volatile long syz_usb_ep_write(volatile long a0, volatile long a1, volatile long a2, volatile long a3) { int fd = a0; uint8_t ep = a1; uint32_t len = a2; char* data = (char*)a3; int ep_handle = lookup_endpoint(fd, ep); if (ep_handle < 0) { return -1; } struct usb_raw_ep_io_data io_data; io_data.inner.ep = ep_handle; io_data.inner.flags = 0; if (len > sizeof(io_data.data)) len = sizeof(io_data.data); io_data.inner.length = len; memcpy(&io_data.data[0], data, len); int rv = usb_raw_ep_write(fd, (struct usb_raw_ep_io*)&io_data); if (rv < 0) { return rv; } sleep_ms(200); return 0; } static void mount_cgroups(const char* dir, const char** controllers, int count) { if (mkdir(dir, 0777)) { return; } char enabled[128] = {0}; int i = 0; for (; i < count; i++) { if (mount("none", dir, "cgroup", 0, controllers[i])) { continue; } umount(dir); strcat(enabled, ","); strcat(enabled, controllers[i]); } if (enabled[0] == 0) { if (rmdir(dir) && errno != EBUSY) exit(1); return; } if (mount("none", dir, "cgroup", 0, enabled + 1)) { if (rmdir(dir) && errno != EBUSY) exit(1); } if (chmod(dir, 0777)) { } } static void mount_cgroups2(const char** controllers, int count) { if (mkdir("/syzcgroup/unified", 0777)) { return; } if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) { if (rmdir("/syzcgroup/unified") && errno != EBUSY) exit(1); return; } if (chmod("/syzcgroup/unified", 0777)) { } int control = open("/syzcgroup/unified/cgroup.subtree_control", O_WRONLY); if (control == -1) return; int i; for (i = 0; i < count; i++) if (write(control, controllers[i], strlen(controllers[i])) < 0) { } close(control); } static void setup_cgroups() { const char* unified_controllers[] = {"+cpu", "+io", "+pids"}; const char* net_controllers[] = {"net", "net_prio", "devices", "blkio", "freezer"}; const char* cpu_controllers[] = {"cpuset", "cpuacct", "hugetlb", "rlimit", "memory"}; if (mkdir("/syzcgroup", 0777)) { return; } mount_cgroups2(unified_controllers, sizeof(unified_controllers) / sizeof(unified_controllers[0])); mount_cgroups("/syzcgroup/net", net_controllers, sizeof(net_controllers) / sizeof(net_controllers[0])); mount_cgroups("/syzcgroup/cpu", cpu_controllers, sizeof(cpu_controllers) / sizeof(cpu_controllers[0])); write_file("/syzcgroup/cpu/cgroup.clone_children", "1"); write_file("/syzcgroup/cpu/cpuset.memory_pressure_enabled", "1"); } static void setup_cgroups_loop() { int pid = getpid(); char file[128]; char cgroupdir[64]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/pids.max", cgroupdir); write_file(file, "32"); snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); snprintf(file, sizeof(file), "%s/memory.soft_limit_in_bytes", cgroupdir); write_file(file, "%d", 299 << 20); snprintf(file, sizeof(file), "%s/memory.limit_in_bytes", cgroupdir); write_file(file, "%d", 300 << 20); snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); } static void setup_cgroups_test() { char cgroupdir[64]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (symlink(cgroupdir, "./cgroup")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.cpu")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.net")) { } } static void initialize_cgroups() { if (mkdir("./syz-tmp/newroot/syzcgroup", 0700)) exit(1); if (mkdir("./syz-tmp/newroot/syzcgroup/unified", 0700)) exit(1); if (mkdir("./syz-tmp/newroot/syzcgroup/cpu", 0700)) exit(1); if (mkdir("./syz-tmp/newroot/syzcgroup/net", 0700)) exit(1); unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE; if (mount("/syzcgroup/unified", "./syz-tmp/newroot/syzcgroup/unified", NULL, bind_mount_flags, NULL)) { } if (mount("/syzcgroup/cpu", "./syz-tmp/newroot/syzcgroup/cpu", NULL, bind_mount_flags, NULL)) { } if (mount("/syzcgroup/net", "./syz-tmp/newroot/syzcgroup/net", NULL, bind_mount_flags, NULL)) { } } static void setup_binderfs(); static void setup_fusectl(); static void sandbox_common_mount_tmpfs(void) { write_file("/proc/sys/fs/mount-max", "100000"); if (mkdir("./syz-tmp", 0777)) exit(1); if (mount("", "./syz-tmp", "tmpfs", 0, NULL)) exit(1); if (mkdir("./syz-tmp/newroot", 0777)) exit(1); if (mkdir("./syz-tmp/newroot/dev", 0700)) exit(1); unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE; if (mount("/dev", "./syz-tmp/newroot/dev", NULL, bind_mount_flags, NULL)) exit(1); if (mkdir("./syz-tmp/newroot/proc", 0700)) exit(1); if (mount("syz-proc", "./syz-tmp/newroot/proc", "proc", 0, NULL)) exit(1); if (mkdir("./syz-tmp/newroot/selinux", 0700)) exit(1); const char* selinux_path = "./syz-tmp/newroot/selinux"; if (mount("/selinux", selinux_path, NULL, bind_mount_flags, NULL)) { if (errno != ENOENT) exit(1); if (mount("/sys/fs/selinux", selinux_path, NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); } if (mkdir("./syz-tmp/newroot/sys", 0700)) exit(1); if (mount("/sys", "./syz-tmp/newroot/sys", 0, bind_mount_flags, NULL)) exit(1); if (mount("/sys/kernel/debug", "./syz-tmp/newroot/sys/kernel/debug", NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); if (mount("/sys/fs/smackfs", "./syz-tmp/newroot/sys/fs/smackfs", NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); if (mount("/proc/sys/fs/binfmt_misc", "./syz-tmp/newroot/proc/sys/fs/binfmt_misc", NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); initialize_cgroups(); if (mkdir("./syz-tmp/pivot", 0777)) exit(1); if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) { if (chdir("./syz-tmp")) exit(1); } else { if (chdir("/")) exit(1); if (umount2("./pivot", MNT_DETACH)) exit(1); } if (chroot("./newroot")) exit(1); if (chdir("/")) exit(1); setup_binderfs(); setup_fusectl(); } static void setup_fusectl() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } } static void setup_binderfs() { if (mkdir("/dev/binderfs", 0777)) { } if (mount("binder", "/dev/binderfs", "binder", 0, NULL)) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); if (getppid() == 1) exit(1); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } static int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static void drop_caps(void) { struct __user_cap_header_struct cap_hdr = {}; struct __user_cap_data_struct cap_data[2] = {}; cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; cap_hdr.pid = getpid(); if (syscall(SYS_capget, &cap_hdr, &cap_data)) exit(1); const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE); cap_data[0].effective &= ~drop; cap_data[0].permitted &= ~drop; cap_data[0].inheritable &= ~drop; if (syscall(SYS_capset, &cap_hdr, &cap_data)) exit(1); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); sandbox_common(); drop_caps(); initialize_netdevices_init(); if (unshare(CLONE_NEWNET)) { } write_file("/proc/sys/net/ipv4/ping_group_range", "0 65535"); initialize_tun(); initialize_netdevices(); sandbox_common_mount_tmpfs(); loop(); exit(1); } #define FS_IOC_SETFLAGS _IOW('f', 2, long) static void remove_dir(const char* dir) { int iter = 0; DIR* dp = 0; const int umount_flags = MNT_FORCE | UMOUNT_NOFOLLOW; retry: while (umount2(dir, umount_flags) == 0) { } dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exit(1); } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); while (umount2(filename, umount_flags) == 0) { } struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EPERM) { int fd = open(filename, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exit(1); if (umount2(filename, umount_flags)) exit(1); } } closedir(dp); for (int i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EPERM) { int fd = open(dir, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, umount_flags)) exit(1); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exit(1); } } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); for (int i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } static void setup_loop() { setup_cgroups_loop(); } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setup_cgroups_test(); write_file("/proc/self/oom_score_adj", "1000"); flush_tun(); if (symlink("/dev/binderfs", "./binderfs")) { } } static void close_fds() { for (int fd = 3; fd < MAX_FDS; fd++) close(fd); } static const char* setup_binfmt_misc() { if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0) && errno != EBUSY) { return NULL; } if (!write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:") || !write_file("/proc/sys/fs/binfmt_misc/register", ":syz1:M:1:\x02::./file0:POC")) return "write(/proc/sys/fs/binfmt_misc/register) failed"; return NULL; } static const char* setup_usb() { if (chmod("/dev/raw-gadget", 0666)) return "failed to chmod /dev/raw-gadget"; return NULL; } static void setup_sysctl() { int cad_pid = fork(); if (cad_pid < 0) exit(1); if (cad_pid == 0) { for (;;) sleep(100); } char tmppid[32]; snprintf(tmppid, sizeof(tmppid), "%d", cad_pid); struct { const char* name; const char* data; } files[] = { {"/proc/sys/kernel/hung_task_check_interval_secs", "20"}, {"/proc/sys/net/core/bpf_jit_kallsyms", "1"}, {"/proc/sys/net/core/bpf_jit_harden", "0"}, {"/proc/sys/kernel/kptr_restrict", "0"}, {"/proc/sys/kernel/softlockup_all_cpu_backtrace", "1"}, {"/proc/sys/fs/mount-max", "100"}, {"/proc/sys/vm/oom_dump_tasks", "0"}, {"/proc/sys/debug/exception-trace", "0"}, {"/proc/sys/kernel/printk", "7 4 1 3"}, {"/proc/sys/kernel/keys/gc_delay", "1"}, {"/proc/sys/vm/oom_kill_allocating_task", "1"}, {"/proc/sys/kernel/ctrl-alt-del", "0"}, {"/proc/sys/kernel/cad_pid", tmppid}, }; for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++) { if (!write_file(files[i].name, files[i].data)) { } } kill(cad_pid, SIGKILL); while (waitpid(cad_pid, NULL, 0) != cad_pid) ; } #define SWAP_FILE "./swap-file" #define SWAP_FILE_SIZE (128 * 1000 * 1000) static const char* setup_swap() { swapoff(SWAP_FILE); unlink(SWAP_FILE); int fd = open(SWAP_FILE, O_CREAT | O_WRONLY | O_CLOEXEC, 0600); if (fd == -1) return "swap file open failed"; fallocate(fd, FALLOC_FL_ZERO_RANGE, 0, SWAP_FILE_SIZE); close(fd); char cmdline[64]; sprintf(cmdline, "mkswap %s", SWAP_FILE); if (runcmdline(cmdline)) return "mkswap failed"; if (swapon(SWAP_FILE, SWAP_FLAG_PREFER) == 1) return "swapon failed"; return NULL; } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { setup_loop(); int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); setup_test(); execute_one(); close_fds(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { sleep_ms(10); if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; if (current_time_ms() - start < 15000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[1] = {0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } NONFAILING(memcpy( (void*)0x20000000, "\x12\x01\x00\x00\x00\x00\x00\x40\x26\x09\x33\x33\x40\x00\x00\x00\x00\x01" "\x09\x02\x24\x00\x01\x00\x00\x00\x00\x09\x04\x00\x00\x01\x03\x01\x00\x00" "\x09\x21\x00\x00\x00\x01\x22\x01\x00\x09\x05\x81\x03\x08", 50)); res = -1; NONFAILING(res = syz_usb_connect(/*speed=*/0, /*dev_len=*/0x36, /*dev=*/0x20000000, /*conn_descs=*/0)); if (res != -1) r[0] = res; NONFAILING(syz_usb_control_io(/*fd=*/r[0], /*descs=*/0, /*resps=*/0)); NONFAILING(*(uint16_t*)0x20000880 = 0); NONFAILING(*(uint16_t*)0x20000882 = 0x4e00); NONFAILING(*(uint16_t*)0x20000884 = 0xc1); NONFAILING(*(uint16_t*)0x20000886 = 0x4e00); NONFAILING(memcpy( (void*)0x20000888, "\xa7\x6c\xcb\x9e\xff\x46\x94\x98\x3d\xf6\x11\xac\x03\xc6\xc2\x3d\xb1\xe3" "\xb8\xa3\x09\x04\xe4\x11\x01\xcd\xd2\x1d\x87\x99\x82\x69\x64\xaa\x88\x86" "\xe9\x36\xf6\x6f\x48\xc2\x39\x37\x91\x40\x22\x4e\xad\x55\x29\xbe\x60\xe4" "\xe1\x03\xee\x38\xd7\x53\x04\x3d\xae\x6f\xf2\xa1\x08\x34\x31\x38\x51\x1e" "\x17\x8a\x6f\xbf\xe3\xbe\x80\x2b\xaf\x1d\x00\x7c\xa1\x75\x28\xd3\x26\x30" "\x1c\x1a\x60\xaf\x74\xa5\xe3\x17\x28\x24\x52\x62\xab\x41\x92\xb1\xd4\x75" "\x7e\xc2\xfb\x54\x91\x5f\x77\x91\xbf\xfa\x73\x4d\xae\xea\x15\x8a\xcb\x4f" "\xb0\x3e\x46\xee\xa1\x93\xd2\xb4\x6d\x98\x75\x6c\x84\xcc\x0e\x39\x18\x61" "\x8c\x11\x49\x1b\x37\xf7\x2d\x16\x2d\x85\x3d\x34\x5d\x61\x88\x71\x42\x4f" "\xfc\x80\x0e\xda\xb5\x55\xb0\xbc\x60\x61\x48\xfb\x32\x9c\x5d\x90\x5b\x80" "\xdf\x39\x04\xba\x01\xe9\x0a\xc4\x63\xf9\xc3\xd9\x10", 193)); NONFAILING(*(uint16_t*)0x2000094c = 0); NONFAILING(*(uint16_t*)0x2000094e = 0x4e00); NONFAILING(*(uint16_t*)0x20000950 = 0xa1); NONFAILING(*(uint16_t*)0x20000952 = 0x4e00); NONFAILING(memcpy( (void*)0x20000954, "\x75\xfb\x4c\x30\x8d\x67\x0b\xfe\xd5\xd2\x33\xee\xd8\xd6\xe1\xb2\x2b\x9d" "\xe2\x75\xbf\x97\xe7\x45\xcb\xc7\x50\xd4\x42\x20\x2b\x41\x38\xe8\xc1\x9e" "\x60\x98\xab\xa4\x1a\x8e\xc2\x08\x71\x8e\x2d\xf1\x66\x76\x30\x22\xfd\x4c" "\x49\x30\xa5\x76\x00\xf9\x30\xbe\xc7\x12\xfa\xef\xbb\x5a\x08\x3f\xf9\x2b" "\xcf\xb0\x39\xc9\xc1\x64\x45\xf9\xd9\x1d\x9c\x23\xef\x84\x49\xc3\x70\x1b" "\xcc\x93\xd7\xa2\xac\x5e\x58\xc8\x36\x42\x51\xef\x80\xa1\xdc\x9c\xc6\xb1" "\x22\x88\x1c\x8e\xa6\x7c\x52\xa4\x4e\x4f\x68\x61\xd9\x20\xf6\xf4\xa1\x66" "\x0d\x04\xb1\xe3\xb1\xe7\x66\x83\x75\x26\x02\x04\x67\xff\x3c\x53\x28\xcb" "\xe2\x7e\x9c\x25\xe7\xa5\x07\x78\xe7\xfb\x9b\x27\xc9\xbe\x7b\xd9\x1a", 161)); NONFAILING(*(uint16_t*)0x200009f8 = 0); NONFAILING(*(uint16_t*)0x200009fa = 0x4e00); NONFAILING(*(uint16_t*)0x200009fc = 0); NONFAILING(*(uint16_t*)0x200009fe = 0x4e00); NONFAILING(*(uint16_t*)0x20000a00 = 0xf5c); NONFAILING(*(uint16_t*)0x20000a02 = 0x4e00); NONFAILING(memcpy( (void*)0x20000a04, "\x55\xd4\x5c\x41\x80\x2a\xd3\x0a\x9d\xe5\x61\xb0\x2d\xbc\xb4\x1e\xc1\x95" "\xc3\x4e\x66\x86\x35\xc5\x05\x7d\x66\x9c\xdf\xef\xc7\x73\x4c\xba\x39\x28" "\x5d\x0e\x90\x80\x9f\x58\x04\x75\x8f\x00\x5a\x19\x53\xd5\x79\x46\x21\xd5" "\x19\xf4\x64\x9c\x10\xae\xf7\xbf\xac\x1c\xc2\xdd\xa2\x9b\xb8\xbb\xdb\xc5" "\x85\xd5\x6c\x77\xab\x68\x96\xf6\x44\x78\x2e\x22\x97\xdc\x16\x08\x48\xbb" "\xfc\xe7\xcb\xaf\xc5\xcb\x7a\x35\xbf\x16\x53\x12\x3d\x4f\xfc\x08\xdd\xeb" "\x4c\xf4\x64\xab\x17\xf1\x3b\xb6\xcf\x01\xb5\x84\xcb\x4a\x8f\x64\x21\x99" "\x3d\x3d\x6d\x39\x7f\x0e\x4c\xc3\xe5\xa4\x98\x17\x71\x54\xe2\xfa\xa0\x96" "\xfb\x80\x20\x64\xae\x9c\x05\xec\x7b\x3a\x85\x00\x84\x51\x25\x14\xb4\x22" "\xf9\x11\xcd\x1f\x96\x4f\x70\x74\x99\x5a\x5d\x33\x2a\xf9\xe4\xfa\xbd\x6e" "\x0b\xfb\x00\x26\x2b\x4c\x5d\x42\xe5\xea\xa5\xc2\xd0\xa5\xbf\x35\xba\x4c" "\x76\xf2\xb0\x52\xa9\xae\x27\xfb\xc5\x0f\x4e\xef\xd2\xb8\xd9\xd7\xc8\xa3" "\x66\xa4\xe5\x82\x4a\x38\xd2\x20\xc4\x78\xba\x77\x83\x1f\x8e\xd3\x35\x5c" "\x10\xc2\xf2\xc6\xbe\x00\x75\xe4\xfb\xf2\x25\x21\xe6\x9f\x68\x82\x90\xff" "\x6a\x8c\x17\x19\xf1\x75\x4a\x68\x76\xa2\x17\x8a\x78\xcf\x8a\xa9\x3a\x57" "\x62\xa9\xac\x07\xf7\xe4\x5d\x0f\xd1\x4f\x5c\x42\x33\xb1\x18\x8e\x95\xd5" "\x14\xb6\x36\x2a\x5b\x6b\x38\x18\x76\xed\xe3\xea\x12\x06\xf1\xcb\xda\x4c" "\xf7\x8d\x50\x28\xf1\x0f\x1c\xc4\x3f\xa9\x7c\x08\xe7\x56\xb5\x7a\x9e\x37" "\xc2\xfa\xef\x46\xcf\x2c\xa6\xfd\x32\xd4\x3c\x83\xc1\x9f\x6f\xa8\x30\xac" "\xeb\x0b\x02\x86\xf1\xdd\xef\x59\x21\x03\x4c\xcb\x0b\xfa\x97\x48\x70\xb3" "\x67\x74\x7d\xe0\x9a\x6a\x88\x80\x7d\x85\x82\x2d\x70\xa1\xd2\x04\xf9\x0e" "\x9e\x26\xfb\xf3\x00\x60\x42\x87\x8a\x0c\x43\x66\x5e\x78\xcb\xb6\x77\x54" "\x02\xb2\x8a\xdb\x39\x75\x12\xe4\x9b\xb0\x9d\x80\x49\xf0\x63\x4a\x2c\x1b" "\x59\x31\x26\x6b\x0d\xd6\xa9\xf6\xb8\x45\x99\x48\xa5\x51\x1d\x49\xc4\xd4" "\x29\xae\xd9\x2f\x40\x16\x13\x0c\xc8\x5e\x1a\x4f\x95\x8f\x62\x1d\xe6\x78" "\x98\x0b\xea\xd0\xc5\x54\xe8\x60\x24\xc8\x1a\x5e\xe1\x46\xff\x9e\x3c\xfc" "\xa9\x77\xed\x26\x6c\x31\xeb\x7d\x94\x81\x8a\xf5\x28\xdc\x47\xf4\x86\x4c" "\xb7\xd0\xad\x69\x7b\x4f\x68\x0a\xd5\xfc\x63\xd3\xac\x03\x98\xd8\x43\xd3" "\xde\x28\xaf\x45\x17\x19\x77\xca\xe5\x0d\x0f\x45\xc7\xad\x6a\xbc\x3d\x13" "\x80\x35\xd9\x64\x0c\xe7\x96\x06\x04\x54\xa7\x80\x90\xcb\xd2\x8e\x4b\xe1" "\x53\xbc\xe2\x49\x0a\xd6\xb2\xdd\x46\x89\x46\x52\x37\x92\x43\x3c\xdd\xc2" "\x53\x14\x5e\xcc\x72\x43\xbe\x3f\xe6\x39\x20\xf9\xe6\x7e\xd9\x61\x41\x0d" "\x05\x68\x2b\x1e\x9a\xd3\xf5\x4f\xb0\x98\xe5\x08\x50\x7a\x2d\xc9\xc8\x7b" "\x44\xe2\xf5\x84\x3c\x7c\x7f\x89\xe6\x5d\x84\x40\xba\x91\x58\x1e\xe0\xf0" "\xd3\x03\xb6\x88\xf0\x63\x36\x1e\x99\xa4\x77\xe3\x98\x0f\x19\x72\x81\xcc" "\x0e\x75\x30\xcd\x11\x5c\xd0\x61\xdd\xd5\x3b\xb7\xad\xe0\x3b\x00\x21\x72" "\x5c\xfd\x83\x2d\x26\x56\x0d\x53\x35\xbc\xce\xab\xe1\x5d\x5a\xc3\x14\xdb" "\x65\x6f\x13\xaf\xce\x4c\xb8\xdb\x11\xca\xa0\x77\x75\x22\x55\xb6\x67\x0f" "\xb3\xc2\x12\x9d\xa9\x54\x8e\xa4\xb3\xc0\xff\x00\x01\x96\x30\x71\x00\xe3" "\x15\x3f\x09\xe8\xc5\x2c\x42\x7e\x65\x10\x15\xa5\x4a\x66\x44\xfa\x3b\x7a" "\x0e\x22\x2f\x68\x0c\xa0\x55\x91\x9e\x78\xc4\x45\x61\x57\x9b\x4f\x7f\x7e" "\xac\x88\xbf\x8f\x1c\x86\x3d\xde\x86\xce\x77\x34\x17\x86\x75\x48\x41\xf5" "\x91\x8b\x38\x32\x0b\x32\x6a\x00\xa1\x8d\x1e\x8a\x1e\x5c\xe5\x79\x23\x2f" "\x28\xb4\x47\x78\x82\x0d\x79\x42\x13\x5c\xc5\xa3\x7b\x1b\x40\xc7\xd3\x96" "\x09\x9a\x55\x65\x20\x7f\x26\xdc\x8c\x55\x3b\xbf\xa1\x1d\x72\x40\x1d\x7c" "\x3d\x73\xdc\x18\xcb\x31\x39\xdd\x8e\x8b\xb4\x0f\x2c\xad\xf7\x1c\x14\x8e" "\x75\xb0\xe3\x18\x8c\x19\x44\xf6\x63\x4d\x12\x1c\x96\x30\xbb\xd8\x44\x97" "\x62\xb6\xf2\x00\x5a\x50\x3f\x80\x72\x5d\xd2\x40\x97\x4f\x94\x67\x94\x1e" "\x3f\x12\xe4\xbb\x84\x0c\x0e\xb4\x4b\x09\x32\x21\xb4\xe6\xe9\x66\x98\x4f" "\x02\x3d\x00\xa4\x53\x13\xca\x24\x14\x4f\xad\x2f\x79\x8c\x99\xcf\x39\x75" "\xde\xb9\xe5\x84\x62\x14\xb8\x23\x63\xc1\x2c\xb8\x21\x32\x45\xfe\x09\x2d" "\x10\x3e\x37\x9c\xa7\x00\x36\x0e\xac\xc2\xce\xd3\xf3\x90\xa6\xd1\xa3\x2a" "\xef\xbb\xd9\x98\x44\x4f\x33\x8f\xeb\x28\x83\x42\x77\x8b\x82\x77\xa9\x47" "\x93\x56\x69\xd4\xc6\x5e\x69\xb5\x4f\x25\xed\x23\x73\x66\x75\x7e\x76\xca" "\xdb\x89\x64\x92\xc4\x8b\x16\x36\xce\x14\x83\x5e\x1f\xb3\xcb\x46\x5a\x44" "\x5a\x7e\x02\x99\x2e\x73\xce\x6b\x18\x20\x47\x16\xcc\xc7\xf7\xec\x33\xd5" "\xc5\x91\x63\x48\x38\x5d\x0f\x66\x76\xa1\x29\xb2\xe9\xd1\x66\x3e\xf1\x83" "\x1f\xea\xec\x49\xd1\xd2\x7b\xb1\x84\x88\x4a\x65\x61\x47\x39\xf7\x8b\x25" "\x90\x37\x3c\xf0\x13\x61\xc8\x18\x9c\xdc\x60\xfa\xd4\x5e\xaf\x65\xec\x06" "\x1b\xbb\xf6\x2d\x62\x70\xc4\x02\xc5\x25\x7a\xc8\x52\xe5\x37\x8e\x44\xdf" "\x72\x08\xf9\xd2\xf4\x67\x0e\xf4\x0d\x80\xd1\x15\xd8\x6b\xe0\xda\x17\x72" "\x6c\x7d\x98\x4a\xac\x46\xec\x39\x1d\xdd\xce\xa7\x20\xf1\x44\x45\x76\xd3" "\xf2\xbb\x62\x47\xc4\x01\x46\x22\xfe\xa9\x3d\xb0\x71\x52\x75\x71\xb3\xa0" "\x4f\x2a\x25\x44\x67\x8b\x3c\x14\xd7\xe1\x43\x97\xea\x86\xdd\x97\x2f\xf4" "\x3c\x4b\x2c\x49\xc7\x46\xf7\x8b\xa5\x0e\x60\xf2\x12\x01\x43\xd7\x59\x0c" "\x12\xf8\xb4\xc4\xf3\x06\x7d\x48\x92\x91\x85\xa5\xcf\x32\x20\x4d\x50\xdf" "\xd2\xfe\x7c\xc0\xd7\x1c\xa4\xf8\x7a\x64\xd7\x75\x3d\x12\xb5\xe9\x14\xe2" "\x4e\x22\xb3\xd6\x18\x5d\xd8\xfe\xe1\x8b\xae\xcc\x18\x56\x46\x2e\x14\x73" "\xdb\xdf\x66\x2c\xfa\xe0\xb8\x5e\x6e\x83\x27\xd0\xf2\xfb\x98\xa4\x34\x86" "\xdb\x46\x2c\xb9\x5e\x9f\x4a\x72\x6b\x52\x37\xf0\x87\xdf\x5c\xa3\xe1\xf1" "\x9c\x67\x98\x8f\x3a\xd0\x45\x0f\xd0\x29\x2e\x2d\xfc\xac\x85\xdf\x76\xc6" "\x38\xeb\xb0\xd6\x5c\x03\xc0\xae\x80\x65\x1c\xde\xb1\xdc\x75\xfb\x6f\x0f" "\x93\x7f\x27\xd2\xab\xeb\x4a\xd2\x68\xab\x23\x85\x6c\x5f\xa4\x6b\x30\xff" "\x23\xce\xa4\xf5\x48\x51\x95\x5d\xc8\x0c\x12\xd7\x56\x6e\x1c\x03\xc7\xbb" "\x06\x41\x97\xba\x33\xba\x73\xc4\xc8\x60\x51\x45\xa4\x27\x51\x12\x74\x53" "\x15\x82\xbe\xf8\xd6\x71\x06\x0c\xed\x84\x3c\x4f\x76\x62\xa0\x11\x9e\xeb" "\x0d\x82\x72\x0d\x0b\xb7\xd5\xca\xa2\xd1\xb2\x40\x0c\xf6\x5b\x67\x69\xc7" "\x52\xf0\x15\x06\x17\x28\xeb\x3f\x1d\x87\xea\xd1\x40\x46\x4a\xc6\xb8\x96" "\xf1\xda\x7d\xdb\x80\x60\x04\x09\xa9\xaf\x55\xf5\x5d\x80\x0a\xc7\x9f\xa9" "\xc8\x69\xd1\xcb\xd7\xe0\x58\xf4\xf4\xee\xa7\xba\x9c\xd5\xa2\xf5\x1a\xd0" "\xf1\x9d\x02\x75\x45\xc7\xe0\x89\x36\x39\x21\xd6\x29\xe8\x5c\xc1\x33\x7b" "\x9e\x8f\x60\x44\x5c\x4f\x00\x6f\x6b\x39\x60\x0e\x83\x17\x88\x21\xce\x3a" "\xf6\x22\x97\x99\x2c\xe6\xf8\xcd\x43\xc1\x64\x7a\xdb\xb0\x0a\x18\xfb\x99" "\x41\xdf\x97\xf0\x2e\x14\x5b\x74\x6d\x51\x2d\xa7\xf9\x05\x89\xd7\x80\xfb" "\xb9\xec\xaa\x3f\x08\x59\x71\x80\xd1\x8f\x71\x74\x7f\x47\x2e\xbe\x7b\x04" "\xa3\x17\x00\x49\x29\x66\x63\x2d\x60\xeb\xe1\x73\x54\x1e\xe8\xd5\x45\xc9" "\x2f\xaa\x56\x24\x13\x33\x19\xd3\x8f\x43\x26\x29\xad\xaf\x34\x1a\xb1\x3b" "\x59\xd9\xc4\xe2\xa5\x15\xf5\x1f\x51\xc0\x51\xdf\x76\xfe\x0e\xd0\xf1\x69" "\xf6\x47\x35\xf2\xe3\x27\x54\x67\x04\x61\xa4\x22\x51\x6c\x55\x58\x08\x4a" "\x77\x96\x26\x1e\x62\xde\xd0\xff\x81\x6b\xb0\xfb\x35\x16\xd6\x08\x70\x8a" "\x70\x84\xb9\x8b\x23\xe7\xab\xc0\x43\x6d\x4a\xde\x07\x5b\x39\x63\xac\x72" "\xe3\x19\x9d\x91\x0a\xbc\x73\x6c\xfe\x0e\xc1\x2e\xf7\x42\x77\x49\xe6\x6e" "\xc9\x32\xdf\xef\xcc\x75\x00\xec\x86\x9a\xa5\x09\x8d\x05\x8d\x36\x74\xad" "\x36\x7c\x98\xb6\x00\xf7\xa4\xd3\x46\x3b\x98\xed\x8e\xc8\xfe\x57\x52\xfe" "\x2e\xad\x9d\xd6\xe9\xa3\xe0\xb0\x4c\x38\xce\x0b\x61\x13\x37\x34\x20\x4e" "\x3b\x06\x09\x0e\x7b\xd0\x1c\x65\xb9\x25\xce\xad\x0c\x13\x92\x8b\x2f\x20" "\xc3\x79\x9d\x9c\x39\x9e\xf4\xcd\xa1\x76\xe0\x1f\xda\xb0\x39\xa8\x5b\xf0" "\xad\x0a\x4e\xce\x03\xda\x31\x17\x6c\xd5\x65\x73\xb5\xa1\xc6\x07\xf9\xd1" "\x5f\xf3\x25\xe6\xed\xf8\xe2\x41\x15\x9f\x4c\xc6\x5e\x40\x9f\xae\xca\x7c" "\xdd\xfe\x44\x4b\x7e\x30\xe4\xd7\x8b\x92\xce\x21\x6f\x43\x73\xfc\x07\x06" "\xda\x20\xfd\x1e\x7b\xd7\xbf\x67\x79\x19\x17\x74\xce\x2f\x96\x07\xf4\x01" "\x33\x1d\xc7\x11\x35\x04\xf1\x2c\x8a\x5f\x01\xa4\xb7\x01\x09\x13\xdc\x2f" "\xfb\x69\x9a\xc7\x5c\xec\xb2\x97\x10\x8e\xc3\x85\x47\x2d\x25\xa3\xb8\x6d" "\x6f\x3c\xdc\x62\x99\x6c\xe2\x6a\x07\xb1\x0b\xe6\x53\x40\x89\xe9\xfb\x8f" "\x28\x4d\x5a\x47\xc0\x54\x4b\x5f\x8b\x55\xdf\xf8\x32\xe9\xe6\xe5\xed\x32" "\x0b\x31\x38\xf0\xe9\xd5\x69\xd5\xc3\x20\xbb\xb2\x7c\xdd\x5e\x2f\x2e\xe5" "\x4e\xf6\x45\x4c\xc5\xc0\x17\x76\x1b\x18\xd8\x2f\x0d\xe5\xfc\x9b\x38\xc0" "\x9a\x7c\xcc\x91\x3e\xf1\xc7\x22\xe4\x1c\xf0\x4e\x56\xab\x4b\x24\xc0\xc1" "\xf1\xe8\x72\xfe\xdc\xe9\xfb\xa5\x1f\xf5\xe5\xba\x8f\xad\x6f\x4c\xc0\xd5" "\xc9\x59\x0a\x1b\x31\xd9\x25\x60\x05\x81\xc1\xea\x24\xdb\x8d\xd4\x21\x42" "\xeb\xf5\x18\xde\xd7\xbc\x4e\x87\xc7\x78\xcc\x23\xec\x21\x9e\x22\x19\xa9" "\xb3\x1b\x5f\xe0\x00\x87\x6e\x7a\xe4\x3f\x93\x5a\x0c\xd1\xfa\x57\x8c\xba" "\x09\x5f\xf9\x56\xba\xa4\xc3\x61\x5a\x3b\xde\x0b\x7e\x2d\xdc\x87\x6d\x9d" "\xe8\x52\xc5\x53\xe1\xcc\xa0\x8a\xce\x85\x36\x2f\x6f\x3d\x63\x60\xb6\xe5" "\x75\xaa\x06\x14\x37\x65\x22\xa7\x18\x40\x99\xbf\x0d\x6c\xb1\xd0\x88\xcf" "\x4b\x08\x75\x46\x59\x5d\x2d\xfe\xef\x48\x89\x48\x53\x0d\x97\x65\xc9\xc2" "\xee\xed\xce\x77\xde\x2c\x8c\x10\xb5\xfb\x45\x86\xf9\x42\x83\x4f\xf2\x38" "\x28\x38\xa3\x68\xbb\xc8\x6f\x56\xf1\x3c\x6e\x90\x8a\x7c\x72\xf1\x6c\x2e" "\xfc\x2a\xee\x41\xcb\x4e\xd7\x18\xb4\x11\x29\x83\xb5\xaf\xfd\x53\x8a\xb3" "\x50\x5e\xbd\x89\x39\x3b\xbb\x14\x73\x34\x35\xd0\x1f\x0f\xa2\x88\x0e\xfa" "\x19\x06\x06\x9b\x75\x5e\x1a\x97\x85\x9e\xef\x74\x5c\x14\x8b\x41\xbf\x04" "\x44\x24\x04\xa0\xb7\x97\x2b\x3c\xbf\x25\x47\x0d\x82\xce\x76\x42\xd7\xdf" "\xc3\x8d\x27\x9f\xdd\x70\xb3\x8f\x5d\x1d\x7b\xed\x66\x67\xe4\x7c\xca\xad" "\x03\x91\xc1\x73\x54\x23\xf9\x11\x00\xd2\xad\x90\x7f\x56\x3e\x49\x38\x93" "\x34\x6b\x95\x0c\xc6\x54\xfa\x39\x35\x5f\xc3\xb2\xf4\xa4\x04\xc1\x6d\x98" "\x90\x94\xaf\xea\x03\xda\x0c\xce\xff\xc6\xd0\xae\xe7\x96\x55\xcb\x10\x6a" "\x98\x1a\x96\x3a\xb5\x04\xe9\x8d\x8d\xfc\xb0\x59\xed\xca\xd6\xa5\x88\xfb" "\x4f\x30\x8d\x4f\x9b\x91\x43\x49\x6d\xc2\xb8\xac\x3a\x0c\xb9\x1b\x04\xc6" "\x2a\x4e\x4d\x35\x8a\x93\x5f\x42\xe0\xd8\xbf\xef\xd3\x72\x35\x79\x4b\xde" "\x31\xd2\x4a\x2f\xd0\xd4\xc2\x43\x79\xb4\x32\x48\x60\x5c\x38\xab\x09\xeb" "\x6e\x7d\x9c\xed\x7e\x56\x66\x33\x0d\x67\xa7\x4b\x38\x36\x53\xa2\xdb\x9b" "\x3f\xfa\xd9\x5a\xc2\x33\xeb\x94\xce\x52\x18\xae\xcc\xa4\x79\x1e\x29\x71" "\x47\xd4\x79\x3d\xd7\xef\x2e\x19\x08\x0f\x04\xbc\xb9\x4c\x8e\xce\xc8\xf0" "\x22\x50\x05\x88\xbc\xbc\x62\x3b\x92\x4a\x14\xbb\x17\x03\xa3\xb2\xcd\x79" "\x2b\x49\x1a\xca\x78\xd4\xfe\x07\x6a\x51\x1c\x68\x35\x68\xee\xe6\x21\xd8" "\x8d\xff\x27\xa4\x66\x07\x3f\x2c\x60\x23\xab\x61\xce\xeb\xde\xf6\xdc\xe8" "\x2d\x72\x9b\x54\xb3\xc8\x26\xfe\xc4\x50\xdf\x77\x93\xb7\x4a\x5f\x31\x0f" "\xaf\xba\x49\xcb\x3e\x32\x85\x30\xb1\x3c\x79\x59\xad\xa3\x3a\xc1\xae\xa5" "\xd1\x15\x0d\x8f\xe6\xa0\x6c\x86\x0c\xe0\xf7\xed\x05\xb9\xc2\xb8\x46\x28" "\x1f\xa2\x68\xf7\x8c\x50\xbe\x42\x32\x58\x68\x64\x44\x12\xa9\x39\xf0\xca" "\x81\x84\x0f\xac\xad\x87\x1a\x11\xc0\x08\x69\x37\x86\x6b\x2b\xb3\x27\x93" "\xbc\xd7\x8d\x7d\x36\x86\x88\x0b\xb0\x35\xb2\x4e\xbd\xa2\x41\x5f\xc9\xb2" "\x8f\x84\xa0\x6e\x26\x73\x09\x2b\x3e\xb3\x96\x2d\x97\x82\x05\x45\x28\xeb" "\xf5\x2a\x26\x30\xd0\x0f\x1f\xaf\x6f\xed\x16\x01\x1b\xab\xe5\xec\x50\x0c" "\x36\x9a\x66\xf9\x4b\x17\x52\xbc\xf6\x60\x65\x93\x5d\xe6\x63\xbf\x3d\x39" "\x33\x77\x65\x52\xbd\x30\x47\x8b\x27\x60\x8b\x9a\x21\xb0\xab\x31\x8c\x0d" "\x47\x9f\xfc\x99\x36\xb8\x66\x41\x61\xc7\x1b\x3b\xef\x01\x01\x92\xf8\x5b" "\xeb\xca\xfc\x16\x5a\xaf\x6d\x47\x2d\x92\x79\xbe\xf4\x7a\x67\xbf\x60\xc6" "\x33\xea\x98\x3a\x90\x9f\x47\xca\x28\x14\x0b\x1b\x19\x5f\xc3\x8c\x4a\xfd" "\x10\xfb\x78\x1a\x91\xa4\x12\xcb\xe1\x95\x6c\x34\x14\x0a\x55\x04\xdf\xcc" "\x13\xad\xe9\x42\xfa\x6c\x2a\x60\x4a\xc3\x7c\x52\x5b\xd3\x99\x71\x53\x99" "\xbe\x4b\x3e\x1f\xaf\x0a\xe5\x3d\x45\x98\xf0\x30\x7e\xdb\xa1\x82\xf8\x16" "\xad\x08\x28\x63\xcb\x72\x4e\xf4\xe2\x83\x83\x3b\xf0\xca\xb8\x6a\x2d\x74" "\xfc\x69\xb9\x44\x4a\x42\x60\x06\xb0\x0e\x0e\x1b\xdb\x10\xf4\x0b\x54\x37" "\x17\x61\xc0\xa4\x41\x58\x6c\xe8\x65\x4a\x83\xf1\x5d\xad\x88\x49\xb2\x60" "\xd1\x1b\x06\x40\xaa\x57\xba\x2f\x56\x91\x53\x97\xe8\x2d\xc5\xae\x0a\x08" "\x24\xda\x23\x1a\xf5\x08\x6a\x9d\xed\x6d\x88\x7a\xe2\xb6\xdf\x7e\x16\x95" "\x82\xc2\xc4\x8f\x57\x4d\xff\xa6\xc9\x48\x74\x77\x46\xca\x99\x2c\x8e\xcb" "\x99\x22\x24\x2b\x89\xea\xe2\xc4\xb4\x24\x70\xdd\x86\xa7\x96\xca\x95\xe9" "\xc7\x5c\xdb\x35\x60\x37\xa7\x32\xad\xa8\x87\x07\xca\xfe\xad\xf4\x20\x19" "\xc4\x27\xc7\xc0\x73\x16\xac\xaa\xfa\x1e\x30\xb0\x5c\xda\xca\xaf\x00\x46" "\xc3\xd0\x56\xb4\x61\xb5\x46\x70\xc4\x20\x5d\x65\x8e\x46\x8a\x3d\x36\x8b" "\x26\x57\x9e\xcc\xa2\xbb\x06\x2e\x21\xa3\xc1\x78\x71\xab\x91\x3e\xa9\x37" "\x94\x22\x09\xad\x9e\xcb\x83\xf0\xfc\x80\x76\x32\xff\x79\x99\xb5\x4d\x42" "\xe2\xb1\x31\x1e\x63\x20\x65\xca\xda\x66\x6d\xbd\x31\xab\x2e\xed\x65\x17" "\x37\xca\x61\xe1\xff\x02\xf1\xc7\x10\xa4\x7e\x74\x35\xc3\x27\xd4\x11\x71" "\x61\x82\xb2\xc7\x5a\x42\xdb\x69\x56\x74\x0b\x0d\x89\x12\x81\x84\x64\x5e" "\x3e\x5b\x51\x40\x52\x3c\x1f\xe3\x76\xf2\xa6\xaf\xfd\xae\x85\x0a\x94\x30" "\x3f\x2b\x7b\x67\xbb\xd5\xac\x80\xaa\x4e\xec\xd1\xe6\x9c\x1a\x02\xb4\x5a" "\x13\x94\x64\x77\x84\x6b\x05\x0f\x43\x4b\xdf\x41\x32\xb0\x64\xf8\x01\x3b" "\x11\xd9\x5e\x95\x6c\xe5\xb8\x3e\x0e\x04\x8e\x87\xa1\x02\x52\x32\xf8\x03" "\xe1\x8f\x39\xd5\x17\x9d\x73\xa2\xab\xa5\x5e\x9c\x12\x5a\x90\xef\x46\xc6" "\x1f\x82\x1c\x8f\xa3\xbb\x7d\x5c\x06\xc1\x5e\x10\x71\x93\x1a\xaf\xc2\x26" "\x7d\x4d\x0e\xcb\x7b\x8d\x8f\xce\xfd\x8b\xfe\xa4\xee\xf2\x61\x95\x54\x43" "\x52\xb0\xfa\x87\x65\x45\x6d\xe7\xa2\xd2\xe6\xd4\x3b\x44\xde\x57\x7b\xe3" "\x7a\xa9\x25\x75\x5c\x79\x0e\x31\xb8\xee\x0a\xc3\xd1\xc0\x34\xfc\x49\xf1" "\x23\x09\x72\x01\x83\xed\xe2\xf8\x37\x4c\xb5\xec\x0b\x52\x90\xb5\x76\x5a" "\x4d\x56\x3b\x95\x45\xb4\xce\xbd\x66\xeb\x1a\x71\xb0\xf7\x12\xd7\xa4\xdc" "\x56\xfc\xf3\x8b\x82\x6f\x40\xfc\xb1\xe6\xb0\x39\xb9\xa9\xa9\x64\xcc\x57" "\xe6\x94\xce\x0a\x12\xbc\xb8\x84\xd0\x10\xfc\x67\x73\xb4\x5c\x2d\x45\x64" "\xa5\xcb\x59\x98\x92\x7d\x1d\xef\x03\xf2\x59\x09\xff\x6a\x3e\x31\xda\x81" "\x84\x7e\xb8\x8e\x14\x2c\x85\x4f\xbc\x42\x29\xb6\x3a\x3f\xf8\x22\x4d\x12" "\x23\xac\x29\x67\x6f\x5c\x5b\x6b\x9c\xe2\x70\xc1\xf0\xb7\xab\x75\xc9\x17" "\xae\xa7\xfb\x21\xc1\xe7\x9c\xcf\xe0\x02\x84\x8a\x1b\x00\x7e\xd0\xde\x15" "\x6e\xdf\xba\x5e\x58\xe0\xc9\xe0\x3f\x9f\x81\x97\xe4\x9e\x8d\x70\xd0\x14" "\x02\xe7\x78\x57\x72\x4e\xc6\xeb\xc1\x5a\xc0\x06\x1a\x3b\x8f\xc9\x66\x1e" "\xa5\x47\xf7\xc3\x12\xbd\x11\x08\x67\x2b\x0d\xd9\x19\x5b\x06\xcc\x9f\xda" "\x32\xa6\xcc\xcf\x90\x2b\xaa\x7f\xcc\x72\x68\x5a\xf8\x76\x71\x31\x37\x5b" "\x08\x2f\x0f\xe3\x97\x92\xbd\xd8\x3a\x17\x17\xaf\xeb\xcf\xc0\xf4\x33\x0b" "\xed\x0f\x72\xa9\x41\x4e\x1f\x4d\x72\x32\x96\xac\xdb\x0a\xaf\x5f\x5e\xd4" "\x5f\xe5\x81\x68\x17\xae\xef\x3f\x30\xee\xaf\xce\x84\x8c\x86\x95\x50\x8b" "\x49\x48\x97\xed\x52\xe6\x79\xca\xb7\x7b\x25\xc6\x18\x4f\x0f\x30\x7e\x19" "\xa0\x58\x1e\x01\x7a\xab\x72\xcb\x5c\x64\x88\xfc\xd4\xe2\xce\x8b\x2c\x73" "\x0e\x4c\x0e\x03\xa4\x7b\x92\x4d\x6d\xed\xf0\xd1\x00\x75\x60\x80\x6a\x1d" "\x7b\x78\x01\xe0\xb2\xff\xbb\x6e\x96\x83\x34\xd0\x57\xbf\x38\xca\x68\xbd" "\xe3\x8c\xd5\x6a\xeb\xb6\xfe\x21\xc3\xa7\x2d\x3a\x7e\x80\x61\x9d\x36\xe1" "\xec\xe0\xaf\xa6\x22\x7a\x07\x85\xd8\x17\x8e\x66\x79\xbe\xd9\x44\xec\x97" "\xed\xd0\x02\x20\x2d\x9f\x99\x6f\xd6\xf5\x21\xea\x25\x52\x72\x21\xd6\x0e" "\x96\x2e\xe1\x89\x0d\x69\xde\xf2\x93\xca\xbc\x45\x19\xbb\x54\x7d\xe2\x7d" "\xd2\xcf\xdd\x7f\x83\x39\xd2\x8d\xa4\xf1\xb5\x50\x10\xe2\x1a\x97\x65\xe7" "\xb2\xab\x7d\x59\x5b\x84\x64\xfb\x61\x48\x70\x26\xb8\xfe\x61\x6c\x7c\xe2" "\x06\x85\x01\x1c\x39\x9e\x73\x0f\x6c\x97\x12\xfc\x5b\x4c\x04\x94\xc3\xc1" "\xa2\x4b\x5a\xdc\xf5\xb9\xa1\x77\xc7\xc5\x81\x80\xcc\x7c\xef\x5c\xed\xf6" "\x9c\x3d\x6a\x4c\x7a\xee\x24\xc9\x43\x22\xd0\x3c\x53\x29\x89\x4a\x65\x2d" "\xda\xeb\x49\xfb\x13\x01\x31\xe3\x50\x71\x7f\x6a\x35\x77\x3c\x14\xe0\xc7" "\xfc\xd1\x76\x0b\x8a\xe0\x04\x2a\x08\x7f\x2f\x76\xb4\xcf\x50\xa0\x1b\x2a" "\x51\xce\xe8\x4f\x09\xf6\xfd\xc3\x7a\x93\x7a\x79\xa2\xa2\x14\x26\x1b\x8a" "\xbe\x0d\xe8\x9d\xe4\x1d\xa6\x69\x9d\xd4\x61\xb1\xa8\xdb\xac\xcf\x6a\x33" "\xd0\x99\x5b\xb1\x1e\xf5\xd8\xe0\xc0\x71\xa4\xe8\xd1\x6b\x7b\x26\xea\xbc" "\xfa\x79\x4e\x33\x66\x0b\xa4\x83\xbf\xf0\x6a\xe0\x74\x57\xda\xc9\xc1\xbb" "\xb7\x4a\xb5\x1a\xd8\x8a\x57\xf7\x08\x8e\xd6\x39\x02\x7a\x90\xb9\x16\xa6" "\x52\x04\x9f\x52\xcb\xca\x17\xd2\x71\x1a\x5d\x7c\xf3\xe4\x62\x6d\x49\x5c" "\xb3\x2c\x93\x9e\xb7\xb3\x59\xe7\x48\x43\xd4\xa2\x4c\x07\x7e\xf3\x5d\x85" "\xde\x8e\x93\x67\x3f\xde\xf1\x80\x1d\x3b\x1f\xd9\x2f\x62\x11\x72\x54\xe7" "\xfa\x00\x6c\xd5\xc2\x37\x88\x82\xa3\x10\xbe\x7e\x72\x39\xcf\xc9\x71\x2f" "\xc4\xeb\x37\x6f\xed\xa6\x10\x96\xc4\x5d\x1e\xae\x5a\x94\xd2\xe1\x66\xd1" "\xc9\xd7\x4d\xa3\x68\x71\xdd\x29\x55\x1f\x85\x35\xae\xc1\xa3\x57\x6e\xc5" "\x7c\x5f\x90\x83\x4e\xdf\x66\x11\xb9\x1f\x47\xa5\xdb\xf0\x60\x87\xda\x47" "\x3d\xb7\xd7\xdc\xdc\xeb\xe4\x5f", 3932)); NONFAILING(*(uint16_t*)0x20001960 = 0x36); NONFAILING(*(uint16_t*)0x20001962 = 0x4e00); NONFAILING(memcpy((void*)0x20001964, "\x60\x4f\x1b\x4d\xe8\x31\xf2\x18\xf3\x74\x12\xc8\x38\x97" "\x9d\x29\x4b\x86\xf8\x03\x65\x04\xcd\xfd\x29\x52\x08\xbe" "\xa7\x9a\x10\x40\xb7\xe9\x1f\xda\xf2\xab\x5f\x21\xdf\xf1" "\x43\x79\xb4\x9c\x02\xc5\xd5\x67\x64\xe9\xda\xb0", 54)); NONFAILING(syz_usb_ep_write(/*fd=*/-1, /*ep=*/0x82, /*len=*/0x111c, /*data=*/0x20000880)); NONFAILING(*(uint32_t*)0x20000080 = 0x2c); NONFAILING(*(uint64_t*)0x20000084 = 0x20000100); NONFAILING(memcpy((void*)0x20000100, "\x00\x00\x02", 3)); NONFAILING(*(uint64_t*)0x2000008c = 0); NONFAILING(*(uint64_t*)0x20000094 = 0); NONFAILING(*(uint64_t*)0x2000009c = 0); NONFAILING(*(uint64_t*)0x200000a4 = 0); NONFAILING( syz_usb_control_io(/*fd=*/r[0], /*descs=*/0x20000080, /*resps=*/0)); NONFAILING(memcpy( (void*)0x200002c0, "\xb9\x42\x5b\x44\x65\x1d\xd2\x32\x41\x96\x35\x99\x00\x00\x00\x11\x00\x00" "\x00\x4a\x16\x94\x1f\xf5\xf4\xb4\xf1\xf0\xad\xd7\xfc\xf2\xb8\x77\xfc\xea" "\xff\xff\xff\xff\xff\xf1\xff\xdf\x4c\xd9\xf5\xd3\x96\x98\x90\x52\x2c\x77" "\x15\x7d\x88\x01\x00\x00\x00\x3a\x5b\xd5\x53\x1d\x45\x9d\xff\xff\x03\x00" "\x00\x00\x00\x00\x91\xff\x00\x00\x00\xe8\xf5\xb3\x37\x1d\xa3\x63\x5b\x8b" "\x4f\xa6\x37\x13\x58\x00\x00\x1f\x65\xe4\xb4\x36\xaa\x9e\x50\xbc\x0f\x19" "\xb7\xd3\x37\x2f\xf9\xeb\xce\xde\x1f\xb5\xe9\x42\x8f\x54\xd5\xd1\xf0\xcc" "\x75\x2c\xf2\x46\xa5\xd2\xda\x34\xa5\xaa\x97\xdc\x14\xa4\x69\xc3\xdd\x3e" "\x26\xb4\x1c\x35\x64\x84\xe4\x6f\xd6\x6e\x3f\x2c\x78\x07\xe8\x77\x3e\xed" "\x7b\x94\xfa\x09\x9a\xb8\x4f\xea\xde\xc2\xea\x95\xf6\x5b\xba\x45\x2e\xae" "\x5b\x09\x00\xf9\x8a\x97\x9a\x88\xc5\x17\xa2\xdc\x36\x0a\x00\x23\x77\x23" "\xe2\xf4\x67\xaf\x70\x6e\xa1\x72\x26\x29\x6b\x3a\x10\xa3\x51\xcb\x47\xab" "\xa2\xc6\xb8\x36\xc9\x06\x79\xb4\xdd\x85\x9d\xdc\x9e\x48\x00\x44\x8a\xab" "\x00\x00\x00\x00\x00\x00\x0d\x75\xf3\x4b\xb5\x0d\x8d\x70\x84", 249)); NONFAILING(syz_usb_ep_write(/*fd=*/r[0], /*ep=*/0x81, /*len=*/0xffffff75, /*data=*/0x200002c0)); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); setup_sysctl(); setup_cgroups(); const char* reason; (void)reason; if ((reason = setup_binfmt_misc())) printf("the reproducer may not work as expected: binfmt_misc setup failed: " "%s\n", reason); if ((reason = setup_usb())) printf("the reproducer may not work as expected: USB injection setup " "failed: %s\n", reason); if ((reason = setup_swap())) printf("the reproducer may not work as expected: swap setup failed: %s\n", reason); install_segv_handler(); for (procid = 0; procid < 2; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; }