// https://syzkaller.appspot.com/bug?id=bf3c4c53a63e7abdf247c9a8b94fd26f75e5b513 // 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 static unsigned long long procid; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _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(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } 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; for (i = 0; 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() { if (setsid() == -1) exit(1); 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; int collide = 0; again: for (call = 0; call < 8; 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 (collide && (call % 2) == 0) break; event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); if (!collide) { collide = 1; goto again; } } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } } } #ifndef SYS_mlockall #define SYS_mlockall 242 #endif #ifndef SYS_mmap #define SYS_mmap 197 #endif #ifndef SYS_open #define SYS_open 5 #endif #ifndef SYS_socket #define SYS_socket 394 #endif #ifndef SYS_writev #define SYS_writev 121 #endif uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: syscall(SYS_mlockall, 3ul); break; case 1: NONFAILING(memcpy((void*)0x20000040, "./file0\000", 8)); res = syscall(SYS_open, 0x20000040ul, 0x615ul, 0ul); if (res != -1) r[0] = res; break; case 2: NONFAILING(memcpy((void*)0x20000100, "./file0\000", 8)); res = syscall(SYS_open, 0x20000100ul, 0x40000400000002c2ul, 0ul); if (res != -1) r[1] = res; break; case 3: syscall(SYS_socket, 0ul, 0ul, 0); break; case 4: NONFAILING(*(uint64_t*)0x20000340 = 0x20000180); NONFAILING(*(uint64_t*)0x20000348 = 0x81700); syscall(SYS_writev, r[1], 0x20000340ul, 0x1000000000000013ul); break; case 5: syscall(SYS_mmap, 0x20000000ul, 0x3000ul, 2ul, 0x11ul, r[0], 0ul, 0ul); break; case 6: NONFAILING(memcpy((void*)0x20000100, "./file0\000", 8)); res = syscall(SYS_open, 0x20000100ul, 0x40000400000002c2ul, 0ul); if (res != -1) r[2] = res; break; case 7: NONFAILING(*(uint64_t*)0x20000640 = 0); NONFAILING(*(uint64_t*)0x20000648 = 0); NONFAILING(*(uint64_t*)0x20000650 = 0); NONFAILING(*(uint64_t*)0x20000658 = 0); NONFAILING(*(uint64_t*)0x20000660 = 0x20000200); NONFAILING(memcpy( (void*)0x20000200, "\x96\x39\x58\x2f\x8d\xca\x02\xc5\x51\x32\x6f\xdb\xfe\xbf\x28\x92\x69" "\x4d\x6d\x01\x83\x4e\x6e\x90\x5d\x56\xec\x43\xd6\x60\xd1\x36\x0c\x7c" "\x4c\xc1\xf9\x80\x6d\xdb\x0d\xd7\x09\xf5\xc7\x48\xfe\xf7\xc8\x56\xec" "\xe9\xa0\x99\x12\x23\x44\xf1\x7a\xc6\xee\x99\x56\xaa\x35\x37\x26\xe5" "\x10\xad\xd8\x49\x5c\xc4\x81\x15\xab\xdf\x19\x03\x68\xb9\x4b\x63\x28" "\x2a\x24\xb9\xa1\x69\x6a\x26\x65\xde\x0b\xe8\x63\x41\x35\x7d\xc7\x15" "\x47\xe5\x13\x6a\x44\x0b\x93\x8f\x50\x0b\xa3\xc6\xff\x0e\x2a\xd5\x84" "\xa9\x13\x36\x40\xca\xef\xef\x48\xac\x32\x0b\x0c\x04\x77\x73\x3b\xcc" "\x06\x78\x70\x31\x9c\x8a\x89\xaa\x6f\x15\xb4\xb6\xcc\xbf\x15\x1a\x37" "\x5a\xa4\x3b\x0b\x7a\xa2\x78\x90\x73\x21\x32\xd9\x9a\x67\x73\xa2\xe1" "\x33\x23\xf4\x49\x41\x27\x54\x7b\x97\x97\x10\x88\xa1\x23\xb0\x54\x90" "\x99\x86\x59\xfd\x29\x8d\xb4\x4e\x47\x8b\x44\x72\xa2\x9e\x4a\x15\xbc" "\xdd\x62\x9b\xff\x4c\x88\x85\x57\x73\xd3\x4c\x94\x17\x59\x56\xd5\xca" "\xae\x12\x76\xaa", 225)); NONFAILING(*(uint64_t*)0x20000668 = 0xe1); NONFAILING(*(uint64_t*)0x20000670 = 0); NONFAILING(*(uint64_t*)0x20000678 = 0); NONFAILING(*(uint64_t*)0x20000680 = 0); NONFAILING(*(uint64_t*)0x20000688 = 0); NONFAILING(*(uint64_t*)0x20000690 = 0x20000440); NONFAILING(memcpy( (void*)0x20000440, "\x44\x06\x5d\x89\x91\x87\xdd\xf5\x21\x6f\x8e\x1e\x26\xab\xa5\x47\xba" "\x22\x6c\x6c\xe5\x23\x14\x80\x11\xf5\x65\x67\xce\x9f\x48\xd7\xa1\x4c" "\x01\xdb\xda\xbd\x15\xa5\x4e\x46\xb0\x41\xa3\xa3\xfa\x32\xd6\x8a\xa3" "\x44\x9a\xc0\x9f\xe3\x93\x11\x72\x59\x66\x31\xc0\xe5\x91\xae\x9e\xb8" "\x4c\x3e\x0d\x8c\x43\x34\xc7\xff\x22\xf3\x0f\x90\xa1\x37\x87\xdd\xbe" "\x23\x7b\xb9\x66\x22\x7e\xe4\x3c\x55\x24\x5d\x83\x4c\xeb\x56\x3c\x69" "\x74\x9a\xe5\x0e\xca\xa6\x46\x2a\xc6\xae\x45\xae\xe3\xb7\x99\x3f\x19" "\xa5\x37\x16\x22\xe9\xb8\x18\x0d\x5a\x18\x4e\x40\x8c\xf2\x91\xa9\xad" "\x59\xf3\x2c\x65\xec\x61\x85\x90\x7d\xdc\x72\x70\x5b\x41\x86\xa7\xb9" "\xdf\xf9\x11\x2f\x96\x2a\x3d\x2a\xbe\x18\xc0\x5d\xb5\xe4\xa7\xfb\xb4" "\x20\x7f\xc2\x6e\x54\xc9\x92\xb4\xb9\x72\x9b\x52\x74\xbf\x39\xfa\x23" "\x65\x99\x39\xa9\x53\x88\x01\x2d\x39\xd3\xd6\xb7\xd4\x45\x6a\x12\xcf" "\xda\x8b\x9b\x96\xe0\xe9\x33\xdd\x1f\xed\x05\x4a\x05\x07", 218)); NONFAILING(*(uint64_t*)0x20000698 = 0xda); NONFAILING(*(uint64_t*)0x200006a0 = 0x200000c0); NONFAILING(*(uint64_t*)0x200006a8 = 0); NONFAILING(*(uint64_t*)0x200006b0 = 0); NONFAILING(*(uint64_t*)0x200006b8 = 0); NONFAILING(*(uint64_t*)0x200006c0 = 0); NONFAILING(*(uint64_t*)0x200006c8 = 0); NONFAILING(*(uint64_t*)0x200006d0 = 0x20000740); NONFAILING(memcpy( (void*)0x20000740, "\x12\xe2\x26\x0a\x83\x61\x2d\xbb\x5a\x55\xb0\x3d\xb8\x88\x6b\x64\xbe" "\xc3\x9b\xf5\x26\xce\xbe\xa8\x98\x82\x34\x4a\xb1\x72\x9d\x47\x36\xe0" "\x5b\x05\x76\x5c\x56\xa1\x1f\xa8\x62\x3e\x56\xbc\xbc\xb4\x82\xb6\x5e" "\x94\x17\xe2\x3e\x61\xa3\x91\xb7\x4c\x83\xc4\x1f\x0e\x0d\x81\xc9\xa7" "\xb9\xd9\x0e\x1a\x94\xfa\xfc\x1f\xf2\xe2\xfc\x76\xd7\x19\xa1\x77\xc3" "\xe9\x82\xe6\xd6\x73\x32\x79\xd6\x27\x58\xc5\x4a\xf0\x0e\xf9\xc9\x2f" "\x8f\x13\xa4\xbe\xb5\x9b\x99\x28\x59\xc5\x3a\x1d\xf6\xaf\x2d\xac\xd4" "\x4c\xad\x8e\xd6\x3d\x53\x72\x29\x07\x8d\x09\xa8\x89\xba\x7f\x5d\xa6" "\xc2\xd3\x17\x36\x8b\x5a\x46\x67\xf6\x5f\xb9\xd3\xfd\x3b\xac\x6c\x10" "\x22\xea\x8d\x3d\xac\x7a\x17\xf2\xb8\xba\x27\x73\x75", 166)); NONFAILING(*(uint64_t*)0x200006d8 = 0xa6); NONFAILING(*(uint64_t*)0x200006e0 = 0x20000300); NONFAILING(memcpy((void*)0x20000300, "\xc4\xd7\x43\x81\x50\x21\x26\x9c\xec" "\x91\x80\x95\x69\x51\xf3\x3f\x47\x3a" "\xa8\x9a\x33\x23\x8e\xd5\x2e\x5e\x3d" "\xcd\xe7\x9f\x99\x37\xb6\xd3\xd3\x63" "\xa4\xa7\xd5\xe6\x72\x74\xf1\xaa", 44)); NONFAILING(*(uint64_t*)0x200006e8 = 0x2c); NONFAILING(*(uint64_t*)0x200006f0 = 0x20000540); NONFAILING(memcpy( (void*)0x20000540, "\xb9\xf9\x1a\xf7\x6a\xa9\xa6\xf5\x28\x9f\xe5\x95\x61\x92\xea\x1f\xb8" "\x34\x79\xac\xbf\xcd\x29\x93\x97\x3a\x81\x6a\xa5\xd7\xe4\xd9\x4a\x1f" "\x02\x75\x32\x75\x8f\x5f\x79\x4c\xe1\x36\x13\x9b\xc9\xe5\xd5\x19\x8b" "\xfb\xe7\x55\x9a\xe9\x95\x21\xb8\xa1\xf3\x65\x1a\x7d\x82\x3f\x9e\x30" "\x8f\x87\x14\xf7\xa2\xc7\x08\x40\x47\xd6\x76\x2a\x12\x11\x26\xec\x47" "\x89\x74\x10\x08\x60\x16\x52\x19\x36\x64\xca\xf2\x72\xfb\x5d\xc1\x88" "\xca\xb8\x33\xb0\xc1\x05\x7d\x80\xaf\x2e\x32\x41\xd9\x7e\x1b\x8b\x54" "\x6f\x18\x01\x70\xd9\xaf\x12\x4a\x6a\x42\xea\xe4\x3d\x6a\x8a\x95\x94" "\x28\xc8\xf0\x65\x28\x74\x4e\xc9\x59\xc5\x69\x3f\x8c\x29\xaf\x8f\x0a" "\x91\x5c\xb5\xbb\x53\x73\x17\xfa\x06\x9a\x53\xee\xfd\xd4\x76\x1b\xa3" "\x7c\x13\x73\x5d\xad\x09\x8c\x78\xa5\x8f\x50\x15\xd1\x48\x2a\xbc\xa8" "\xb3\xc2\x54\xf6\x70\xda\xcc\x25\x84\xc6\x59\xf5\xe4\xce\x85\x6a\x0a" "\xea\x31\xfc\xca\x13\x2d\x63\x5e\xd2\xe2\x13\x4a\x88\x6b\xf1\xd5\x86" "\x39\xf9\x4e\x35\xd7\xfd\x77", 228)); NONFAILING(*(uint64_t*)0x200006f8 = 0xe4); syscall(SYS_writev, r[2], 0x20000640ul, 0xcul); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); install_segv_handler(); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { do_sandbox_none(); } } sleep(1000000); return 0; }