// 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*)0x20004940, "\x6c\x6f\x63\x6b\x70\x72\x6f\x74\x6f\x3d\x6c\x6f\x63\x6b\x5f\x6e\x6f" "\x6c\x6f\x63\x6b\x2c\x6c\x6f\x63\x6b\x74\x61\x62\x6c\x65\x3d\x67\x66" "\x73\x32\x6d\x65\x74\x61\x00\x2c\x00\xb6\x91\x27\x03\x2f\x72\x0d\xdf" "\x13\x64\x60\x39\x3f\x3b\x1b\xb7\x6b\x50\xd9\x6a\x27\x10\xfb\x10\xd4" "\xe5\x7f\x8a\xe6\xbb\x28\x2d\x9c\xeb\xc7\x3c\x3a\x5c\xeb\x5f\xe5\x6a" "\xe3\x13\x7c\xd6\x47\x1d\xba\x88\xda\x49\x41\xf4\x09\xd2\x87\x05\xc4" "\xa3\xc9\x0e\x27\xff\x7f\x30\xbb\x9f\x57\x7d\x80\x87\xc5\x5e\xce\xfe" "\x7d\x94\xb2\xc1\x83\x55\x22\xc3\x2c\xf1\x3b\xb3\x5e\x17\x88\xdf\x01" "\xe1\x64\x17\xc6\x7c\x44\x43\xb8\xd7\xbc\x23\x5c\xd1\xe5\xc8\xe8\x72" "\x38\x9c\x3b\x3c\x38\x51\x48\x99\x6f\x11\x4c\xf6\xb2\x71\x01\x51\xbd" "\x1b\x14\xaa\xf0", 174); syz_mount_image(0x20000040, 0x20000080, 0, 0, 0x20000440, 0, 0x20004940); } 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; }