// https://syzkaller.appspot.com/bug?id=9463343a39f66062536eca45450081f837781f88 // 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 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; } 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); 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[1] = {0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(SYS_socket, 0x1cul, 1ul, 0x84); if (res != -1) r[0] = res; break; case 1: *(uint8_t*)0x200000c0 = 0x1c; *(uint8_t*)0x200000c1 = 0x1c; *(uint16_t*)0x200000c2 = htobe16(0x4e22 + procid * 4); *(uint32_t*)0x200000c4 = 0; *(uint64_t*)0x200000c8 = htobe64(0); *(uint64_t*)0x200000d0 = htobe64(1); *(uint32_t*)0x200000d8 = 0; syscall(SYS_connect, r[0], 0x200000c0ul, 0x1cul); break; case 2: memcpy( (void*)0x20000d80, "\x16\x0d\xe4\xf9\xf0\xad\xa4\x14\xb4\x0e\x42\x6f\xc3\x63\x42\xc8\xe3" "\x71\xcb\x0f\x5e\xd1\xa1\x6a\xe2\x31\x4d\x26\x78\xf5\xfc\xdf\xac\xe7" "\x6e\x34\x87\x90\x8f\x04\x5d\x53\x9a\xdc\xb3\xf6\xee\xb8\x73\x25\xe3" "\x34\x23\xf2\x47\xc8\x04\x3b\x87\x60\x78\xef\x2c\x7e\xf5\x92\x33\xc4" "\x87\x64\xa5\xc2\x9d\xb2\x2e\x7b\xbe\x27\x75\xf4\xaf\x8a\xa8\xa3\x3f" "\x66\xf6\x0c\x84\xc6\xe4\x0f\x6a\x9c\x11\xce\x4a\x15\x07\x9f\x52\x93" "\xe9\x1c\x38\xb4\xa8\xa0\x70\xe7\x36\x48\x9a\x5a\x61\xbc\x1a\x73\x14" "\xe8\x75\x79\x50\x88\x17\x2f\xdb\x35\x44\x5f\x92\x1d\x82\x43\x19\xbf" "\x81\xf0\x84\xd1\x9e\x1c\xff\xc6\x85\xab\x6e\x9a\xba\x9d\x14\x50\x7d" "\x26\x08\x17\x83\x1a\x10\x9a\x0a\x86\x1c\x82\x90\x9d\x43\x29\xd7\xf8" "\x5b\x99\xdf\x7a\xc5\x51\xd3\x24\x8e\x81\x30\x4f\x1c\x72\xf3\x0a\xde" "\xdd\x31\x55\x1a\x8d\x41\xef\x04\xf4\x8f\x05\xbd\x7f\x3c\x9f\xd4\x8b" "\x3a\x25\xb6\xb2\x76\x3a\xe4\xf0\x01\xf3\xf5\x7a\xa9\x4b\x34\x0b\x35" "\xb4\xce\x47\x30\x81\x4e\x5b\xf8\x92\x1a\xfb\x04\xfa\xaf\x4f\xc1\xe9" "\x19\xd4\xbb\x0b\x7d\x34\x17\x71\x33\x15\xa0\x27\xe1\x88\xc1\xe3\xc6" "\xad\xe2\x44\xc7\x6c\x0a\xd0\x01\xcd\x2e\x6c\xce\xb7\x7a\x36\xe6\x8a" "\x94\xb7\x32\x84\xc1\x7a\x91\x15\xb7\xb7\x9f\xd3\x26\xd4\xb1\xc6\x3d" "\x89\xdf\x5a\x8d\xa5\x06\x22\x22\x5d\xf9\x6c\xfb\x47\x95\x81\x73\x79" "\x23\xca\x38\x1a\xac\xb8\xb5\xca\x67\xde\x65\x51\x90\x49\x2b\x3e\xea" "\xe4\x63\x2e\x0d\xc1\x3a\x20\xdc\x95\x52\xda\xb9\xfc\xbd\x2b\xc1\x6a" "\x22\x9e\xe1\x7b\x5e\x99\x4a\x9a\x38\xbb\x20\xe0\x63\x7b\x55\x93\x67" "\x3f\x79\x6a\xe7\x63\xc4\xce\xca\x25\x68\x78\x5c\x62\xbe\x38\xcb\xc3" "\xf2\x78\xca\x00\x82\xfb\xb2\xbc\x1c\x47\x8e\x7f\x64\xcb\xe1\x9e\xce" "\x18\xd2\x84\xb2\x17\xc2\xb6\x49", 399); syscall(SYS_sendto, r[0], 0x20000d80ul, 0x18ful, 0x20108ul, 0ul, 0ul); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x1012ul, -1, 0ul); for (procid = 0; procid < 4; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }