// https://syzkaller.appspot.com/bug?id=597b2fc85015dc9145b56a848e646e78217acba9 // 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() { 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); if (pthread_create(&th, &attr, fn, arg)) exit(1); pthread_attr_destroy(&attr); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_RELAXED)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } static long syz_open_procfs(long a0, long a1) { char buf[128]; memset(buf, 0, sizeof(buf)); if (a0 == 0) { snprintf(buf, sizeof(buf), "/proc/self/%s", (char*)a1); } else if (a0 == -1) { snprintf(buf, sizeof(buf), "/proc/thread-self/%s", (char*)a1); } else { snprintf(buf, sizeof(buf), "/proc/self/task/%d/%s", (int)a0, (char*)a1); } int fd = open(buf, O_RDWR); if (fd == -1) fd = open(buf, O_RDONLY); return fd; } 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() { int i, call, thread; int collide = 0; again: for (call = 0; call < 4; call++) { for (thread = 0; thread < 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) { long res; switch (call) { case 0: memcpy((void*)0x20000180, "\x74\x61\x73\x6b\x00\x7b\xc6\x9d\x49\x4c\x9f\x65\xf3\xb0\x84\xe2" "\x02\xa4\x7b\x84\x57\x32\x93\x05\x45\xea\xc9\x0c\x90\x1a\x30\x94" "\xb8\xfe\x22\xde\x36\xf0\xd8\x5a\xe8\xed\x6c\xf3\x36\x57\xb8\x79" "\x39\x60\x0f\x31\x6d\x92\x07\xfe\xf2\xaf\xfc\xa8\x74\xab\x29\x70" "\x00\x5b\x20\x1a\xc6\x57\x86\x26\x84\xe0\x17\xca\x2d\x02\xb4\xe7" "\xee\xcb\x5d\xbb\xe2\x84\x25\xdf\xd4\xf3\xe8\xd1\x6a\xd6\x2c\x9f" "\xaa\x66\x7d\x1b\xe6\xf4\x55\x0d\x41\x86\x1a\x4e\xe7\x65\xa0\x04" "\xd1\xf5\x6b\xd1\x69\x29\x12\xca\x86\x1e\xe3\x15\xa5\x7e\xc3\x23" "\x52\x99\xfc\xdf\x53\x2f\xce\x59\x74\x02\x29\x6c\x9c\xcd\x54\xbb" "\x43\x65\x3c\xef\x30\xe1\xa1\x18\x78\x82\x56\xf8\xf4\xec\x35\x67" "\xe8\x82\x1c\x44\xa7\x34\xba\xbb\xe7\x25\x0d\xa2\xcc\x5a\x87\x2b" "\x3b\xda\x93\xcc\xd5\x43\x42\x5d\x18\xdc\x61\x7d\x7f\x6a\xbf\xbf" "\xa0\xc6\x6d\xbc\xc6\x9f\x75\x38\x94\xee\x34", 203); res = syz_open_procfs(0, 0x20000180); if (res != -1) r[0] = res; break; case 1: syscall(__NR_getdents64, r[0], 0x20001380, 0x1000); break; case 2: syscall(__NR_fcntl, r[0], 0x402, 0x31); break; case 3: syscall(__NR_exit, 0); break; } } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); loop(); return 0; }