// https://syzkaller.appspot.com/bug?id=5313586d7e1118a80e51b62907b52b8315ef1e43 // 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 #include #include #include #include #include #ifndef __NR_memfd_create #define __NR_memfd_create 319 #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 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 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 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 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); } static int runcmdline(char* cmdline) { int ret = system(cmdline); if (ret) { } return ret; } 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 #define BTPROTO_HCI 1 #define ACL_LINK 1 #define SCAN_PAGE 2 typedef struct { uint8_t b[6]; } __attribute__((packed)) bdaddr_t; #define HCI_COMMAND_PKT 1 #define HCI_EVENT_PKT 4 #define HCI_VENDOR_PKT 0xff struct hci_command_hdr { uint16_t opcode; uint8_t plen; } __attribute__((packed)); struct hci_event_hdr { uint8_t evt; uint8_t plen; } __attribute__((packed)); #define HCI_EV_CONN_COMPLETE 0x03 struct hci_ev_conn_complete { uint8_t status; uint16_t handle; bdaddr_t bdaddr; uint8_t link_type; uint8_t encr_mode; } __attribute__((packed)); #define HCI_EV_CONN_REQUEST 0x04 struct hci_ev_conn_request { bdaddr_t bdaddr; uint8_t dev_class[3]; uint8_t link_type; } __attribute__((packed)); #define HCI_EV_REMOTE_FEATURES 0x0b struct hci_ev_remote_features { uint8_t status; uint16_t handle; uint8_t features[8]; } __attribute__((packed)); #define HCI_EV_CMD_COMPLETE 0x0e struct hci_ev_cmd_complete { uint8_t ncmd; uint16_t opcode; } __attribute__((packed)); #define HCI_OP_WRITE_SCAN_ENABLE 0x0c1a #define HCI_OP_READ_BUFFER_SIZE 0x1005 struct hci_rp_read_buffer_size { uint8_t status; uint16_t acl_mtu; uint8_t sco_mtu; uint16_t acl_max_pkt; uint16_t sco_max_pkt; } __attribute__((packed)); #define HCI_OP_READ_BD_ADDR 0x1009 struct hci_rp_read_bd_addr { uint8_t status; bdaddr_t bdaddr; } __attribute__((packed)); #define HCI_EV_LE_META 0x3e struct hci_ev_le_meta { uint8_t subevent; } __attribute__((packed)); #define HCI_EV_LE_CONN_COMPLETE 0x01 struct hci_ev_le_conn_complete { uint8_t status; uint16_t handle; uint8_t role; uint8_t bdaddr_type; bdaddr_t bdaddr; uint16_t interval; uint16_t latency; uint16_t supervision_timeout; uint8_t clk_accurancy; } __attribute__((packed)); struct hci_dev_req { uint16_t dev_id; uint32_t dev_opt; }; struct vhci_vendor_pkt_request { uint8_t type; uint8_t opcode; } __attribute__((packed)); struct vhci_pkt { uint8_t type; union { struct { uint8_t opcode; uint16_t id; } __attribute__((packed)) vendor_pkt; struct hci_command_hdr command_hdr; }; } __attribute__((packed)); #define HCIDEVUP _IOW('H', 201, int) #define HCISETSCAN _IOW('H', 221, int) static int vhci_fd = -1; static void rfkill_unblock_all() { int fd = open("/dev/rfkill", O_WRONLY); if (fd < 0) exit(1); struct rfkill_event event = {0}; event.idx = 0; event.type = RFKILL_TYPE_ALL; event.op = RFKILL_OP_CHANGE_ALL; event.soft = 0; event.hard = 0; if (write(fd, &event, sizeof(event)) < 0) exit(1); close(fd); } static void hci_send_event_packet(int fd, uint8_t evt, void* data, size_t data_len) { struct iovec iv[3]; struct hci_event_hdr hdr; hdr.evt = evt; hdr.plen = data_len; uint8_t type = HCI_EVENT_PKT; iv[0].iov_base = &type; iv[0].iov_len = sizeof(type); iv[1].iov_base = &hdr; iv[1].iov_len = sizeof(hdr); iv[2].iov_base = data; iv[2].iov_len = data_len; if (writev(fd, iv, sizeof(iv) / sizeof(struct iovec)) < 0) exit(1); } static void hci_send_event_cmd_complete(int fd, uint16_t opcode, void* data, size_t data_len) { struct iovec iv[4]; struct hci_event_hdr hdr; hdr.evt = HCI_EV_CMD_COMPLETE; hdr.plen = sizeof(struct hci_ev_cmd_complete) + data_len; struct hci_ev_cmd_complete evt_hdr; evt_hdr.ncmd = 1; evt_hdr.opcode = opcode; uint8_t type = HCI_EVENT_PKT; iv[0].iov_base = &type; iv[0].iov_len = sizeof(type); iv[1].iov_base = &hdr; iv[1].iov_len = sizeof(hdr); iv[2].iov_base = &evt_hdr; iv[2].iov_len = sizeof(evt_hdr); iv[3].iov_base = data; iv[3].iov_len = data_len; if (writev(fd, iv, sizeof(iv) / sizeof(struct iovec)) < 0) exit(1); } static bool process_command_pkt(int fd, char* buf, ssize_t buf_size) { struct hci_command_hdr* hdr = (struct hci_command_hdr*)buf; if (buf_size < (ssize_t)sizeof(struct hci_command_hdr) || hdr->plen != buf_size - sizeof(struct hci_command_hdr)) exit(1); switch (hdr->opcode) { case HCI_OP_WRITE_SCAN_ENABLE: { uint8_t status = 0; hci_send_event_cmd_complete(fd, hdr->opcode, &status, sizeof(status)); return true; } case HCI_OP_READ_BD_ADDR: { struct hci_rp_read_bd_addr rp = {0}; rp.status = 0; memset(&rp.bdaddr, 0xaa, 6); hci_send_event_cmd_complete(fd, hdr->opcode, &rp, sizeof(rp)); return false; } case HCI_OP_READ_BUFFER_SIZE: { struct hci_rp_read_buffer_size rp = {0}; rp.status = 0; rp.acl_mtu = 1021; rp.sco_mtu = 96; rp.acl_max_pkt = 4; rp.sco_max_pkt = 6; hci_send_event_cmd_complete(fd, hdr->opcode, &rp, sizeof(rp)); return false; } } char dummy[0xf9] = {0}; hci_send_event_cmd_complete(fd, hdr->opcode, dummy, sizeof(dummy)); return false; } static void* event_thread(void* arg) { while (1) { char buf[1024] = {0}; ssize_t buf_size = read(vhci_fd, buf, sizeof(buf)); if (buf_size < 0) exit(1); if (buf_size > 0 && buf[0] == HCI_COMMAND_PKT) { if (process_command_pkt(vhci_fd, buf + 1, buf_size - 1)) break; } } return NULL; } #define HCI_HANDLE_1 200 #define HCI_HANDLE_2 201 #define HCI_PRIMARY 0 #define HCI_OP_RESET 0x0c03 static void initialize_vhci() { int hci_sock = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); if (hci_sock < 0) exit(1); vhci_fd = open("/dev/vhci", O_RDWR); if (vhci_fd == -1) exit(1); const int kVhciFd = 202; if (dup2(vhci_fd, kVhciFd) < 0) exit(1); close(vhci_fd); vhci_fd = kVhciFd; struct vhci_vendor_pkt_request vendor_pkt_req = {HCI_VENDOR_PKT, HCI_PRIMARY}; if (write(vhci_fd, &vendor_pkt_req, sizeof(vendor_pkt_req)) != sizeof(vendor_pkt_req)) exit(1); struct vhci_pkt vhci_pkt; if (read(vhci_fd, &vhci_pkt, sizeof(vhci_pkt)) != sizeof(vhci_pkt)) exit(1); if (vhci_pkt.type == HCI_COMMAND_PKT && vhci_pkt.command_hdr.opcode == HCI_OP_RESET) { char response[1] = {0}; hci_send_event_cmd_complete(vhci_fd, HCI_OP_RESET, response, sizeof(response)); if (read(vhci_fd, &vhci_pkt, sizeof(vhci_pkt)) != sizeof(vhci_pkt)) exit(1); } if (vhci_pkt.type != HCI_VENDOR_PKT) exit(1); int dev_id = vhci_pkt.vendor_pkt.id; pthread_t th; if (pthread_create(&th, NULL, event_thread, NULL)) exit(1); int ret = ioctl(hci_sock, HCIDEVUP, dev_id); if (ret) { if (errno == ERFKILL) { rfkill_unblock_all(); ret = ioctl(hci_sock, HCIDEVUP, dev_id); } if (ret && errno != EALREADY) exit(1); } struct hci_dev_req dr = {0}; dr.dev_id = dev_id; dr.dev_opt = SCAN_PAGE; if (ioctl(hci_sock, HCISETSCAN, &dr)) exit(1); struct hci_ev_conn_request request; memset(&request, 0, sizeof(request)); memset(&request.bdaddr, 0xaa, 6); *(uint8_t*)&request.bdaddr.b[5] = 0x10; request.link_type = ACL_LINK; hci_send_event_packet(vhci_fd, HCI_EV_CONN_REQUEST, &request, sizeof(request)); struct hci_ev_conn_complete complete; memset(&complete, 0, sizeof(complete)); complete.status = 0; complete.handle = HCI_HANDLE_1; memset(&complete.bdaddr, 0xaa, 6); *(uint8_t*)&complete.bdaddr.b[5] = 0x10; complete.link_type = ACL_LINK; complete.encr_mode = 0; hci_send_event_packet(vhci_fd, HCI_EV_CONN_COMPLETE, &complete, sizeof(complete)); struct hci_ev_remote_features features; memset(&features, 0, sizeof(features)); features.status = 0; features.handle = HCI_HANDLE_1; hci_send_event_packet(vhci_fd, HCI_EV_REMOTE_FEATURES, &features, sizeof(features)); struct { struct hci_ev_le_meta le_meta; struct hci_ev_le_conn_complete le_conn; } le_conn; memset(&le_conn, 0, sizeof(le_conn)); le_conn.le_meta.subevent = HCI_EV_LE_CONN_COMPLETE; memset(&le_conn.le_conn.bdaddr, 0xaa, 6); *(uint8_t*)&le_conn.le_conn.bdaddr.b[5] = 0x11; le_conn.le_conn.role = 1; le_conn.le_conn.handle = HCI_HANDLE_2; hci_send_event_packet(vhci_fd, HCI_EV_LE_META, &le_conn, sizeof(le_conn)); pthread_join(th, NULL); close(hci_sock); } //% This code is derived from puff.{c,h}, found in the zlib development. The //% original files come with the following copyright notice: //% Copyright (C) 2002-2013 Mark Adler, all rights reserved //% version 2.3, 21 Jan 2013 //% This software is provided 'as-is', without any express or implied //% warranty. In no event will the author be held liable for any damages //% arising from the use of this software. //% Permission is granted to anyone to use this software for any purpose, //% including commercial applications, and to alter it and redistribute it //% freely, subject to the following restrictions: //% 1. The origin of this software must not be misrepresented; you must not //% claim that you wrote the original software. If you use this software //% in a product, an acknowledgment in the product documentation would be //% appreciated but is not required. //% 2. Altered source versions must be plainly marked as such, and must not be //% misrepresented as being the original software. //% 3. This notice may not be removed or altered from any source distribution. //% Mark Adler madler@alumni.caltech.edu //% BEGIN CODE DERIVED FROM puff.{c,h} #define MAXBITS 15 #define MAXLCODES 286 #define MAXDCODES 30 #define MAXCODES (MAXLCODES + MAXDCODES) #define FIXLCODES 288 struct puff_state { unsigned char* out; unsigned long outlen; unsigned long outcnt; const unsigned char* in; unsigned long inlen; unsigned long incnt; int bitbuf; int bitcnt; jmp_buf env; }; static int puff_bits(struct puff_state* s, int need) { long val = s->bitbuf; while (s->bitcnt < need) { if (s->incnt == s->inlen) longjmp(s->env, 1); val |= (long)(s->in[s->incnt++]) << s->bitcnt; s->bitcnt += 8; } s->bitbuf = (int)(val >> need); s->bitcnt -= need; return (int)(val & ((1L << need) - 1)); } static int puff_stored(struct puff_state* s) { s->bitbuf = 0; s->bitcnt = 0; if (s->incnt + 4 > s->inlen) return 2; unsigned len = s->in[s->incnt++]; len |= s->in[s->incnt++] << 8; if (s->in[s->incnt++] != (~len & 0xff) || s->in[s->incnt++] != ((~len >> 8) & 0xff)) return -2; if (s->incnt + len > s->inlen) return 2; if (s->outcnt + len > s->outlen) return 1; for (; len--; s->outcnt++, s->incnt++) { if (s->in[s->incnt]) s->out[s->outcnt] = s->in[s->incnt]; } return 0; } struct puff_huffman { short* count; short* symbol; }; static int puff_decode(struct puff_state* s, const struct puff_huffman* h) { int first = 0; int index = 0; int bitbuf = s->bitbuf; int left = s->bitcnt; int code = first = index = 0; int len = 1; short* next = h->count + 1; while (1) { while (left--) { code |= bitbuf & 1; bitbuf >>= 1; int count = *next++; if (code - count < first) { s->bitbuf = bitbuf; s->bitcnt = (s->bitcnt - len) & 7; return h->symbol[index + (code - first)]; } index += count; first += count; first <<= 1; code <<= 1; len++; } left = (MAXBITS + 1) - len; if (left == 0) break; if (s->incnt == s->inlen) longjmp(s->env, 1); bitbuf = s->in[s->incnt++]; if (left > 8) left = 8; } return -10; } static int puff_construct(struct puff_huffman* h, const short* length, int n) { int len; for (len = 0; len <= MAXBITS; len++) h->count[len] = 0; int symbol; for (symbol = 0; symbol < n; symbol++) (h->count[length[symbol]])++; if (h->count[0] == n) return 0; int left = 1; for (len = 1; len <= MAXBITS; len++) { left <<= 1; left -= h->count[len]; if (left < 0) return left; } short offs[MAXBITS + 1]; offs[1] = 0; for (len = 1; len < MAXBITS; len++) offs[len + 1] = offs[len] + h->count[len]; for (symbol = 0; symbol < n; symbol++) if (length[symbol] != 0) h->symbol[offs[length[symbol]]++] = symbol; return left; } static int puff_codes(struct puff_state* s, const struct puff_huffman* lencode, const struct puff_huffman* distcode) { static const short lens[29] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}; static const short lext[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; static const short dists[30] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; static const short dext[30] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; int symbol; do { symbol = puff_decode(s, lencode); if (symbol < 0) return symbol; if (symbol < 256) { if (s->outcnt == s->outlen) return 1; if (symbol) s->out[s->outcnt] = symbol; s->outcnt++; } else if (symbol > 256) { symbol -= 257; if (symbol >= 29) return -10; int len = lens[symbol] + puff_bits(s, lext[symbol]); symbol = puff_decode(s, distcode); if (symbol < 0) return symbol; unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]); if (dist > s->outcnt) return -11; if (s->outcnt + len > s->outlen) return 1; while (len--) { if (dist <= s->outcnt && s->out[s->outcnt - dist]) s->out[s->outcnt] = s->out[s->outcnt - dist]; s->outcnt++; } } } while (symbol != 256); return 0; } static int puff_fixed(struct puff_state* s) { static int virgin = 1; static short lencnt[MAXBITS + 1], lensym[FIXLCODES]; static short distcnt[MAXBITS + 1], distsym[MAXDCODES]; static struct puff_huffman lencode, distcode; if (virgin) { lencode.count = lencnt; lencode.symbol = lensym; distcode.count = distcnt; distcode.symbol = distsym; short lengths[FIXLCODES]; int symbol; for (symbol = 0; symbol < 144; symbol++) lengths[symbol] = 8; for (; symbol < 256; symbol++) lengths[symbol] = 9; for (; symbol < 280; symbol++) lengths[symbol] = 7; for (; symbol < FIXLCODES; symbol++) lengths[symbol] = 8; puff_construct(&lencode, lengths, FIXLCODES); for (symbol = 0; symbol < MAXDCODES; symbol++) lengths[symbol] = 5; puff_construct(&distcode, lengths, MAXDCODES); virgin = 0; } return puff_codes(s, &lencode, &distcode); } static int puff_dynamic(struct puff_state* s) { static const short order[19] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; int nlen = puff_bits(s, 5) + 257; int ndist = puff_bits(s, 5) + 1; int ncode = puff_bits(s, 4) + 4; if (nlen > MAXLCODES || ndist > MAXDCODES) return -3; short lengths[MAXCODES]; int index; for (index = 0; index < ncode; index++) lengths[order[index]] = puff_bits(s, 3); for (; index < 19; index++) lengths[order[index]] = 0; short lencnt[MAXBITS + 1], lensym[MAXLCODES]; struct puff_huffman lencode = {lencnt, lensym}; int err = puff_construct(&lencode, lengths, 19); if (err != 0) return -4; index = 0; while (index < nlen + ndist) { int symbol; int len; symbol = puff_decode(s, &lencode); if (symbol < 0) return symbol; if (symbol < 16) lengths[index++] = symbol; else { len = 0; if (symbol == 16) { if (index == 0) return -5; len = lengths[index - 1]; symbol = 3 + puff_bits(s, 2); } else if (symbol == 17) symbol = 3 + puff_bits(s, 3); else symbol = 11 + puff_bits(s, 7); if (index + symbol > nlen + ndist) return -6; while (symbol--) lengths[index++] = len; } } if (lengths[256] == 0) return -9; err = puff_construct(&lencode, lengths, nlen); if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1])) return -7; short distcnt[MAXBITS + 1], distsym[MAXDCODES]; struct puff_huffman distcode = {distcnt, distsym}; err = puff_construct(&distcode, lengths + nlen, ndist); if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1])) return -8; return puff_codes(s, &lencode, &distcode); } static int puff(unsigned char* dest, unsigned long* destlen, const unsigned char* source, unsigned long sourcelen) { struct puff_state s = { .out = dest, .outlen = *destlen, .outcnt = 0, .in = source, .inlen = sourcelen, .incnt = 0, .bitbuf = 0, .bitcnt = 0, }; int err; if (setjmp(s.env) != 0) err = 2; else { int last; do { last = puff_bits(&s, 1); int type = puff_bits(&s, 2); err = type == 0 ? puff_stored(&s) : (type == 1 ? puff_fixed(&s) : (type == 2 ? puff_dynamic(&s) : -1)); if (err != 0) break; } while (!last); } *destlen = s.outcnt; return err; } //% END CODE DERIVED FROM puff.{c,h} #define ZLIB_HEADER_WIDTH 2 static int puff_zlib_to_file(const unsigned char* source, unsigned long sourcelen, int dest_fd) { if (sourcelen < ZLIB_HEADER_WIDTH) return 0; source += ZLIB_HEADER_WIDTH; sourcelen -= ZLIB_HEADER_WIDTH; const unsigned long max_destlen = 132 << 20; void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0); if (ret == MAP_FAILED) return -1; unsigned char* dest = (unsigned char*)ret; unsigned long destlen = max_destlen; int err = puff(dest, &destlen, source, sourcelen); if (err) { munmap(dest, max_destlen); errno = -err; return -1; } if (write(dest_fd, dest, destlen) != (ssize_t)destlen) { munmap(dest, max_destlen); return -1; } return munmap(dest, max_destlen); } static int setup_loop_device(unsigned char* data, unsigned long size, const char* loopname, int* loopfd_p) { int err = 0, loopfd = -1; int memfd = syscall(__NR_memfd_create, "syzkaller", 0); if (memfd == -1) { err = errno; goto error; } if (puff_zlib_to_file(data, size, memfd)) { err = errno; goto error_close_memfd; } loopfd = open(loopname, O_RDWR); if (loopfd == -1) { err = errno; goto error_close_memfd; } if (ioctl(loopfd, LOOP_SET_FD, memfd)) { if (errno != EBUSY) { err = errno; goto error_close_loop; } ioctl(loopfd, LOOP_CLR_FD, 0); usleep(1000); if (ioctl(loopfd, LOOP_SET_FD, memfd)) { err = errno; goto error_close_loop; } } close(memfd); *loopfd_p = loopfd; return 0; error_close_loop: close(loopfd); error_close_memfd: close(memfd); error: errno = err; return -1; } static long syz_mount_image(volatile long fsarg, volatile long dir, volatile long flags, volatile long optsarg, volatile long change_dir, volatile unsigned long size, volatile long image) { unsigned char* data = (unsigned char*)image; int res = -1, err = 0, loopfd = -1, need_loop_device = !!size; char* mount_opts = (char*)optsarg; char* target = (char*)dir; char* fs = (char*)fsarg; char* source = NULL; char loopname[64]; if (need_loop_device) { memset(loopname, 0, sizeof(loopname)); snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid); if (setup_loop_device(data, size, loopname, &loopfd) == -1) return -1; source = loopname; } mkdir(target, 0777); char opts[256]; memset(opts, 0, sizeof(opts)); if (strlen(mount_opts) > (sizeof(opts) - 32)) { } strncpy(opts, mount_opts, sizeof(opts) - 32); if (strcmp(fs, "iso9660") == 0) { flags |= MS_RDONLY; } else if (strncmp(fs, "ext", 3) == 0) { bool has_remount_ro = false; char* remount_ro_start = strstr(opts, "errors=remount-ro"); if (remount_ro_start != NULL) { char after = *(remount_ro_start + strlen("errors=remount-ro")); char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1); has_remount_ro = ((before == '\0' || before == ',') && (after == '\0' || after == ',')); } if (strstr(opts, "errors=panic") || !has_remount_ro) strcat(opts, ",errors=continue"); } else if (strcmp(fs, "xfs") == 0) { strcat(opts, ",nouuid"); } res = mount(source, target, fs, flags, opts); if (res == -1) { err = errno; goto error_clear_loop; } res = open(target, O_RDONLY | O_DIRECTORY); if (res == -1) { err = errno; goto error_clear_loop; } if (change_dir) { res = chdir(target); if (res == -1) { err = errno; } } error_clear_loop: if (need_loop_device) { ioctl(loopfd, LOOP_CLR_FD, 0); close(loopfd); } errno = err; return res; } 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 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)) { } } 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(); initialize_vhci(); sandbox_common(); drop_caps(); if (unshare(CLONE_NEWNET)) { } write_file("/proc/sys/net/ipv4/ping_group_range", "0 65535"); initialize_tun(); setup_binderfs(); loop(); exit(1); } #define FS_IOC_SETFLAGS _IOW('f', 2, long) static void remove_dir(const char* dir) { int iter = 0; DIR* dp = 0; retry: while (umount2(dir, MNT_DETACH | UMOUNT_NOFOLLOW) == 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, MNT_DETACH | UMOUNT_NOFOLLOW) == 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, MNT_DETACH | UMOUNT_NOFOLLOW)) 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, MNT_DETACH | UMOUNT_NOFOLLOW)) 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 reset_loop() { char buf[64]; snprintf(buf, sizeof(buf), "/dev/loop%llu", procid); int loopfd = open(buf, O_RDWR); if (loopfd != -1) { ioctl(loopfd, LOOP_CLR_FD, 0); close(loopfd); } } 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 void setup_sysctl() { char mypid[32]; snprintf(mypid, sizeof(mypid), "%d", getpid()); struct { const char* name; const char* data; } files[] = { {"/sys/kernel/debug/x86/nmi_longest_ns", "10000000000"}, {"/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", mypid}, }; for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); i++) { if (!write_file(files[i].name, files[i].data)) printf("write to %s failed: %s\n", files[i].name, strerror(errno)); } } #define SWAP_FILE "./swap-file" #define SWAP_FILE_SIZE (128 * 1000 * 1000) static void setup_swap() { swapoff(SWAP_FILE); unlink(SWAP_FILE); int fd = open(SWAP_FILE, O_CREAT | O_WRONLY | O_CLOEXEC, 0600); if (fd == -1) { exit(1); return; } fallocate(fd, FALLOC_FL_ZERO_RANGE, 0, SWAP_FILE_SIZE); close(fd); char cmdline[64]; sprintf(cmdline, "mkswap %s", SWAP_FILE); if (runcmdline(cmdline)) { exit(1); return; } if (swapon(SWAP_FILE, SWAP_FLAG_PREFER) == 1) { exit(1); return; } } 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 < 6; 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); if (call == 0 || call == 5) break; event_timedwait(&th->done, 50 + (call == 0 ? 4000 : 0) + (call == 5 ? 4000 : 0)); 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) { setup_loop(); int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); reset_loop(); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); 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; } remove_dir(cwdbuf); } } uint64_t r[1] = {0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x200005c0, "ext4\000", 5); memcpy((void*)0x20000000, "./file0\000", 8); memcpy( (void*)0x20001400, "\x6e\x6f\x64\x69\x73\x63\x61\x72\x64\x2c\x62\x61\x72\x72\x69\x65\x72" "\x2c\x6e\x6f\x75\x69\x64\x33\x32\x2c\x67\x72\x70\x71\x75\x6f\x74\x61" "\x2c\x00\xfa\x00\xb6\x1a\x75\xee\x71\x40\xf8\xce\xc7\x26\xc4\x17\xb4" "\xf8\x18\xb3\x5a\x1b\x01\xa4\x3f\xb4\xac\xb8\xdd\xff\xff\x9d\xf9\xff" "\xff\xff\xe8\xf5\xa7\x8b\x59\x4d\xe8\xdf\xef\xea\x29\x3d\xf8\x6e\xfe" "\x49\xce\x1e\xbf\xb1\x83\x7a\xd6\x0b\x3e\x04\x08\x88\x26\xff\xf1\x1b" "\x8e\xde\x48\xde\x24\xf1\x29\xd0\x76\xb3\x59\x78\xc4\x85\xde\x8a\xb6" "\xff\x00\x2d\x4d\xb9\x93\xd1\xb9\x0c\xe6\x67\x33\x41\x4a\x5e\x32\xc4" "\xab\x21\x44\x95\x7e\x87\xd0\xba\xe4\x1d\x35\x93\x03\x61\x37\xc9\xbf" "\xcf\x0b\xbb\x2e\x80\x89\xbb\x42\xbf\x48\xc0\xc4\x30\xc6\x4d\xe2\xda" "\x04\xf0\x02\x00\x00\x00\x00\x00\x00\x00\x8f\x86\x87\xdc\xd7\x4e\xcc" "\xa0\x45\xa1\xcc\xa1\x6c\x81\x24\x0d\x68\xba\x9b\xc8\x25\x48\xfe\xf6" "\x46\x75\x3e\xbe\xea\x45\x76\xf3\x99\xcc\xb0\x83\x41\x8e\xa1\xa8\xd8" "\x12\x6f\xea\xad\x43\x02\x00\x00\x61\x8c\x65\xed\x53\x7b\xbc\x58\xa0" "\x2c\x5b\xce\x89\x03\x8a\x85\x4e\x50\x20\x0b\xa8\x45\x4f\x2c\x66\xff" "\x07\x3d\x0b\x13\x97\x17\x70\x7b\xdb\x40\x0f\x60\x96\x05\x69\x19\xb0" "\xc8\x53\xed\x34\x8f\x82\xac\x7f\x4c\xa7\x11\x46\xe2\xab\x58\x00\x00" "\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x1a\x00\x00\x9c\x04\x6b\x2f" "\x76\x31\x2e\x76\xb1\x95\xd9\x1c\x80\x1c\x59\x5f\x3a\x30\x4a\x00\x00" "\x32\xc0\xe9\x8c\x09\xd5\xb3\x58\x8b\xac\xfd\x2c\x54\xcb\xe4\x62\xd0" "\xe9\x00\x3b\x5d\xc6\x05\x12\x9c\xb1\x84\x9e\x48\x8c\x8d\xff\x07\x70" "\x4b\x70\x47\x50\x5b\x0d\x63\x08\x49\x4c\x23\x44\xd9\x4e\xfe\x79\x56" "\x5f\x6a\x45\xc6\xa4\xb9\xff\xff\xff\xff\xff\xff\xe0\x00\x00\xe4\x98" "\x07\x01\x00\x00\x00\x00\x00\x00\x80\x0f\x5c\x58\x30\x56\x23\xd8\xf1" "\x48\x9b\x0f\xe7\x8a\x40\x72\x81\x5f\x71\x87\x91\x3b\xc3\xd3\x37\x53" "\xc3\x87\x65\xc0\x17\x84\xfa\x06\xd3\x0a\x95\x55\x92\x3b\xfe\x75\x15" "\x05\xe7\x86\x2d\xf7\xa0\xc7\xa4\xc3\xd2\x32\x4e\x2b\xbc\xd0\x89\xec" "\x4b\x92\xb1\x6e\x39\x64\xb7\x09\x46\xbd\x59\x03\x47\xb9\xc3\x37\x8d" "\x80\x6d\x46\x17\x6c\xe9\x3c\x9d\x1e\x21\xb8\x1d\x86\x74\xed\x6b\x6e" "\xa1\x2d\xb6\x01\x2b\xd1\x82\xb5\xef\x66\x4d\x13\x77\x1c\x2c\x93\xf4" "\x15\x7d\x16\xed\xbd\xaf\xa4\xaf\x38\x03\xd9\x18\x30\x39\x63\xeb\x9f" "\x10\xab\x7e\x4c\xed\xd9\x58\xa6\x26\x0d\xff\x5d\x2a\x66\xd9\x06\x26" "\x82\xdc\xa6\xc8\xbe\xca\x29\xc1\x51\x5c\xec\xb1\xc1\x47\x85\x3f\x1f" "\x63\x36\xb3\x71\xe9\xca\x89\x05\x6a\x26\x92\x68\x0c\xbd\xdf\xa5\x96" "\xa0\xfa\x6b\x4a\x0a\xc3\x27\xa8\x03\x1d\xb6\x07\x31\xce\xa8\xc0\x7f" "\x34\xd4\x07\xe4\xe6\xd3\x51\xdf\x16\xdc\x3c\xda\xe5\x1f\x29\x4c\x85" "\xee\x0a\xf4\x96\xac\x3d\xea\xfb\x78\xca\xad\xf8\x6b\x47\x18\xc3\x30" "\xab\x04\xa1\x9a\x96\x8f\xfb\xaf\xf4\xe1\xf4\x2f\x85\xe0\x12\x8e\x51" "\xff\x02\x63\x49\xf4\x10\x2f\x6c\xb3\x1e\x69\xa3\xb1\xb1\x9c\x73\xf4" "\x29\xe4\xc7\x7e\xc1\x02\x59\xaa\xfc\x9c\xd8\x86\xd2\xdd\x48\x78\x8a" "\x1f\x97\xc9\x55\xf5\xb0\x15\x15\x3e\x28\xaa\x46\x9e\x77\x8c\x24\x43" "\x53\x1f\xc6\xad\x76\x1f\x98\xbd\x41\xb1\x2a\x42\xb0\x4f\xb4\x8a\x7c" "\x71\x71\x38\x26\xaa\x57\x1d\xfa\xf5\x76\x0e\x8c\x91\x57\x3a\x0a\x46" "\x76\x38\xf0\x78\xb2\x3e\xc6\x74\xf5\x14\x0c\x60\x6f\x25\x6a\x4c\xa8" "\xc5\x1e\x72\xc0\x07\xf7\x17\x98\xd3\x0d\xb2\x86\x3e\xfe\xd3\x5c\x52" "\xdc\x1c\x26\xd1\x93\xa7\x6b\xf4\x97\x73\xcb\x8b\xc0\x1d\x3c\x61\x60" "\xb2\xd9\x33\xb8\x2b\x67\xb9\xf9\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\xe5\x08\x85\xa6\x5c\x0b\xe8\xa6\xfa\xba\x17\x32\x7f\x9f" "\x42\x41\x55\x0c\xff\x98\x31\x67\x7c\x12\xe6\x7e\xc0\x3a\xbf\x81\x69" "\x8e\x82\x11\x4d\xa0\x94\x75\x78\xf9\x2f\x46\x0b\x45\xd6\x8d\x3b\x72" "\x85\x3d\xd7\xfe\x7e\x86\xdb\x93\xa9\xee\x4e\x87\xb7\x55\x04\x2e\x44" "\x52\x6f\x32\x32\x49\xe8\x2d\xc0\xef\x5c\x5a\x35\xe1\x67\xb0\x8a\x01" "\x5c\xda\x66\x53\xd0\xe8\xa4\x21\x46\x54\x7a\xe3\x2a\xaf\x4e\xca\x75" "\xa6\x7d\xf7\x31\x9b\xc4\xaa\xf5\xb7\xf8\x13", 912); memcpy( (void*)0x20001790, "\x97\xb6\x37\xe2\xc9\xf8\xd7\xa9\xbd\xe1\x9b\xbb\xe5\xe4\xfa\x3f\x79" "\x4d\x6c\xec\x5f\xa1\xf4\x5b\xee\x89\xf3\x8c\xd5\x01\x00\x43\x19\xc9" "\x0c\xf7\x0f\x1f\xfc\x62\xc9\x2e\xda\xbd\xa3\x07\xea\x2f\x80\x79\xe8" "\x7c\x86\x84\x01\x1e\x60\xf2\x23\x80\x44\x77\x07\x00\x58\x44\x4b\x9a" "\xe9\x67\xaf\x91\xf4\x10\xc6\xcf\x75\xfc\xc2\xed\x0b\x13\x17\x7b\xaa" "\xb6\x78\x7c\x5e\x89\x79\xc9\x79\xc6\xa2\x4e\xe7\x8e\x2d\x49\xb1\xcb" "\x62\xc7\x72\x09\xe6\x13\xe7\x49\xdf\x56\xec\x72\x72\x00\x00\x8d\x14" "\xac\x8f\x6c\xa9\x85\x0d\x38\xaf\x57\x41\x90\xac\xda\x5c\x2e\x16\x5c" "\x38\x1d\x00\x00\x00\x00\x0b\x55\x81\x66\x0b\x42\x8f\x32\xc4\x6f\xb1" "\xfa\x7a\x3d\x17\x3b\x3d\x2b\x93\xf1\xab\x36\xa3\x57\x1a\xc5\x1e\x0e" "\x60\x14\x85\x98\x43\xcb\xaf\x8d\x17\x31\xb6\x14\x0e\x42\x93\x08\x6a" "\xb9\xbc\xf1\xab\x88\x07\x3a\x0a\xf0\x6d\xc6\xe9\x8a\xaf\x8f\x08\x92" "\x5b\x84\xbd\xd0\x7a\x8e\x63\xe6\xf1\x32\x75\x03\x84\x1f\x20\xbf\x81" "\xbc\x00\x1b\xda\x94\x7d\x22\xb2\x01\xe9\x56\x7f\xd3\xbc\x24\x38\x58" "\xb3\xea\xf5\x80\x0a\x79\xc3\xb4\xe2\xed\x7c\x24\x1f\x43\x57\x81\x33" "\xc6\x46\xac\x1a\x98\x22\x85\x3b\x76\x95\x49\x37\xa0\x3c\x89\x55\x90" "\xfe\x67\x5b\x01\x4e\xac\xd9\x1a\x2a\x63\x61\xef\xf1\x45\xdc\x47\xb2" "\x0e\x80\xc8\x06\x75\x1b\xf5\xff\x43\x57\xf8\xc0\xf1\x85\xaa\xcb\x8d" "\x13\x5a\x54\x4e\x79\x4c\x5a\xe2\x23\x29\x78\x18\x83\x04\x35\xb8\x67" "\x0a\xa6\xa1\x62\x7a\x06\x6c\x59\x07\xa7\xb4\xbc\xc6\x54\xe3\x5e\x89" "\xe3\xa0\xa1\x05\xdd\x03\xd4\xa0\x0c\xef\xe1\xbe\x4c\xda\x5d\x0f\xcc" "\x92\xc5\xe7\xa6\xa2\x0c\x52\x91\xd4\xf2\x9e\x6a\xe3\x02\x32\x97\xf4" "\xbf\xa6\x6b\xa0\xb1\xf2\xad\x2f\x61\xc7\x74\x2c\x70\xae\x44\x3b\x41" "\xb1\x8c\xf4\x68\xe8\x23\x0e\x53\x89\xb8\xd6\xa7\x05\x14\x97\x0f\x1e" "\xe8\x40\x65\x1b\x49\x2e\xa2\x8a\x9f\xfd\xdf\x4c\xab\x74\x98\x04\x53" "\x70\x03\x60\x38\xd3\xe0\x73\x49\x3c\xdd\xa4\xfe\x84\x7f\x46\xb7\xf9" "\x0d\x60\x2c\xfa\xab\x93\x0f\x01\x77\xf8\xbc\x68\x16\x87\x28\xc8\xa1" "\xbc\xf8\x2c\x13\x1b\xfb\x02\x7c\xe9\xe9\xc8\x0f\xe4\x25\x9d\xf8\xde" "\x9c\x55\x22\x12\xd2\x10\xbd\x0e\xb0\xd6\xab\x57\xf9\x78\x74\x3c\xbb" "\x6c\x85\x8b\x37\xf2\xd7\x8f\x2f\xff\x42\xc1\x12\x79\x92\x53\x03\x56" "\x01\x69\xbe\x12\x2d\x62\x25\x7d\x89\x19\x50\xf4\x79\x71\xcc\xd7\xfa" "\x9f\xab\xd3\x10\x30\xfb\x06\x13\x26\x7f\xc0\x74\xdb\xa2\x34\x5d\xf4" "\x2d\x97\x0d\xf6\xb5\xd6\x68\x22\x24\x94\x26\x93\x1a\xb4\x6b\x99\x05" "\x58\x0f\xf9\x60\x3e\xa0\x18\x32\xa8\x9c\xca\x13\xf9\x3d\x17\xbd\x4a" "\x3c\x28\xeb\xe2\x90\xf6\x56\x26\x9b\xee\xf9\xea\xed\x6a\x7b\xb5\xc9" "\x35\x9d\x81\xc8\xce\xd8\xe2\x37\x49\x38\xdc\xae\xe4\xcd\x2c\x9e\xe9" "\x04\x30\x81\x1c\x73\x7c\x2b\x32\xbc\x75\xe3\x8e\x88\xb0\x1a\x9b\x28" "\xbf\xf7\xe0\x15\xa2\x69\x9e\xe4\x79\xac\x40\x15\x1e\xaa\x32\xfb\x99" "\xba\x9e\x4b\x66\xf6\xc1\x38\x7a\xae\x74\x4e\xdd\x7d\xdf\xef\x38\xf8" "\x4b\x39\x12\xdf\x55\x30\x08\x68\x2b\x5b\x25\xcc\x9e\x24\x0b\x00\x00", 680); memcpy( (void*)0x20000f00, "\x78\x9c\xec\xdd\x4d\x6f\x54\x5f\x19\x00\xf0\x67\xa6\x6f\xd3\x52\x68" "\x41\x16\x6a\x54\x10\x51\x34\x84\x69\x3b\x40\x43\x58\x28\xae\x8c\x31" "\x24\x46\x96\x9a\x40\x6d\x87\xa6\xe9\x4c\xa7\xe9\x4c\x91\x56\x16\xe5" "\x3b\x98\x48\xe2\x4a\x97\x7e\x00\xd7\xac\xdc\xbb\x31\xba\x73\x83\x0b" "\x13\x5f\x1a\x0d\x25\x71\x31\xff\xdc\x3b\xb7\x65\x28\x1d\xda\x3f\x7d" "\x19\xd2\xf9\xfd\x92\x9b\x7b\xcf\x39\x33\xf3\x9c\xc3\xe4\x9e\xc3\x3c" "\x84\x7b\x02\xe8\x59\x97\x23\x62\x23\x22\x06\x23\xe2\x51\x44\x8c\x65" "\xf5\xb9\xec\x88\x7b\xad\x23\x79\xdd\xeb\xcd\x67\xb3\x5b\x9b\xcf\x66" "\x73\xd1\x6c\x3e\xf8\x77\x2e\x6d\x4f\xea\xa2\xed\x3d\x89\x33\xd9\x67" "\x16\x22\xe2\x27\x3f\x88\xf8\x79\xee\xfd\xb8\xf5\xb5\xf5\xc5\x99\x4a" "\xa5\xbc\x92\x95\x27\x1a\xd5\xe5\x89\xfa\xda\xfa\x8d\x85\xea\xcc\x7c" "\x79\xbe\xbc\x54\x2a\x4d\x4f\x4d\x4f\xde\xb9\x79\xbb\x74\x64\x63\xbd" "\x54\x1d\xcc\xae\xbe\xfa\xea\x4f\x1b\xdf\xf9\x65\xd2\xad\xd1\xac\xa6" "\x7d\x1c\x47\xa9\x35\xf4\x81\x9d\x38\x89\xfe\x88\xf8\xd1\x71\x04\xeb" "\x82\xbe\x6c\x3c\x83\xdd\xee\x08\x1f\x25\x1f\x11\x17\x22\xe2\x4a\x7a" "\xff\x8f\x45\x5f\xfa\x6d\x02\x00\xa7\x59\xb3\x39\x16\xcd\xb1\xf6\x32" "\x00\x70\xda\xe5\xd3\x1c\x58\x2e\x5f\xcc\x72\x01\xa3\x91\xcf\x17\x8b" "\xad\x1c\xde\xc5\x18\xc9\x57\x6a\xf5\xc6\xf5\xc7\xb5\xd5\xa5\xb9\x56" "\xae\x6c\x3c\x06\xf2\x8f\x17\x2a\xe5\xc9\x2c\x57\x38\x1e\x03\xb9\xa4" "\x3c\x95\x5e\xbf\x2d\x97\x76\x95\x6f\x46\xc4\xf9\x88\xf8\xd5\xd0\x70" "\x5a\x2e\xce\xd6\x2a\x73\xdd\xfc\x8b\x0f\x00\xf4\xb0\x33\xbb\xd6\xff" "\xff\x0d\xb5\xd6\x7f\x00\xe0\x94\x2b\x74\xbb\x03\x00\xc0\x89\xb3\xfe" "\x03\x40\xef\xb1\xfe\x03\x40\xef\xb1\xfe\x03\x40\xef\xb1\xfe\x03\x40" "\xef\xb1\xfe\x03\x40\xef\xb1\xfe\x03\x40\x4f\xf9\xf1\xfd\xfb\xc9\xd1" "\xdc\xca\x9e\x7f\x3d\xf7\x64\x6d\x75\xb1\xf6\xe4\xc6\x5c\xb9\xbe\x58" "\xac\xae\xce\x16\x67\x6b\x2b\xcb\xc5\xf9\x5a\x6d\x3e\x7d\x66\x4f\x75" "\xbf\xcf\xab\xd4\x6a\xcb\x53\xb7\x62\xf5\xe9\xf8\x77\x97\xeb\x8d\x89" "\xfa\xda\xfa\xc3\x6a\x6d\x75\xa9\xf1\x30\x7d\xae\xf7\xc3\xf2\xc0\x89" "\x8c\x0a\x00\xf8\x90\xf3\x97\x5e\xfe\x35\x17\x11\x1b\x77\x87\xd3\x23" "\xda\xf6\x72\xb0\x56\xc3\xe9\x96\xef\x76\x07\x80\xae\xe9\xeb\x76\x07" "\x80\xae\xb1\xdb\x17\xf4\xae\x43\xfc\xc6\x97\x1e\x80\x53\x62\x8f\x2d" "\x7a\xdf\x51\x88\x88\xe1\xdd\x95\xcd\x66\xb3\x79\x7c\x5d\x02\x8e\xd9" "\xb5\x2f\xc9\xff\x43\xaf\x92\xff\x87\xde\x25\xff\x0f\xbd\x4b\xfe\x1f" "\x7a\x57\xb3\x99\x3b\xe8\x9e\xff\x71\xd0\x17\x02\x00\x9f\x36\x39\x7e" "\xa0\xc3\xbf\xff\x5f\xc8\xce\xbf\xcf\x1e\x11\xf2\xb3\xb9\xdd\xaf\x78" "\x71\x9c\xbd\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x4f\xdb\xf6\xfe\xbf\xc5" "\x6c\x2f\xf0\xd1\xc8\xe7\x8b\xc5\x88\xb3\x11\x31\x1e\x03\xb9\xc7\x0b" "\x95\xf2\x64\x44\x9c\x8b\x88\xbf\x0c\x0d\x0c\x25\xe5\xa9\x2e\xf7\x19" "\x00\x38\xac\xfc\x3f\x72\xd9\xfe\x5f\xd7\xc6\xae\x8e\xee\x6e\x1d\xcc" "\xbd\x19\x4a\xcf\x11\xf1\x8b\xdf\x3c\xf8\xf5\xd3\x99\x46\x63\xe5\xcf" "\x49\xfd\x7f\x76\xea\x1b\x2f\xb2\xfa\x52\x37\xfa\x0f\x00\xec\x67\x7b" "\x9d\x4e\xcf\x6d\x3f\xe4\x5f\x6f\x3e\x9b\xdd\x3e\x4e\xb2\x3f\xff\xfc" "\x7e\x44\x14\x5a\xf1\xb7\x36\x07\x63\x6b\x27\x7e\x7f\xf4\xa7\xe7\x42" "\x0c\x44\xc4\xc8\x7f\x73\x59\xb9\x25\xd7\x96\xbb\x38\x8c\x8d\xe7\x11" "\xf1\xc5\xbd\xc6\x9f\x8b\xd1\x34\x07\xd2\xda\xf9\x74\x77\xfc\x24\xf6" "\xd9\x13\x8d\x9f\x7f\x27\x7e\x3e\x6d\x6b\x9d\x93\x3f\x8b\x2f\x1c\x41" "\x5f\xa0\xd7\xbc\x4c\xe6\x9f\x7b\x7b\xdd\x7f\xf9\xb8\x9c\x9e\xf7\xbe" "\xff\x0b\xe9\x0c\x75\x78\xd9\xfc\x97\x7c\xd4\xec\x56\x3a\x07\xbe\x8d" "\xbf\x3d\xff\xf5\x75\x98\xff\x2e\x1f\x34\xc6\xad\x3f\xfe\xb0\x75\x35" "\xfc\x7e\xdb\xf3\x88\x2f\xf7\x47\x6c\xc7\xde\x6a\x9b\x7f\xb6\xe3\xe7" "\x3a\xc4\xbf\x7a\xc0\xf8\x7f\xfb\xca\xd7\xae\x74\x6a\x6b\xfe\x36\xe2" "\x5a\xec\x1d\xbf\x3d\xd6\x44\xa3\xba\x3c\x51\x5f\x5b\xbf\xb1\x50\x9d" "\x99\x2f\xcf\x97\x97\x4a\xa5\xe9\xa9\xe9\xc9\x3b\x37\x6f\x97\x26\xd2" "\x1c\xf5\x44\xe7\xd5\xe0\x5f\x77\xaf\x9f\xeb\xd4\x96\x8c\x7f\xa4\x43" "\xfc\xc2\x3e\xe3\xff\xe6\x01\xc7\xff\xbb\xff\x3f\xfa\xe9\xd7\x3f\x10" "\xff\xdb\xdf\xd8\x2b\x7e\x3e\x2e\x7e\x20\x7e\xb2\x26\x7e\xeb\x80\xf1" "\x67\x46\xfe\x50\xe8\xd4\x96\xc4\x9f\xeb\x30\xfe\xfd\xbe\xff\xeb\x07" "\x8c\xff\xea\xef\xeb\xef\x6d\x1b\x0e\x00\x74\x4f\x7d\x6d\x7d\x71\xa6" "\x52\x29\xaf\xb8\x70\xe1\xe2\x30\x17\xdf\x3b\xa9\x58\x83\xf1\xb9\xde" "\xd5\x6c\x7e\x54\xac\x4e\x33\xc6\x51\x64\xdd\x80\x4f\xc1\xce\x4d\x1f" "\x11\x6f\xba\xdd\x19\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x60" "\x4f\x27\xf1\x3f\x96\xba\x3d\x46\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x4e\xaf\xcf\x02\x00\x00\xff\xff\x77\x94\xd3" "\xd4", 1242); syz_mount_image(/*fs=*/0x200005c0, /*dir=*/0x20000000, /*flags=*/0x200810, /*opts=*/0x20001400, /*chdir=*/4, /*size=*/0x4da, /*img=*/0x20000f00); break; case 1: memcpy((void*)0x20000100, "./bus\000", 6); syscall(__NR_creat, /*file=*/0x20000100ul, /*mode=*/0ul); break; case 2: memcpy((void*)0x20001280, "/dev/loop", 9); *(uint8_t*)0x20001289 = 0x30 + procid * 1; *(uint8_t*)0x2000128a = 0; memcpy((void*)0x20001240, "./bus\000", 6); syscall(__NR_mount, /*src=*/0x20001280ul, /*dst=*/0x20001240ul, /*type=*/0ul, /*flags=*/0x1000ul, /*data=*/0ul); break; case 3: memcpy((void*)0x20000400, "./bus\000", 6); res = syscall(__NR_open, /*file=*/0x20000400ul, /*flags=*/0x14103eul, /*mode=*/0ul); if (res != -1) r[0] = res; break; case 4: syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x600000ul, /*prot=*/0x3000002ul, /*flags=*/0x11ul, /*fd=*/r[0], /*offset=*/0ul); break; case 5: memcpy((void*)0x20000000, "ext4\000", 5); memcpy((void*)0x20000140, "./mnt\000", 6); memcpy((void*)0x200000c0, "noinit_itable,data_err=abort,delalloc,lazytime,nosuid=", 54); sprintf((char*)0x200000f6, "0x%016llx", (long long)0xee00); memset((void*)0x20000108, 0, 2); memcpy( (void*)0x20000280, "\x78\x9c\xec\xdd\x3f\x68\x24\x55\x1c\x07\xf0\xef\xcc\xee\x7a\xe6\x6e" "\xd1\x53\x1b\x41\xfc\x03\x22\xa2\x81\x70\x76\x82\xcd\xd9\x28\x1c\xc8" "\x71\x8a\x08\x2a\x9c\x88\xd8\x28\x77\x42\x4c\xd0\x2a\xb1\xb2\xb1\xd0" "\x5a\x25\x95\x4d\x10\x3b\xa3\xa5\xa4\x09\x36\x8a\x60\x15\x35\x45\x6c" "\x84\x18\x2c\x0c\x16\x5a\xac\xcc\x4e\x22\x31\xd9\x60\x74\xb3\xbb\x92" "\xf9\x7c\x60\x76\x66\x76\xdf\x9b\xdf\x1b\x66\xbe\x6f\xb7\x19\x36\x40" "\x63\x9d\x4f\x72\x31\x49\x2b\xc9\x74\x92\x4e\x92\x62\x7f\x83\x7b\xea" "\xe5\xfc\xee\xee\xd2\xd4\xda\xd5\xa4\xd7\x7b\xea\x97\xa2\xdf\xae\xde" "\xaf\xed\xf5\x3b\x97\x64\x31\xc9\xc3\x49\x56\xcb\x22\xaf\xb4\x93\xf9" "\x95\xe7\x36\x7f\x5b\x7f\xfc\xfe\x77\xe6\x3a\xf7\x7d\xb4\xf2\xec\xd4" "\x58\x4f\x72\xd7\xf6\xe6\xc6\x13\x3b\x1f\x5e\x7e\xfb\xd3\x4b\x0f\xcd" "\x7f\xfd\xed\xd6\xe5\x22\x17\xd3\xfd\xdb\x79\x9d\xbc\x62\xc0\x7b\xed" "\x22\xb9\x75\x14\xc5\xfe\x27\x8a\xf6\xa4\x47\xc0\x71\x5c\x79\xe3\x93" "\xef\xaa\xdc\xdf\x96\xe4\xde\x7e\xfe\x3b\x29\x53\x5f\xbc\x77\x67\x6f" "\x58\xed\xe4\xc1\x0f\x8e\xea\xfb\xde\xcf\xdf\xdc\x31\xce\xb1\x02\x27" "\xaf\xd7\xeb\x54\xdf\x81\x8b\x3d\xa0\x71\xca\x24\xdd\x14\xe5\x4c\x92" "\x7a\xbb\x2c\x67\x66\xea\xdf\xf0\xdf\xb7\xce\x96\xaf\x5e\x9f\x7d\x7d" "\xfa\xe5\xeb\x73\xd7\x5e\x9a\xf4\x4c\x05\x9c\x94\x6e\xb2\xf1\xd8\xe7" "\x67\x3e\x3b\x77\x20\xff\x3f\xb5\xea\xfc\x03\xa7\x57\x95\xff\xa7\xaf" "\x2c\xff\x50\x6d\xef\xb4\x06\xb5\x78\x72\x6b\xec\x83\x02\x46\xeb\xce" "\x7a\x55\xe5\x7f\xfa\x85\x85\x07\x72\x64\xfe\x81\xd3\x4a\xfe\xa1\xb9" "\xe4\x1f\x9a\x4b\xfe\xa1\xb9\xe4\x1f\x9a\x4b\xfe\xa1\xb9\xe4\x1f\x9a" "\x4b\xfe\xa1\xb9\xe4\x1f\x9a\x4b\xfe\xa1\xb9\xf6\xe7\x1f\x00\x68\x96" "\xde\x99\x49\x3f\x81\x0c\x4c\xca\xa4\xe7\x1f\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\xe0\xb0\xa5\xa9\xb5\xab\x7b\xcb\xb8" "\x6a\x7e\xf9\x7e\xb2\xfd\x68\x92\xf6\xa0\xfa\xad\xfe\xff\x11\x27\x37" "\xf6\x5f\xcf\xfe\x5a\x54\xcd\xfe\x52\xd4\xdd\x86\xf2\xfc\xdd\x43\x1e" "\x60\x48\x1f\x8f\xe6\xe9\xeb\x37\x6f\x3e\x66\xc3\x9b\x7e\x1c\x49\xfd" "\x63\xfb\xea\xae\xc9\xd6\x5f\xb8\x96\x2c\xbe\x95\xe4\x42\xbb\x7d\xf8" "\xfe\x2b\x76\xef\xbf\xff\xee\x96\x7f\xf8\xbc\xf3\xe2\x90\x05\xfe\xa5" "\xe2\xc0\xfe\x23\xcf\x8c\xb7\xfe\x41\x7f\x2c\x4f\xb6\xfe\xa5\xf5\xe4" "\x8b\x6a\xfe\xb9\x30\x68\xfe\x29\x73\x7b\x7f\x3d\x78\xfe\xe9\x56\xd7" "\x6f\xc8\xfa\xaf\xfd\x3e\xe4\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x18\x9b\x3f\x03\x00\x00\xff\xff\xf4\x61\x6f\x0c", 591); syz_mount_image(/*fs=*/0x20000000, /*dir=*/0x20000140, /*flags=*/0x10, /*opts=*/0x200000c0, /*chdir=*/-1, /*size=*/0x24f, /*img=*/0x20000280); 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); setup_sysctl(); setup_cgroups(); setup_swap(); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; }