// https://syzkaller.appspot.com/bug?id=2d36e7f205f5655cb59ce49754c466cd6c0a2b22 // 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 #ifndef __NR_bpf #define __NR_bpf 321 #endif static unsigned long long procid; 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 thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } 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); } #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 == 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 static void setup_common() { 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)) { } if (symlink("/dev/binderfs", "./binderfs")) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setsid(); 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); setup_common(); 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(); setup_binderfs(); loop(); 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_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); write_file("/proc/self/oom_score_adj", "1000"); flush_tun(); } static void close_fds() { for (int fd = 3; fd < MAX_FDS; fd++) close(fd); } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 11; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); close_fds(); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter = 0; for (;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { setup_test(); execute_one(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(__NR_socket, /*domain=*/2ul, /*type=*/1ul, /*proto=*/0); if (res != -1) r[0] = res; break; case 1: *(uint16_t*)0x20e5b000 = 2; *(uint16_t*)0x20e5b002 = htobe16(0x4e20); *(uint32_t*)0x20e5b004 = htobe32(0xe0000001); syscall(__NR_bind, /*fd=*/r[0], /*addr=*/0x20e5b000ul, /*addrlen=*/0x10ul); break; case 2: *(uint16_t*)0x20ccb000 = 2; *(uint16_t*)0x20ccb002 = htobe16(0x4e20); *(uint8_t*)0x20ccb004 = 0xac; *(uint8_t*)0x20ccb005 = 0x14; *(uint8_t*)0x20ccb006 = 0x14; *(uint8_t*)0x20ccb007 = 0xaa; syscall(__NR_connect, /*fd=*/r[0], /*addr=*/0x20ccb000ul, /*addrlen=*/0x10ul); break; case 3: *(uint32_t*)0x20000100 = 1; *(uint32_t*)0x20000104 = 3; *(uint64_t*)0x20000108 = 0x200011c0; memcpy( (void*)0x200011c0, "\x18\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\xa0\x12\x54\x4f\x95" "\x00\x2b\x00\x00\x00\x00\x00\x93\xad\xff\xa8\x22\x55\xf6\x74\x41\x2d" "\x02\x00\x00\x00\x00\x00\x00\x5a\xb5\x27\xee\x36\x97\xf1\xed\x44\x36" "\xdd\x11\x64\xb1\xb3\xf4\x27\xf6\xba\x6b\x34\xf9\x81\x25\xf3\x0e\x63" "\x1d\x27\x36\x83\x62\x6e\x00\xdc\x25\x4d\x57\x0d\x4a\x6b\x78\xa5\x83" "\x34\x88\xcf\xe4\x10\x09\x00\x00\x00\x4a\xa9\x00\x00\x3d\x3c\xd6\x2f" "\x00\x15\x8e\x6e\xee\x85\x01\x00\x00\x00\x52\x0a\x00\x00\x15\x1d\x01" "\x00\x00\x00\x01\x00\xbf\x00\x00\x00\x00\x3b\xbd\x42\x4c\x6e\x6c\xaf" "\xbe\x93\x09\xab\xa2\x18\x81\x28\x68\xa5\x1d\x12\x9e\x78\xf6\xae\x17" "\x0b\xf5\xa5\x20\x01\xa3\xcd\x00\x00\x41\xf0\xdb\x74\x59\x6f\xd7\x2c" "\x00\x2a\x60\xc1\xbc\x7d\xc8\xc3\x8b\x00\x00\x24\xd8\x89\x77\x65\x2b" "\x36\xb9\xdd\x11\x45\xd0\x3f\xf4\x5f\x70\x68\x5c\x6b\xd9\xff\x41\xc6" "\x9b\x7d\xe4\x75\x8c\x10\x96\xa1\xdc\x52\xf2\x9e\x8b\x70\x1d\x2d\x17" "\xeb\xc4\x06\xe8\x9d\xcb\xb7\x67\x7e\x65\x28\xb0\x85\x6e\x31\xeb\x94" "\x74\xc0\x10\x6f\xc4\x8e\x1f\x8c\x1a\x5f\x69\x45\xac\x24\xcf\x60\x80" "\x68\xf6\xff\x21\xe8\x8b\x3c\xfc\x22\xdf\x01\xd5\x1e\x24\x24\x43\x61" "\x8c\x02\xe0\xa4\x28\xda\x65\x13\x66\xe4\xba\xc9\xd9\x73\x28\xfa\x2a" "\x82\xb5\xe8\x74\x1e\x02\x05\x6d\x93\x3b\xed\xf5\x9f\xf2\x32\xce\xbc" "\x68\xb9\x1a\xf5\x04\x79\x38\x74\x67\x82\x42\x62\x85\x2c\x79\x39\xdb" "\x56\x72\xd0\x7c\xdb\xe8\xe1\x48\xbf\x56\x49\x7e\x5d\x56\xd0\x6c\x75" "\x51\xb8\x70\xb2\x85\x1c\x3f\x0a\x1a\xab\x71\x58\xed\xee\xcc\xd9\x2e" "\x3a\x88\xdc\x0f\x43\x21\x87\xce\x92\xd7\xb1\x7a\x21\xc8\xf1\xb3\x36" "\x9e\xbf\xcb\x4c\xb2\x94\x66\x01\xb0\xf0\x4e\xdb\x25\x6c\x60\x4f\x06" "\x87\x73\xf6\xdb\x9d\x66\x1b\xd7\xf0\xe2\x53\x6f\x00\x00\x00\x00\x00" "\x00\x00\x00\x55\x21\x45\x8b\x7d\x1e\x34\x1c\x6f\x86\x4f\x98\x3d\x74" "\x5f\x58\x65\xaa\xd4\x1d\x29\x15\x8a\xe7\x60\x2a\x2d\x6c\xd4\x15\xe8" "\x35\x1e\xbc\x28\x3d\xf5\x4d\x6b\xec\x66\x47\x09\xff\x03\xf1\xaa\x3d" "\xc7\xf1\x58\x0a\xce\x9b\xf2\xaf\xd2\x8d\x71\x57\xe6\x7f\xb9\x8d\x12" "\x1a\x96\xeb\x37\x38\x45\x25\x50\x12\xe0\x28\xcb\x26\x54\xd4\x93\xa0" "\xb4\xb3\x5f\xaa\xe1\x76\xf9\x9b\x74\x5e\xda\x29\x67\x19\x9c\xc9\x36" "\x85\xbb\x53\x7e\x8e\x48\x71\xd4\xac\xf3\xe3\xdc\x10\xe1\x3e\xf2\x27" "\xf6\x27\xa4\x00\x00\xad\x1f\xa2\x53\xd3\x3f\xa7\x4f\x17\x2d\x00\x07" "\xae\x4e\x1e\x34\x7c\x0c\xff\x28\x23\x5a\x6b\xb7\xaa\x38\x04\xb9\x07" "\xa8\xf2\x88\x0c\x5c\xb1\xcb\x38\x5e\x6a\xdd\x14\x65\x20\x03\xc7\xcd" "\xd3\x32\x4f\x07\xd1\x34\xd3\xed\x07\xf1\xc1\x09\x00\x00\x00\x09\xdd" "\x87\x2e\xc6\x4f\xa6\xc7\x18\xbb\xd1\xaa\x59\x11\x40\xcf\xf0\xbe\x4c" "\x6f\x8d\xf0\x84\xc5\xe9\x73\x4a\xe3\x0a\xa9\xaf\xdc\x71\x25\xf0\x1a" "\xb0\x3a\x9b\x10\x74\x40\x71\x36\xb4\x50\x60\x00\xf0\x91\x6a\xad\xa0" "\x35\xdf\x2e\x04\x52\xa9\xb3\x9e\x73\xae\xeb\x6e\xaf\x14\x65\x2d\xda" "\x68\x9e\x20\x51\xd9\xb7\xeb\x85\xf3\xf2\xd5\xae\x2c\x51\x94\x4d\xa8" "\xd7\x39\x1d\x5b\x6b\x97\x41\x9a\x3b\x76\x60\x0c\xd1\xaa\x0a\xfe\x5f" "\x8f\x46\xdf\x4c\x51\x24\xca\x42\x5d\x37\x4b\x37\x18\x67\xa7\x9b\x31" "\xc6\x61\x7f\xc3\x32\x71\x91\xf3\xf5\x14\x57\x3f\x1e\x30\xd1\xfd\x2d" "\x76\x3f\x3e\xe9\x21\x8b\x15\xc1\xd6\x0b\xe2\x16\x8f\xff\xcd\x59\x9a" "\x2c\xb7\x7f\x12\x4e\x22\xf8\x76\x73\x67\x58\x05\x49\x4d\xb8\x21\xf3" "\x9b\x50\xd5\xfd\x8c\x6b\x2a\x3a\x32\x4c\x25\x7b\xc9\x7d\xef\x5f\x07" "\xf2\xb7\x7f\x05\xa4\xf8\x1a\x9c\xf8\x11\x09\x71\xb7\x49\xcc\xd7\x40" "\x89\xed\x6b\x86\xf8\x1c\xa3\xd2\x47\xd8\xf7\x1d\x29\x0e\xd1\xb1\xa1" "\x1f\x7a\x67\x12\x51\x70\xc8\x8c\x3b\x6a\x50\x69\x63\x32\x22\x64\x01" "\xb1\x10\xda\x9c\x44\x07\xec\xa2\x2d\xeb\xc9\x93\x35\x58\x3b\x00\x01" "\x3c\x31\x30\x97\x8f\xa0\x69\xaf\x82\x23\xb3\x8c\xed\x73\x5c\x2d\x90" "\xc6\xd8\x4c\x30\xa0\xd8\x7d\x42\x64\x74\x89\xb3\x96\x01\xbe\x5c\x27" "\x69\x6c\xf2\xf1\x66\x25\xc0\xc1\x02\x00\x00\x00\x00\x00\x00\x00\x09" "\x00\x00\x00\x84\x2e\x64\x17\x1f\x39\x63\x84\x10\x86\xe3\x79\x7a\x48" "\x25\xd0\x81\xf2\x40\x08\x00\x00\x53\x41\x87\x73\x86\x55\xd7\xa6\x24" "\x04\x12\xc8\xf2\x83\xcc\x0c\x1e\xba\x28\x66\xdc\x95\x80\x00\x00\x00" "\x00\x00\x00\x00\x7f\xff\xff\xff\xff\x55\x4b\x82\xd9\xc1\x62\xf3\x55" "\x60\x76\xb8\x05\x52\xd9\x61\xca\x74\xd1\xff\xda\xcc\xf0\xea\x5f\x02" "\xe0\x16\x3a\x9c\xcb\x90\x87\xe6\xc3\xb3\x91\x7b\xb7\x4f\xd3\xd5\x60" "\x70\x0a\x1f\xab\x44\xe7\x7e\x31\x2b\x3b\x12\x9e\x00\x03\x02\xd6\x13" "\x91\x6c\x9b\xcf\x9f\x00\x00\xfa\xc7\x3a\x5b\x6b\xfb\x01\xef\xad\xa8" "\x00\xe5\x00\x00\x00\x00\x00\xfd\xaf\x2f\x7b\x3b\x79\xa4\x33\xe0\x80" "\x74\xea\x24\x62\x97\x4a\xb2\xcb\xd2\x47\xeb\x1c\xfa\x26\x38\xf5\x6d" "\xae\xe5\x7e\xd1\x4b\xc7\x4d\xe0\xfd\x87\xa9\xce\x63\x81\x90\xf3\x57" "\x0e\x0b\x4c\x80\xef\x68\x2d\xf2\x22\x37\x27\x09\x55\xaf\xb6\x00\x88" "\x46\x55\x7e\xe3\xbc\x09\xfd\xa6\xdb\xb6\x55\x0d\x59\x73\x00\xeb\x82" "\xa1\x84\xc9\x6f\xfd\xe5\xa3\x0e\x54\x33\xd8\x66\x66\x5b\x98\xca\x20" "\x02\xc8\x36\xe8\x9f\xee\xf9\x04\xc2\x2f\xf2\x63\x4b\x7b\xfb\xf5\xc0" "\xd5\x86\xcd\xa5\xb4\x5f\xd0\x0d\xed\xe1\xe8\x8a\x4d\x41\xde\xe7\xcc" "\x8d\x08\x34\xfb\x8d\x12\x46\x38\xfe\xc5\x8f\xae\xb4\xc1\x6a\xbb\x44" "\x0d\xf2\xa6\x94\xf4\xcd\xca\xa4\xf6\x5c\x22\xf0\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\xd5\x03\xd7\x99\x06\x95\x81\x02\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\xff\xf0\xef\x89\xb2\xa6\x8d" "\x2b\xb2\xdd\x16\x3e\x86\x33\x14\xe8\x44\x98\x01\xb5\x2b\xb9\x3f\x6c" "\x90\x84\x65\x9c\xe7\x77\xdd\xa8\x56\x3c\x85\x96\x56\xa3\x57\x77\x02" "\x89\xa6\x1f\xaa\x95\xa8\x2b\xf1\xcf\xb7\xf2\xf9\x72\x52\xe9\x32\x2a" "\xbe\x28\x2c\x33\x44\xfc\x67\x38\xb4\x46\x78\x93\xb9\xbf\x0d\x1c\x81" "\x30\xae\x6b\x00\x11\x06\x2a\x35\x37\x64\x13\xc2\x9f\x7c\x6f\x7b\xde" "\x29\xb9\xf4\xbd\xdd\x5e\x32\x86\x61\xf4\x61\x5e\x62\x7a\x6f\x60\x8a" "\xd5\x3a\x41\x68\xfe\x8e\x5d\x7d\x93\x4a\xa2\x89\xb4\xbd\x2b\x87\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfc\x4b\x4f\xf5" "\x00\x00\x00\x9b\x77\x78\x83\xa0\x2f\xfd\x92\xdf\xc4\xcb\x41\x14\xb9" "\xf9\xcf\x4a\xd1\x55\x11\x0c\xd3\xac\xe2\xb3\x22\xae\x31\xbf\xa2\x78" "\x47\xc7\x99\xc8\x86\x9a\x1e\xa5\xb9\x8e\x52\x5e\x63\x83\xad\x7f\xd9" "\x79\x51\x70\xe7\xb1\x1e\x24\x76\x03\x00\x00\x00\x00\x14\x59\xc7\xf6" "\x06\xd7\x21\xd3\x97\x96\x76\xbf\xfb\x30\x49\x16\x6a\xb8\x4a\xc1\x06" "\x19\x91\xbd\x57\xc2\x56\x6c\x10\xc2\x96\x4e\x3f\x24\x91\xe4\x79\x3e" "\x2b\x70\x59\x0d\xcc\x71\xf1\x10\xda\x96\x36\x6c\x40\xdd\x44\xa2\xc9" "\x88\x2d\x3a\xa0\xf8\xa7\x97\xb8\xfe\xa6\xef\xcf\xb5\x27\x6b\x76\x79" "\xf1\x55\x59\xcd\xaa\xbf\x5f\xc1\x4a\xdd\x71\xd0\xbc\xa3\x74\x05\xde" "\xd6\x9b\x77\xab\x4a\x3d\x74\x87\xfd\x50\xc5\xe2\x2a\xde\xf9\x54\x6a" "\xbb\x7a\x2d\x9c\x08\x5b\x18\x9b\x5f\xf3\x0e\x4e\x0c\x13\xf6\x08\x70" "\xfd\xe1\xf8\x8d\x83\x0b\x11\x00\x21\x35\xe8\xe7\x26\x2f\x29\xb6\xd7" "\x92\x3b\xfb\xe0\xbd\x2a\x8b\xe1\x79\xe5\x6b\x41\xff\x37\x92\xce\xe2" "\xfc\x37\xee\xe7\x39\xc3\x54\xf3\xa0\x0f\x9d\x8d\x99\x21\xaa\xfc\x85" "\x56\x7e\xc9\x83\x00\x8c\xe7\x40\xd8\x80\x4f\x8e\x70\x5f\x0d\xc5\x9d" "\x00\x00\x21\x36\x3e\x8d\xf9\x4f\xfa\x75\xb4\x8d\xc8\xc1\x2d\xef\x68" "\x1a\x11\x64\x79\x46\x59\x54\x45\xbf\x1c\xb7\xd2\x77\x8c\xd2\x7a\x6b" "\x3b\x29\x66\xb0\x8b\xe6\x00\x00\x00\x20\xa8\xa7\x11\xd1\x93\xba\xe0" "\xab\x2d\xb9\xed\x9c\x6c\xb3\xc3\xde\x42\xab\x89\x52\x44\x14\xca\xe9" "\x22\x14\x1f\x7b\xaf\x17\xeb\xb7\x90\xad\x60\xbd\x03\x87\x0c\x39\xd1" "\xad\x12\xc7\x50\x83\x7e\x63\xf9\x88\x0f\xd7\x02\x59\xe3\x55\x90\xaf" "\xb4\x84\x3c\xd4\xe9\x98\x93\x98\xea\xa8\xaf\xef\xb3\xaa\x13\xca\xb8" "\xd0\x15\xcb\xaf\x15\x61\xd9\x53\x62\xde\xdd\x73\xb8\xf8\xcb\xf8\x26" "\x9c\xac\x09\x1c\xfa\xaa\x3c\x7e\x46\xd6\xe7\x91\x45\xfc\x0f\x1d\x1b" "\x38\x37\x52\xcc\xb4\x05\x15\xa7\x72\x35\x6d\x74\x69\x14\x54\x02\x16" "\xad\xf4\xaf\xa2\x52\x72\x0e\xc6\xda\xd3\xa9\x86\x71\xec\xda\xff\x46" "\xcd\xdf\xfb\x1f\x05\xa0\xc0\x97\x60\x70\xd6\x03\xa4\x42\xd0\x14\x82" "\x23\x69\xfa\x3e\xac\xbb\x69\xbd\x1b\x0a\x07\x43\x57\xac\xd5\xd0\x21" "\x61\xfe\xd1\x46\xad\x3a\xa1\x5d\x2b\x81\x01\xb7\xbd\x1e\x09\x1a\xda" "\x78\xec\xd5\x01\x81\xf4\xb3\x5c\xae\x1b\x29\xaf\xf9\x14\x94\xc9\x16" "\x32\x3b\x61\xf8\x15\xc4\xe0\x70\x16\x57\x08\x7a\xd1\x1e\xef\x97\x95" "\x29\x21\x36\x5b\xc8\x98\xba\x2c\x76\xa9\xb6\xe0\x05\x2f\x43\xb1\xad" "\x2d\xfd\xf3\xf9\x58\xfc\x1d\x32\xe6\x92\xbc\x88\x46\xc7\x8a\x95\x6a" "\xda\x45\x3c\x67\xc1\xc2\xcd\xc4\xf8\xb1\xc9\x4e\x9a\xdc\x10\x6e\x85" "\xb3\x1e\x03\x0d\x95\x5c\x55\x78\xe1\x07\xa6\xe8\xca\x0d\x4d\xd0\x53" "\x44\xc3\xe2\xaf\x25\xd9\xa3\xb0\xf7\x80\x56\x24\x01\x6a\xea\xb2\x71" "\xa7\x5f\x0b\xac\xb1\x01\xa1\x56\xef\x89\x48\x06\x45\x69\x15\x4a\x7d" "\xe0\x8f\x80\xe4\xdf\x4c\x33\x9b\x69\x43\x1b\x0a\x56\x71\x09\x7d\x89" "\x21\x2b\x46\x5b\x0b\x32\x27\x5d\xea\xe1\x0a\x77\xe3\x34\xc9\xfc\x07" "\x4d\x18\x1b\xde\xb5\xbe\x80\xa6\x24\x9d\x47\x2e\x78\xe6\xbe\x57\xa5" "\xcc\xd3\x54\xcf\x18\x1e\x09\x96\x05\xa6\x44\xec\xad\xe2\x21\xa2\xbe" "\x92\x62\x10\xb2\x69\x0d\x09\xe4\xb7\xa3\xde\xa2\x54\x03\x39\x74\x39" "\x97\x9c\x27\xd5\x61\x32\x62\xde\x10\xba\xce\xcf\xff\x2d\x58\x43\x7f" "\x42\x2d\xf4\x25\x2c\x01\x87\x95\x31\x0c\x25\xe8\xfc\xe1\x8e\xd3\x66" "\xac\x2c\xaa\xde\x56\x4c\xa8\x69\x72\x7a\x7d\x63\xc2\x62\x71\xe1\x7d" "\x7a\xba\x48\x97\x18\x35\x53\x03\x11\x54\x52\x73\xd3\xca\xad\xeb\x5d" "\x20\x17\xdc\xdd\xab\x8f\x38\xf2\x06\x8f\x68\xa4\x11\x1d\xdd\x58\x7b" "\x5d\xf4\xb5\xd8\xf1\xce\x00\x23\x1a\x20\x92\xeb\x2e\x79\x7c\x49\x1a" "\x1e\x66\xf7\x36\x06\xfd\x95\xbb\xe0\xf1\x05\x21\x86\x2b\x62\x62\xf0" "\x25\x9d\xa5\x1f\xf7\x51\x7a\xce\x73\x61\x46\x0a\x46\x69\xa9\x7f\x7d" "\x0b\xf0\x95\xc2\x78\x7f\x00\xbd\xbf\xee\x19\x67\x0d\x1e\x0e\xc5\xe6" "\xc3\xcb\x09\x97\x2f\xa4\xd9\x49\x86\x15\x7b\x96\xd6\x69\x51\x77\xc9" "\x9d\x83\x71\x66\x51\x12\x93\x20\x92\x43\x52\xcd\xa7\xb8\xea\xd9\x1c" "\x33\x01\xaf\x62\x0c\x1e\x8d\x70\x3d\xd2\x9a\xd7\x7f\x54\x83\x67\x79" "\x60\x0b\xb0\xdb\x3e\xcf\xbd\x36\xfa\x81\x64\xfa\xbd\xcf\x2e\x58\xb7" "\x20\xe8\xe1\xc0\x3a\x74\xda\xf5\x93\xf9\x2a\x8e\xcc\x03\xf8\xc8\xe3" "\xaf\x9a\xe0\x7d\xc0\x37\x80\xcc\x0d\x69\x00\x00\x00\x00\x00\x00\x00" "\x00\x19\x98\x73\x19\x92\xce\xb2\x7d\xcc\x0b\xe5\xbe\x4d\xec\xef\xe4" "\x1b\x78\xbc\x18\x47\xbf\x54\xb0\x87\xe0\x95\x17\x2f\x06\xcf\xa6\xd4" "\xbf\x95\x8b\x1d\x45\x44\x94\x7f\xf1\x23\x06\x55\x19\x9d\xb4\xf4\x75" "\x00\x60\x47\xfe\x83\xca\xca\x97\x75\x8d\xff\xa5\x3c\xee\x76\x4f\x85" "\x93\x2e\xb2\x0d\x54\x24\x1b\x2d\x51\x5c\x08\x26\xdf\xe1\xf0\xf4\x0a" "\xe9\x20\x45\x5a\x45\x48\xfb\x35\xe2\xa3\x45\xc0\x5b\x1c\x25\x2b\x78" "\x77\xbb\x3d\x83\x4b\x0b\x35\x79\xa3\x62\x49\x14\x6f\x83\x2e\xf2\x58" "\xdf\x51\x27\x31\x8c\x70\x17\xac\x1a\x99\x6c\x4f\x90\x2f\x82\xde\xb6" "\x0f\xd1\x13\xcc\xf8\x12\xd5\x5f\xfd\x62\x50\x57\xbd\x4f\xf3\x96\x09" "\x92\xb8\x5b\xc8\xd3\x2e\xdf\xca\x38\x6b\xe1\x6b\x1c\x54\x9a\xec\x52" "\xe3\x1e\x14\x05\xf8\x6c\x77\x60\x28\x29\x01\x75\x0b\x73\x2e\xc0\x6b" "\x0d\xb7\x35\x22\x2a\x56\xf3\xeb\xb1\x6f\xad\x3e\x92\x69\x49\x52\x30" "\xcd\x88\xb0\xea\x2e\x3a\xff\xa1\x96\xa2\xf0\xad\xf7\x33\xbc\x6a\xfd" "\x37\xa6\x59\xec\xc9\x33\xd6\x36\xc1\xb2\x7d\x3a\x16\xc5\xea\x25\x30" "\x1f\x9b\x57\x89\xe4\xaa\x8e\x72\x28\xe3\x00\x2f\x14\x6a\xa5\xe5\x75" "\xbb\x74\xb1\xeb\xb8\x21\x47\xed\xf8\x16\x1d\x36\x27\x04\x37\x70\x58" "\xe8\x87\xc6\x08\xbe\x87\x19\xea\x1b\x6c\x49\x0f\x79\xe0\x83\x2e\x2d" "\xdd\x7e\x21\x7c\x7a\xdd\xdd\x47\x31\xe0\x32\xd7\xeb\x35\xbd\xc3\x81" "\x60\xc6\x76\xd8\x40\xe2\xe8\xbe\x90\x33\xa6\x86\xcf\x70\x61\xf5\xf5" "\x5e\x28\x51\x73\x6a\x04\x00\xf3\xba\xd8\xac\x05\xc0\x48\xe2\x0d\x8c" "\x03\xb6\x80\x08\xa7\x0b\x8f\x80\xc9\x3e\xbd\x2a\xba\xbb\x5c\x65\xfe" "\x9a\xbc\x46\x42\xd7\xef\xd7\xb6\xb3\x9c\x68\xa1\x6d\x75\xa7\x85\x2d" "\xfc\x37\xa6\xa5\x0c\xb2\x8a\x9b\x6f\x68\x5a\x46\xbe\x14\x01\xa8\xbe" "\x77\x48\xa7\x1f\xcd\xc8\x5b\xa2\x04\x9e\x96\xc4\xe6\xdc\xe5\x9b\x88" "\xcd\x54\x72\x72\x6b\xc2\x37\xfb\xcf\x3f\xfc\xbf\x32\xe2\xaa\xc9\xb2" "\xf9\xd6\x01\x3b\x59\x78\x0d\xed\x72\x3b\x08\xc7\x67\xfa\x09\x1e\x2f" "\xa4\xd5\x18\x63\x50\x0f\xcd\x50\x41\xbc\xc9\x8a\x68\x55\x04\x83\x57" "\x43\x19\x41\x13\xea\x0b\x97\xb4\xf9\xdd\xc3\x95\xb9\xac\x4d\xef\xef" "\xad\xd3\x7a\x88\x71\xfd\x91\xf3\x1a\x56\xeb\x96\xec\xf9\x00\x00\x00" "\x00\x00\x00\x00\x94\x91\x21\x54\x21\x0d\x72\x7b\x8e\x9a\x0d\xed\x21" "\x17\x1a\x98\x60\xc0\xdf\xdf\x84\x14\x2e\x90\xc0\x87\x5e\x89\x36\x77" "\xb1\xe5\xbd\x9c\x1e\xe8\x91\xf4\x80\x90\x0b\x59\xf2\x5d\xd4\xfe\x84" "\xa2\x8e\x59\x9d\x41\xdd\xde\x4f\x20\xda\x81\xde\xa2\x67\xe9\x3e\x61" "\xd0\xfd\xed\x6b\x60\xea\xb3\x7d\x44\x01\x05\x99\x58\x70\xe7\xbb\x21" "\x64\x04\x7e\xd1\x64\x86\xa0\x14\xd4\x4c\xf3\x66\xf2\x91\x5c\xbc\x79" "\x65\x45\xf3\x6a\xf1\xf7\xb5\xfd\x8d\xfc\xcf\xe1\x19\xa5\xcd\xba\x78" "\xa4\x47\xf1\x06\x84\x4c\x34\x79\x20\x4f\x57\x4e\xfb\x1f\x00\xea\x24" "\xb2\xc5\x14\xc1\xaa\x38\x85\x7b\xbe\xed\x63\x17\x59\xe6\xc1\x2f\x8f" "\x0c\xdf\x4b\x45\xc6\x7a\x4b\x55\xe3\x33\x0e\xf4\xcb\x71\x8b\xb3\x96" "\x19\x3a\xa8\x9c\x37\xd7\x38\x44\x52\x6b\x9a\x81\x12\x06\x84\x8a\xcf" "\xd8\x88\xa8\x14\x15\x92\x57\xf4\xf9\xed\xad\xe9\xd0\xe5\x40\xe8\xa8" "\x5e\xe4\xe3\xbb\x03\xa3\x75\x21\x06\xec\x75\xe5\x35\x10\x76\x0e\xb7" "\x92\xce\xf6\x3c\x2a\x38\xbf\x70\x77\xba\xcd\xd7\x74\x6b\x7d\xdd\x45" "\x9e\x7e\xc1\xef\xee\xf1\x90\x1b\x4b\xa6\x9a\x7a\x51\x7d\x12\x68\x82" "\x4b\x48\xc3\x63\x86\x8f\x91\x99\xaa\x9f\xf1\x0d\xb8\x3d\x34\xd7\x7b" "\xc1\x44\xa1\x77\xa0\xa4\xd6\x07\x41\xf1\xb5\x7f\xdf\x5b\xce\xe1\x79" "\x39\x8f\x27\xaa\x8a\xa0\x4c\x1e\x62\x7d\x37\x73\xc3\x7c\x75\x85\x80" "\x2b\x8a\xd4\x47\x9f\x84\x46\xfc\xf1\x6a\x8e\x90\x87\xda\xbf\x39\x58" "\xd6\x99\xdf\x49\x58\x5f\xd0\x78\xec\x2b\xfd\x75\xae\xa8\x15\xd5\xbe" "\x6e\x6b\x93\x05\x7c\xdf\xc6\x42\x65\xa5\xc6\x82\x4f\x13\xe3\x95\x1e" "\xe0\x64\x14\xc7\xc4\x35\xba\xf7\x6b\x92\xde\x3a\x4c\xbf\x87\x68\x26" "\x56\x66\x84\x29\x46\x0a\x6c\x0d\x38\x65\x9e\xb1\x38\xd9\xc5\xf4\xa3" "\x45\x05\xf1\x4d\x3d\x01\xb9\xc0\x1d\x42\xe4\x69\x6b\x01\xc4\xfe\xc6" "\xfd\x67\x4f\x61\xa2\xae\x8b\x27\xbd\xc5\x07\x9b\xe4\x09\x58\xaf\x02" "\x86\x00\x8c\x3c\xc3\x84\x4b\x24\x1d\xa1\xda\xc4\x86\x31\xe2\x39\x94" "\xe6\x71\x4d\x61\xd9\x1d\x3f\xd6\x0b\x74\x1f\x1f\xcf\x42\x81\x8e\x45" "\xba\x8a\x94\x9a\x2d\x5b\xdd\xdf\x2e\xca\x65\x01\x91\xeb\x0f\x65\x01" "\x27\xef\x31\x01\xad\x86\x84\x91\x3a\xae\xa7\x58\xad\x1d\xfd\xc0\x78" "\xf5\x83\x12\x7a\x24\x94\xef\x02\x94\xaa\x0f\x9a\xbf\xa4\xc9\xee\xeb" "\xa1\x68\x19\xdf\x44\x42\x02\xaa\x5e\x6a\xd6\x4d\x63\x08\xd4\x4f\x50" "\x86\x63\x32\x6f\x8c\xb6\xe8\x9a\x32\xfc\xcd\x56\xcc\x52\x7b\x38\x2d" "\x99\x17\xc9\x5b\x0f\x61\x2a\x74\x9d\x5c\x90\xdd\xbf\x92\x8a\x8c\x6c" "\x3d\xd1\x94\x00\x00\x00\x00\x00\x00", 3409); *(uint64_t*)0x20000110 = 0x202bf000; memcpy((void*)0x202bf000, "syzkaller\000", 10); *(uint32_t*)0x20000118 = 4; *(uint32_t*)0x2000011c = 0x436; *(uint64_t*)0x20000120 = 0x20000040; *(uint32_t*)0x20000128 = 0; *(uint32_t*)0x2000012c = 0; memset((void*)0x20000130, 0, 16); *(uint32_t*)0x20000140 = 0; *(uint32_t*)0x20000144 = 0; *(uint32_t*)0x20000148 = -1; *(uint32_t*)0x2000014c = 8; *(uint64_t*)0x20000150 = 0x20000000; *(uint32_t*)0x20000000 = 0; *(uint32_t*)0x20000004 = 0; *(uint32_t*)0x20000158 = 7; *(uint32_t*)0x2000015c = 0x10; *(uint64_t*)0x20000160 = 0; *(uint32_t*)0x20000168 = 0; *(uint32_t*)0x2000016c = 0; *(uint32_t*)0x20000170 = -1; *(uint32_t*)0x20000174 = 0; *(uint64_t*)0x20000178 = 0; *(uint64_t*)0x20000180 = 0; *(uint32_t*)0x20000188 = 0x10; *(uint32_t*)0x2000018c = 0; res = syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x20000100ul, /*size=*/0x48ul); if (res != -1) r[1] = res; break; case 4: memcpy((void*)0x20000180, "net_prio.prioidx\000", 17); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x20000180ul, /*flags=*/0x275aul, /*mode=*/0ul); if (res != -1) r[2] = res; break; case 5: syscall(__NR_write, /*fd=*/r[2], /*data=*/0x20000400ul, /*len=*/0x208e24bul); break; case 6: syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0xb36000ul, /*prot=*/2ul, /*flags=*/0x28011ul, /*fd=*/r[2], /*offset=*/0ul); break; case 7: res = syscall(__NR_socket, /*domain=*/0x29ul, /*type=*/5ul, /*proto=*/0); if (res != -1) r[3] = res; break; case 8: *(uint32_t*)0x20000180 = r[0]; *(uint32_t*)0x20000184 = r[1]; syscall(__NR_ioctl, /*fd=*/r[3], /*cmd=*/0x89e0, /*arg=*/0x20000180ul); break; case 9: *(uint64_t*)0x20002940 = 0; *(uint32_t*)0x20002948 = 0; *(uint64_t*)0x20002950 = 0x20002800; *(uint64_t*)0x20002800 = 0x20002980; *(uint64_t*)0x20002808 = 0xfffffe09; *(uint64_t*)0x20002958 = 1; *(uint64_t*)0x20002960 = 0; *(uint64_t*)0x20002968 = 0; *(uint32_t*)0x20002970 = 0; syscall(__NR_sendmsg, /*fd=*/r[3], /*msg=*/0x20002940ul, /*f=*/0ul); break; case 10: syscall(__NR_write, /*fd=*/r[3], /*buf=*/0ul, /*count=*/0ul); break; } } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=*/7ul, /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { do_sandbox_none(); } } sleep(1000000); return 0; }