// autogenerated by syzkaller (http://github.com/google/syzkaller) #ifndef __NR_socket #define __NR_socket 41 #endif #ifndef __NR_syz_fuse_mount #define __NR_syz_fuse_mount 1000004 #endif #ifndef __NR_syz_fuseblk_mount #define __NR_syz_fuseblk_mount 1000005 #endif #ifndef __NR_syz_open_pts #define __NR_syz_open_pts 1000003 #endif #ifndef __NR_syz_test #define __NR_syz_test 1000001 #endif #ifndef __NR_mmap #define __NR_mmap 9 #endif #ifndef __NR_connect #define __NR_connect 42 #endif #ifndef __NR_sendmsg #define __NR_sendmsg 46 #endif #ifndef __NR_syz_open_dev #define __NR_syz_open_dev 1000002 #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include __thread int skip_segv; __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* uctx) { if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED)) _longjmp(segv_env, 1); exit(sig); } static void install_segv_handler() { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } 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_open_pts(uintptr_t a0, uintptr_t a1) { int ptyno = 0; if (ioctl(a0, TIOCGPTN, &ptyno)) return -1; char buf[128]; sprintf(buf, "/dev/pts/%d", ptyno); return open(buf, a1, 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 uintptr_t syz_fuseblk_mount(uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7) { uint64_t target = a0; uint64_t blkdev = a1; uint64_t mode = a2; uint64_t uid = a3; uint64_t gid = a4; uint64_t maxread = a5; uint64_t blksize = a6; uint64_t flags = a7; int fd = open("/dev/fuse", O_RDWR); if (fd == -1) return fd; if (syscall(SYS_mknodat, AT_FDCWD, blkdev, S_IFBLK, makedev(7, 199))) return fd; char buf[256]; 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 (blksize != 0) sprintf(buf + strlen(buf), ",blksize=%ld", (long)blksize); if (mode & 1) strcat(buf, ",default_permissions"); if (mode & 2) strcat(buf, ",allow_other"); syscall(SYS_mount, blkdev, target, "fuseblk", flags, buf); return fd; } static uintptr_t execute_syscall(int nr, uintptr_t a0, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6, uintptr_t a7, uintptr_t a8) { switch (nr) { default: return syscall(nr, a0, a1, a2, a3, a4, a5); case __NR_syz_test: return 0; case __NR_syz_open_dev: return syz_open_dev(a0, a1, a2); case __NR_syz_open_pts: return syz_open_pts(a0, a1); case __NR_syz_fuse_mount: return syz_fuse_mount(a0, a1, a2, a3, a4, a5); case __NR_syz_fuseblk_mount: return syz_fuseblk_mount(a0, a1, a2, a3, a4, a5, a6, a7); } } long r[25]; int main() { install_segv_handler(); memset(r, -1, sizeof(r)); r[0] = execute_syscall(__NR_mmap, 0x20000000ul, 0xf60000ul, 0x3ul, 0x32ul, 0xfffffffffffffffful, 0x0ul, 0, 0, 0); r[1] = execute_syscall(__NR_socket, 0x1dul, 0x80002ul, 0x2ul, 0, 0, 0, 0, 0, 0); NONFAILING(*(uint16_t*)0x20f57000 = (uint16_t)0x27); NONFAILING(*(uint32_t*)0x20f57004 = (uint32_t)0x0); NONFAILING(*(uint32_t*)0x20f57008 = (uint32_t)0x0); NONFAILING(*(uint32_t*)0x20f5700c = (uint32_t)0x0); NONFAILING(*(uint8_t*)0x20f57010 = (uint8_t)0x0); NONFAILING(*(uint8_t*)0x20f57011 = (uint8_t)0x0); NONFAILING(memcpy( (void*)0x20f57012, "\x34\x1b\x3a\x01\xb2\x57\x84\x9c\xa1\xd7\xd1\xff\x9f\x99\x9d\x81" "\x27\xb1\x85\xf8\x8d\x1d\x77\x5d\x59\xc8\x8a\x3a\xa6\xa8\xdd\xac" "\xdf\x2b\xdc\x32\x4e\xa6\x57\x8a\x21\xb8\x51\x14\x61\x01\x86\xc3" "\x81\x7c\x34\xb0\x5e\xaf\xfd\x2c\x3f\x54\xf5\x7f\xa8\x1b\xa0", 63)); NONFAILING(*(uint64_t*)0x20f57058 = (uint64_t)0x0); r[10] = execute_syscall(__NR_connect, r[1], 0x20f57000ul, 0x60ul, 0, 0, 0, 0, 0, 0); NONFAILING(*(uint64_t*)0x20b05000 = (uint64_t)0x20f55000); NONFAILING(*(uint32_t*)0x20b05008 = (uint32_t)0x0); NONFAILING(*(uint64_t*)0x20b05010 = (uint64_t)0x20008fe0); NONFAILING(*(uint64_t*)0x20b05018 = (uint64_t)0x2); NONFAILING(*(uint64_t*)0x20b05020 = (uint64_t)0x20f54000); NONFAILING(*(uint64_t*)0x20b05028 = (uint64_t)0x0); NONFAILING(*(uint32_t*)0x20b05030 = (uint32_t)0x0); NONFAILING(*(uint64_t*)0x20008fe0 = (uint64_t)0x20d5fff1); NONFAILING(*(uint64_t*)0x20008fe8 = (uint64_t)0xf); NONFAILING(*(uint64_t*)0x20008ff0 = (uint64_t)0x20f55000); NONFAILING(*(uint64_t*)0x20008ff8 = (uint64_t)0x69); NONFAILING(memcpy( (void*)0x20d5fff1, "\x05\x00\x00\x00\x8d\x13\x00\x00\x00\x00\x17\x14\xb7\x7e\xa6", 15)); NONFAILING(memcpy( (void*)0x20f55000, "\x12\x6f\x39\xb6\x5b\x4e\xed\x90\x77\xe0\x54\xbf\xb6\xb2\x41\xd7" "\x36\x5d\x58\xfa\xa8\x32\x7a\x6d\x25\x89\x01\x00\xdd\x00\xc5\x89" "\x07\xec\xc2\x76\x8d\x02\x00\x00\x00\x10\xb4\x27\xab\x6c\x2a\x41" "\xe2\x54\x47\xcc\x08\xca\x75\x2a\x03\x89\xd3\x04\x71\x3f\x75\x90" "\xf4\xda\xc6\xd9\xa7\x50\xff\xe8\x3e\xff\xcd\x31\x1b\xa2\x0a\xee" "\x8a\x72\x6b\xda\x74\x75\x92\xbf\xad\xf0\x71\xb9\xb7\x70\x04\xbb" "\x58\x40\x7d\x50\x14\x6b\xd7\xc2\x60", 105)); r[24] = execute_syscall(__NR_sendmsg, r[1], 0x20b05000ul, 0x0ul, 0, 0, 0, 0, 0, 0); return 0; }