// https://syzkaller.appspot.com/bug?id=3c1f47967b7cbd399d3ba3e65f297a29aa1c5f92 // 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 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); 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; } } } } uint64_t r[1] = {0xffffffffffffffff}; uint64_t procid; void execute_call(int call) { long res; switch (call) { case 0: memcpy((void*)0x20005000, "/dev/sg#", 9); res = syz_open_dev(0x20005000, 0, 0x8002); if (res != -1) r[0] = res; break; case 1: memcpy((void*)0x20000440, "\xb6\x3d\xc0\x7f\x34\x33\x02\x00\xf6\x0c\x00\x00\x00\x72\x4a\xed" "\x8b\x27\x00\x3e\xf0\x6d\x7f\x7a\x26\x2f\x89\x4b\x4c\x3e\x37\xd5" "\x01\x1d\xcc\x60\x6a\xed\x5e\x95\xd2\xbc\x70\x18\xce\xbc\xdc\xd1" "\xb3\x18\x82\xe5\xcb\x00\x00\x01\x00\x00\x00\x00\x00\xfb\x1e\xef" "\x15\x87\x16\x00\x4f\x76\xac\xb2\xc3\x86\xe3\x24\x11\x49\xc3\x36" "\x48\xa6\xb1\x69\xd9\x79\xb6\xd5\x90\x06\x1b\xf7\xdb\x76\x70\xb4" "\xbe\xd1\x24\xde\x49\x08\xa8\xd6\xc5\x55\x74\x65\x72\x46\x44\x8a" "\x1b\x78\xde\xcc\x6d\x96\x39\x35\xdd\x7c\x57\x58\x39\xc7\x60\xa6" "\xf7\xf0\xbe\xcb\x0e\xe8\x79\xa6\x58\xb9\x10\x58\x71\x25\xff\x73" "\xbe\xc0\xa8\x96\x40\xb3\xe8\xe8\x54\xe0\x36\x7f\x4c\xf9\x80\x30" "\x38\x24\x72\xcf\x24\xce\xc9\x52\x02\x50\x67\xde\x5b\xa6\xd7\xa7" "\x23\x2f\x2e\x2b\xa1\x24\xb3\x12\x11\xbf\x52\x39\x96\xa2\xf9\xe5" "\x3e\xfa\x40\xf4\xdc\x84\xbe\x71\xa4\xb3\x7a\xd6\x91\x8d\xe4\x95" "\x65\x4e\x38\x0a\x1e\x5d\xeb\xc7\x37\x2b\xb2\xaa\x10\xd7\x5f\xce" "\x17\x07\x06\x62\x74\xca\xd6\x91\xd4\x24\x65\x53\x2a\x17\xd4\x3f" "\x46\x20\xcb\xc4\x78\xb3\xae\xb5\x7b\xda\x6e\x6c\xea\xac\x85\xcb" "\x18\x0e\xd5\x6b\x04\x2c\x4e\x37\x58\x3f\xd0\x8f\x35\xef\x63\xcc" "\xe5\x3c\x0e\x6c\x11\xd1\xfb\xd0\x73\xab\x5d\xbd\x7a\x74\xc0\xb2" "\x7b\xd4\x7e\x38\x30\x12\x22\x2a\x54\xf8\xc8\x4c\x22\x51\x9f\x4f" "\xa1\x8c\x32\xe8\x1a\xdd\x51\x47\x54\x71\x72\xd8\x35\x01\xa6\x30" "\xc9\x0a\x27\xf1\x7a\x9c\x9a\x79\x67\x72\xb8\x9a\x8b\xea\x8b\x7a" "\xe2\x59\x5f\xd3\xef\x7b\xdf\x1c\x5b\x73\xf1\x1c\xe2\x17\x36\xe7" "\xdc\xf8\xea\x27\x3f\xf5\x58\xf1\x6d\xa3\x23", 363); syscall(__NR_write, r[0], 0x20000440, 0x16b); break; case 2: *(uint64_t*)0x2085dff0 = 0x20e94000; *(uint64_t*)0x2085dff8 = 0x10295; syscall(__NR_readv, r[0], 0x2085dff0, 1); break; } } void test() { execute(3); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (procid = 0; procid < 8; procid++) { if (fork() == 0) { for (;;) { loop(); } } } sleep(1000000); return 0; }