// 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 #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; } 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_ioctl #define __NR_ioctl 54 #endif #ifndef __NR_pwritev #define __NR_pwritev 334 #endif #ifndef __NR_epoll_create #define __NR_epoll_create 254 #endif #ifndef __NR_sched_setaffinity #define __NR_sched_setaffinity 241 #endif #ifndef __NR_readv #define __NR_readv 145 #endif #ifndef __NR_write #define __NR_write 4 #endif #ifndef __NR_mmap #define __NR_mmap 192 #endif #ifndef __NR_getresgid #define __NR_getresgid 171 #endif #ifndef __NR_openat #define __NR_openat 295 #endif #ifndef __NR_mkdir #define __NR_mkdir 39 #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: 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: syscall(__NR_pwritev, -1, 0x20623ff0, 0, 0x7fffc); break; case 5: memcpy((void*)0x20bf5ff6, "./control", 10); syscall(__NR_mkdir, 0x20bf5ff6, 0); break; case 6: memcpy((void*)0x20559ff6, "/dev/ptmx", 10); r[1] = syscall(__NR_openat, 0xffffff9c, 0x20559ff6, 0x106, 0); break; case 7: *(uint8_t*)0x20933000 = 7; *(uint8_t*)0x20933001 = -1; syscall(__NR_ioctl, r[1], 0x541c, 0x20933000); break; case 8: *(uint32_t*)0x20201ffc = 0x7fff; syscall(__NR_ioctl, r[1], 0x5420, 0x20201ffc); break; case 9: memcpy((void*)0x20cf1ff6, "./control", 10); syz_fuse_mount(0x20cf1ff6, 0x6000, 0, 0, 0x1cc8, 0xffe); break; case 10: syscall(__NR_epoll_create, 0x88); break; case 11: *(uint64_t*)0x20060000 = 0xffff; syscall(__NR_sched_setaffinity, 0, 8, 0x20060000); break; case 12: memcpy((void*)0x20e48000, "/dev/sg#", 9); r[2] = syz_open_dev(0x20e48000, 0, 2); break; case 13: *(uint32_t*)0x20016000 = 0x207bb000; *(uint32_t*)0x20016004 = 1; syscall(__NR_readv, r[2], 0x20016000, 1); break; case 14: *(uint32_t*)0x20001000 = 0; *(uint32_t*)0x20001004 = 6; *(uint16_t*)0x20001008 = 0; *(uint16_t*)0x2000100a = 0; *(uint32_t*)0x2000100c = 0; *(uint32_t*)0x20001010 = 0; *(uint32_t*)0x20001014 = 0; *(uint16_t*)0x20001018 = 0; *(uint16_t*)0x2000101a = 0; *(uint32_t*)0x2000101c = 0; *(uint32_t*)0x20001020 = 0; *(uint32_t*)0x20001024 = 0x2710; *(uint16_t*)0x20001028 = 0; *(uint16_t*)0x2000102a = 0; *(uint32_t*)0x2000102c = 0; *(uint32_t*)0x20001030 = 0; *(uint32_t*)0x20001034 = 0; *(uint16_t*)0x20001038 = 0; *(uint16_t*)0x2000103a = 0; *(uint32_t*)0x2000103c = 0; syscall(__NR_write, r[2], 0x20001000, 0x60); break; } } void loop() { memset(r, -1, sizeof(r)); execute(15); collide = 1; execute(15); } int main() { loop(); return 0; }