// https://syzkaller.appspot.com/bug?id=6dcd14a729df98f989c7b76d254226ae67084efd // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2) { if (a0 == 0xc || a0 == 0xb) { char buf[128]; sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2); return open(buf, O_RDWR, 0); } else { char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf)); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } static void test(); void loop() { while (1) { test(); } } struct thread_t { int created, running, call; pthread_t th; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static int collide; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { while (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &th->running, FUTEX_WAIT, 0, 0); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 0, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); } return 0; } static void execute(int num_calls) { int call, thread; running = 0; for (call = 0; call < num_calls; call++) { for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); pthread_create(&th->th, &attr, thr, th); } if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) { th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); if (collide && call % 2) break; struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 20 * 1000 * 1000; syscall(SYS_futex, &th->running, FUTEX_WAIT, 1, &ts); if (running) usleep((call == num_calls - 1) ? 10000 : 1000); break; } } } } #ifndef __NR_socket #define __NR_socket 359 #endif #ifndef __NR_setsockopt #define __NR_setsockopt 366 #endif #ifndef __NR_write #define __NR_write 4 #endif #ifndef __NR_read #define __NR_read 3 #endif #ifndef __NR_mmap #define __NR_mmap 192 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 long r[1]; void execute_call(int call) { switch (call) { case 0: syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0); break; case 1: syscall(__NR_socket, 1, 0xb, 0); break; case 2: *(uint16_t*)0x20000fe0 = 7; *(uint16_t*)0x20000fe2 = 6; *(uint16_t*)0x20000fe4 = 2; *(uint32_t*)0x20000fe8 = 0x401; *(uint32_t*)0x20000fec = 1; *(uint32_t*)0x20000ff0 = 4; *(uint32_t*)0x20000ff4 = 1; *(uint32_t*)0x20000ff8 = 2; *(uint32_t*)0x20000ffc = 0; syscall(__NR_setsockopt, -1, 0x84, 0xa, 0x20000fe0, 0x20); break; case 3: memcpy((void*)0x20005000, "/dev/sg#", 9); r[0] = syz_open_dev(0x20005000, 0, 0x8002); break; case 4: *(uint32_t*)0x2010dffc = 6; syscall(__NR_setsockopt, r[0], 1, 0x1d, 0x2010dffc, 4); break; case 5: memcpy((void*)0x2074dfc1, "\xb6\x3d\xb8\x5e\x1e\x8d\x22\x5d\xbb\xf3\xb2\x9d\x73\x93\x15\xd6" "\x1d\xcc\x43\x6a\xed\x5e\xd2\xbc\x70\x18\xce\xbc\x9b\x97\xae\x21" "\x91\x4d\x87\x2c\x67\x8c\xe2\x2c\x9b\x16\x0e\x96\xaa\x1f\xae\x1a", 48); syscall(__NR_write, r[0], 0x2074dfc1, 0x30); break; case 6: syscall(__NR_read, r[0], 0x20e31f0f, 0); break; } } void test() { memset(r, -1, sizeof(r)); execute(7); collide = 1; execute(7); } int main() { for (;;) { loop(); } }