// https://syzkaller.appspot.com/bug?id=311e3c9687f028b7c83a7f327936f38313dd2529 // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include #include #include #include #include static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* uctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } doexit(sig); } static void install_segv_handler() { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); 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); \ } extern unsigned long long procid; struct fs_image_segment { void* data; uintptr_t size; uintptr_t offset; }; #define IMAGE_MAX_SEGMENTS 4096 #define IMAGE_MAX_SIZE (32 << 20) #define SYZ_memfd_create 319 static uintptr_t syz_mount_image(uintptr_t fs, uintptr_t dir, uintptr_t size, uintptr_t nsegs, uintptr_t segments, uintptr_t flags, uintptr_t opts) { char loopname[64]; int loopfd, err = 0, res = -1; uintptr_t i; struct fs_image_segment* segs = (struct fs_image_segment*)segments; if (nsegs > IMAGE_MAX_SEGMENTS) nsegs = IMAGE_MAX_SEGMENTS; for (i = 0; i < nsegs; i++) { if (segs[i].size > IMAGE_MAX_SIZE) segs[i].size = IMAGE_MAX_SIZE; segs[i].offset %= IMAGE_MAX_SIZE; if (segs[i].offset > IMAGE_MAX_SIZE - segs[i].size) segs[i].offset = IMAGE_MAX_SIZE - segs[i].size; if (size < segs[i].offset + segs[i].offset) size = segs[i].offset + segs[i].offset; } if (size > IMAGE_MAX_SIZE) size = IMAGE_MAX_SIZE; int memfd = syscall(SYZ_memfd_create, "syz_mount_image", 0); if (memfd == -1) { err = errno; goto error; } if (ftruncate(memfd, size)) { err = errno; goto error_close_memfd; } for (i = 0; i < nsegs; i++) { if (pwrite(memfd, segs[i].data, segs[i].size, segs[i].offset) < 0) { } } snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid); loopfd = open(loopname, O_RDWR); if (loopfd == -1) { err = errno; goto error_close_memfd; } if (ioctl(loopfd, LOOP_SET_FD, memfd)) { if (errno != EBUSY) { err = errno; goto error_close_loop; } ioctl(loopfd, LOOP_CLR_FD, 0); usleep(1000); if (ioctl(loopfd, LOOP_SET_FD, memfd)) { err = errno; goto error_close_loop; } } mkdir((char*)dir, 0777); NONFAILING(if (strcmp((char*)fs, "iso9660") == 0) flags |= MS_RDONLY); if (mount(loopname, (char*)dir, (char*)fs, flags, (char*)opts)) { err = errno; goto error_clear_loop; } res = 0; error_clear_loop: ioctl(loopfd, LOOP_CLR_FD, 0); error_close_loop: close(loopfd); error_close_memfd: close(memfd); error: errno = err; return res; } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; unsigned long long procid; void loop() { long res = 0; NONFAILING(memcpy((void*)0x20000080, "./file0", 8)); syscall(__NR_mknod, 0x20000080, 0, 0); NONFAILING(memcpy((void*)0x20000000, "ext2", 5)); NONFAILING(memcpy((void*)0x20000040, "./file0", 8)); NONFAILING(*(uint8_t*)0x20002840 = 0); syz_mount_image(0x20000000, 0x20000040, 0, 0, 0x200027c0, 0x1008, 0x20002840); NONFAILING(memcpy((void*)0x20712ff8, "./file0", 8)); NONFAILING(memcpy((void*)0x20faffe7, "security.capability", 20)); NONFAILING(memcpy((void*)0x202b2fec, "\x00\x00\x00\x02\x01\x00\x00\x00\x00" "\x00\x00\x01\x04\x00\x00\x00\x00\x00" "\x00\x00", 20)); syscall(__NR_lsetxattr, 0x20712ff8, 0x20faffe7, 0x202b2fec, 0x14, 0); NONFAILING(memcpy((void*)0x20000000, "./bus", 6)); syscall(__NR_open, 0x20000000, 0x100000141842, 0); NONFAILING(memcpy((void*)0x20000440, "ntfs", 5)); NONFAILING(memcpy((void*)0x20000480, "./bus", 6)); syz_mount_image(0x20000440, 0x20000480, 0, 0, 0x200006c0, 0x1000, 0x20000740); NONFAILING(memcpy((void*)0x20002000, "./bus", 6)); res = syscall(__NR_open, 0x20002000, 0x141042, 0); if (res != -1) r[0] = res; NONFAILING(memcpy((void*)0x20000080, "hfs", 4)); NONFAILING(memcpy((void*)0x20000100, "./bus", 6)); NONFAILING(*(uint64_t*)0x20000340 = 0x20000140); NONFAILING(*(uint64_t*)0x20000348 = 0); NONFAILING(*(uint64_t*)0x20000350 = 0x55c3); syz_mount_image(0x20000080, 0x20000100, 0, 1, 0x20000340, 0, 0x20000780); res = syscall(__NR_dup, r[0]); if (res != -1) r[1] = res; NONFAILING(*(uint8_t*)0x200004c0 = 0x7f); NONFAILING(*(uint8_t*)0x200004c1 = 0x45); NONFAILING(*(uint8_t*)0x200004c2 = 0x4c); NONFAILING(*(uint8_t*)0x200004c3 = 0x46); NONFAILING(*(uint8_t*)0x200004c4 = 0); NONFAILING(*(uint8_t*)0x200004c5 = 0); NONFAILING(*(uint8_t*)0x200004c6 = 0); NONFAILING(*(uint8_t*)0x200004c7 = 0); NONFAILING(*(uint64_t*)0x200004c8 = 0); NONFAILING(*(uint16_t*)0x200004d0 = 0); NONFAILING(*(uint16_t*)0x200004d2 = 0); NONFAILING(*(uint32_t*)0x200004d4 = 0); NONFAILING(*(uint32_t*)0x200004d8 = 0); NONFAILING(*(uint32_t*)0x200004dc = 0x38); NONFAILING(*(uint32_t*)0x200004e0 = 0); NONFAILING(*(uint32_t*)0x200004e4 = 0); NONFAILING(*(uint16_t*)0x200004e8 = 0); NONFAILING(*(uint16_t*)0x200004ea = 0x20); NONFAILING(*(uint16_t*)0x200004ec = 0); NONFAILING(*(uint16_t*)0x200004ee = 0); NONFAILING(*(uint16_t*)0x200004f0 = 0); NONFAILING(*(uint16_t*)0x200004f2 = 0); NONFAILING(*(uint32_t*)0x200004f8 = 0); NONFAILING(*(uint32_t*)0x200004fc = 0); NONFAILING(*(uint32_t*)0x20000500 = 0); NONFAILING(*(uint32_t*)0x20000504 = 0); NONFAILING(*(uint32_t*)0x20000508 = 0); NONFAILING(*(uint32_t*)0x2000050c = 0); NONFAILING(*(uint32_t*)0x20000510 = 0); NONFAILING(*(uint32_t*)0x20000514 = 0); NONFAILING(*(uint64_t*)0x20000518 = 0); NONFAILING(*(uint64_t*)0x20000520 = 0); NONFAILING(*(uint64_t*)0x20000528 = 0); NONFAILING(*(uint64_t*)0x20000530 = 0); NONFAILING(*(uint64_t*)0x20000538 = 0); NONFAILING(*(uint64_t*)0x20000540 = 0); NONFAILING(*(uint64_t*)0x20000548 = 0); NONFAILING(*(uint64_t*)0x20000550 = 0); NONFAILING(*(uint64_t*)0x20000558 = 0); NONFAILING(*(uint64_t*)0x20000560 = 0); NONFAILING(*(uint64_t*)0x20000568 = 0); NONFAILING(*(uint64_t*)0x20000570 = 0); NONFAILING(*(uint64_t*)0x20000578 = 0); NONFAILING(*(uint64_t*)0x20000580 = 0); NONFAILING(*(uint64_t*)0x20000588 = 0); NONFAILING(*(uint64_t*)0x20000590 = 0); NONFAILING(*(uint64_t*)0x20000598 = 0); NONFAILING(*(uint64_t*)0x200005a0 = 0); NONFAILING(*(uint64_t*)0x200005a8 = 0); NONFAILING(*(uint64_t*)0x200005b0 = 0); NONFAILING(*(uint64_t*)0x200005b8 = 0); NONFAILING(*(uint64_t*)0x200005c0 = 0); NONFAILING(*(uint64_t*)0x200005c8 = 0); NONFAILING(*(uint64_t*)0x200005d0 = 0); NONFAILING(*(uint64_t*)0x200005d8 = 0); NONFAILING(*(uint64_t*)0x200005e0 = 0); NONFAILING(*(uint64_t*)0x200005e8 = 0); NONFAILING(*(uint64_t*)0x200005f0 = 0); NONFAILING(*(uint64_t*)0x200005f8 = 0); NONFAILING(*(uint64_t*)0x20000600 = 0); NONFAILING(*(uint64_t*)0x20000608 = 0); NONFAILING(*(uint64_t*)0x20000610 = 0); syscall(__NR_write, r[1], 0x200004c0, 0x158); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); install_segv_handler(); loop(); return 0; }