// https://syzkaller.appspot.com/bug?id=7db3a0ee48a805cd26f19586fd8b7f32f84f304b // 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; } 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); memcpy((void*)0x20000180, "bfs\000", 4); memcpy((void*)0x20000100, "./file0\000", 8); *(uint64_t*)0x20000200 = 0x20010000; memcpy((void*)0x20010000, "\xce\xfa\xad\x1b\x00\x0e\x00\x00\xff\x7f\x00\x00\xff\xff\xff\xff\xff" "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x73\x79\x7a\x6b\x61\x03" "\x01\x00\x00\x00\x00\x00\x00\x12\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00", 62); *(uint64_t*)0x20000208 = 0x3e; *(uint64_t*)0x20000210 = 0; *(uint64_t*)0x20000218 = 0x20010040; memcpy( (void*)0x20010040, "\x02\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00\x1f\x0e\x00\x00\x02\x00" "\x00\x00\xed\x41\x00\x00\x00\x6b\x1f\x1f\x63\x6b\x1f\x1f\x63\x6b\x1f\x1f" "\x63\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 53); *(uint64_t*)0x20000220 = 0x35; *(uint64_t*)0x20000228 = 0x200; *(uint64_t*)0x20000230 = 0x20000cc0; memcpy( (void*)0x20000cc0, "\x02\x00\x00\x00\x00\x00\x0e\xfd\x5c\x5b\x00\x00\x02\x00\x2e\x2e\x00\xc9" "\x08\xa4\x3f\x85\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xae\x2d\xb2" "\xb9\x78\x75\xd4\x88\x4f\x62\xeb\xb3\x4f\xed\x20\x49\x30\x7f\xc5\x53\x73" "\x53\xf7\x50\xf8\x5b\xdf\xc6\x5a\x0f\xe9\x6e\xbd\xb8\x01\xbb\x2e\xf4\x7e" "\xb0\xdd\x07\x6d\x42\x16\xc8\x60\xe8\x54\xfe\xf9\x11\x33\xc3\x45\xfe\x81" "\x11\xab\x90\xa4\x4d\x75\xcf\xf4\xe9\x99\x66\x05\xd0\x24\x7f\xe9\x8c\xa2" "\xf4\x7a\x29\xbb\x58\x2e\x2d\xe0\x5a\x0b\xb2\xa2\x3f\x08\xe7\xc1\x61\x22" "\x3e\x62\x63\x8e\x5b\x89\xd7\x90\xad\x56\x1f\xd9\xe6\x70\x63\xc3\xff\x46" "\x33\x58\xcb\x85\x09\x4a\xb7\xbd\xc8\x2b\xd9\xbb\xf8\xc4\xd3\x58\xe3\x95" "\x35\xc3\xc6\xbe\x52\xa5\x4b\xe7\x72\x5a\x5e\x84\x28\x3a\x1a\xc9\x35\xc1" "\x19\xa5\xa4\x09\xd1\x92\x3b\x10\x08\xfa\xd6\xc8\xcd\x88\x86\x80\x25\xa6" "\x0c\x5e\x87\x43\x18\xd0\x41\xcf\xf2\xa0\xf1\xa8\x58\x63\x30\x0e\x30\x5b" "\x06\x44\xee\x17\xd3\x21\x4d\x79\x8b\xc3\x52\x6b\x81\x96\x42\x80\x97\xc9" "\x73\xfa\xc0\x3e\xcb\x5a\xb4\x95\x68\xae\x6f\xdc\x0d\x10\x81\x79\xc2\x79" "\x4d\x79\x65\xdc\xfb\xc0\x19\xc5\x6e\x28\xca\x9e\x2c\x8f\xfa\x21\x79\xac" "\xcd\x55\x33\x62\x7d\xcf\x4a\x47\x55\x42\x9f\xbd\x5d\xa2\xe2\x21\xd0\xb0" "\xd3\xcb\xa7\x5b\x87\x41\x1f\xb3\x64\x5a\x2c\x0d\x9b\x81\x8a\x64\x38\xb4" "\x35\x54\xcb\x8c\xb9\x96\x35\x7d\xc0\x7e\xea\x8e\xd2\x04\x38\x29\xd4\xd8" "\x81\xec\xe0\x70\x42\x3b\x40\xce\x40\x73\xcf\x5a\x16\xfd\xf3\x91\x42\x89" "\x1b\xcb\x0f\x11\xc3\x1e\xb1\x52\x76\x9e\x4f\x16\xce\x1b\xad\xe4\x2b\x2e" "\x78\x45\xc1\x6d\x2b\xec\x6b\x59\xbd\x03\x12\x67\xc2\x32\x38\x77\x3b\x8b" "\x2d\x66\x2f\xc0\x5d\xe2\x1e\xbb\x04\x5e\x39\xe0\xb4\xde\x37\x6e\x03\x11" "\x7d\x1d\xe1\xad\x35\x63\x7d\x4d\xd3\x64\xcd\x10\x21\x26\x1c\x4c\x2c\x74" "\xce\x6a\x0f\x16\x9a\x29\x54\x81\xf0\xd1\xba\xd9\xf8\x99\xbf\x84\xba\x68" "\xc4\x9e\x27\x58\xed\x5f\xc9\xc7\xb0\x56\x9b\xca\xbd\x2a\xe7\x13\xfa\x21" "\x8d\x96\x39\x8d\xd9\xb6\xc8\xd2\x69\x7d\x55\x39\xc4\xf3\x70\x27\xd0\x43" "\x44\xfc\xb0\x67\xc2\x72\x91\x97\x4d\xe6\x37\xd8\xbb\xfd\x06\x94\x3e\x3e" "\x33\xc8\x87\xa9\xf1\xab\x6c\x32\x2d\x74\xc5\x00\x8c\xb7\x6f\xeb\xac\x8d" "\xd0\xb6\xf8\xcb\xf0\x02\x6c\xe4\x1e\x09\xea\x0e\x1d\x0b\xff\x81\x3f\x11" "\xff\x41\x96\x0f\x7d\x0f\xe1\x44\x5f\x21\x3b\xd0\x96\xc6\xcc\x9a\xd1\xb6" "\xa5\x98\xcf\xdf\xcd\xef\x80\x09\x7b\x12\x11\xb2\xa8\xa1\x46\xae\xbf\x54" "\xab\x73\xf7\xc8\xf6\x73\xc1\x69\x26\x17\xf0\x79\xdc\x6e\x8a\x30\xdf\xb3" "\x8f\x98\x3a\x9b\xba\x90\x1d\x6e\xfe\xa8\x0a\xab\xe2\x15\x87\xb1\x71\x60" "\xfe\x9e\x6c\x6b\x53\x58\xdf\x06\x8d\x26\x17\x08\x34\x2f\x15\xd9\x24\x81" "\xd1\x68\xb8\x76\x9b\x24\x3c\xc5\x89\x49\x5b\xbd\x53\x9b\x28\x87\x3d\xf3" "\x68\x3e\xea\xe8\x88\xe9\x7e\x95\x6f\xdc\xd8\x31\x77\x2a\x5e\x6e\xa8\x86" "\x17\xaa\x53\xbb\x82\x65\x2b\x20\xd9\x05\xe1\x5e\x0c\x1e\x11\xbe\xb8\xf0" "\x3d\x96\xa4\x67\x83\xd1\x5f\xa4\x79\x1c\xb3\x3a\x17\x48\xb4\x9c\xe4\x77" "\x4f\x7c\x87\x70\x26\x94\x59\xe0\x5e\x26\x82\x3f\x64\x11\x22\x88\x98\x71" "\x38\xb2\x4c\x8b\x13\x19\x36\x52\xab\x07\x2d\x9f\x52\x62\xab\x00\xbb\x8a" "\xda\xc3\x06\x6e\xd8\x1f\xe1\x45\xbd\x5a\x7b\x9c\x87\x77\x6c\x3a\x90\x90" "\x3c\x50\xc5\xbd\x67\x1d\xf3\xcc\x73\x08\x2f\x30\xc4\x49\x47\xb2\xe1\x10" "\xac\xbb\x4e\xc3\x35\x18\xb5\x0b\x4d\x50\x2f\x08\xec\x4b\xe4\x79\xe3\x72" "\x54\x33\x75\x14\x81\xb0\xb6\x0a\xc2\xc1\xe6\x4b\x17\xbf\x9d\x24\x2d\xb6" "\x12\x9a\x10\x01\x06\x39\x67\xd1\xa1\xf8\x67\x3a\x12\xdf\xc7\x04\xc6\xb8" "\x5e\x2b\x6a\x5f\x36\x73\x9f\x45\xfa\x75\x6c\x8b\x6a\x89\x95\xe7\x39\x74" "\x1f\x87\x13\x9a\x9e\xa3\xdb\x7a\x31\x96\x51\x7b\x00\x64\x51\x46\xbb\x9b" "\x94\x64\xc3\x70\x42\x00\x4e\x92\x5c\xb2\x06\x3d\x66\xe1\x0c\xe9\xbe\x12" "\x2c\xed\xbd\xb0\x2a\xce\x85\x99\xf2\x94\xc8\x62\xbb\xa5\x74\x5e\x18\x3f" "\x4d\xe8\xc4\x7a\x15\x16\x88\xe4\xff\xb8\x8d\xbf\xc5\x88\x31\x4b\x8d\x26" "\xf9\x3f\x6a\x9b\xa3\x5e\x68\x84\x1f\xa8\x06\x3b\xa7\x34\x00\xb6\x18\x9e" "\x5f\x0d\xc1\xc0\x92\x7b\x63\x67\x38\x15\x33\x85\x05\x44\x5c\x40\xc7\xcc" "\x18\x43\x51\x01\x8c\x1d\xbe\x7f\xab\x78\xb1\xef\xa5\xc3\x79\xe9\x0f\x75" "\xb9\x1f\x4e\xd4\xc4\x1e\x06", 961); *(uint64_t*)0x20000238 = 0x3c1; *(uint64_t*)0x20000240 = 0xe00; *(uint64_t*)0x20000000 = 0; *(uint64_t*)0x20000008 = 0; *(uint16_t*)0x20000010 = -1; sprintf((char*)0x20000012, "%020llu", (long long)-1); sprintf((char*)0x20000026, "0x%016llx", (long long)-1); syz_mount_image(0x20000180, 0x20000100, 0x8000, 3, 0x20000200, 0, 0x20000000, 1); memcpy((void*)0x20000940, "./file1\000", 8); syscall(__NR_creat, 0x20000940ul, 0ul); return 0; }