// 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; } 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_writev #define __NR_writev 146 #endif #ifndef __NR_readv #define __NR_readv 145 #endif #ifndef __NR_ioctl #define __NR_ioctl 54 #endif #ifndef __NR_mount #define __NR_mount 21 #endif #ifndef __NR_epoll_create #define __NR_epoll_create 254 #endif #ifndef __NR_write #define __NR_write 4 #endif #ifndef __NR_socket #define __NR_socket 359 #endif #ifndef __NR_pwritev #define __NR_pwritev 334 #endif #ifndef __NR_sched_setaffinity #define __NR_sched_setaffinity 241 #endif #ifndef __NR_mmap #define __NR_mmap 192 #endif #ifndef __NR_getsockopt #define __NR_getsockopt 365 #endif #ifndef __NR_openat #define __NR_openat 295 #endif #ifndef __NR_getresuid #define __NR_getresuid 165 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 long r[4]; void execute_call(int call) { switch (call) { case 0: syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0); break; case 1: *(uint32_t*)0x2044fffc = 0xc; syscall(__NR_getsockopt, -1, 1, 0x11, 0x20a51000, 0x2044fffc); break; case 2: *(uint32_t*)0x20950ffc = 0xe8; syscall(__NR_getsockopt, -1, 0, 0x11, 0x2086cf18, 0x20950ffc); break; case 3: r[0] = syscall(__NR_socket, 0x11, 0x802, 0); break; case 4: *(uint32_t*)0x20455000 = 0x40; syscall(__NR_ioctl, r[0], 0x894c, 0x20455000); break; case 5: syscall(__NR_pwritev, r[0], 0x20623ff0, 0, 0x7fffc); break; case 6: *(uint32_t*)0x2036bfd0 = 0x20b51000; *(uint32_t*)0x2036bfd4 = 0; syscall(__NR_writev, -1, 0x2036bfd0, 1); break; case 7: 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 8: *(uint16_t*)0x20cdf000 = 0x7ff; *(uint16_t*)0x20cdf002 = 0; *(uint16_t*)0x20cdf004 = 0; *(uint16_t*)0x20cdf006 = 0; *(uint8_t*)0x20cdf008 = 0; *(uint8_t*)0x20cdf009 = 0; *(uint8_t*)0x20cdf00a = 0; *(uint8_t*)0x20cdf00b = 0; *(uint32_t*)0x20cdf00c = 8; *(uint8_t*)0x20cdf010 = 0; syscall(__NR_ioctl, -1, 0x5402, 0x20cdf000); break; case 9: *(uint32_t*)0x20457000 = 0x202dd000; *(uint32_t*)0x20457004 = 0; *(uint32_t*)0x20457008 = 0x20bbb000; *(uint32_t*)0x2045700c = 0; *(uint32_t*)0x20457010 = 0x20764000; *(uint32_t*)0x20457014 = 0; *(uint32_t*)0x20457018 = 0x20fbf000; *(uint32_t*)0x2045701c = 0; syscall(__NR_writev, -1, 0x20457000, 4); break; case 10: *(uint8_t*)0x20be9ffe = 7; *(uint8_t*)0x20be9fff = 0; syscall(__NR_ioctl, -1, 0x541c, 0x20be9ffe); break; case 11: *(uint32_t*)0x20201ffc = 0x7fff; syscall(__NR_ioctl, -1, 0x5420, 0x20201ffc); break; case 12: memcpy((void*)0x20457000, "/dev/hwrng", 11); syscall(__NR_openat, 0xffffff9c, 0x20457000, 0x200000, 0); break; case 13: if (syscall(__NR_getresuid, 0x200bf000, 0x20289000, 0x20386ffc) != -1) r[1] = *(uint32_t*)0x20289000; break; case 14: *(uint32_t*)0x201b9000 = 0xc; if (syscall(__NR_getsockopt, r[0], 1, 0x11, 0x20210ff4, 0x201b9000) != -1) r[2] = *(uint32_t*)0x20210ffc; break; case 15: memcpy((void*)0x20cf1ff6, "./control", 10); syz_fuse_mount(0x20cf1ff6, 0x6000, r[1], r[2], 0x1cc8, 0x1000); break; case 16: syscall(__NR_epoll_create, 0x400); break; case 17: *(uint64_t*)0x20060000 = 0x86b2; syscall(__NR_sched_setaffinity, 0, 8, 0x20060000); break; case 18: memcpy((void*)0x200c8ff7, "/dev/sg#", 9); r[3] = syz_open_dev(0x200c8ff7, 0, 2); break; case 19: *(uint32_t*)0x20016000 = 0x207bb000; *(uint32_t*)0x20016004 = 1; syscall(__NR_readv, r[3], 0x20016000, 1); break; case 20: *(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[3], 0x20001000, 0x60); break; } } void test() { memset(r, -1, sizeof(r)); execute(21); collide = 1; execute(21); } int main() { for (;;) { loop(); } }