// https://syzkaller.appspot.com/bug?id=5f0cd57405a44ff70b6597bc0bc5b2d75a91791f // 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 #ifndef __NR_memfd_create #define __NR_memfd_create 319 #endif static unsigned long long procid; static __thread int clone_ongoing; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { if (__atomic_load_n(&clone_ongoing, __ATOMIC_RELAXED) != 0) { exit(sig); } uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0; int valid = addr < prog_start || addr > prog_end; if (skip && valid) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ ({ \ int ok = 1; \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } else \ ok = 0; \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ ok; \ }) static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void 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 //% 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"); } else if (strncmp(fs, "gfs2", 4) == 0 && (strstr(opts, "errors=panic") || strstr(opts, "debug"))) { strcat(opts, ",errors=withdraw"); } 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_gadgetfs(); 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/newroot/syz-inputs", 0700)) exit(1); if (mount("/syz-inputs", "./syz-tmp/newroot/syz-inputs", NULL, bind_mount_flags | MS_RDONLY, 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_gadgetfs(); setup_binderfs(); setup_fusectl(); } static void setup_gadgetfs() { if (mkdir("/dev/gadgetfs", 0777)) { } if (mount("gadgetfs", "/dev/gadgetfs", "gadgetfs", 0, NULL)) { } } 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)) { } if (symlink("/dev/binderfs", "./binderfs")) { } } 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"); sandbox_common_mount_tmpfs(); loop(); exit(1); } 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 loop(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 == 5 ? 4000 : 0) + (call == 6 ? 4000 : 0)); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); close_fds(); } void execute_call(int call) { switch (call) { case 0: // syz_mount_image$hfs arguments: [ // fs: ptr[in, buffer] { // buffer: {68 66 73 00} (length 0x4) // } // dir: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8) // } // flags: mount_flags = 0x1000812 (8 bytes) // opts: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // union ANYUNION { // ANYBLOB: buffer: {71 75 69 65 74 2c 63 6f 64 65 70 61 67 65 3d // 63 70 38 36 30 2c 69 6f 63 68 61 72 73 65 74 3d 63 70 38 36 31 // 2c 00 80 8f ea d0 42 bd 35 dc 78 f7 f0 63 33 a5 e7 16 5b 82 71 // e4 1a ee 85 e5 9c bb 6c 2d f3 d4 e4 c1 6b 06 c7 3f 2e 3b 34 8a // 7f ba 46 e2 86 37 8a 15 ee 51 6b ac 8d 48 13 c9 c3 d9 ce e1 dd // b9 5d 1b bc f5 04 e0 65 b3 74 9a 1c bd 84 1e 68 5a 55 85 98 cf // 0d b1 0b 55 88 59 46 e6 78 d0 a7 18 77 03 7a 09 00 00 00 07 00 // 84 88 79 ef 16 04 ca dc 1f ac a3 aa 22 a5 76 75 0d 55 9c 4e 12 // 4d 4c b7 29 3e 73 93 b7 72 86 fa 8c 6d c4 49 ed a0 a0 3d 34 23 // 82 e8 4d 6d 3c 29 ab 95 cc 92 3f be 25 e1 34 d1 c4 21 32 0a 3b // ff aa 17 fc d6 b5 17 8e 32 2c c4 71 33 b3 81 1e 3d 3b c3 49 98 // dc 7e d0 29 83 4a d5 91 d9 d5 6c 41 06 3d 8d e2 d5 0a 23 98 e7 // 3f f2 91 3a 9f e8 e9 54 a4 e4 ca 99 ce b5 73 7e 57 19 3c 5f 47 // fd 63 b1 6c 8b 34 f2 56 db ac 0e 5e bd 00 90 78 df 2c b1 ca 10 // 51 ad 09 1a db fe e5 12 6d 8a 59 fa 54 38 73 4b c3 e8 cc 7b 7e // dc 10 71 6a 0a 9b 71 19 52 cd f9 65 86 e0 6f ba ce 21 dc 04 bd // b4 a1 a2 07 2c e5 f7 2c f0} (length 0x153) // } // union ANYUNION { // ANYRESOCT: ANYRES64 (resource) // } // union ANYUNION { // ANYRES32: ANYRES32 (resource) // } // union ANYUNION { // ANYRES32: ANYRES32 (resource) // } // union ANYUNION { // ANYRESHEX: ANYRES64 (resource) // } // union ANYUNION { // ANYRES32: ANYRES32 (resource) // } // } // } // chdir: int8 = 0x1 (1 bytes) // size: len = 0x305 (8 bytes) // img: ptr[in, buffer] { // buffer: (compressed buffer with length 0x305) // } // ] // returns fd_dir NONFAILING(memcpy((void*)0x200000000180, "hfs\000", 4)); NONFAILING(memcpy((void*)0x2000000000c0, "./file1\000", 8)); NONFAILING(memcpy( (void*)0x200000001cc0, "\x71\x75\x69\x65\x74\x2c\x63\x6f\x64\x65\x70\x61\x67\x65\x3d\x63\x70" "\x38\x36\x30\x2c\x69\x6f\x63\x68\x61\x72\x73\x65\x74\x3d\x63\x70\x38" "\x36\x31\x2c\x00\x80\x8f\xea\xd0\x42\xbd\x35\xdc\x78\xf7\xf0\x63\x33" "\xa5\xe7\x16\x5b\x82\x71\xe4\x1a\xee\x85\xe5\x9c\xbb\x6c\x2d\xf3\xd4" "\xe4\xc1\x6b\x06\xc7\x3f\x2e\x3b\x34\x8a\x7f\xba\x46\xe2\x86\x37\x8a" "\x15\xee\x51\x6b\xac\x8d\x48\x13\xc9\xc3\xd9\xce\xe1\xdd\xb9\x5d\x1b" "\xbc\xf5\x04\xe0\x65\xb3\x74\x9a\x1c\xbd\x84\x1e\x68\x5a\x55\x85\x98" "\xcf\x0d\xb1\x0b\x55\x88\x59\x46\xe6\x78\xd0\xa7\x18\x77\x03\x7a\x09" "\x00\x00\x00\x07\x00\x84\x88\x79\xef\x16\x04\xca\xdc\x1f\xac\xa3\xaa" "\x22\xa5\x76\x75\x0d\x55\x9c\x4e\x12\x4d\x4c\xb7\x29\x3e\x73\x93\xb7" "\x72\x86\xfa\x8c\x6d\xc4\x49\xed\xa0\xa0\x3d\x34\x23\x82\xe8\x4d\x6d" "\x3c\x29\xab\x95\xcc\x92\x3f\xbe\x25\xe1\x34\xd1\xc4\x21\x32\x0a\x3b" "\xff\xaa\x17\xfc\xd6\xb5\x17\x8e\x32\x2c\xc4\x71\x33\xb3\x81\x1e\x3d" "\x3b\xc3\x49\x98\xdc\x7e\xd0\x29\x83\x4a\xd5\x91\xd9\xd5\x6c\x41\x06" "\x3d\x8d\xe2\xd5\x0a\x23\x98\xe7\x3f\xf2\x91\x3a\x9f\xe8\xe9\x54\xa4" "\xe4\xca\x99\xce\xb5\x73\x7e\x57\x19\x3c\x5f\x47\xfd\x63\xb1\x6c\x8b" "\x34\xf2\x56\xdb\xac\x0e\x5e\xbd\x00\x90\x78\xdf\x2c\xb1\xca\x10\x51" "\xad\x09\x1a\xdb\xfe\xe5\x12\x6d\x8a\x59\xfa\x54\x38\x73\x4b\xc3\xe8" "\xcc\x7b\x7e\xdc\x10\x71\x6a\x0a\x9b\x71\x19\x52\xcd\xf9\x65\x86\xe0" "\x6f\xba\xce\x21\xdc\x04\xbd\xb4\xa1\xa2\x07\x2c\xe5\xf7\x2c\xf0", 339)); NONFAILING(sprintf((char*)0x200000001e13, "%023llo", (long long)-1)); NONFAILING(*(uint32_t*)0x200000001e2a = -1); NONFAILING(*(uint32_t*)0x200000001e2e = 0); NONFAILING(sprintf((char*)0x200000001e32, "0x%016llx", (long long)0)); NONFAILING(*(uint32_t*)0x200000001e44 = -1); NONFAILING(memcpy( (void*)0x200000000340, "\x78\x9c\xec\xdd\x4d\x6b\x13\x5b\x1c\xc7\xf1\xdf\x99\xa4\x4d\x7a\x9b" "\xdb\x9b\x3e\x5c\x2e\xdc\x65\xb5\xa0\x1b\xd1\xba\x11\x37\x11\xc9\x5b" "\x10\xc4\x85\x68\xdb\x08\xc5\x50\x51\x2b\xa8\x1b\x53\x71\x25\xa2\x7b" "\xf7\xbe\x05\x5f\x84\x1b\xc5\x37\xa0\x2b\x17\xe2\x0b\x68\x37\x8e\x9c" "\x33\x0f\xc9\x24\x93\x99\x34\x24\x1d\x83\xdf\x0f\x88\x93\xc9\xfc\xe7" "\xfc\xcf\x3c\xfe\x4f\xa0\x1c\x01\xf8\x63\x5d\x6d\x7e\x79\x77\xf1\x9b" "\xfd\x67\xa4\x92\x4a\xd2\xcb\xcb\x92\x27\xa9\x2a\x95\x25\xfd\xab\xff" "\xaa\x8f\xf6\xf6\x77\xf7\xdb\xad\x9d\xac\x1d\x95\x5c\x84\x8e\x7c\x19" "\x05\x91\x66\x60\x9b\xed\xbd\x96\xfb\xff\x20\xb9\xda\xc6\xb9\x88\x50" "\xdd\x7e\x2a\xab\xd6\xbb\x0e\xd3\xe1\xfb\xfe\x95\xaf\x7d\xeb\xbe\x7b" "\x05\x25\x83\xc2\xb8\xbb\x3f\x85\x27\x55\xc2\xbb\xd3\x7d\x5f\x3d\xf1" "\xcc\xb2\x1d\x8c\x19\xd7\x99\x70\x1e\xb3\xc6\x1c\xea\x50\x8f\xb5\x54" "\x74\x1e\x00\x80\x62\xd9\xf7\xff\x41\x50\xf8\xdb\xf7\x7c\x2d\xac\xdf" "\x3d\x4f\xda\x08\x5f\xfb\xbf\xe5\xfb\x7f\x5c\x87\x45\x27\x30\x75\x7e" "\xe6\xb7\x3d\xef\x7f\x37\xca\xf2\x8d\x3d\xbf\xff\xb8\xaf\xba\xe3\x3d" "\x37\x84\xb3\xdf\x7b\xd1\x28\x71\x94\x96\xe7\xfa\x3e\xcf\x2b\x28\x24" "\x13\x05\xa6\x49\x1f\x55\x76\x87\x7c\x2e\x17\x6f\xe1\xce\x6e\xbb\x75" "\x6e\xfb\x5e\x7b\xc7\xd3\x73\x35\x42\x3d\x01\x6b\x71\x0b\x21\x7b\x85" "\xe6\x64\xbb\x9e\x32\x36\xcd\x30\x42\xdf\x4d\x6a\x45\x19\xa4\xe5\xcd" "\xd9\x3e\x6c\x0e\xc9\x7f\x75\xcc\x16\x33\x0c\x0c\xdf\x12\x27\xc4\x7c" "\x30\x9f\xcc\x4d\x53\xd7\x5b\xed\xc4\xf5\x5f\xd9\x37\x36\x5b\x97\x70" "\xbd\xef\x4c\x05\xf9\x9f\x1f\xde\xde\xa2\x8b\xb2\x5b\x29\x7c\x6c\x34" "\x1a\x0d\xcf\xed\x28\xb2\xec\x1a\xf9\x3f\x79\xa6\x72\x7a\x59\x4d\x1f" "\x91\x28\x3a\xb0\xcb\x4a\xfe\x40\x50\xcf\xcb\xd3\x45\xad\xf4\x45\x05" "\xbd\xbb\x90\x1a\x50\x89\xa3\x56\x53\xa3\x36\xa3\x4f\x43\xda\x5a\x4b" "\x44\xd9\xde\xc4\x57\xf3\xf0\x2c\xa7\xcd\xbc\x36\xd7\xcd\xba\x7e\xe8" "\xbd\x9a\x3d\xf5\xbf\x67\xf3\xdb\xd0\xf0\x3b\x33\xf1\x8b\x8e\xd9\x08" "\x6e\x34\x77\xc4\x83\xfe\xcc\xa7\x37\x57\x76\xfb\xac\x0f\xbc\x39\x3a" "\xba\x51\x4b\xae\x89\x8f\x62\x65\x58\xea\x47\xd9\xcf\x34\x8c\x20\x3a" "\x87\xaf\xb4\xa5\x4b\x5a\x7a\xf8\xe4\xe9\xdd\x52\xbb\xdd\x7a\x60\x17" "\x6e\xa7\x2c\xdc\xaf\xc5\x6b\xe6\x5e\x48\xa9\xdb\x14\xbc\xa0\x4e\x77" "\x4d\x45\xbe\x33\xb0\x71\xf4\x0c\x4c\x84\x2f\x84\x2b\xa7\x94\xd8\xd9" "\x89\xee\xd0\x3e\x3f\x72\x37\xb6\x77\xd9\x89\x1c\xf9\xde\x2b\x21\xba" "\x61\x27\xd6\x84\xbc\xe2\x2f\xad\xac\x6b\xa3\xf9\xb1\xef\x42\x9a\xd8" "\x82\x5f\x99\xf0\x0e\x7f\xfa\x63\x44\xfd\x7d\xc2\x0f\x25\x14\xa5\x7b" "\xd2\x8b\xce\x04\x05\xb1\x75\x97\x09\xc6\x7f\xae\x92\x0f\xeb\x7d\x57" "\xaf\xd9\x6a\xe1\x5a\x65\x78\x9d\x1e\x15\x64\x69\x25\x9b\xab\xde\xc3" "\x3d\xfa\xb6\xc6\x8e\x47\x40\xd5\x44\xfc\x8a\x5b\xfa\x2b\x59\x46\xe7" "\x8c\x0d\x16\xc3\x3a\x26\x65\x1c\xd7\xd1\x68\x63\xae\x53\x67\xa4\xd3" "\xa3\xb7\x58\x0f\xf3\x9c\x0d\xfe\xb3\x9c\x0d\x4c\x53\x9f\x75\x8b\xdf" "\xff\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x66" "\xcd\xf1\xff\xae\x60\xe1\xd8\x51\x45\xf7\x11\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x59\x17\xcf\xff\xab\x68" "\xfe\x5f\x8d\x36\xff\x6f\xff\x54\x2c\xe1\xfc\xbf\x55\xe5\xcc\xff\xbb" "\x35\x98\xc3\xc0\xfc\xbf\x6f\xf6\x64\x3a\x12\xf3\xff\x02\xd3\xf5\x2b" "\x00\x00\xff\xff\xff\x2c\x77\xb3", 773)); NONFAILING(syz_mount_image( /*fs=*/0x200000000180, /*dir=*/0x2000000000c0, /*flags=MS_SYNCHRONOUS|MS_STRICTATIME|MS_NOSUID|MS_NODIRATIME*/ 0x1000812, /*opts=*/0x200000001cc0, /*chdir=*/1, /*size=*/0x305, /*img=*/0x200000000340)); break; case 1: // openat arguments: [ // fd: fd_dir (resource) // file: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8) // } // flags: open_flags = 0x101042 (4 bytes) // mode: open_mode = 0x40 (2 bytes) // ] // returns fd NONFAILING(memcpy((void*)0x200000000040, "./file1\000", 8)); syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000040ul, /*flags=O_SYNC|O_CREAT|O_RDWR*/ 0x101042, /*mode=S_IXUSR*/ 0x40); break; case 2: // openat$cgroup_ro arguments: [ // fd: fd_cgroup (resource) // file: ptr[in, buffer] { // buffer: {63 70 75 2e 73 74 61 74 00} (length 0x9) // } // flags: const = 0x275a (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd NONFAILING(memcpy((void*)0x200000000040, "cpu.stat\000", 9)); syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000040ul, /*flags=*/0x275a, /*mode=*/0); break; case 3: // open arguments: [ // file: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8) // } // flags: open_flags = 0x1607c0 (8 bytes) // mode: open_mode = 0x78e22799f4a46ffe (8 bytes) // ] // returns fd NONFAILING(memcpy((void*)0x200000000000, "./file0\000", 8)); syscall( __NR_open, /*file=*/0x200000000000ul, /*flags=O_TRUNC|O_NOFOLLOW|O_NOCTTY|O_NOATIME|O_EXCL|O_CREAT|0x100400*/ 0x1607c0ul, /*mode=S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x78e22799f4a46f00*/ 0x78e22799f4a46ffeul); break; case 4: // creat arguments: [ // file: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 00} (length 0x101) // } // mode: open_mode = 0x0 (8 bytes) // ] // returns fd NONFAILING(memcpy( (void*)0x200000000580, "./" "file0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\000", 257)); syscall(__NR_creat, /*file=*/0x200000000580ul, /*mode=*/0ul); break; case 5: // syz_mount_image$vfat arguments: [ // fs: ptr[in, buffer] { // buffer: {76 66 61 74 00} (length 0x5) // } // dir: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 // 61 61 61 61 61 61 00} (length 0x101) // } // flags: mount_flags = 0x2c600 (8 bytes) // opts: nil // chdir: int8 = 0xbf (1 bytes) // size: len = 0x0 (8 bytes) // img: ptr[in, buffer] { // buffer: (compressed buffer with length 0x0) // } // ] // returns fd_dir NONFAILING(memcpy((void*)0x2000000002c0, "vfat\000", 5)); NONFAILING(memcpy( (void*)0x2000000006c0, "./" "file0aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\000", 257)); NONFAILING(syz_mount_image( /*fs=*/0x2000000002c0, /*dir=*/0x2000000006c0, /*flags=MS_UNBINDABLE|MS_REC|MS_SILENT|MS_NOATIME|0x200*/ 0x2c600, /*opts=*/0, /*chdir=*/0xbf, /*size=*/0, /*img=*/0x2000000007c0)); break; case 6: // syz_mount_image$vfat arguments: [ // fs: ptr[in, buffer] { // buffer: {76 66 61 74 00} (length 0x5) // } // dir: ptr[in, buffer] { // buffer: {13 13 77 c5 fc 35 d4 14 54 d5 d4 1d 29 ad 1a 60 29 59 81 46 // e6 be 16 6e 41 ad 0d bd 40 54 03 3c 9f 33 bb da 82 24 a2 f3 d7 72 e7 // 63 6e 48 b3 3c bf 70 83 72 e8 f1 b9 93 3e c5 12 77 43 be 22 06 20 9e // f0 2d f9 cb f2 f6 e8 80 d3 38 2f 00} (length 0x4e) // } // flags: mount_flags = 0x1885cfe (8 bytes) // opts: nil // chdir: int8 = 0xf1 (1 bytes) // size: len = 0x0 (8 bytes) // img: ptr[in, buffer] { // buffer: (compressed buffer with length 0x0) // } // ] // returns fd_dir NONFAILING(memcpy((void*)0x200000000000, "vfat\000", 5)); NONFAILING(memcpy( (void*)0x200000000dc0, "\023\023w\305\3745\324\024T\325\324\035)\255\032`)" "Y\201F\346\276\026nA\255\r\275@T\003<\2373\273\332\202$" "\242\363\327r\347cnH\263<\277p\203r\350\361\271\223>" "\305\022wC\276\"\006 \236\360-\371\313\362\366\350\200\3238/\000", 78)); NONFAILING(syz_mount_image( /*fs=*/0x200000000000, /*dir=*/0x200000000dc0, /*flags=MS_I_VERSION|MS_SLAVE|MS_REC|MS_SYNCHRONOUS|MS_STRICTATIME|MS_REMOUNT|0x1cce*/ 0x1885cfe, /*opts=*/0, /*chdir=*/0xf1, /*size=*/0, /*img=*/0x2000000000c0)); break; case 7: // truncate arguments: [ // file: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 31 00} (length 0x8) // } // len: intptr = 0x3000000 (8 bytes) // ] NONFAILING(memcpy((void*)0x200000000900, "./file1\000", 8)); syscall(__NR_truncate, /*file=*/0x200000000900ul, /*len=*/0x3000000ul); break; case 8: // openat$cgroup_ro arguments: [ // fd: fd_cgroup (resource) // file: ptr[in, buffer] { // buffer: {63 67 72 6f 75 70 2e 73 74 61 74 00} (length 0xc) // } // flags: const = 0x275a (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd NONFAILING(memcpy((void*)0x200000000080, "cgroup.stat\000", 12)); syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x200000000080ul, /*flags=*/0x275a, /*mode=*/0); break; case 9: // mkdir arguments: [ // path: ptr[in, buffer] { // buffer: {2e 2f 62 75 73 00} (length 0x6) // } // mode: open_mode = 0x10b (8 bytes) // ] NONFAILING(memcpy((void*)0x200000000040, "./bus\000", 6)); syscall(__NR_mkdir, /*path=*/0x200000000040ul, /*mode=S_IXOTH|S_IWOTH|S_IXGRP|S_IRUSR*/ 0x10bul); break; case 10: // open arguments: [ // file: ptr[in, buffer] { // buffer: {2e 2f 62 75 73 00} (length 0x6) // } // flags: open_flags = 0x4440 (8 bytes) // mode: open_mode = 0x129 (8 bytes) // ] // returns fd NONFAILING(memcpy((void*)0x200000000240, "./bus\000", 6)); syscall(__NR_open, /*file=*/0x200000000240ul, /*flags=O_DIRECT|O_CREAT|O_APPEND*/ 0x4440ul, /*mode=S_IXOTH|S_IXGRP|S_IRGRP|S_IRUSR*/ 0x129ul); break; } } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; install_segv_handler(); do_sandbox_none(); return 0; }