// https://syzkaller.appspot.com/bug?id=ac7d83330e5b421283436e44cb7e186da15b8f9c // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include 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); 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; } static void execute_one(); extern unsigned long long procid; void loop() { while (1) { execute_one(); } } unsigned long long procid; void execute_one() { memcpy((void*)0x20000040, "gfs2", 5); memcpy((void*)0x20000080, "./file0", 8); *(uint64_t*)0x20000200 = 0x200000c0; *(uint64_t*)0x20000208 = 0; *(uint64_t*)0x20000210 = 1; *(uint64_t*)0x20000218 = 0x20000100; *(uint64_t*)0x20000220 = 0; *(uint64_t*)0x20000228 = 0xfffffffffffffffe; *(uint64_t*)0x20000230 = 0x20000140; *(uint64_t*)0x20000238 = 0; *(uint64_t*)0x20000240 = 0xfbb3; *(uint64_t*)0x20000248 = 0x20000180; *(uint64_t*)0x20000250 = 0; *(uint64_t*)0x20000258 = 0x62; memcpy((void*)0x200003c0, "\x6e\x6f\x72\x67\x72\x70\x6c\x76\x62\x2c\x6e\x6f\x64\x69\x73\x63\x61" "\x72\x64\x2c\x65\x72\x72\x6f\x72\x73\x3d\x77\x69\x74\x68\x64\x72\x61" "\x77\x2c\x6e\x6f\x62\x61\x72\x72\x69\x65\x72\x2c\x6c\x6f\x63\x6b\x70" "\x72\x6f\x74\x6f\x3d\x6c\x6f\x63\x6b\x5f\x6e\x6f\x6c\x6f\x63\x6b\x2c" "\x64\x69\x73\x63\x61\x72\x64\x2c\x75\x70\x67\x72\x61\x64\x65\x2c\x73" "\x74\x61\x74\x66\x73\x5f\x71\x75\x61\x6e\x74\x75\x6d\x3d\x36\x37\x38" "\x35\x2c\x6e\x6f\x71\x75\x6f\x74\x61\x2c\x6c\x6f\x63\x6b\x74\x61\x62" "\x6c\x65\x3d\x2f\x64\x65\x76\x2f\x64\x73\x70\x23\x00\x2c\x00\x7b\xd2" "\x1b\x06\xfb\x74\x85\xd2\x76\x6c\x50\xce\xfe\x66\x9e\x84\x9c\x16\xc3" "\xb3\xee\x0c\xca\x8b\xcb\x2a\xd5\x55\x03\x0c\x12\x92\x96\xb7\xeb", 169); syz_mount_image(0x20000040, 0x20000080, 0, 4, 0x20000200, 2, 0x200003c0); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (procid = 0; procid < 8; procid++) { if (fork() == 0) { for (;;) { loop(); } } } sleep(1000000); return 0; }