// https://syzkaller.appspot.com/bug?id=ae28a692910f2e066889b98c890adc67d88a4fda // 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 #ifndef SYS_aio_writev #define SYS_aio_writev 578 #endif #ifndef SYS_copy_file_range #define SYS_copy_file_range 569 #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 (sig == SIGBUS) valid = 1; 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_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 kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } 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 reset_flags(const char* filename) { struct stat st; if (lstat(filename, &st)) exit(1); st.st_flags &= ~(SF_NOUNLINK | UF_NOUNLINK | SF_IMMUTABLE | UF_IMMUTABLE | SF_APPEND | UF_APPEND); if (lchflags(filename, st.st_flags)) exit(1); } static void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } 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); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) { if (errno == EPERM) { reset_flags(filename); reset_flags(dir); if (unlink(filename) == 0) continue; } exit(1); } } closedir(dp); while (rmdir(dir)) { if (errno == EPERM) { reset_flags(dir); if (rmdir(dir) == 0) break; } 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 { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static void sandbox_common() { struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 0; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); } static void loop(); static int do_sandbox_none(void) { sandbox_common(); loop(); return 0; } 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 < 27; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); 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[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: // setsockopt$inet6_IPV6_HOPOPTS arguments: [ // fd: sock_in6 (resource) // level: const = 0x29 (4 bytes) // optname: const = 0x31 (4 bytes) // optval: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // } // } // optlen: len = 0x28 (8 bytes) // ] syscall(SYS_setsockopt, /*fd=*/(intptr_t)-1, /*level=*/0x29, /*optname=*/0x31, /*optval=*/0x2000000016c0ul, /*optlen=*/0x28ul); break; case 1: // kevent arguments: [ // kqueue: kqueue (resource) // changelist: ptr[in, array[kevent]] { // array[kevent] { // kevent { // ident: intptr = 0x0 (8 bytes) // filter: filters = 0xfffffffffffffff9 (2 bytes) // flags: evflags = 0x9 (2 bytes) // fflags: fflags = 0x8 (4 bytes) // data: int64 = 0xe8c5 (8 bytes) // udata: intptr = 0x0 (8 bytes) // ext: array[int64] { // int64 = 0x0 (8 bytes) // int64 = 0x0 (8 bytes) // int64 = 0x7 (8 bytes) // int64 = 0x40000000000000 (8 bytes) // } // } // } // } // nchanges: len = 0x1 (8 bytes) // eventlist: nil // nevents: len = 0x0 (8 bytes) // timeout: nil // ] NONFAILING(*(uint64_t*)0x200000000040 = 0); NONFAILING(*(uint16_t*)0x200000000048 = 0xfff9); NONFAILING(*(uint16_t*)0x20000000004a = 9); NONFAILING(*(uint32_t*)0x20000000004c = 8); NONFAILING(*(uint64_t*)0x200000000050 = 0xe8c5); NONFAILING(*(uint64_t*)0x200000000058 = 0); NONFAILING(*(uint64_t*)0x200000000060 = 0); NONFAILING(*(uint64_t*)0x200000000068 = 0); NONFAILING(*(uint64_t*)0x200000000070 = 7); NONFAILING(*(uint64_t*)0x200000000078 = 0x40000000000000); syscall(SYS_kevent, /*kqueue=*/(intptr_t)-1, /*changelist=*/0x200000000040ul, /*nchanges=*/1ul, /*eventlist=*/0ul, /*nevents=*/0ul, /*timeout=*/0ul); break; case 2: // kqueue arguments: [ // ] // returns kqueue res = syscall(SYS_kqueue); if (res != -1) r[0] = res; break; case 3: // kevent arguments: [ // kqueue: kqueue (resource) // changelist: ptr[in, array[kevent]] { // array[kevent] { // kevent { // ident: intptr = 0x0 (8 bytes) // filter: filters = 0xfffffffffffffff9 (2 bytes) // flags: evflags = 0x9 (2 bytes) // fflags: fflags = 0x8 (4 bytes) // data: int64 = 0xe8c5 (8 bytes) // udata: intptr = 0x0 (8 bytes) // ext: array[int64] { // int64 = 0x0 (8 bytes) // int64 = 0x1 (8 bytes) // int64 = 0x8 (8 bytes) // int64 = 0x9 (8 bytes) // } // } // } // } // nchanges: len = 0x1 (8 bytes) // eventlist: nil // nevents: len = 0x0 (8 bytes) // timeout: nil // ] NONFAILING(*(uint64_t*)0x200000000280 = 0); NONFAILING(*(uint16_t*)0x200000000288 = 0xfff9); NONFAILING(*(uint16_t*)0x20000000028a = 9); NONFAILING(*(uint32_t*)0x20000000028c = 8); NONFAILING(*(uint64_t*)0x200000000290 = 0xe8c5); NONFAILING(*(uint64_t*)0x200000000298 = 0); NONFAILING(*(uint64_t*)0x2000000002a0 = 0); NONFAILING(*(uint64_t*)0x2000000002a8 = 1); NONFAILING(*(uint64_t*)0x2000000002b0 = 8); NONFAILING(*(uint64_t*)0x2000000002b8 = 9); syscall(SYS_kevent, /*kqueue=*/r[0], /*changelist=*/0x200000000280ul, /*nchanges=*/1ul, /*eventlist=*/0ul, /*nevents=*/0ul, /*timeout=*/0ul); break; case 4: // ktimer_create arguments: [ // id: clock_id = 0x4 (8 bytes) // evp: nil // timerid: nil // ] syscall(SYS_ktimer_create, /*id=CLOCK_MONOTONIC*/ 4ul, /*evp=*/0ul, /*timerid=*/0ul); break; case 5: // cpuset_setaffinity arguments: [ // level: cpuset_level = 0x1 (8 bytes) // which: cpuset_which = 0x9 (8 bytes) // id: int64 = 0xa28 (8 bytes) // size: bytesize = 0x8 (8 bytes) // mask: ptr[in, cpuset_mask] { // cpuset_mask { // mask: array[int64] { // int64 = 0x3f6 (8 bytes) // } // } // } // ] NONFAILING(*(uint64_t*)0x2000000000c0 = 0x3f6); syscall(SYS_cpuset_setaffinity, /*level=CPU_LEVEL_ROOT*/ 1ul, /*which=CPU_WHICH_ITHREAD|CPU_WHICH_TID*/ 9ul, /*id=*/0xa28ul, /*size=*/8ul, /*mask=*/0x2000000000c0ul); break; case 6: // open$dir arguments: [ // file: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8) // } // flags: open_flags = 0x40000400000002c2 (8 bytes) // mode: open_mode = 0x0 (8 bytes) // ] // returns fd_dir NONFAILING(memcpy((void*)0x200000000240, "./file0\000", 8)); res = syscall(SYS_open, /*file=*/0x200000000240ul, /*flags=O_SYNC|O_CREAT|FASYNC|O_RDWR|0x4000040000000000*/ 0x40000400000002c2ul, /*mode=*/0ul); if (res != -1) r[1] = res; break; case 7: // freebsd10_pipe arguments: [ // pipefd: nil // ] syscall(SYS_freebsd10_pipe, /*pipefd=*/0ul); break; case 8: // cap_rights_limit arguments: [ // fd: fd (resource) // rights: nil // ] syscall(SYS_cap_rights_limit, /*fd=*/(intptr_t)-1, /*rights=*/0ul); break; case 9: // kevent arguments: [ // kqueue: kqueue (resource) // changelist: ptr[in, array[kevent]] { // array[kevent] { // kevent { // ident: intptr = 0x0 (8 bytes) // filter: filters = 0xfffffffffffffff9 (2 bytes) // flags: evflags = 0x9 (2 bytes) // fflags: fflags = 0x8 (4 bytes) // data: int64 = 0xe8c5 (8 bytes) // udata: intptr = 0x1 (8 bytes) // ext: array[int64] { // int64 = 0x0 (8 bytes) // int64 = 0x0 (8 bytes) // int64 = 0x2 (8 bytes) // int64 = 0x0 (8 bytes) // } // } // } // } // nchanges: len = 0x1 (8 bytes) // eventlist: nil // nevents: len = 0x0 (8 bytes) // timeout: nil // ] NONFAILING(*(uint64_t*)0x200000000040 = 0); NONFAILING(*(uint16_t*)0x200000000048 = 0xfff9); NONFAILING(*(uint16_t*)0x20000000004a = 9); NONFAILING(*(uint32_t*)0x20000000004c = 8); NONFAILING(*(uint64_t*)0x200000000050 = 0xe8c5); NONFAILING(*(uint64_t*)0x200000000058 = 1); NONFAILING(*(uint64_t*)0x200000000060 = 0); NONFAILING(*(uint64_t*)0x200000000068 = 0); NONFAILING(*(uint64_t*)0x200000000070 = 2); NONFAILING(*(uint64_t*)0x200000000078 = 0); syscall(SYS_kevent, /*kqueue=*/(intptr_t)-1, /*changelist=*/0x200000000040ul, /*nchanges=*/1ul, /*eventlist=*/0ul, /*nevents=*/0ul, /*timeout=*/0ul); break; case 10: // ppoll arguments: [ // fds: nil // nfds: len = 0x0 (8 bytes) // tsp: nil // sigmask: nil // size: len = 0x0 (8 bytes) // ] syscall(SYS_ppoll, /*fds=*/0ul, /*nfds=*/0ul, /*tsp=*/0ul, /*sigmask=*/0ul, /*size=*/0ul); break; case 11: // semop arguments: [ // semid: ipc_sem (resource) // ops: nil // nops: len = 0x0 (8 bytes) // ] syscall(SYS_semop, /*semid=*/0, /*ops=*/0ul, /*nops=*/0ul); break; case 12: // aio_writev arguments: [ // iocb: ptr[in, aiocb] { // aiocb { // aio_fildes: fd (resource) // pad = 0x0 (4 bytes) // aio_offset: int64 = 0x8 (8 bytes) // aio_buf: nil // aio_nbytes: len = 0x0 (8 bytes) // spare: array[int32] { // int32 = 0x8 (4 bytes) // int32 = 0x1ff (4 bytes) // } // spare2: intptr = 0x1 (8 bytes) // aio_lio_opcode: lio_opcodes = 0x5 (4 bytes) // aio_reqprio: int32 = 0x3 (4 bytes) // aiocb_private: aiocb_private { // status: intptr = 0x24d9339b (8 bytes) // error: intptr = 0x6 (8 bytes) // kernelinfo: nil // } // aio_sigevent: sigevent { // notify: sigev_notify = 0x3 (4 bytes) // signo: int32 = 0x20 (4 bytes) // val: union sigval { // sigval_int: int32 = 0x2 (4 bytes) // } // u: union sigevent_u { // tid: pid (resource) // } // } // } // } // ] NONFAILING(*(uint32_t*)0x200000001200 = -1); NONFAILING(*(uint64_t*)0x200000001208 = 8); NONFAILING(*(uint64_t*)0x200000001210 = 0); NONFAILING(*(uint64_t*)0x200000001218 = 0); NONFAILING(*(uint32_t*)0x200000001220 = 8); NONFAILING(*(uint32_t*)0x200000001224 = 0x1ff); NONFAILING(*(uint64_t*)0x200000001228 = 1); NONFAILING(*(uint32_t*)0x200000001230 = 5); NONFAILING(*(uint32_t*)0x200000001234 = 3); NONFAILING(*(uint64_t*)0x200000001238 = 0x24d9339b); NONFAILING(*(uint64_t*)0x200000001240 = 6); NONFAILING(*(uint64_t*)0x200000001248 = 0); NONFAILING(*(uint32_t*)0x200000001250 = 3); NONFAILING(*(uint32_t*)0x200000001254 = 0x20); NONFAILING(*(uint32_t*)0x200000001258 = 2); NONFAILING(*(uint32_t*)0x200000001260 = 0); syscall(SYS_aio_writev, /*iocb=*/0x200000001200ul); break; case 13: // mkdir arguments: [ // path: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8) // } // mode: open_mode = 0x0 (8 bytes) // ] NONFAILING(memcpy((void*)0x200000000180, "./file0\000", 8)); syscall(SYS_mkdir, /*path=*/0x200000000180ul, /*mode=*/0ul); break; case 14: // mkdir arguments: [ // path: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 2f 66 69 6c 65 30 00} (length 0xe) // } // mode: open_mode = 0x0 (8 bytes) // ] NONFAILING(memcpy((void*)0x200000000000, "./file0/file0\000", 14)); syscall(SYS_mkdir, /*path=*/0x200000000000ul, /*mode=*/0ul); break; case 15: // open$dir arguments: [ // file: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8) // } // flags: open_flags = 0x40000400000002c2 (8 bytes) // mode: open_mode = 0x0 (8 bytes) // ] // returns fd_dir NONFAILING(memcpy((void*)0x200000000240, "./file0\000", 8)); res = syscall(SYS_open, /*file=*/0x200000000240ul, /*flags=O_SYNC|O_CREAT|FASYNC|O_RDWR|0x4000040000000000*/ 0x40000400000002c2ul, /*mode=*/0ul); if (res != -1) r[2] = res; break; case 16: // open arguments: [ // file: nil // flags: open_flags = 0x615 (8 bytes) // mode: open_mode = 0x0 (8 bytes) // ] // returns fd syscall(SYS_open, /*file=*/0ul, /*flags=O_TRUNC|O_NONBLOCK|O_CREAT|O_WRONLY|0x10*/ 0x615ul, /*mode=*/0ul); break; case 17: // open$dir arguments: [ // file: nil // flags: open_flags = 0x40000400000002c2 (8 bytes) // mode: open_mode = 0x0 (8 bytes) // ] // returns fd_dir res = syscall(SYS_open, /*file=*/0ul, /*flags=O_SYNC|O_CREAT|FASYNC|O_RDWR|0x4000040000000000*/ 0x40000400000002c2ul, /*mode=*/0ul); if (res != -1) r[3] = res; break; case 18: // pwritev arguments: [ // fd: fd (resource) // vec: ptr[in, array[iovec_in]] { // array[iovec_in] { // iovec_in { // addr: ptr[in, buffer] { // buffer: {} (length 0x0) // } // len: len = 0x0 (8 bytes) // } // } // } // vlen: len = 0x1 (8 bytes) // off: intptr = 0xb542 (8 bytes) // ] NONFAILING(*(uint64_t*)0x2000000000c0 = 0x200000000000); NONFAILING(*(uint64_t*)0x2000000000c8 = 0); syscall(SYS_pwritev, /*fd=*/r[3], /*vec=*/0x2000000000c0ul, /*vlen=*/1ul, /*off=*/0xb542ul); break; case 19: // lchflags arguments: [ // file: nil // flags: chflags_flags = 0x60091 (8 bytes) // ] syscall(SYS_lchflags, /*file=*/0ul, /*flags=UF_SYSTEM|UF_NOUNLINK|UF_NODUMP|SF_IMMUTABLE|SF_APPEND*/ 0x60091ul); break; case 20: // copy_file_range arguments: [ // infd: fd (resource) // inoffp: nil // outfd: fd (resource) // outoffp: nil // len: int64 = 0x7 (8 bytes) // flags: copy_file_range_flags = 0x0 (8 bytes) // ] syscall(SYS_copy_file_range, /*infd=*/r[3], /*inoffp=*/0ul, /*outfd=*/r[2], /*outoffp=*/0ul, /*len=*/7ul, /*flags=*/0ul); break; case 21: // mprotect arguments: [ // addr: VMA[0x800000] // len: len = 0x800000 (8 bytes) // prot: mmap_prot = 0x1 (8 bytes) // ] syscall(SYS_mprotect, /*addr=*/0x200000000000ul, /*len=*/0x800000ul, /*prot=PROT_READ*/ 1ul); break; case 22: // socket$inet6_udp arguments: [ // domain: const = 0x1c (8 bytes) // type: const = 0x2 (8 bytes) // proto: const = 0x0 (1 bytes) // ] // returns sock_udp6 res = syscall(SYS_socket, /*domain=*/0x1cul, /*type=*/2ul, /*proto=*/0); if (res != -1) r[4] = res; break; case 23: // setsockopt$inet6_IPV6_DSTOPTS arguments: [ // fd: sock_in6 (resource) // level: const = 0x29 (4 bytes) // optname: const = 0x32 (4 bytes) // optval: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // } // } // optlen: len = 0x8 (8 bytes) // ] syscall(SYS_setsockopt, /*fd=*/r[4], /*level=*/0x29, /*optname=*/0x32, /*optval=*/0x200000000300ul, /*optlen=*/8ul); break; case 24: // getsockopt$inet6_buf arguments: [ // fd: sock_in6 (resource) // level: const = 0x29 (4 bytes) // optname: inet6_option_types_buf = 0x32 (4 bytes) // optval: ptr[out, buffer] { // buffer: (DirOut) // } // optlen: ptr[inout, len] { // len = 0x1000 (4 bytes) // } // ] NONFAILING(*(uint32_t*)0x200000000000 = 0x1000); syscall(SYS_getsockopt, /*fd=*/r[4], /*level=*/0x29, /*optname=IPV6_DSTOPTS*/ 0x32, /*optval=*/0x200000001040ul, /*optlen=*/0x200000000000ul); break; case 25: // open$dir arguments: [ // file: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 2f 66 69 6c 65 30 2f 66 69 00} (length // 0x11) // } // flags: open_flags = 0x41f00 (8 bytes) // mode: open_mode = 0x80 (8 bytes) // ] // returns fd_dir NONFAILING(memcpy((void*)0x200000000080, "./file0/file0/fi\000", 17)); syscall(SYS_open, /*file=*/0x200000000080ul, /*flags=O_EXEC|O_TRUNC|O_NOFOLLOW|O_EXCL|O_CREAT|0x1000*/ 0x41f00ul, /*mode=S_IWUSR*/ 0x80ul); break; case 26: // fcntl$dupfd arguments: [ // fd: fd (resource) // cmd: fcntl_dupfd = 0x11 (8 bytes) // arg: fd (resource) // ] // returns fd syscall(SYS_fcntl, /*fd=*/r[4], /*cmd=F_DUPFD_CLOEXEC*/ 0x11ul, /*arg=*/r[1]); break; } } int main(void) { syscall(SYS_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x1012ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; install_segv_handler(); for (procid = 0; procid < 4; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; }