// 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_fcntl #define __NR_fcntl 55 #endif #ifndef __NR_execve #define __NR_execve 11 #endif #ifndef __NR_readv #define __NR_readv 145 #endif #ifndef __NR_mmap #define __NR_mmap 192 #endif #ifndef __NR_ioctl #define __NR_ioctl 54 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 long r[3]; void execute_call(int call) { switch (call) { case 0: syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0); break; case 1: memcpy((void*)0x20dd5000, "/dev/snd/seq", 13); r[0] = syz_open_dev(0x20dd5000, 0, 0x400); break; case 2: *(uint8_t*)0x206bffb0 = 0; *(uint8_t*)0x206bffb1 = 5; *(uint8_t*)0x206bffb2 = 0xe; *(uint8_t*)0x206bffb3 = 0; *(uint32_t*)0x206bffb4 = 0; *(uint32_t*)0x206bffb8 = 3; *(uint8_t*)0x206bffbc = 1; *(uint8_t*)0x206bffbd = 0; *(uint8_t*)0x206bffbe = 0; *(uint8_t*)0x206bffbf = 0; *(uint8_t*)0x206bffc0 = 0; *(uint8_t*)0x206bffc1 = 0; *(uint8_t*)0x206bffc2 = 0; *(uint8_t*)0x206bffc3 = 0; *(uint8_t*)0x206bffc4 = 0; *(uint8_t*)0x206bffc5 = 0; *(uint8_t*)0x206bffc6 = 0; *(uint8_t*)0x206bffc7 = 0; *(uint8_t*)0x206bffc8 = 0; *(uint8_t*)0x206bffc9 = 0; *(uint8_t*)0x206bffca = 0; *(uint8_t*)0x206bffcb = 0; *(uint8_t*)0x206bffcc = 0; *(uint8_t*)0x206bffcd = 0; *(uint8_t*)0x206bffce = 0; *(uint8_t*)0x206bffcf = 0; *(uint8_t*)0x206bffd0 = 0; *(uint8_t*)0x206bffd1 = 0; *(uint8_t*)0x206bffd2 = 0; *(uint8_t*)0x206bffd3 = 0; *(uint8_t*)0x206bffd4 = 0; *(uint8_t*)0x206bffd5 = 0; *(uint8_t*)0x206bffd6 = 0; *(uint8_t*)0x206bffd7 = 0; *(uint8_t*)0x206bffd8 = 0; *(uint8_t*)0x206bffd9 = 0; *(uint8_t*)0x206bffda = 0; *(uint8_t*)0x206bffdb = 0; *(uint8_t*)0x206bffdc = 0; *(uint8_t*)0x206bffdd = 0; *(uint8_t*)0x206bffde = 0; *(uint8_t*)0x206bffdf = 0; *(uint8_t*)0x206bffe0 = 0; *(uint8_t*)0x206bffe1 = 0; *(uint8_t*)0x206bffe2 = 0; *(uint8_t*)0x206bffe3 = 0; *(uint8_t*)0x206bffe4 = 0; *(uint8_t*)0x206bffe5 = 0; *(uint8_t*)0x206bffe6 = 0; *(uint8_t*)0x206bffe7 = 0; *(uint8_t*)0x206bffe8 = 0; *(uint8_t*)0x206bffe9 = 0; *(uint8_t*)0x206bffea = 0; *(uint8_t*)0x206bffeb = 0; *(uint8_t*)0x206bffec = 0; *(uint8_t*)0x206bffed = 0; *(uint8_t*)0x206bffee = 0; *(uint8_t*)0x206bffef = 0; *(uint8_t*)0x206bfff0 = 0; *(uint8_t*)0x206bfff1 = 0; *(uint8_t*)0x206bfff2 = 0; *(uint8_t*)0x206bfff3 = 0; *(uint8_t*)0x206bfff4 = 0; *(uint8_t*)0x206bfff5 = 0; *(uint8_t*)0x206bfff6 = 0; *(uint8_t*)0x206bfff7 = 0; *(uint8_t*)0x206bfff8 = 0; *(uint8_t*)0x206bfff9 = 0; *(uint8_t*)0x206bfffa = 0; *(uint8_t*)0x206bfffb = 0; *(uint8_t*)0x206bfffc = 0; *(uint8_t*)0x206bfffd = 0; *(uint8_t*)0x206bfffe = 0; *(uint8_t*)0x206bffff = 0; syscall(__NR_ioctl, r[0], 0x40505330, 0x206bffb0); break; case 3: r[1] = syscall(__NR_fcntl, r[0], 9); break; case 4: syscall(__NR_fcntl, r[0], 8, r[1]); break; case 5: memcpy((void*)0x20844ff8, "./file0", 8); *(uint32_t*)0x20966ff8 = 0x20aa4000; memcpy((void*)0x20aa4000, "md5sumcgroupselfvboxnet0)),keyring", 35); *(uint32_t*)0x20a83000 = 0x20981ff6; *(uint32_t*)0x20a83004 = 0x20777000; *(uint32_t*)0x20a83008 = 0x2078a000; *(uint32_t*)0x20a8300c = 0x20299ffe; *(uint32_t*)0x20a83010 = 0x202b9fff; *(uint32_t*)0x20a83014 = 0x200d2000; *(uint32_t*)0x20a83018 = 0x2044bfff; *(uint32_t*)0x20a8301c = 0x2096c000; memcpy((void*)0x20981ff6, "%'", 3); memcpy((void*)0x20777000, "vboxnet0%", 10); memcpy((void*)0x2078a000, "])em1em1vmnet1md5sumsecurity]#vboxnet1nodev", 44); memcpy((void*)0x20299ffe, "@", 2); memcpy((void*)0x202b9fff, "", 1); memcpy((void*)0x200d2000, "]", 2); memcpy((void*)0x2044bfff, "", 1); memcpy((void*)0x2096c000, "", 1); syscall(__NR_execve, 0x20844ff8, 0x20966ff8, 0x20a83000); break; case 6: memcpy((void*)0x20005000, "/dev/sg#", 9); r[2] = syz_open_dev(0x20005000, 0, 0x101000); break; case 7: *(uint32_t*)0x20ff4fe0 = 0x20163f7e; *(uint32_t*)0x20ff4fe4 = 0; *(uint32_t*)0x20ff4fe8 = 0x201e9000; *(uint32_t*)0x20ff4fec = 0x3f; syscall(__NR_readv, r[2], 0x20ff4fe0, 2); break; case 8: syscall(__NR_ioctl, r[2], 0x2285, 0x20007000); break; } } void test() { memset(r, -1, sizeof(r)); execute(9); collide = 1; execute(9); } int main() { for (;;) { loop(); } }