// 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_getgroups #define __NR_getgroups 80 #endif #ifndef __NR_mkdir #define __NR_mkdir 39 #endif #ifndef __NR_write #define __NR_write 4 #endif #ifndef __NR_openat #define __NR_openat 295 #endif #ifndef __NR_mount #define __NR_mount 21 #endif #ifndef __NR_readv #define __NR_readv 145 #endif #ifndef __NR_mmap #define __NR_mmap 192 #endif #ifndef __NR_getsockopt #define __NR_getsockopt 365 #endif #ifndef __NR_socket #define __NR_socket 359 #endif #ifndef __NR_writev #define __NR_writev 146 #endif #ifndef __NR_getresuid #define __NR_getresuid 165 #endif #ifndef __NR_epoll_create #define __NR_epoll_create 254 #endif #ifndef __NR_ioctl #define __NR_ioctl 54 #endif #ifndef __NR_pwritev #define __NR_pwritev 334 #endif #ifndef __NR_fcntl #define __NR_fcntl 55 #endif #ifndef __NR_sched_setaffinity #define __NR_sched_setaffinity 241 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 long r[5]; void execute_call(int call) { switch (call) { case 0: syscall(__NR_mmap, 0x20000000, 0xfff000, 0x3, 0x32, 0xffffffff, 0x0); break; case 1: *(uint32_t*)0x2044fffc = 0xc; syscall(__NR_getsockopt, 0xffffffff, 0x1, 0x11, 0x20a51000, 0x2044fffc); break; case 2: syscall(__NR_getgroups, 0x0, 0x20b88ffc); break; case 3: *(uint32_t*)0x20950ffc = 0xe8; syscall(__NR_getsockopt, 0xffffffff, 0x0, 0x11, 0x2086cf18, 0x20950ffc); break; case 4: r[0] = syscall(__NR_socket, 0x11, 0x802, 0x0); break; case 5: *(uint32_t*)0x20455000 = 0x40; syscall(__NR_ioctl, r[0], 0x894c, 0x20455000); break; case 6: syscall(__NR_pwritev, r[0], 0x20623ff0, 0x0, 0x7fffc); break; case 7: memcpy((void*)0x20bf5ff6, "./control", 10); syscall(__NR_mkdir, 0x20bf5ff6, 0x1); break; case 8: memcpy((void*)0x201b4ff6, "/dev/ptmx", 10); r[1] = syscall(__NR_openat, 0xffffff9c, 0x201b4ff6, 0x106, 0x0); break; case 9: syscall(__NR_fcntl, r[1], 0x0, r[0]); break; case 10: *(uint32_t*)0x20a21ff0 = 0x20b51000; *(uint32_t*)0x20a21ff4 = 0x0; syscall(__NR_writev, r[0], 0x20a21ff0, 0x1); break; case 11: 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 12: *(uint16_t*)0x20cdf000 = 0x7ff; *(uint16_t*)0x20cdf002 = 0x0; *(uint16_t*)0x20cdf004 = 0x0; *(uint16_t*)0x20cdf006 = 0x0; *(uint8_t*)0x20cdf008 = 0x0; *(uint8_t*)0x20cdf009 = 0x0; *(uint8_t*)0x20cdf00a = 0x0; *(uint8_t*)0x20cdf00b = 0x0; *(uint32_t*)0x20cdf00c = 0x8; *(uint8_t*)0x20cdf010 = 0x0; syscall(__NR_ioctl, r[1], 0x5402, 0x20cdf000); break; case 13: *(uint32_t*)0x20457000 = 0x202dd000; *(uint32_t*)0x20457004 = 0x0; *(uint32_t*)0x20457008 = 0x20bbb000; *(uint32_t*)0x2045700c = 0x0; *(uint32_t*)0x20457010 = 0x20764000; *(uint32_t*)0x20457014 = 0x0; *(uint32_t*)0x20457018 = 0x20fbf000; *(uint32_t*)0x2045701c = 0x0; syscall(__NR_writev, r[1], 0x20457000, 0x4); break; case 14: *(uint8_t*)0x20be9ffe = 0x7; *(uint8_t*)0x20be9fff = 0x0; syscall(__NR_ioctl, r[1], 0x541c, 0x20be9ffe); break; case 15: *(uint32_t*)0x20201ffc = 0x7fff; syscall(__NR_ioctl, r[1], 0x5420, 0x20201ffc); break; case 16: memcpy((void*)0x20457000, "/dev/hwrng", 11); syscall(__NR_openat, 0xffffff9c, 0x20457000, 0x200000, 0x0); break; case 17: if (syscall(__NR_getresuid, 0x200bf000, 0x20289000, 0x20386ffc) != -1) { r[2] = *(uint32_t*)0x20289000; } break; case 18: *(uint32_t*)0x201b9000 = 0xc; if (syscall(__NR_getsockopt, r[0], 0x1, 0x11, 0x204ffff4, 0x201b9000) != -1) { r[3] = *(uint32_t*)0x204ffffc; } break; case 19: memcpy((void*)0x20cf1ff6, "./control", 10); syz_fuse_mount(0x20cf1ff6, 0x6000, r[2], r[3], 0x1cc8, 0x1000); break; case 20: syscall(__NR_epoll_create, 0x9); break; case 21: *(uint64_t*)0x20060000 = 0x86b2; syscall(__NR_sched_setaffinity, 0x0, 0x8, 0x20060000); break; case 22: memcpy((void*)0x20e48000, "/dev/sg#", 9); r[4] = syz_open_dev(0x20e48000, 0x0, 0x2); break; case 23: *(uint32_t*)0x20016000 = 0x207bb000; *(uint32_t*)0x20016004 = 0x1; syscall(__NR_readv, r[4], 0x20016000, 0x1); break; case 24: *(uint32_t*)0x20001000 = 0x0; *(uint32_t*)0x20001004 = 0x6; *(uint16_t*)0x20001008 = 0x0; *(uint16_t*)0x2000100a = 0x0; *(uint32_t*)0x2000100c = 0x0; *(uint32_t*)0x20001010 = 0x0; *(uint32_t*)0x20001014 = 0x0; *(uint16_t*)0x20001018 = 0x0; *(uint16_t*)0x2000101a = 0x0; *(uint32_t*)0x2000101c = 0x0; *(uint32_t*)0x20001020 = 0x0; *(uint32_t*)0x20001024 = 0x2710; *(uint16_t*)0x20001028 = 0x0; *(uint16_t*)0x2000102a = 0x0; *(uint32_t*)0x2000102c = 0x0; *(uint32_t*)0x20001030 = 0x0; *(uint32_t*)0x20001034 = 0x0; *(uint16_t*)0x20001038 = 0x0; *(uint16_t*)0x2000103a = 0x0; *(uint32_t*)0x2000103c = 0x0; syscall(__NR_write, r[4], 0x20001000, 0x60); break; } } void loop() { memset(r, -1, sizeof(r)); execute(25); collide = 1; execute(25); } int main() { loop(); return 0; }