// https://syzkaller.appspot.com/bug?id=b6aff64ebd79a1ee5ee7e787ca5b8673ba722226 // 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; int collide = 0; again: for (call = 0; call < 10; 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, 50); 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 = 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[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: *(uint32_t*)0x20000140 = 0; *(uint16_t*)0x20000144 = 0xe; *(uint8_t*)0x20000146 = 1; syscall(SYS_setsockopt, -1, 0x84, 0x1e, 0x20000140ul, 8ul); break; case 1: syscall(SYS_pipe2, 0ul, 4ul); break; case 2: *(uint8_t*)0x200000c0 = 0x10; *(uint8_t*)0x200000c1 = 2; *(uint16_t*)0x200000c2 = htobe16(0x4e21 + procid * 4); *(uint32_t*)0x200000c4 = htobe32(-1); *(uint8_t*)0x200000c8 = 0; *(uint8_t*)0x200000c9 = 0; *(uint8_t*)0x200000ca = 0; *(uint8_t*)0x200000cb = 0; *(uint8_t*)0x200000cc = 0; *(uint8_t*)0x200000cd = 0; *(uint8_t*)0x200000ce = 0; *(uint8_t*)0x200000cf = 0; syscall(SYS_connect, -1, 0x200000c0ul, 0x10ul); break; case 3: res = syscall(SYS_socket, 2ul, 1ul, 0x84); if (res != -1) r[0] = res; break; case 4: res = syscall(SYS_dup, r[0]); if (res != -1) r[1] = res; break; case 5: *(uint64_t*)0x200007c0 = 0x20000180; *(uint8_t*)0x20000180 = 0x1c; *(uint8_t*)0x20000181 = 0x1c; *(uint16_t*)0x20000182 = htobe16(0x4e23 + procid * 4); *(uint32_t*)0x20000184 = 0xfff; *(uint64_t*)0x20000188 = htobe64(0); *(uint64_t*)0x20000190 = htobe64(1); *(uint32_t*)0x20000198 = 0x253f; *(uint32_t*)0x200007c8 = 0x1c; *(uint64_t*)0x200007d0 = 0; *(uint32_t*)0x200007d8 = 0; *(uint64_t*)0x200007e0 = 0x20000780; *(uint32_t*)0x20000780 = 0x1c; *(uint32_t*)0x20000784 = 0x84; *(uint32_t*)0x20000788 = 0xa; *(uint64_t*)0x2000078c = htobe64(0); *(uint64_t*)0x20000794 = htobe64(1); *(uint32_t*)0x2000079c = 0x1c; *(uint32_t*)0x200007a0 = 0x84; *(uint32_t*)0x200007a4 = 0xa; memcpy((void*)0x200007a8, "\x71\xfd\x17\x9d\x1d\x53\x17\x9f\xb7\x03\x0c\x21\xd4\x78\xae\x70", 16); *(uint32_t*)0x200007e8 = 0x38; *(uint32_t*)0x200007ec = 0x10000; syscall(SYS_sendmsg, r[1], 0x200007c0ul, 0x108ul); break; case 6: *(uint64_t*)0x20000a40 = 0x20000800; memcpy( (void*)0x20000800, "\x42\xcb\x14\x75\x0b\x9c\xb5\xcc\xa0\x5b\xb7\xbc\x66\xb5\x3c\xee\x62" "\x7f\x33\x29\xd7\x1e\xb3\xec\xe6\xd6\xb9\x9d\x87\xd7\x6a\x3d\x6c\xe3" "\x12\x2e\x1d\xf4\x0f\x02\xd6\xd8\x61\x5a\xd1\x44\x5f\xfa\x0f\x77\x1b" "\xca\x50\x75\x1a\xed\xa7\xd7\x5b\xce\x6a\xf8\xdb\x1c\x9e\xe8\xcd\xfd" "\xcd\x59\x34\xfc\x2a\xfc\x35\x7c\xf5\x9e\x3a\x36\x32\x93\xee\x91\xe4" "\xcb\xfe\x80\x34\xb3\x2a\x7e\x4f\xf2\x73\x1d\x33\x2f\xf8\x66\x42\x1f" "\xc0\xad\xed\x7f\xa7\x5b\x3d\xc5\x77\x46\x5a\x5b\xeb\xda\x0c\x39\x5a" "\xa9\x93\x72\xa7\x1e\x25\x21\x3e\x11\x06\xf3\xaa\xcb\xd8\x26\xed\xcd" "\xb8\x10\x61\x56\x26\x94\xd7\x8f\xac\x26\xec\x46\xea\xb8\xaa", 151); *(uint64_t*)0x20000a48 = 0x97; *(uint64_t*)0x20000a50 = 0x200008c0; *(uint64_t*)0x20000a58 = 0; *(uint64_t*)0x20000a60 = 0x20000940; memcpy( (void*)0x20000940, "\xa4\x3f\xf5\xc7\xb5\x13\xef\x61\x97\x0f\xcd\x2c\x84\xe3\x3d\x11\xd4" "\x97\xeb\x8f\x99\x5a\x2f\x00\xf9\xe7\xb4\x9a\x12\xfb\xd7\xdd\x6e\x3c" "\x4a\x1d\xc4\xc4\x8e\x09\x33\x38\x80\x8f\x7d\xca\x41\x7b\xa6\x58\x3c" "\x88\x55\x6c\x88\xb4\x10\x5c\x52\x78\x61\xc1\x60\x51\x7e\xe9\xac\xb7" "\x39\x83\xc1\x09\x4e\x0f\x47\x1f\xc8\xc6\x94\x4f\x34\x0e\x2b\x83\x50" "\xb0\xa9\x76\xd1\x27\xb1\x40\x0f\xc9\xce\x60\x95\x0b\xea\x8d\x44\x1e" "\x9e\x3a\x4f\x12\x3b\x8d\xc7\xf0\x10\x54\x26\x9c\x2c\x3e\xf7\x82\x06" "\x57\x6f\x0b\xaf\x62\x3f\x44\x1e\xa5\x83\x5e\x0a\xfe\xa5\x67\xb1\x1a" "\x01\x72\xf1\x4d\xa9\xd4\x83\xf6\x3f\x1a\x70\x9a\xd8\xe6\x0b\x97\x8e" "\x8e\x02\x06\x6c\xc0\xda\x89\x89\x56\x38\x0d\xe9\x49\x07\x9d\x82\x46" "\x51\xc6\x09\xbb\x7e\xf0\x88\x10\xe3\xbe\x6f\x31\xf4\xc9\xbd\xaa\x3a" "\x14\x6f\xa5\xc7\xd1\x1c\xfe\x3d\x6e\x3a\xb5\xfd\x10", 200); *(uint64_t*)0x20000a68 = 0xc8; syscall(SYS_writev, -1, 0x20000a40ul, 3ul); break; case 7: *(uint8_t*)0x20000300 = 0x10; *(uint8_t*)0x20000301 = 2; *(uint16_t*)0x20000302 = htobe16(0x4e23 + procid * 4); *(uint8_t*)0x20000304 = 0xac; *(uint8_t*)0x20000305 = 0x14; *(uint8_t*)0x20000306 = 0 + procid * 1; *(uint8_t*)0x20000307 = 0xaa; *(uint8_t*)0x20000308 = 0; *(uint8_t*)0x20000309 = 0; *(uint8_t*)0x2000030a = 0; *(uint8_t*)0x2000030b = 0; *(uint8_t*)0x2000030c = 0; *(uint8_t*)0x2000030d = 0; *(uint8_t*)0x2000030e = 0; *(uint8_t*)0x2000030f = 0; syscall(SYS_bind, r[0], 0x20000300ul, 0x10ul); break; case 8: *(uint8_t*)0x20000000 = 0x10; *(uint8_t*)0x20000001 = 2; *(uint16_t*)0x20000002 = htobe16(0x4e23 + procid * 4); *(uint8_t*)0x20000004 = 0xac; *(uint8_t*)0x20000005 = 0x14; *(uint8_t*)0x20000006 = 0 + procid * 1; *(uint8_t*)0x20000007 = 0xaa; *(uint8_t*)0x20000008 = 0; *(uint8_t*)0x20000009 = 0; *(uint8_t*)0x2000000a = 0; *(uint8_t*)0x2000000b = 0; *(uint8_t*)0x2000000c = 0; *(uint8_t*)0x2000000d = 0; *(uint8_t*)0x2000000e = 0; *(uint8_t*)0x2000000f = 0; syscall(SYS_connect, r[0], 0x20000000ul, 0x10ul); break; case 9: syscall(SYS_listen, r[0], 0xffffff78); 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; }