// https://syzkaller.appspot.com/bug?id=f95b5ff2a219684ecc266ffa24cf3d08839739e0 // 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 #ifndef __NR_ioctl #define __NR_ioctl 29 #endif #ifndef __NR_memfd_create #define __NR_memfd_create 279 #endif #ifndef __NR_mmap #define __NR_mmap 222 #endif #ifndef __NR_openat #define __NR_openat 56 #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; } #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, 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", "+memory", "+io", "+pids"}; const char* net_controllers[] = {"net", "net_prio", "devices", "blkio", "freezer"}; const char* cpu_controllers[] = {"cpuset", "cpuacct", "hugetlb", "rlimit"}; 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/memory.low", cgroupdir); write_file(file, "%d", 298 << 20); snprintf(file, sizeof(file), "%s/memory.high", cgroupdir); write_file(file, "%d", 299 << 20); snprintf(file, sizeof(file), "%s/memory.max", cgroupdir); write_file(file, "%d", 300 << 20); 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(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"); 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"); if (symlink("/dev/binderfs", "./binderfs")) { } } static void close_fds() { for (int fd = 3; fd < MAX_FDS; fd++) close(fd); } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 3; 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 == 1) break; event_timedwait(&th->done, 50 + (call == 0 ? 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); } } void execute_call(int call) { switch (call) { case 0: memcpy((void*)0x20000380, "hfs\000", 4); memcpy((void*)0x20000300, "./file0\000", 8); memcpy((void*)0x20000080, "file_umask", 10); *(uint8_t*)0x2000008a = 0x3d; sprintf((char*)0x2000008b, "%023llo", (long long)0x401); *(uint8_t*)0x200000a2 = 0x2c; memcpy((void*)0x200000a3, "uid", 3); *(uint8_t*)0x200000a6 = 0x3d; sprintf((char*)0x200000a7, "0x%016llx", (long long)0); *(uint8_t*)0x200000b9 = 0x2c; memcpy((void*)0x200000ba, "iocharset", 9); *(uint8_t*)0x200000c3 = 0x3d; memcpy((void*)0x200000c4, "macturkish", 10); *(uint8_t*)0x200000ce = 0x2c; memcpy((void*)0x200000cf, "quiet", 5); *(uint8_t*)0x200000d4 = 0x2c; memcpy((void*)0x200000d5, "dir_umask", 9); *(uint8_t*)0x200000de = 0x3d; sprintf((char*)0x200000df, "%023llo", (long long)0x5fffffff); *(uint8_t*)0x200000f6 = 0x2c; memcpy((void*)0x200000f7, "quiet", 5); *(uint8_t*)0x200000fc = 0x2c; *(uint8_t*)0x200000fd = 0; memcpy( (void*)0x20000600, "\x78\x9c\xec\xdd\xcf\x6a\x13\x51\x14\xc7\xf1\xdf\xbd\x89\x1a\x6d\xa9" "\xd3\x3f\x22\xb8\xac\x16\x5c\x49\x5b\x37\xe2\x46\x90\x3c\x84\x2b\x51" "\x9b\x08\xc5\x50\x41\x2b\xa8\x2b\x71\x2d\x3e\x80\x7b\x5f\xc1\x87\x70" "\xa3\xf8\x02\xba\x72\xe5\x03\x64\x37\x72\xef\xdc\x98\x49\x3a\x7f\xd2" "\xea\xe4\xda\xf6\xfb\x81\x0c\x57\xe7\x9e\xcc\x39\x9d\x99\xcc\x3d\x81" "\x52\x01\x38\xb5\xee\x76\xbf\x7f\xbc\xf9\xd3\xbd\x8c\xd4\x52\x4b\xd2" "\x6d\xc9\x4a\xea\x48\x6d\x49\x97\x74\xb9\xf3\x62\x6f\x7f\x77\x7f\xd0" "\xef\x55\xbd\x51\xcb\x47\xb8\x97\x51\x16\x69\x0e\xcc\xd9\xd9\xeb\x17" "\x85\xba\x38\x1f\x11\x24\xee\x5f\x6d\x2d\xe6\xff\x0f\xcd\x48\xd3\x34" "\xfd\x11\x3b\x09\x44\xe7\xef\xfe\x02\x56\x3a\x17\xee\x4e\xbf\xbf\x33" "\xf7\xcc\x9a\xf1\x26\x76\x02\x91\x99\xa1\x86\x7a\xa9\xa5\xd8\x79\x00" "\x00\xe2\x0a\xcf\x7f\x1b\x9e\xf3\x8b\x61\xfd\x6e\xad\xb4\x11\x1e\xfb" "\x27\xea\xf9\x3f\x8c\x9d\x40\xe3\xd2\xca\xbd\xb9\xe7\xbf\xef\xb2\x52" "\xe3\xce\xef\x45\xbf\x6b\xdc\xef\xf9\x16\xce\xed\xb7\xa3\x2e\xf1\x28" "\x99\x9c\x55\x76\x65\x4d\x2c\x30\x4d\x5d\x57\xe9\x73\xb1\xe7\x1f\xef" "\x0e\xfa\x37\x76\x9e\x0e\x7a\x56\x6f\x75\x27\xc8\x4d\x5b\xf3\xdb\x5e" "\x76\xe9\x8e\xd4\x64\xbb\x5e\xd0\x9b\x56\x38\x7a\xed\x0b\xbe\x86\x33" "\xae\x86\xed\x92\xfc\x57\xff\xed\x11\xeb\x99\xcf\xe6\xab\xb9\x6f\x12" "\x7d\x50\xef\xcf\xfa\xaf\x9d\x1a\x77\x9a\xfc\x99\x4a\xa6\xce\x54\x96" "\xff\x66\xf9\x3b\xfa\x2a\x13\x37\x4b\xe1\x63\xe3\x40\x95\xcb\xfe\x20" "\x57\xc2\x11\x82\x9a\x2a\x3b\xc5\x1d\x89\x46\x57\xd4\xb2\x26\xbf\x20" "\x48\xea\xf2\xf4\x51\x2b\x53\x51\x59\x75\x5b\x35\x51\xab\x85\x51\xdb" "\x35\x51\x6b\xd3\x51\xe3\xab\xb9\x3c\xb2\x69\xe6\xbd\xb9\x67\xd6\xf5" "\x4b\x9f\xd4\xcd\xad\xff\xad\xfb\x69\x6f\x68\x96\x3b\xd3\xcd\xf1\x33" "\xc3\x95\x51\x59\x4f\xdb\xcf\x4c\x66\x48\xcc\x1e\xaa\x0c\xfc\x9d\x77" "\x7a\xa4\x5b\x5a\x7a\xfe\xea\xf5\x93\xd6\x60\xd0\x7f\xe6\x06\x0f\x19" "\x30\x60\x50\x3f\xe8\x7e\x91\xfe\x83\x34\x1a\x1d\xc4\xfe\x80\xc2\x3c" "\x8c\x4f\x7a\xec\x4c\x10\x89\x5b\x77\x99\xac\xff\xcb\xf5\x2b\x9b\xbe" "\x45\x72\x9b\xa4\x62\x9d\x5e\xdd\x64\x4e\x76\x40\x5b\x25\x1d\xd0\x8a" "\xdf\x5e\x38\x54\x07\xb7\x50\xde\xc1\xcd\xda\x73\x5d\xbd\x2e\x5d\x9b" "\xfd\x88\x49\xc8\xf3\x84\x30\x5d\x7d\xd3\x03\xbe\xff\x07\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x38\x6e\xe6\xf1\xeb\x04" "\xb1\x6b\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\xe0\xb8\xe3\xef\xff\x02\xa7\xd7\xef\x00\x00\x00\xff\xff\x8f" "\x15\x80\x92", 581); syz_mount_image(0x20000380, 0x20000300, 0x1008003, 0x20000080, 0x21, 0x245, 0x20000600); break; case 1: memcpy((void*)0x200001c0, "./file0\000", 8); syscall(__NR_openat, 0xffffff9c, 0x200001c0ul, 0ul, 0ul); break; case 2: *(uint64_t*)0x20000100 = 0; *(uint64_t*)0x20000108 = 0; *(uint64_t*)0x20000110 = 0; *(uint64_t*)0x20000118 = 0; memcpy( (void*)0x20000120, "\x4f\x8f\x06\x11\x02\xb5\x8c\x59\x9f\xf4\x6a\x08\xc1\xcc\x52\x42\x74" "\x77\xfa\x3a\x40\x53\xbe\x11\xad\x69\x9c\x9a\x66\x3f\x0c\x55\x9e\x1f" "\x06\x13\x7d\x2d\xd6\x0f\x10\x31\x0d\x73\x42\xf5\xa4\x77\x79\xb7\xc8" "\xe2\x18\x88\x1d\x50\x1b\xff\xda\x1b\x43\x1b\x68\xfa\xbe\x80\x35\x8e" "\x13\x20\xc3\x23\xe3\xc1\x03\xc0\x3c\x7a\x21\x05\x81\xb0\x02\x16\x2d" "\x29\x15\xa3\x57\x23\xe2\x1e\x48\x4f\x7d\xba\xe3\xbb\xf4\xfc\x0b\xbf" "\x20\xef\xf9\xf8\xc9\x87\x0a\x85\xe6\xaa\x0c\x2f\x95\x67\x1a\x93\xeb" "\xd9\x0b\x66\xa8\xe5\x2c\x7f\x2b\x8e\x22\x61\xe7\x9c\x3f\xcd\x36\xf7" "\x23\xdb\x3a\xd8\x09\xef\x1b\xfd\x5a\x40\x6a\xdb\xca\x58\xc6\x50\x02" "\xed\x41\x68\xb4\x1a\xb5\xbc\x63\x16\x76\xd9\xb8\x56\x6a\x7e\xd2\xb3" "\xba\x48\xbd\x67\xfc\x67\xc2\x43\xd6\x03\x5e\xcb\xb2\xf4\x60\x0a\x7e" "\xbd\xb6\xa2\x4b\xf3\x3b\xec\x4e\x2d\xed\xf2\x2c\x4e\x20\x92\xc7\x2b" "\x21\x22\x3d\xd7\xfb\x03\xdc\x01\x98\xe9\x31\xb6\x7c\xfe\x91\x61\x73" "\x91\xa1\x35\x2d\x9f\xb4\x17\xa4\x0a\x7d\xbb\x64\xbd\x9e\x18\x64\x3b" "\x64\xa5\x66\xbb\xa8\x38\x1d\xcf\x2a\xc2\x39\x6e\x97\x8d\x37\x79\x32" "\x8c\x5e\x98\xb3\xc5\x29\xf5\x49\x8e\x5f\x5d\x86\xe2\x47\x1a\xbd\xee" "\xfa\xd1\xb6\x5f\x70\x94\xa2\x16\x1e\x0d\xc3\xb1\xe6\x4c\x83\x3e\x95" "\xa7\x6a\x5e\x9b\xb4\x93\x4f\x96\x30\x6a\x60\x73\x7e\x79\xc9\xa7\x4b" "\xc5\xc4\xcf\x93\xee\xf4\x63\x26\x81\x40\x7d\x08\x47\xd6\x38\xd8\x4f" "\xe5\x30\xfc\xcb\xad\xf5\xca\x98\xac\x21\x48\xcf\xde\x06\x0c\xf1\x7d" "\x37\x92\x48\x71\x7a\xe7\x4c\xe8\xab\xdc\xc6\x35\xfb\xb5\x78\x3a\xdd" "\x10\xac\xd1\x1e\x15\xc4\x1d\x15\xd3\x08\x75\x09\x73\x51\xe4\xb0\x08" "\xa1\xa0\x61\x40\x99\x97\x67\xd8\x8a\x97\xfd\x85\x4f\x11\x2d\x79\x19" "\x92\x07\x69\x9d\xd7\xb8\x7e\x4f\xa6\x99\x29\x1b\x22\x1a\x29\xd6\xd5" "\xa9\xd8\xbb\x0c\x5b\x07\x3a\x48\x65\xf6\xb5\x2b\xdb\x9b\xcc\xc5\x65" "\x64\x33\x25\xc9\xf7\x3d\x35\xaa\x09\x55\x58\xaa\xf1\x1d\x3a\x2e\x48" "\x83\x53\x82\xac\x93\xbb\xf3\xac\xc3\x79\xf3\x87\x22\xc5\x2b\x08\x5e" "\x4d\xd3\x24\x9c\xd1\x2e\x3c\xdf\x59\x5a\x5b\xc6\xf8\x33\xd5\xe3\x21" "\x66\xf8\xb0\xfe\x48\xca\x10\xd0\xbb\x2f\x85\xac\x60\x6b\x99\xc2\x15" "\x6c\x49\x3e\x7d\x9c\xf2\xdc\x8f\x90\x9e\xe4\xae\x70\xbd\x92\x69\xae" "\x4b\xba\x4c\xbf\xa8\x92\x74\x40\xa2\x8d\x5f\xa0\x19\xd9\x4c\x11\x78" "\xdd\x58\x04\xce\x50\x44\xe5\xb7\xf5\xae\x0e\xb5\x8b\x5b\xa0\x62\x11" "\xa2\x10\x79\xf3\x41\xc3\x9e\x1a\x5f\xb8\x70\x36\xcd\x07\x54\xd4\xba" "\xa1\x90\x2c\x6f\x9c\x89\x5d\xa9\xdb\xda\xcd\x06\xd8\x51\xe8\x0d\xc3" "\x50\x90\xdc\xa9\x1b\x1e\xb3\xbb\x09\x0d\x53\xce\x16\x4c\xd6\xc5\xe5" "\x07\x8b\x13\x08\x16\xad\x49\x95\x0d\x9f\xa3\x3b\x1f\x6d\x0d\x1d\xf4" "\x32\xc3\xeb\xe7\x66\xe5\xef\x0d\xb4\xfe\x1f\x3b\xad\xf5\xf0\xb9\x8d" "\x9b\x21\x5a\x3b\xba\xaf\x2b\x5c\x22\x28\xa7\x94\x10\x87\xce\x11\x86" "\x17\xb1\xd2\x6f\xb4\xdc\x8c\x0c\x4f\x03\x4e\xc5\x67\x67\x9a\x4b\xca" "\x35\x91\xe2\x84\xe0\xf3\x20\x79\x0d\x26\xcf\xb7\x2e\x42\xde\x4c\xba" "\x97\xad\x98\xf8\x86\x7d\x0d\xbc\xf8\x67\x0c\xe2\x54\xf1\x3f\x23\xe9" "\x48\x82\x7c\x75\x47\xb2\x21\xf1\x9e\x06\x60\x18\xcb\xe0\x16\x32\xf8" "\xd0\x8e\xd9\x68\x56\x9f\xeb\x88\x13\xdd\x0c\xdf\x61\x2e\x2c\xd3\xed" "\x8b\xcc\xfe\xb3\xbf\x33\x15\xd8\x1e\x26\x91\x52\xe9\xd4\x6e\xae\xec" "\x10\x82\xf6\x0a\x3f\xb2\xa6\xda\x29\x81\x7f\x87\x99\xa1\xd3\x4d\xdc" "\xca\x29\xad\x54\xf4\x76\xab\x33\xfa\x0e\x70\x97\x69\xb8\x7b\xfa\x66" "\x15\x0d\xfe\x22\xc3\x07\x5d\x27\x34\x02\x98\xde\x5e\xd0\x7c\x97\x05" "\xb3\xca\xa7\x31\xbc\x42\x70\x33\xd7\x88\x75\x39\xd7\xad\x99\x77\x5d" "\x14\x7f\x12\x12\xdc\x72\x7a\x1b\x19\xf1\x1a\xe3\xc7\x6f\x3c\x81\x74" "\x6f\xb9\x34\x37\xed\x58\xee\x1a\x47\xf3\x3f\x09\x6a\x7d\xb8\xa4\xb5" "\xfc\x6d\x60\x07\x6c\x55\x8c\x4a\x48\x40\x87\x85\x5b\x74\xe4\x8a\x8b" "\x0e\xfc\xd5\xa2\x67\x73\x33\x2c\xdd\x27\x5c\x91\x36\xf0\x24\x6c\x8d" "\x89\xd5\xda\x09\xf5\x2a\x96\xd5\x5a\x37\x3d\xb4\xe3\x18\x54\x8b\x6d" "\x21\xeb\xb8\x8a\xa6\x1b\x23\xa9\xd6\xeb\xd0\xf2\x59\xd5\x57\x61\xff" "\x7a\x7b\xd7\x53\xb0\x31\xe5\xd4\xe2\x88\xdc\x9e\xab\x97\x64\x65\xf8" "\xc0\xff\x2a\x8f\xa5\x29\xc2\xff\x7f\x19\x18\x4c\xef\xc1\x8b\x4f\xc7" "\xa1\xe3\x95\x44\xd5\x4d\xb2\x08\x72\x71\xa1\xea\xf3\x01\xc2\x5d\x39" "\xad\x65\x98\x4f\x7e\xbc\xbc\x94\x42\x82\xb7\x68\xb9\x6b\x42\x57\xcc" "\x8f\x38\x66\x64\x00\x53\x24\x3a\x9a\x41\x56\x26\x71\x68\x97\xca\xab" "\xa6\x0a\x1b\xa4\x4c\xe8\x4e\x38\xf2\x47\xfd\x66\xfb\xc1\x90\x7a\x0a" "\xf3\x4b\xca\x5b\x01", 1025); memcpy( (void*)0x20000521, "\x76\xf5\x47\xe5\xec\xcd\xc6\x9d\x44\x1a\x00\xd3\xb7\xa9\x4c\x20\x9c" "\x50\x34\x3d\xb9\x1b\xbc\x3b\x27\x8d\x22\x09\xba\xc1\x9b\xb7\x8f\x80" "\xec\x60\x0b\xf7\x2b\x31\xf4\x19\x69\x33\xef\xa9\x00\x8c\x17\x09\x69" "\x67\xad\x6b\x96\xa0\xcf\x5e\x97\xc0\x28\x25\x50\xcd\x41\x62\x1e\xda" "\x86\xb3\xb3\x2f\x50\x10\xad\xba\x1d\x67\x4b\x48\xc5\xd5\xd2\x06\x5e" "\xd8\xda\x5d\xed\x54\x25\xc9\x78\x4d\x47\x70\xae\x03\x94\xcb\xf6\xa6" "\x24\x94\x52\xff\x63\xb3\x78\xb3\xdb\xcf\xf3\xb3\xca\x50\x75\x29\xbf" "\x87\x7d\x8a\x6d\x34\x47\x6a\x17\xae\x51\x28\xf0\x3a\xc2\x65\x60\x64" "\xdc\xae\x0c\xf8\x56\x73\x44\xc4\x28\xf6\x7e\x94\x94\x65\x74\x21\xfb" "\xfb\xbe\xf9\x93\x43\xea\xb1\x00\x7d\x1d\x2d\x36\xe1\x61\x03\xff\xfc" "\x20\xb9\x4d\xc1\xa5\x36\xab\x6c\x7c\xa6\x0a\x95\x37\x2e\x48\x65\xe1" "\x6d\x8c\x37\x0c\x7e\xb3\xad\x73\xb5\xac\x91\xf1\x49\x43\xf4\x89\x60" "\xfe\x62\x2a\x2f\x86\x15\x5b\xfe\x18\xe9\xd9\xc2\xba\x78\x25\x50\xcd" "\x1c\x11\x93\x3d\x7f\x6b\x3e\xb1\x0b\xa9\x1c\x44\xb6\x68\x4f\x19\x8c" "\xa2\x34\x8c\x21\x5b\x03\x4a\x1b\xab\x9f\xc6\x83\x29\xcb\x1b\xa0\x7d" "\x7b\xd0\x94\xb8\xfe\xa8\x5a\x88\x00\x88\x00\x07\xc3\xc2\x0e\xd7\x33" "\x73\xb6\x19\x31\x2d\x6f\x49\x3c\xe4\xf6\x3b\xf2\x71\xbd\x0a\x64\xeb" "\x7d\x67\x67\x35\x8a\xaa\x96\xa4\x7d\x2d\x0d\x91\xce\x9e\xa7\x96\xf0" "\xae\x19\x34\xf9\x83\xf8\x30\xa8\xd8\x9c\x49\xc8\xc7\x27\x1e\x6a\xf3" "\x3d\xd5\x5b\x58\xa6\x22\xc5\x68\xd6\x72\xcf\xff\x79\x4f\xc1\xea\xb8" "\x7b\x5a\x00\x90\xf9\x79\xbd\x01\xae\x93\x12\x7e\x43\xd4\x46\x6a\x6f" "\x17\x53\xd4\xc4\x03\x62\x24\xec\x3b\x54\xa5\x97\xe3\x06\x2d\xaa\x54" "\x77\xa1\x2c\x58\xb3\x2e\x5b\xaa\x70\x1e\x40\x27\x8a\x53\xc5\xae\x00" "\x6d\x20\xf5\xe8\x81\xb3\x59\x7c\xf4\x21\xcb\x43\x0a\x2b\xdc\x49\x27" "\xd3\x19\x30\x81\x67\x0f\xa8\x7c\xb1\x80\xe4\x98\xdc\x88\xa4\x7d\x8c" "\x79\xb3\x63\xaf\x8f\xb1\x4b\xb9\x6d\xd3\xaa\x78\x7f\x22\xe8\x88\x5b" "\x70\x05\x44\xd9\xd0\xa1\x0b\x4e\xd3\xf0\xda\x36\x72\x5f\x8a\xda\x9b" "\xd2\x92\xf9\xc4\x95\x54\x8d\xb7\x68\xe0\x43\x67\x4b\x81\x80\xa8\x6d" "\x78\x52\xee\x97\x50\x71\xcd\xe5\xa4\x33\x0c\x83\x98\xa6\x48\x18\xaa" "\xa3\x74\x72\x92\xb8\xfa\x43\x91\x61\x3c\x8e\xf0\x27\x3f\x44\xed\xc5" "\x24\x07\x9a\x84\xe1\x5b\x2d\xd9\xc1\xd5\x61\xc6\x03\x42\xe3\x67\x90" "\x3e\x07\x20\x5b\x5a\xe1\x3e\x9f\x5d\x4e\x3b\x09\x79\x34\x64\xf8\xcb" "\x34\x36\x13\x52\xde\x93\x08\x99\xbb\xa1\xb3\xd0\x34\xf3\x74\x72\x1e" "\x57\xc0\xbf\x33\xc4\xc2\x10\xfa\xa4\xd1\x52\x47\x2b\x0f\xf5\xcd\x07" "\x59\x46\xe4\xe0\x9f\x8d\x13\xd5\xf4\xc1\xea\x82\xba\x0f\x24\x85\x66" "\xb4\xcd\x4f\x66\x4b\xf1\xed\x21\x6a\xcb\x51\x51\x76\x6f\x97\xa6\xd7" "\x85\x42\xf7\x45\xaa\xfa\x4c\x74\xab\xfa\xb4\xaf\xcf\x78\x11\x00\x85" "\x2c\x52\x7b\x62\xe7\x0c\x1d\xe5\x87\xf2\xe3\x25\x84\x43\x11\x24\xd5" "\x86\x6c\xba\x95\x8c\xa3\xd7\x5b\x37\x87\x27\xaa\x8e\x38\xbf\x5c\x4e" "\xcf\xcb\xb8\xb5\x11\xa6\x03\x27\xbe\x57\x40\xa5\xca\xbd\xdf\x0b\x99" "\x38\x80\xd3\x4e\xe9\xb2\x58\x6e\x52\x84\x86\x43\x71\xb6\xe5\x92\xd2" "\xb2\x43\x2c\xb0\xf6\x00\x5f\x4e\x4d\x39\xc9\x51\x9d\x14\x75\xe7\xec" "\x0f\xe9\xb9\x20\xa8\xc4\x54\xd6\x9e\x49\x19\x99\xbe\xf0\xea\xf7\x0f" "\xe2\x3c\xa9\xa8\x15\xbd\x44\xc8\x79\xce\x40\xa7\x44\xfa\x8e\x79\xff" "\xe1\xbc\x16\x16\x8d\xce\x06\x61\x4a\x18\x55\x07\x7e\x57\xa0\xdc\x5b" "\x94\x55\x75\xf0\xb0\xe6\x31\x24\xf2\x64\x3c\x8b\x11\xe1\x8d\x06\x92" "\xfc\xd0\x73\x16\x2b\xec\xf0\x65\x08\x0a\x3a\x43\x33\x90\x7a\xf0\xe6" "\x43\xeb\x7a\xd6\x08\xeb\xd2\x87\xe2\x51\xd8\x9b\x07\xdc\x5f\x94\x7f" "\xe0\x90\x34\x2c\x3b\xb7\x56\xc2\x11\xe0\xf1\x80\xec\x45\x87\xb2\xf2" "\x89\x95\x71\xca\xdd\xe0\x07\xc7\x62\xf3\xeb\xdf\xea\x60\x9c\x17\x29" "\x0b\xa4\x61\x8f\x7f\x66\x11\x3d\xa0\x0f\x61\x68\xfd\x8b\xa3\xdc\x83" "\x0f\x0f\x56\x50\xee\x4c\xf9\xb1\xe4\x78\xa3\x84\xc5\x2c\x88\xc8\xd4" "\x47\xcf\x7f\xdc\x3c\xe6\xec\xbd\x32\xb5\x5f\xa0\x2d\x36\xdf\x47\x8a" "\x30\xc2\xf6\xf9\x90\xf4\x9e\xec\x84\x2f\x89\xd3\xd4\x9e\x77\x0a\xa7" "\xcd\xb6\x14\x92\x31\xd5\x6b\x9f\x82\x55\xf2\x1a\xe8\x64\x94\x17\x02" "\x71\x95\x33\x8f\x28\xe0\xa6\x7d\x76\x7f\x42\xf9\x21\x24\xbd\x70\x04" "\x12\xf6\x82\x82\xe2\xfb\x31\x9b\x43\x98\xee\xf5\x5a\xc4\x8b\xaa\x95" "\x35\xd6\x2f\x68\x04\x9c\x97\x42\x54\x7a\xe3\x1e\xc8\x3e\x41\xcd\x9a" "\x1a\x6a\x93\x29\x3e\xe9\xec\xdf\x2a\x64\xf7\x19\x06\xdf\xe5\xd2\x79" "\xc2\x3b\xb9\x9e\xca\xe1\x01\x4e\xf3\x55\x18\x67\x7a\x5e\x2b\x0f\xe0" "\x0e\x8a\x39\xc8\x97", 1025); *(uint64_t*)0x20000928 = 0; *(uint64_t*)0x20000930 = 0; *(uint64_t*)0x20000938 = 0; *(uint64_t*)0x20000940 = 0; *(uint64_t*)0x20000948 = 0; *(uint64_t*)0x20000950 = 0; *(uint64_t*)0x20000958 = 0; *(uint64_t*)0x20000960 = 0; *(uint64_t*)0x20000968 = 0; *(uint64_t*)0x20000970 = 0; *(uint64_t*)0x20000978 = 0; *(uint64_t*)0x20000980 = 0; *(uint64_t*)0x20000988 = 0; *(uint64_t*)0x20000990 = 0; *(uint64_t*)0x20000998 = 0; *(uint64_t*)0x200009a0 = 0; *(uint64_t*)0x200009a8 = 0; *(uint64_t*)0x200009b0 = 0; *(uint64_t*)0x200009b8 = 0; *(uint64_t*)0x200009c0 = 0; *(uint64_t*)0x200009c8 = 0; *(uint64_t*)0x200009d0 = 0; *(uint64_t*)0x200009d8 = 0; *(uint64_t*)0x200009e0 = 0; *(uint64_t*)0x200009e8 = 0; *(uint64_t*)0x200009f0 = 0; *(uint64_t*)0x200009f8 = 0; *(uint64_t*)0x20000a00 = 0; *(uint64_t*)0x20000a08 = 0; *(uint64_t*)0x20000a10 = 0; *(uint64_t*)0x20000a18 = 0; *(uint64_t*)0x20000a20 = 0; *(uint64_t*)0x20000a28 = 0; *(uint64_t*)0x20000a30 = 0; *(uint64_t*)0x20000a38 = 0; *(uint64_t*)0x20000a40 = 0; *(uint64_t*)0x20000a48 = 0; *(uint64_t*)0x20000a50 = 0; *(uint64_t*)0x20000a58 = 0; *(uint64_t*)0x20000a60 = 0; *(uint64_t*)0x20000a68 = 0; *(uint64_t*)0x20000a70 = 0; *(uint64_t*)0x20000a78 = 0; *(uint64_t*)0x20000a80 = 0; *(uint64_t*)0x20000a88 = 0; *(uint64_t*)0x20000a90 = 0; *(uint64_t*)0x20000a98 = 0; *(uint64_t*)0x20000aa0 = 0; *(uint64_t*)0x20000aa8 = 0; *(uint64_t*)0x20000ab0 = 0; *(uint64_t*)0x20000ab8 = 0; *(uint64_t*)0x20000ac0 = 0; *(uint64_t*)0x20000ac8 = 0; *(uint64_t*)0x20000ad0 = 0; *(uint64_t*)0x20000ad8 = 0; *(uint64_t*)0x20000ae0 = 0; *(uint64_t*)0x20000ae8 = 0; *(uint64_t*)0x20000af0 = 0; *(uint64_t*)0x20000af8 = 0; *(uint64_t*)0x20000b00 = 0; *(uint64_t*)0x20000b08 = 0; *(uint64_t*)0x20000b10 = 0; *(uint64_t*)0x20000b18 = 0; *(uint64_t*)0x20000b20 = 0; syscall(__NR_ioctl, -1, 0xc0c09425, 0x20000100ul); break; } } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); setup_cgroups(); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; }