// https://syzkaller.appspot.com/bug?id=f82f8fba49a7138ffc83001e6ca9a19d6d9c4955 // 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 #ifndef SYS_mmap #define SYS_mmap 197 #endif #ifndef SYS_openat #define SYS_openat 468 #endif #ifndef SYS_write #define SYS_write 4 #endif static unsigned long long procid; 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 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 = 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) { int i, call, thread; for (call = 0; call < 7; 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++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { 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; } } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: memcpy((void*)0x20000180, "./file0\000", 8); syscall(SYS_openat, 0xffffff9c, 0x20000180ul, 0x200ul, 0ul); break; case 1: memcpy((void*)0x20000040, "./file0\000", 8); res = syscall(SYS_openat, 0xffffff9c, 0x20000040ul, 0x1c1401ul, 0ul); if (res != -1) r[0] = res; break; case 2: memcpy((void*)0x2000c380, "./file0\000", 8); res = syscall(SYS_openat, 0xffffff9c, 0x2000c380ul, 0x8f0801ul, 0ul); if (res != -1) r[1] = res; break; case 3: memcpy((void*)0x20001640, "/proc/self/exe\000", 15); res = syscall(SYS_openat, -1, 0x20001640ul, 0ul, 0ul); if (res != -1) r[2] = res; break; case 4: syscall(SYS_mmap, 0x20000000ul, 0x800000ul, 1ul, 0x10ul, r[2], 0ul, 0ul); break; case 5: memset((void*)0x20004200, 116, 1); syscall(SYS_write, r[1], 0x20004200ul, 0x11523ul); break; case 6: memcpy( (void*)0x20000200, "\x71\x27\x24\x3b\xab\x06\x6f\x38\xbc\xb3\xdf\xcc\x66\x99\x24\xee\x75" "\x17\x1b\x21\x7a\x06\xd0\x7b\xf8\x6f\xb2\x5a\x5a\xce\xee\x4e\xdb\x56" "\xf0\x06\x84\xcc\x32\x33\x2d\x13\x66\x7a\xeb\xeb\xb3\x25\x68\xe4\x84" "\x57\x74\xac\x9d\xa4\x58\x38\xf2\xbb\x65\xed\xbf\x69\x5f\xe9\xd5\x00" "\xb4\x6c\x73\x08\xcd\xe1\x1d\xe3\x83\x4b\x1a\x43\xf6\x82\xf9\x40\xd2" "\x35\xb5\x7c\xd0\x91\xde\x12\x95\x42\xe6\x91\xd9\x39\x15\x31\x4d\xf0" "\xa4\x7a\xe1\x94\xa5\xa1\x07\xf9\x9e\x6a\x96\xa7\x45\x4a\x35\xf5\x89" "\x99\x54\x4f\xf9\x40\xac\x22\x53\x1e\xbe\x5d\x02\xe2\xbb\x80\xdc\xe4" "\x96\xac\x23\x04\x47\xc3\x05\x1d\x9f\xa9\x52\xd4\xb3\xa8\x9d\x47\x07" "\xb5\xb2\x39\x1d\x31\x92\xd3\x26\x95\x07\x04\xe2\x90\x6c\xf4\x50\xca" "\xcb\x7c\xe0\xbb\xcd\x8f\x1a\xb5\xba\xcd\x62\xf2\x8a\x1f\x48\x5c\x8b" "\x8f\x61\x87\x74\x60\xa4\xb7\x99\x1a\xea\x70\xa7\x67\x6a\x4a\x21\x5d" "\xce\xca\xc4\xbd\x67\x9c\x9e\xf9\xbd\x81\x36\x8d\x01\x88\x0c\xdf\x2c" "\xcd\x0f\xa8\xa2\x56\x92\x49\x0f\x86\x4f\xb9\xfd\x0d\x41\x2f\xd3\x37" "\xc2\x14\x0d\x67\x1f\x80\xa7\x95\x2e\xa6\x1c\x50\xfa\x72\x0f\x31\x66" "\x9e\xdc\xf1\x31\xcd\x41\xc3\x4d\xf9\x3f\x41\xf5\xe6\x3c\xb7\x6d\xde" "\xbb\x0e\xaf\xc7\x0f\x68\x5e\x57\x68\xd9\xd6\x68\xef\x6a\x33\x8f\x38" "\x3c\x11\x55\xbd\xb6\xd7\x39\x7d\xf9\x91\x86\x10\x18\x70\x9a\x05\x88" "\x32\x37\x91\x9c\xe4\xea\xad\x4d\xf7\x59\xd9\xc2\x74\xe8\xb7\x99\x56" "\x38\x03\x02\x10\xb1\xe0\xeb\x28\x81\xb0\xf2\x74\xdd\x9f\x53\x4b\xbe" "\xcc\x62\xc4\x43\xf2\x54\xc7\x27\x23\xd9\xf7\x9e\x1c\xd2\x28\x43\x2b" "\xbe\xaf\x1c\xee\x02\xd4\xad\xfa\xef\xed\x4e\xa7\x4a\x06\x6e\x6b\x4b" "\x9e\x0b\x57\xde\x7b\xd9\xaf\xa8\xcc\x5f\x88\xb9\xba\x2b\x29\x0f\xe9" "\xbb\xdd\x9e\x79\xa0\xd7\x61\xd2\x2b\x41\x12\x1d\x0a\x56\x29\x04\x9e" "\x00\xf0\x45\x26\xd9\xc5\x59\x13\xbe\xef\x70\x04\x59\x4b\xa7\xe8\x19" "\x81\x24\x62\x61\x49\xcf\xcb\xde\x25\x7e\x9f\x48\x31\x37\x2c\x23\xc6" "\xdc\x4c\x1d\x0f\x4c\xb7\x56\xd2\x6a\x47\xfe\xbf\xd8\x39\x5c\x38\x80" "\xec\x10\xcc\xce\x8b\x0d\x6a\xdb\xac\x5b\xdd\x9d\x13\x3c\x98\xc2\xaa" "\x9e\xf5\x96\x39\x02\x4f\x1a\xa7\x46\xea\x1c\x5d\xed\xf0\xaf\x5f\xcd" "\x80\x03\x01\x62\xe8\x03\x64\x60\x9d\xc9\xf4\x15\x2e\x8a\x9d\x18\x93" "\x9a\x1c", 512); syscall(SYS_write, r[0], 0x20000200ul, 0x200ul); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { do_sandbox_none(); } } sleep(1000000); return 0; }