// 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 #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 uintptr_t syz_fuse_mount(uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5) { uint64_t target = a0; uint64_t mode = a1; uint64_t uid = a2; uint64_t gid = a3; uint64_t maxread = a4; uint64_t flags = a5; int fd = open("/dev/fuse", O_RDWR); if (fd == -1) return fd; char buf[1024]; sprintf(buf, "fd=%d,user_id=%ld,group_id=%ld,rootmode=0%o", fd, (long)uid, (long)gid, (unsigned)mode & ~3u); if (maxread != 0) sprintf(buf + strlen(buf), ",max_read=%ld", (long)maxread); if (mode & 1) strcat(buf, ",default_permissions"); if (mode & 2) strcat(buf, ",allow_other"); syscall(SYS_mount, "", target, "fuse", flags, buf); return fd; } 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; } } } } long r[4]; void execute_call(int call) { switch (call) { case 0: syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0); break; case 1: syscall(__NR_getresgid, 0x20436000, 0x209beffc, 0x2087affc); break; case 2: memcpy((void*)0x208ce000, "./file0", 8); r[0] = syscall(__NR_openat, -1, 0x208ce000, 0x8000, 0x140); break; case 3: syscall(__NR_ioctl, r[0], 0x4b49, 0x2058b000); break; case 4: *(uint32_t*)0x20a88ffc = 0xc; if (syscall(__NR_getsockopt, 0xffffff9c, 1, 0x11, 0x20ac6000, 0x20a88ffc) != -1) r[1] = *(uint32_t*)0x20ac6000; break; case 5: syscall(__NR_sched_rr_get_interval, r[1], 0x2052f000); break; case 6: syscall(__NR_pwritev, -1, 0x20623ff0, 0, 0x7fffc); break; case 7: memcpy((void*)0x20bf5ff6, "./control", 10); syscall(__NR_mkdir, 0x20bf5ff6, 0); break; case 8: memcpy((void*)0x20559ff6, "/dev/ptmx", 10); r[2] = syscall(__NR_openat, 0xffffffffffffff9c, 0x20559ff6, 0x106, 0); break; case 9: *(uint64_t*)0x20343ff0 = 0x208eb000; *(uint64_t*)0x20343ff8 = 0; syscall(__NR_writev, r[0], 0x20343ff0, 1); break; case 10: memcpy((void*)0x20057000, "./control", 10); memcpy((void*)0x20649ff6, "./control", 10); memcpy((void*)0x200e9000, "hpfs", 5); syscall(__NR_mount, 0x20057000, 0x20649ff6, 0x200e9000, 0x4000, 0x2075cf5a); break; case 11: *(uint8_t*)0x20933000 = 7; *(uint8_t*)0x20933001 = -1; syscall(__NR_ioctl, r[2], 0x541c, 0x20933000); break; case 12: *(uint32_t*)0x20201ffc = 0x7fff; syscall(__NR_ioctl, r[2], 0x5420, 0x20201ffc); break; case 13: memcpy((void*)0x20cf1ff6, "./control", 10); syz_fuse_mount(0x20cf1ff6, 0x6000, 0, 0, 0x1cc8, 0xffe); break; case 14: syscall(__NR_epoll_create, 0x88); break; case 15: *(uint64_t*)0x20060000 = 0xffff; syscall(__NR_sched_setaffinity, r[1], 8, 0x20060000); break; case 16: memcpy((void*)0x20e48000, "/dev/sg#", 9); r[3] = syz_open_dev(0x20e48000, 0, 2); break; case 17: *(uint64_t*)0x20016000 = 0x207bb000; *(uint64_t*)0x20016008 = 1; syscall(__NR_readv, r[3], 0x20016000, 1); break; case 18: *(uint64_t*)0x20001000 = 0; *(uint64_t*)0x20001008 = 6; *(uint16_t*)0x20001010 = 0; *(uint16_t*)0x20001012 = 0; *(uint32_t*)0x20001014 = 0; *(uint64_t*)0x20001018 = 0; *(uint64_t*)0x20001020 = 0; *(uint16_t*)0x20001028 = 0; *(uint16_t*)0x2000102a = 0; *(uint32_t*)0x2000102c = 0; *(uint64_t*)0x20001030 = 0; *(uint64_t*)0x20001038 = 0x2710; *(uint16_t*)0x20001040 = 0; *(uint16_t*)0x20001042 = 0; *(uint32_t*)0x20001044 = 0; *(uint64_t*)0x20001048 = 0; *(uint64_t*)0x20001050 = 0; *(uint16_t*)0x20001058 = 0; *(uint16_t*)0x2000105a = 0; *(uint32_t*)0x2000105c = 0; syscall(__NR_write, r[3], 0x20001000, 0x60); break; } } void test() { memset(r, -1, sizeof(r)); execute(19); collide = 1; execute(19); } int main() { for (;;) { loop(); } }