// https://syzkaller.appspot.com/bug?id=32bb6b1e54413e5328f301cce8f18a0e62297890 // 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 #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 == EBADF || errno == EBADFD) return -1; exit(1); } return rv; } static void flush_tun() { char data[1000]; while (read_tun(&data[0], sizeof(data)) != -1) { } } #define MAX_FDS 30 //% 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 void reset_loop_device(const char* loopname) { int loopfd = open(loopname, O_RDWR); if (loopfd == -1) { return; } if (ioctl(loopfd, LOOP_CLR_FD, 0)) { } close(loopfd); } 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, 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) { int loopfd; memset(loopname, 0, sizeof(loopname)); snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid); if (setup_loop_device(data, size, loopname, &loopfd) == -1) return -1; close(loopfd); 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) reset_loop_device(loopname); errno = err; return res; } static void setup_binderfs(); static void setup_fusectl(); static void sandbox_common_mount_tmpfs(void) { write_file("/proc/sys/fs/mount-max", "100000"); if (mkdir("./syz-tmp", 0777)) exit(1); if (mount("", "./syz-tmp", "tmpfs", 0, NULL)) exit(1); if (mkdir("./syz-tmp/newroot", 0777)) exit(1); if (mkdir("./syz-tmp/newroot/dev", 0700)) exit(1); unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE; if (mount("/dev", "./syz-tmp/newroot/dev", NULL, bind_mount_flags, NULL)) exit(1); if (mkdir("./syz-tmp/newroot/proc", 0700)) exit(1); if (mount("syz-proc", "./syz-tmp/newroot/proc", "proc", 0, NULL)) exit(1); if (mkdir("./syz-tmp/newroot/selinux", 0700)) exit(1); const char* selinux_path = "./syz-tmp/newroot/selinux"; if (mount("/selinux", selinux_path, NULL, bind_mount_flags, NULL)) { if (errno != ENOENT) exit(1); if (mount("/sys/fs/selinux", selinux_path, NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); } if (mkdir("./syz-tmp/newroot/sys", 0700)) exit(1); if (mount("/sys", "./syz-tmp/newroot/sys", 0, bind_mount_flags, NULL)) exit(1); if (mount("/sys/kernel/debug", "./syz-tmp/newroot/sys/kernel/debug", NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); if (mount("/sys/fs/smackfs", "./syz-tmp/newroot/sys/fs/smackfs", NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); if (mount("/proc/sys/fs/binfmt_misc", "./syz-tmp/newroot/proc/sys/fs/binfmt_misc", NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); if (mkdir("./syz-tmp/pivot", 0777)) exit(1); if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) { if (chdir("./syz-tmp")) exit(1); } else { if (chdir("/")) exit(1); if (umount2("./pivot", MNT_DETACH)) exit(1); } if (chroot("./newroot")) exit(1); if (chdir("/")) exit(1); setup_binderfs(); setup_fusectl(); } static void setup_fusectl() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } } static void setup_binderfs() { if (mkdir("/dev/binderfs", 0777)) { } if (mount("binder", "/dev/binderfs", "binder", 0, NULL)) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); if (getppid() == 1) exit(1); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } static int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static void drop_caps(void) { struct __user_cap_header_struct cap_hdr = {}; struct __user_cap_data_struct cap_data[2] = {}; cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; cap_hdr.pid = getpid(); if (syscall(SYS_capget, &cap_hdr, &cap_data)) exit(1); const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE); cap_data[0].effective &= ~drop; cap_data[0].permitted &= ~drop; cap_data[0].inheritable &= ~drop; if (syscall(SYS_capset, &cap_hdr, &cap_data)) exit(1); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); sandbox_common(); drop_caps(); if (unshare(CLONE_NEWNET)) { } write_file("/proc/sys/net/ipv4/ping_group_range", "0 65535"); initialize_tun(); sandbox_common_mount_tmpfs(); loop(); exit(1); } #define FS_IOC_SETFLAGS _IOW('f', 2, long) static void remove_dir(const char* dir) { int iter = 0; DIR* dp = 0; const int umount_flags = MNT_FORCE | UMOUNT_NOFOLLOW; retry: while (umount2(dir, umount_flags) == 0) { } dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exit(1); } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); while (umount2(filename, umount_flags) == 0) { } struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EPERM) { int fd = open(filename, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exit(1); if (umount2(filename, umount_flags)) exit(1); } } closedir(dp); for (int i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EPERM) { int fd = open(dir, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, umount_flags)) exit(1); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exit(1); } } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); for (int i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } static void 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(); write_file("/proc/self/oom_score_adj", "1000"); flush_tun(); if (symlink("/dev/binderfs", "./binderfs")) { } } static void close_fds() { for (int fd = 3; fd < MAX_FDS; fd++) close(fd); } static const char* setup_binfmt_misc() { if (mount(0, "/proc/sys/fs/binfmt_misc", "binfmt_misc", 0, 0) && errno != EBUSY) { return NULL; } if (!write_file("/proc/sys/fs/binfmt_misc/register", ":syz0:M:0:\x01::./file0:") || !write_file("/proc/sys/fs/binfmt_misc/register", ":syz1:M:1:\x02::./file0:POC")) return "write(/proc/sys/fs/binfmt_misc/register) failed"; return NULL; } static const char* setup_usb() { if (chmod("/dev/raw-gadget", 0666)) return "failed to chmod /dev/raw-gadget"; return NULL; } #define SWAP_FILE "./swap-file" #define SWAP_FILE_SIZE (128 * 1000 * 1000) static const char* setup_swap() { swapoff(SWAP_FILE); unlink(SWAP_FILE); int fd = open(SWAP_FILE, O_CREAT | O_WRONLY | O_CLOEXEC, 0600); if (fd == -1) return "swap file open failed"; fallocate(fd, FALLOC_FL_ZERO_RANGE, 0, SWAP_FILE_SIZE); close(fd); char cmdline[64]; sprintf(cmdline, "mkswap %s", SWAP_FILE); if (runcmdline(cmdline)) return "mkswap failed"; if (swapon(SWAP_FILE, SWAP_FLAG_PREFER) == 1) return "swapon failed"; return NULL; } 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) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } 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 + (call == 0 ? 4000 : 0) + (call == 6 ? 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) { 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 (;;) { sleep_ms(10); if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x20000180, "ext4\000", 5); memcpy((void*)0x20001300, "./file2\000", 8); memcpy((void*)0x20000680, "prjquota", 8); *(uint8_t*)0x20000688 = 0x2c; memcpy((void*)0x20000689, "grpquota", 8); *(uint8_t*)0x20000691 = 0x2c; memcpy((void*)0x20000692, "debug_want_extra_isize", 22); *(uint8_t*)0x200006a8 = 0x3d; sprintf((char*)0x200006a9, "0x%016llx", (long long)0x5c); *(uint8_t*)0x200006bb = 0x2c; memcpy((void*)0x200006bc, "sysvgroups", 10); *(uint8_t*)0x200006c6 = 0x2c; memcpy((void*)0x200006c7, "lazytime", 8); *(uint8_t*)0x200006cf = 0x2c; memcpy((void*)0x200006d0, "errors=continue", 15); *(uint8_t*)0x200006df = 0x2c; memcpy((void*)0x200006e0, "grpjquota=", 10); *(uint8_t*)0x200006ea = 0x2c; *(uint8_t*)0x200006eb = 0; memcpy( (void*)0x20000980, "\x78\x9c\xec\xdb\xcf\x6f\x14\x55\x1c\x00\xf0\xef\xcc\xb6\x45\x41\x68" "\x45\x14\x41\x54\x14\x8d\x8d\x3f\x5a\x5a\x50\x39\x78\xd1\x68\xe2\x41" "\x13\x13\x3d\xe0\xb1\xb6\x85\x00\x0b\x35\xb4\x26\x42\x88\x56\x63\xf0" "\x68\x48\xbc\x1b\x8f\x26\xfe\x05\x9e\xf4\x62\xd4\x93\x89\x57\xbc\x1b" "\x12\xa2\x5c\x40\x4f\x6b\x66\x77\xa6\x6c\x97\xdd\xed\x2e\x94\x5d\xe8" "\x7e\x3e\xc9\x36\xef\xed\xbc\xe9\x7b\xdf\x9d\x79\x33\x6f\xe6\xcd\x04" "\x30\xb0\xf6\x66\x7f\x92\x88\xfb\x22\xe2\x62\x44\x8c\xd6\xb2\x2b\x2a" "\x79\xa1\xac\xdc\xb5\x2b\xe7\x66\xff\xbd\x72\x6e\x36\x89\x4a\xe5\xdd" "\xbf\x93\x6a\xb9\xab\x57\xce\xcd\x16\x65\x8b\xf5\xb6\xe4\x99\xf1\x34" "\x22\xfd\x22\xc9\x2b\x59\x6d\xf1\xcc\xd9\x13\x33\xe5\xf2\xfc\xe9\x3c" "\x3f\xb9\x74\xf2\xc3\xc9\xc5\x33\x67\x5f\x38\x76\x72\xe6\xe8\xfc\xd1" "\xf9\x53\xd3\x87\x0e\x1d\x3c\x30\xf5\xf2\x4b\xd3\x2f\xae\x4b\x9c\x59" "\x7c\x57\x77\x7f\xb2\xb0\x67\xd7\x9b\xef\x5f\x78\x7b\xf6\xf0\x85\x0f" "\x7e\xfd\x3e\xc9\xbf\x8f\x86\x38\x3a\x31\xdc\x41\x99\xbd\x59\xe0\xff" "\x54\xaa\x1a\x97\x3d\xdd\x4d\x65\x77\x81\xad\x75\xe9\x64\xa8\x8f\x0d" "\xa1\x2b\xa5\x88\x18\xca\xf7\xe7\x8b\x31\x1a\xa5\xb8\xbe\xf1\x46\xe3" "\x8d\xcf\xfb\xda\x38\xe0\xb6\xca\xce\x4d\x9b\x5a\x2f\x5e\xae\x00\x1b" "\x58\x12\xfd\x6e\x01\xd0\x1f\xc5\x89\x3e\xbb\xfe\x2d\x3e\x3d\x1a\x7a" "\xdc\x11\x2e\xbf\x5a\xbb\x00\xca\xe2\xbe\x96\x7f\x6a\x4b\x86\x22\xcd" "\xcb\x0c\x37\x5c\xdf\xae\xa7\xbd\x11\x71\x78\xf9\xbf\x6f\xb2\x4f\xdc" "\xc4\x7d\x08\x00\x80\x6e\xfd\x98\x8d\x7f\x9e\x6f\x36\xfe\x4b\xa3\x7e" "\x8c\xb8\x2d\x9f\x1b\x1a\x8b\x88\xfb\x23\x62\x7b\x44\x3c\x10\x11\x3b" "\x22\xe2\xc1\x88\x78\x28\x22\x76\x46\xc4\xc3\x9d\x55\x7b\xbc\x48\x34" "\x4e\x0d\xdd\x38\xfe\x49\x2f\xdd\x6a\x8c\xed\x64\xe3\xbf\x57\xf2\xb9" "\xad\xd5\xe3\xbf\x62\xf4\x17\x63\xa5\x3c\xb7\xb5\x1a\xff\x70\x72\xe4" "\x58\x79\x7e\x7f\xfe\x9b\x8c\xc7\xf0\xa6\x2c\x3f\xd5\xa6\x8e\x9f\x5e" "\xff\xe3\xab\x56\xcb\xea\xc7\x7f\xd9\x27\xab\xff\xf0\xaa\xc9\xa5\xf4" "\xd2\x50\xc3\x0d\xba\xb9\x99\xa5\x99\x8e\x26\xa0\x3a\x70\xf9\xb3\x88" "\xdd\x43\xcd\xe2\x4f\x56\x66\x02\x92\x88\xd8\x15\x11\xbb\xbb\xfb\xd7" "\xdb\x8a\xc4\xb1\x67\xbf\xdb\xd3\xaa\x50\xd3\xf8\xf3\xb1\xf0\x9a\xd6" "\x61\x9e\xa9\xf2\x6d\xc4\x33\xb5\xed\xbf\x1c\x0d\xf1\x17\x92\xf6\xf3" "\x93\x93\xf7\x44\x79\x7e\xff\x64\xb1\x57\xdc\xe8\xb7\xdf\xcf\xbf\xd3" "\xaa\xfe\x5b\x8a\x7f\x1d\x64\xdb\x7f\xf3\xea\xfd\xbf\xb1\xc8\x58\x52" "\x3f\x5f\xbb\xd8\x7d\x1d\xe7\xff\xfc\xb2\xe5\x35\xcd\xda\xf1\x37\xdf" "\xff\x47\x92\xf7\xaa\xc7\xa3\x91\xfc\xbb\x8f\x67\x96\x96\x4e\x4f\x45" "\x8c\x24\x6f\xd5\xd6\xaa\xff\x7e\xfa\xfa\xba\x45\xbe\x28\x9f\xc5\x3f" "\xbe\xaf\x79\xff\xdf\x9e\xaf\x93\xc5\xff\x48\x44\x64\x3b\xf1\xa3\x11" "\xf1\x58\x44\x3c\x9e\xb7\xfd\x89\x88\x78\x32\x22\xf6\xb5\x89\xff\x97" "\xd7\x9e\x3a\xde\x65\xfc\x49\x9b\x7f\xb7\xae\xb2\xf8\xe7\x9a\x1e\xff" "\x56\x9a\xd0\xb0\xfd\xbb\x4f\x94\x4e\xfc\xfc\x43\xab\xfa\x3b\xdb\xfe" "\x07\xab\xa9\xf1\xfc\x9b\xea\xf1\x6f\x0d\x9d\x36\xf0\x56\x7e\x3b\x00" "\x00\x00\xb8\x5b\xa4\xd5\x67\xe0\x93\x74\x62\x25\x9d\xa6\x13\x13\xb5" "\x67\xf8\x77\xc4\xe6\xb4\xbc\xb0\xb8\xf4\xdc\x91\x85\x8f\x4e\xcd\xd5" "\x9e\x95\x1f\x8b\xe1\xb4\xb8\xd3\x35\x5a\x77\x3f\x74\x2a\x59\xce\x9f" "\x26\x8e\xea\xd5\xf7\x74\x7e\xaf\xb8\x58\x7e\x20\xbf\x6f\xfc\x75\xe9" "\xde\x6a\x7e\x62\x76\xa1\x3c\xd7\xe7\xd8\x61\xd0\x6d\xa9\xeb\xff\xdb" "\x77\x5e\xef\xff\x99\xbf\x4a\xab\xcb\xae\xcc\x88\x78\xbf\x03\x36\x0e" "\xfd\x19\x06\x57\x63\xff\x4f\xfb\xd4\x0e\xa0\xf7\x9c\xff\x61\x70\xe9" "\xff\x30\xb8\xf4\x7f\x18\x5c\xcd\xfa\xff\xa7\x0d\xf9\x52\x8f\xda\x02" "\xf4\x96\xf3\x3f\x0c\xae\xb5\xfa\x7f\xcf\xde\x46\x02\x7a\xce\xf9\x1f" "\x06\x97\xfe\x0f\x03\xa9\xdd\xbb\xf1\xc9\xcd\xbf\xf2\x2f\xd1\xdf\x44" "\x2c\xdf\xfe\x2a\xd2\x3b\x22\xd2\xdb\x95\x18\xe9\xa0\x83\x6c\xe8\xc4" "\x8d\xc7\x8a\x21\xe3\x04\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\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\xe0\x2e\xf4\x7f\x00" "\x00\x00\xff\xff\x18\xe0\xef\x43", 1130); syz_mount_image(/*fs=*/0x20000180, /*dir=*/0x20001300, /*flags=*/0, /*opts=*/0x20000680, /*chdir=*/1, /*size=*/0x46a, /*img=*/0x20000980); break; case 1: memcpy((void*)0x20000000, "./file0\000", 8); syscall(__NR_chdir, /*dir=*/0x20000000ul); break; case 2: memcpy((void*)0x20000040, "./bus\000", 6); syscall(__NR_creat, /*file=*/0x20000040ul, /*mode=*/0ul); break; case 3: memcpy((void*)0x20000380, "/dev/loop", 9); *(uint8_t*)0x20000389 = 0x30 + procid * 1; *(uint8_t*)0x2000038a = 0; memcpy((void*)0x20000140, "./bus\000", 6); syscall(__NR_mount, /*src=*/0x20000380ul, /*dst=*/0x20000140ul, /*type=*/0ul, /*flags=MS_BIND*/ 0x1000ul, /*data=*/0ul); break; case 4: memcpy((void*)0x200003c0, "./bus\000", 6); res = syscall( __NR_open, /*file=*/0x200003c0ul, /*flags=O_NONBLOCK|O_NOCTTY|O_DIRECT|O_CLOEXEC|O_RDWR*/ 0x84902ul, /*mode=*/0ul); if (res != -1) r[0] = res; break; case 5: syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0xb36000ul, /*prot=PROT_WRITE*/ 2ul, /*flags=MAP_FIXED|MAP_SHARED*/ 0x11ul, /*fd=*/r[0], /*offset=*/0ul); break; case 6: memcpy((void*)0x20000100, "ext4\000", 5); memcpy((void*)0x20000500, "./file0\000", 8); *(uint8_t*)0x20000080 = 0; memcpy( (void*)0x20000a80, "\x78\x9c\xec\xdd\xcf\x6f\x23\x57\x1d\x00\xf0\xef\x4c\x7e\x76\x9b\x36" "\xbb\xd0\x03\x54\xc0\x2e\x50\x58\xd0\x6a\xed\x8d\xb7\x5d\x55\xbd\xb4" "\x7b\x01\xa1\xaa\x12\xa2\xe2\x80\x38\x6c\x43\xe2\x8d\x42\xec\x38\xc4" "\x4e\x69\x42\x24\xd2\xbf\x01\x24\x90\x38\xc1\x9f\xc0\x01\x89\x03\x52" "\x4f\x1c\xb8\x71\x44\xe2\x80\x90\xca\x01\x69\x81\x08\xb4\x41\x02\xc9" "\x68\xc6\x93\xd4\x4d\x9c\xc6\x34\x8e\x0d\xf1\xe7\x23\x8d\x66\xde\x3c" "\xfb\x7d\xdf\x5b\xef\xcc\x9b\x79\x76\xe6\x05\x30\xb6\x6e\x44\xc4\x5e" "\x44\x4c\x47\xc4\x1b\x11\x31\x5f\xec\x4f\x8a\x25\x5e\xe9\x2c\xd9\xeb" "\x1e\xef\xef\x2e\x1d\xec\xef\x2e\x25\xd1\x6e\xbf\xfe\xd7\x24\xcf\xcf" "\xf6\x45\xd7\x7b\x32\x4f\x16\x65\xce\x46\xc4\xd7\xbe\x1c\xf1\xad\xe4" "\x64\xdc\xe6\xf6\xce\xda\x62\xad\x56\xdd\x2c\xd2\xe5\x56\x7d\xa3\xdc" "\xdc\xde\xb9\xbd\x5a\x5f\x5c\xa9\xae\x54\xd7\x2b\x95\x7b\x0b\xf7\xee" "\xbc\x78\xf7\x85\xca\xc0\xda\x7a\xbd\xfe\xf3\x47\x5f\x5a\x7d\xf5\xeb" "\xbf\xfa\xe5\x27\xdf\xfd\xed\xde\x17\xbf\x97\x55\x6b\xae\xc8\xeb\x6e" "\xc7\x20\x75\x9a\x3e\x75\x14\x27\x33\x19\x11\xaf\x5e\x44\xb0\x11\x98" "\x28\xd6\xd3\x23\xae\x07\x1f\x4e\x1a\x11\x1f\x89\x88\xcf\xe4\xc7\xff" "\x7c\x4c\xe4\xff\x3b\x01\x80\xcb\xac\xdd\x9e\x8f\xf6\x7c\x77\x1a\x00" "\xb8\xec\xd2\x7c\x0c\x2c\x49\x4b\xc5\x58\xc0\x5c\xa4\x69\xa9\xd4\x19" "\xc3\x7b\x26\xae\xa4\xb5\x46\xb3\x75\xeb\x61\x63\x6b\x7d\xb9\x33\x56" "\x76\x35\xa6\xd2\x87\xab\xb5\xea\x9d\x6b\x33\xbf\xff\x4e\x7e\xc5\x30" "\x95\x64\xe9\x85\x3c\x2f\xcf\xcf\xd3\x95\x63\xe9\xbb\x11\x71\x2d\x22" "\x7e\x38\xf3\x44\x9e\x2e\x2d\x35\x6a\xcb\xa3\xbb\xec\x01\x80\xb1\xf6" "\xe4\xb1\xfe\xff\x1f\x33\x9d\xfe\xbf\x0f\x3d\xbe\xd5\x03\x00\xfe\x6f" "\xcc\x8e\xba\x02\x00\xc0\xd0\xe9\xff\x01\x60\xfc\xe8\xff\x01\x60\xfc" "\xf4\xd1\xff\x17\x5f\xf6\xef\x5d\x78\x5d\x00\x80\xe1\x70\xff\x0f\x00" "\xe3\x47\xff\x0f\x00\xe3\x47\xff\x0f\x00\x63\xe5\xab\xaf\xbd\x96\x2d" "\xed\x83\xe2\xf9\xd7\xcb\x6f\x6e\x6f\xad\x35\xde\xbc\xbd\x5c\x6d\xae" "\x95\xea\x5b\x4b\xa5\xa5\xc6\xe6\x46\x69\xa5\xd1\x58\xc9\x9f\xd9\x53" "\x3f\xab\xbc\x5a\xa3\xb1\xb1\xf0\x7c\x6c\xbd\x55\x6e\x55\x9b\xad\x72" "\x73\x7b\xe7\x41\xbd\xb1\xb5\xde\x7a\x90\x3f\xd7\xfb\x41\x75\x6a\x28" "\xad\x02\x00\x3e\xc8\xb5\xeb\xef\xfc\x2e\x89\x88\xbd\x97\x9e\xc8\x97" "\xe8\x9a\xcb\x41\x5f\x0d\x97\x5b\x3a\xea\x0a\x00\x23\x33\x31\xea\x0a" "\x00\x23\x63\xb6\x2f\x18\x5f\xfd\xdf\xe3\xff\xe6\x42\xeb\x01\x8c\x4e" "\xcf\x87\x79\xcf\xf6\xdc\x7c\xbf\x1f\xff\x17\x41\xfc\xce\x08\xfe\xa7" "\xdc\xfc\x78\xff\xe3\xff\xe6\x78\x86\xcb\xc5\xf8\x3f\x8c\xaf\x0f\x37" "\xfe\xff\xf2\xc0\xeb\x01\x0c\x9f\xf1\x7f\x18\x5f\xed\x76\x72\x7c\xce" "\xff\xe9\xa3\x2c\x00\xe0\x52\x3a\xc7\x6f\xfc\xdb\xdf\x1f\xd4\x45\x08" "\x30\x52\x67\x4d\xe6\x3d\x90\xef\xff\x01\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0" "\x92\x99\x8b\x88\x6f\x47\x92\x96\x8a\xb9\xc0\xe7\x22\x4d\x4b\xa5\x88" "\xa7\x22\xe2\x6a\x4c\x25\x0f\x57\x6b\xd5\x3b\x11\xf1\x74\x5c\x8f\x88" "\xa9\x99\x2c\xbd\x30\xea\x4a\x03\x00\xe7\x94\xfe\x39\x29\xe6\xff\xba" "\x39\xff\xdc\xdc\xf1\xdc\xe9\xe4\x9f\x33\xf9\x3a\x22\xbe\xfb\x93\xd7" "\x7f\xf4\xd6\x62\xab\xb5\xb9\x90\xed\xff\xdb\xd1\xfe\x99\xc3\xe9\xc3" "\x2a\xef\xbd\xef\x1c\xf3\x0a\x02\x00\x03\x96\xf7\xdf\x95\x62\xdd\x75" "\x23\xff\x78\x7f\x77\xe9\x70\x19\x66\x7d\x1e\xdd\x8f\x7f\x17\x53\x11" "\x2f\x1d\xec\xef\xe6\x4b\x27\x67\x32\x26\xf3\xf5\x6c\x7e\x2d\x71\xe5" "\xef\x49\x91\xee\xcc\x45\xfa\x6c\x44\x4c\x0c\x20\xfe\xde\xdb\x11\xf1" "\xb1\x5e\xed\x4f\xf2\xb1\x91\xab\xc5\xcc\xa7\xdd\xf1\xa3\x88\xfd\xd4" "\x50\xe3\xa7\xef\x8b\x9f\xe6\x79\x9d\x75\x76\xf1\xf5\xd1\x01\xd4\x05" "\xc6\xcd\x3b\xf7\x23\xe2\x95\x5e\xc7\x5f\x1a\x37\xf2\x75\xef\xe3\x7f" "\x36\x3f\x43\x9d\xdf\xa3\xfb\x9d\xc2\x0e\xcf\x7d\x07\x5d\xf1\x0f\xcf" "\x7f\x13\x3d\xe2\x67\xc7\xfc\x8d\x7e\x63\x3c\xff\xeb\xaf\x9c\xd8\xd9" "\x9e\xef\xe4\xbd\x1d\xf1\xec\x64\xaf\xf8\xc9\x51\xfc\xe4\x94\xf8\xcf" "\xf5\x19\xff\x0f\x9f\xf8\xd4\x0f\x5e\x3e\x25\xaf\xfd\xd3\x88\x9b\xd1" "\x3b\x7e\x77\xac\x72\xab\xbe\x51\x6e\x6e\xef\xdc\x5e\xad\x2f\xae\x54" "\x57\xaa\xeb\x95\xca\xbd\x85\x7b\x77\x5e\xbc\xfb\x42\xa5\x9c\x8f\x51" "\x97\x0f\x47\xaa\x4f\xfa\xcb\x4b\xb7\x9e\x3e\xad\x6e\x59\xfb\xaf\x9c" "\x12\x7f\xb6\x67\xfb\xa7\x8f\xde\xfb\xb9\x3e\xdb\xff\xb3\x7f\xbd\xf1" "\xcd\x4f\x7f\x40\xfc\x2f\x7c\xb6\xf7\xe7\xff\x4c\xcf\xf8\x1d\x59\x9f" "\xf8\xf9\x3e\xe3\x2f\x5e\xf9\xc5\xa9\xd3\x77\x67\xf1\x97\x4f\x69\xff" "\x59\x9f\xff\xad\x3e\xe3\xbf\xfb\xa7\x9d\xe5\x3e\x5f\x0a\x00\x0c\x41" "\x73\x7b\x67\x6d\xb1\x56\xab\x6e\x9e\x6b\x23\xbb\x0b\x1d\x44\x39\x27" "\x36\xb2\x2a\x0e\xb4\xc0\x33\x36\xfe\x18\xc3\x8b\x75\xe6\xc6\xd4\x45" "\xfd\xab\x5e\xf8\xc6\xe4\xd1\xb5\xe2\x60\x4b\xfe\x46\x56\xe2\x90\x9b" "\x93\x0e\xbc\x15\xe7\xda\x78\x3c\xac\x58\xa3\x3d\x2f\x01\x17\xef\xbd" "\x83\x7e\xd4\x35\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4e" "\x33\x8c\x3f\x5d\x1a\x75\x1b\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\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\xb8\xbc\xfe\x13\x00\x00\xff\xff\xb6\x28\xcc\x8d", 1326); syz_mount_image(/*fs=*/0x20000100, /*dir=*/0x20000500, /*flags=MS_LAZYTIME|MS_NOSUID*/ 0x2000002, /*opts=*/0x20000080, /*chdir=*/1, /*size=*/0x52e, /*img=*/0x20000a80); break; case 7: memcpy((void*)0x200000c0, "memory.events\000", 14); syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000c0ul, /*flags=*/0x26e1, /*mode=*/0); break; case 8: memcpy((void*)0x20000100, "memory.events\000", 14); res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x20000100ul, /*flags=*/0x100002, /*mode=*/0); if (res != -1) r[1] = res; break; case 9: sprintf((char*)0x20000200, "0x%016llx", (long long)0); syscall(__NR_write, /*fd=*/r[1], /*buf=*/0x20000200ul, /*len=*/0x43451ul); break; case 10: *(uint64_t*)0x20002500 = 0; *(uint32_t*)0x20002508 = 0; *(uint64_t*)0x20002510 = 0; *(uint64_t*)0x20002518 = 0; *(uint64_t*)0x20002520 = 0; *(uint64_t*)0x20002528 = 0; *(uint32_t*)0x20002530 = 0; *(uint32_t*)0x20002538 = 0; *(uint64_t*)0x20002540 = 0; *(uint32_t*)0x20002548 = 0; *(uint64_t*)0x20002550 = 0x20002400; *(uint64_t*)0x20002400 = 0; *(uint64_t*)0x20002408 = 0; *(uint64_t*)0x20002410 = 0; *(uint64_t*)0x20002418 = 0; *(uint64_t*)0x20002420 = 0; *(uint64_t*)0x20002428 = 0; *(uint64_t*)0x20002430 = 0x20000400; memcpy( (void*)0x20000400, "\xcc\x6b\x2f\x8d\x45\xca\xaf\x28\x19\x02\xdc\x15\x4c\xb0\xb8\xa2\x75" "\x4a\x58\x76\x69\x78\x2e\x57\x41\xb6\xf0\x43\xc5\xc1\xce\x71\xa3", 33); *(uint64_t*)0x20002438 = 0x21; *(uint64_t*)0x20002440 = 0; *(uint64_t*)0x20002448 = 0; *(uint64_t*)0x20002450 = 0; *(uint64_t*)0x20002458 = 0; *(uint64_t*)0x20002558 = 6; *(uint64_t*)0x20002560 = 0; *(uint64_t*)0x20002568 = 0; *(uint32_t*)0x20002570 = 0; *(uint32_t*)0x20002578 = 0; syscall(__NR_sendmmsg, /*fd=*/r[0], /*mmsg=*/0x20002500ul, /*vlen=*/2ul, /*f=MSG_NOSIGNAL|MSG_DONTWAIT*/ 0x4040ul); break; } } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, /*offset=*/0ul); const char* reason; (void)reason; if ((reason = setup_binfmt_misc())) printf("the reproducer may not work as expected: binfmt_misc setup failed: " "%s\n", reason); if ((reason = setup_usb())) printf("the reproducer may not work as expected: USB injection setup " "failed: %s\n", reason); if ((reason = setup_swap())) printf("the reproducer may not work as expected: swap setup failed: %s\n", reason); for (procid = 0; procid < 5; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; }