// https://syzkaller.appspot.com/bug?id=0599a9428d39ccf1325a44ba03dd6668fd308828 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef __NR_memfd_create #define __NR_memfd_create 319 #endif static unsigned long long procid; struct fs_image_segment { void* data; uintptr_t size; uintptr_t offset; }; static int setup_loop_device(long unsigned size, long unsigned nsegs, struct fs_image_segment* segs, const char* loopname, int* memfd_p, int* loopfd_p) { int err = 0, loopfd = -1; int memfd = syscall(__NR_memfd_create, "syzkaller", 0); if (memfd == -1) { err = errno; goto error; } if (ftruncate(memfd, size)) { err = errno; goto error_close_memfd; } for (size_t i = 0; i < nsegs; i++) { if (pwrite(memfd, segs[i].data, segs[i].size, segs[i].offset) < 0) { } } 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; } } *memfd_p = memfd; *loopfd_p = loopfd; return 0; error_close_loop: close(loopfd); error_close_memfd: close(memfd); error: errno = err; return -1; } static long syz_mount_image(volatile long fsarg, volatile long dir, volatile unsigned long size, volatile unsigned long nsegs, volatile long segments, volatile long flags, volatile long optsarg, volatile long change_dir) { struct fs_image_segment* segs = (struct fs_image_segment*)segments; int res = -1, err = 0, loopfd = -1, memfd = -1, need_loop_device = !!segs; char* mount_opts = (char*)optsarg; char* target = (char*)dir; char* fs = (char*)fsarg; char* source = NULL; char loopname[64]; if (need_loop_device) { memset(loopname, 0, sizeof(loopname)); snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid); if (setup_loop_device(size, nsegs, segs, loopname, &memfd, &loopfd) == -1) return -1; source = loopname; } mkdir(target, 0777); char opts[256]; memset(opts, 0, sizeof(opts)); if (strlen(mount_opts) > (sizeof(opts) - 32)) { } strncpy(opts, mount_opts, sizeof(opts) - 32); if (strcmp(fs, "iso9660") == 0) { flags |= MS_RDONLY; } else if (strncmp(fs, "ext", 3) == 0) { if (strstr(opts, "errors=panic") || strstr(opts, "errors=remount-ro") == 0) strcat(opts, ",errors=continue"); } else if (strcmp(fs, "xfs") == 0) { strcat(opts, ",nouuid"); } res = mount(source, target, fs, flags, opts); if (res == -1) { err = errno; goto error_clear_loop; } res = open(target, O_RDONLY | O_DIRECTORY); if (res == -1) { err = errno; goto error_clear_loop; } if (change_dir) { res = chdir(target); if (res == -1) { err = errno; } } error_clear_loop: if (need_loop_device) { ioctl(loopfd, LOOP_CLR_FD, 0); close(loopfd); close(memfd); } errno = err; return res; } uint64_t r[1] = {0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); intptr_t res = 0; memcpy((void*)0x20000000, "erofs\000", 6); memcpy((void*)0x20000140, "./file0\000", 8); *(uint64_t*)0x20001340 = 0x20000300; memcpy((void*)0x20000300, "\x96\x26\x7e\xf7\x32\x60\xfc\xee\xeb\x07\x19\x31\x33\x38\x51\x24\x0f" "\x0c\xfe\x4a\x9b\xcf\xfc\xc0\xfe\x06\x8a\x16\x8f\xb0\xe2\xb5\x99\x6a" "\x8f\xd1\x8d\xc6\x3d\xee\x79\x6d\xb9\x9a\x00\x06\x57\xc5\x87\xbf\x7a" "\xbe\x78\x95\x17\x12\xb3\x82\x64\x9d", 60); *(uint64_t*)0x20001348 = 0x3c; *(uint64_t*)0x20001350 = 4; *(uint64_t*)0x20001358 = 0x20001400; memcpy( (void*)0x20001400, "\x3c\x17\x7f\x52\x16\xfa\x70\x33\x4e\x8d\xac\x8e\xb3\x3b\xab\xdc\x52\xdb" "\x8a\x85\x5c\x4a\x39\xde\x6c\x89\xcf\x7a\x7b\x64\xa8\x1d\x63\x22\x86\x58" "\x77\x9d\xa0\x09\xbb\x42\xc5\xb7\x7f\x3c\x1a\xd1\x18\xa2\xf1\xfd\xde\x59" "\x9a\xec\xef\xe1\x99\x04\x53\x9e\xcf\x75\x5c\xd3\xba\x46\x53\x89\x9b\x0e" "\xe8\xd1\xbb\x70\xe2\x15\xb0\x8f\x31\xd2\x53\xaa\x9c\xd6\x47\xef\x13\x9a" "\xc0\x32\xb3\x11\xb0\xc8\xaf\x5a\xe4\x71\x16\xd5\x6c\x60\x3e\x6b\x20\x96" "\x74\x47\x58\xf8\xfc\x1f\xb0\x7e\x50\x87\xbd\xc6\xeb\xe6", 122); *(uint64_t*)0x20001360 = 0x7a; *(uint64_t*)0x20001368 = 0x40; *(uint64_t*)0x20001370 = 0x20001300; memcpy((void*)0x20001300, "\x7e\x32\xd3\x17\x72\xce\xa3\x71\x7c\x3a\x04\xb4\xfc\x4b\x66", 15); *(uint64_t*)0x20001378 = 0xf; *(uint64_t*)0x20001380 = 0xba; *(uint64_t*)0x20001388 = 0x200000c0; memcpy((void*)0x200000c0, "\xe2\xe1\xf5\xe0\x95\x21\xe9\x3c\x02\x00\x18\x00\x0c\x00\x24", 15); *(uint64_t*)0x20001390 = 0xf; *(uint64_t*)0x20001398 = 0x400; *(uint64_t*)0x200013a0 = 0x20000400; memcpy((void*)0x20000400, "\x06\x00\x00\x00\x00\x45\x42\x3f\x62\xba\xe6\xa3\x60\xf5\x17\xe4\x76" "\x06\x63\xdb\x33\x1e\xca\xfd\x0a\x59\x41\xc4\x0f\xca\xa2\xac\x40\x98" "\xae\xf0\xeb\x87\x24\x83\x4f\x3d\x66\x34\x8c\xbe\x08\xde\xe4\x10\xe3" "\x28\x1c\x00\xa8\x6a\x73\x62\x7e\x22\xdb\x7b\x6e\xdc\xc5\xd0\x59\xea" "\x3d\x39\x41\x97\x6b\xb0\x31\x42\x36\xae\x62\x4f\xc8\x36\xca\xb9\xa4" "\xc5\xdd\x24\x83\x33\x4a\xc9\x76\xac\xb5\x8e\x1f\x7b\xe5\x92\x04\x0e" "\x60\x13\x9f\xa2\x17\xdb\xf7\x6e\x25\x38\xcb\xaf\xb6\x7f\x11\xd4\x46" "\xbb\x5d\xc7\xf4\x7f\x65\x8c\xee\x75\x36\x80\x37\x93\x6c\x1c\x6a\x68" "\xd1\x9e\x45\x60\x21\xc9\x14\x86\x22\xa6\xf3\x33\xa6\x06\xf7\x31\xa2" "\x31\x54\x06\x6b\x10\xc0\x4f\xbd\xac\x13\xc7\x82\x72\xec\x28\x95\xe9" "\x74\x22\xfe\x08\xcb\xed\x27\x7f\xa0\x95\xcf", 181); *(uint64_t*)0x200013a8 = 0xb5; *(uint64_t*)0x200013b0 = 0x480; *(uint64_t*)0x200013b8 = 0x20000180; memcpy( (void*)0x20000180, "\x4a\x64\x80\xb1\x76\xcd\xf2\x09\xa5\xbd\x67\x01\xd5\x6a\x6c\x71\x60\xa8" "\x05\xf1\x6a\x4d\xe7\x3b\x89\xa0\xdd\x26\x87\xb6\xa6\x63\xef\xf9\xf9\x40" "\x7e\xd5\x69\xf2\x38\x94\xab\x02\x95\x34\xd0\xe6\x52\xd0\x40\xa3\xfd\xa3" "\x65\xc1\x73\x25\xe9\xf3\x89\x1c\x46\x07\xd0\xbc\x6a\x62\x80\x9c\x0c\x1b" "\xab\x0d\x03\x08\xd2\x76\x57\x40\x90\xec\x1f\x90\x59\x3b\x19\xa5\x77\x6d" "\x6f\xc4\x19\xb9\xe7\x6e\xe9\x8f\x59\x12\x6a\x12\x7e\xcd\x75\x50\xea\x8e" "\x5e\xd1\x43\x5f\xf5\x0f\x76\x99\xaa\xf2\x11\xe1\xf3\x5b\x44\x8b\xbe\x66" "\xa4\x8b\xdb\x15\xf9\x96\xbd\xba\x38\x91\x30\x52\xfe\xf1\x03\x1a\x35\x91" "\xc8\x95\x00\x8d\x2e\x9e\x72\xfb\x0d\x0e\x4e\x8d\x22\x1d\x19\xab\x14\xa2" "\x62\x32\xbb\x7f\x51\x9f\x9a\x7f\x55\x35", 172); *(uint64_t*)0x200013c0 = 0xac; *(uint64_t*)0x200013c8 = 0x7ff; res = -1; res = syz_mount_image(0x20000000, 0x20000140, 0x8100000, 6, 0x20001340, 0, 0x200002c0, 0); if (res != -1) r[0] = res; memcpy((void*)0x200002c0, "./file0\000", 8); syscall(__NR_mkdirat, r[0], 0x200002c0ul, 0ul); return 0; }