// 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); memcpy((void*)0x20000180, "\x6c\x6f\x63\x6b\x74\x61\x62\x6c\x65\x3d\x2e\x2c\x6c\x6f\x63\x6b\x70" "\x72\x6f\x74\x6f\x3d\x6c\x6f\x63\x6b\x5f\x6e\x6f\x53\x6f\x63\x6b\x2c" "\x00\xb3\xda\xe4\x38\x35\x79\xb4\xdb\x93\xe3\xba\xc9\x97\xb9\xe4\xef" "\x9e\x86\x6e\x5b\x7f\xf8\x4b\xf6\x58\x8c\x78\xa4\xfd\x23\x68\xf8\xc0" "\x10\x3a\x53\x40\x04\x67\x92\xd1\xb7\xb9\x50\xef\x12\x2a\x2b\x54\x10" "\x19\xf4\xd7\x6d\x04\x9a\x12\xe8\x87\x65\x3d\x79\x8e\xbc\x82\x21\xa7" "\xc9\x94\x98\x0a\xe0\x51\x09\xdc\xf5\xf0\x5d\x76\x35\x63\x38\x6c\xaa" "\x2d\x4c\xb9\x47\xec\x7d\x9a\x12\x85\xbc\x1c\x0c\xcc\x73\x2c\x18\x36" "\x0a\xe7\x77", 139); syz_mount_image(0x20000040, 0x20000080, 0, 0, 0x20000280, 0, 0x20000180); } 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; }