// https://syzkaller.appspot.com/bug?id=fabf30f1ed65a56e0b0171fe91fcf3fb5085d3b2 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include 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; } #define __syscall syscall 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) { int i, call, thread; int collide = 0; again: 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 (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; } } uint64_t r[1] = {0xffffffffffffffff}; void execute_call(int call) { intptr_t res; switch (call) { case 0: memcpy((void*)0x20000000, "/dev/pf\000\000", 9); res = syscall(SYS_openat, 0xffffffffffffff9cul, 0x20000000ul, 0ul, 0ul); if (res != -1) r[0] = res; break; case 1: *(uint32_t*)0x20000080 = 0; syscall(SYS_ioctl, r[0], 0xc0504417ul, 0x20000080ul); break; case 2: memcpy( (void*)0x200000c0, "\x00\x00\x00\x00\x00\x00\x00\x00\x50\xf1\xf2\x48\xbb\x7e\x91\xfd\xb5" "\x7c\x6b\xac\x50\x64\x6e\x64\x70\x72\x00\x9a\x1a\x70\xb4\xfe\xf2\xc9" "\xcc\x4e\x3f\xed\x29\x0f\xa6\x59\x95\xd4\x3d\xee\xfa\x8d\x4b\x1b\xe0" "\x10\x80\x26\x50\xfa\x0a\x92\xf3\xe7\x08\x1f\x64\x5d\x29\xa7\xe0\xfd" "\x44\x9d\xc6\x1a\x95\x27\xf1\x1c\x2c\x66\x93\xa9\x90\xa9\xb5\x33\x3d" "\x0b\xab\xa4\xe8\x83\xfe\xda\x38\x22\xa2\xdb\x39\xf7\xe5\x87\xa9\x52" "\x42\x5f\xa4\x24\x5f\xcb\x61\x3b\x57\x48\x5d\xb5\x88\x46\x8b\x92\x73" "\x88\xa9\xe4\x4c\xfc\x1b\x0e\x67\x93\x83\x32\x78\xde\x74\xc9\xd8\x30" "\x2d\xbb\xd2\x93\xf1\x15\x9f\xdf\xaa\x3b\x1e\x01\x86\xe9\xeb\x7c\xa0" "\xea\xca\x6e\xdd\x20\x03\x55\x35\x8c\x14\xd2\x57\x7e\x04\xfe\x24\x1a" "\x63\x0f\x54\xc6\x63\xa7\x01\x3e\x17\xb6\x39\x88\x72\x82\xb8\x57\x82" "\xa3\xbc\x0d\x05\xa8\x10\xa5\x31\xa9\x52\x1d\x8b\x42\x40\xeb\xf9\x66" "\xda\x67\x23\x72\x03\xe1\x09\xef\x71\x70\x38\x32\xd1\x8f\x97\x53\x71" "\x4b\xc0\x6b\x31\x20\x96\x40\xa9\xd2\xab\xd8\x3c\xd7\x68\x9b\x89\x8e" "\x25\x29\x0c\xfa\x61\x35\x5b\xa3\x9b\x9a\x98\xa4\x18\xc0\x05\xc4\x0a" "\x9c\xfb\xb6\xe3\x00\xc5\xe2\x53\x41\x62\x72\x6c\x8c\x2b\x3c\x47\x44" "\xa3\x81\xd8\x27\xe8\x96\xd9\x18\xd1\xf1\x9d\xfe\x2f\xc5\x45\xe5\x11" "\xc6\x16\xb4\x01\xd3\x53\xe9\xab\xe9\xad\x73\xf2\x41\x7b\x47\x24\x25" "\xf3\xb1\xfe\xbb\x7f\xac\xb4\xcf\x48\xe9\x46\xf7\xcf\x42\x4c\x28\x48" "\x96\x83\x8b\x1f\x7b\xef\x44\x7b\x6e\x30\xb1\x65\xd5\x12\xf8\xa3\xd0" "\x17\x5a\x55\x9b\x32\x76\xc2\x96\xbf\x4c\x24\x36\x4f\xfe\x8d\x11\xca" "\x71\x2b\xb4\x82\xf4\xc6\x84\xba\xf8\x5c\xcc\xaa\x7b\x5c\x9b\x39\x3c" "\x96\x73\x28\x1b\x57\x78\xfe\x27\x07\x9d\x2d\x5c\x8e\x40\xae\x93\xb3" "\x75\xec\xbb\xed\x42\xe3\xb8\xea\xc9\x16\x49\x0d\x85\x44\xed\x24\xc2" "\x34\xb8\x51\x2c\x6f\x74\x92\xf2\x6d\x77\xb7\xa6\x5d\xdd\xe3\x73\xe4" "\x35\x0c\xf2\x25\xe8\x1d\x99\xf0\x8a\xc0\xf0\x5d\x58\x4c\x72\x72\x7b" "\x89\x0b\xec\xcd\x62\xc6\x10\xd7\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00", 466); syscall(SYS_msgsnd, 0, 0x200000c0ul, 0x101ul, 0x800ul); break; } } int main(void) { syscall(SYS_mmap, 0x20000000ul, 0x1000000ul, 3ul, 0x1012ul, -1, 0ul, 0ul); loop(); return 0; }