// https://syzkaller.appspot.com/bug?id=d91e323ce924658204882ab5ac5baf5bfebf932d // 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 #include #include #include unsigned long long procid; static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static long syz_open_dev(long a0, long a1, long a2) { if (a0 == 0xc || a0 == 0xb) { char buf[128]; sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2); return open(buf, O_RDWR, 0); } else { char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf) - 1); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 0); } } struct fs_image_segment { void* data; uintptr_t size; uintptr_t offset; }; #define IMAGE_MAX_SEGMENTS 4096 #define IMAGE_MAX_SIZE (129 << 20) #define SYZ_memfd_create 319 static long syz_read_part_table(unsigned long size, unsigned long nsegs, long segments) { char loopname[64], linkname[64]; int loopfd, err = 0, res = -1; unsigned long i, j; 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_read_part_table", 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; } } struct loop_info64 info; if (ioctl(loopfd, LOOP_GET_STATUS64, &info)) { err = errno; goto error_clear_loop; } info.lo_flags |= LO_FLAGS_PARTSCAN; if (ioctl(loopfd, LOOP_SET_STATUS64, &info)) { err = errno; goto error_clear_loop; } res = 0; for (i = 1, j = 0; i < 8; i++) { snprintf(loopname, sizeof(loopname), "/dev/loop%llup%d", procid, (int)i); struct stat statbuf; if (stat(loopname, &statbuf) == 0) { snprintf(linkname, sizeof(linkname), "./file%d", (int)j++); if (symlink(loopname, linkname)) { } } } 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 kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); int i; for (i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } #define SYZ_HAVE_RESET_LOOP 1 static void reset_loop() { char buf[64]; snprintf(buf, sizeof(buf), "/dev/loop%llu", procid); int loopfd = open(buf, O_RDWR); if (loopfd != -1) { ioctl(loopfd, LOOP_CLR_FD, 0); close(loopfd); } } #define SYZ_HAVE_SETUP_TEST 1 static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); } #define SYZ_HAVE_RESET_TEST 1 static void reset_test() { int fd; for (fd = 3; fd < 30; fd++) close(fd); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter; for (iter = 0;; iter++) { reset_loop(); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { setup_test(); execute_one(); reset_test(); exit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; sleep_ms(1); if (current_time_ms() - start < 5 * 1000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[2] = {0x0, 0xffffffffffffffff}; void execute_one(void) { long res = 0; *(uint32_t*)0x200000c0 = -1; *(uint32_t*)0x200000c4 = 3; *(uint32_t*)0x200000c8 = 0x7f; *(uint32_t*)0x200000cc = 0; *(uint32_t*)0x200000d0 = 0; *(uint8_t*)0x200000d4 = 0; *(uint8_t*)0x200000d5 = 0; *(uint8_t*)0x200000d6 = 0; *(uint8_t*)0x200000d7 = 0; *(uint8_t*)0x200000d8 = 0; *(uint8_t*)0x200000d9 = 0; *(uint8_t*)0x200000da = 0; *(uint8_t*)0x200000db = 0; *(uint8_t*)0x200000dc = 0; *(uint8_t*)0x200000dd = 0; *(uint8_t*)0x200000de = 0; *(uint8_t*)0x200000df = 0; *(uint8_t*)0x200000e0 = 0; *(uint8_t*)0x200000e1 = 0; *(uint8_t*)0x200000e2 = 0; *(uint8_t*)0x200000e3 = 0; *(uint8_t*)0x200000e4 = 0; *(uint8_t*)0x200000e5 = 0; *(uint8_t*)0x200000e6 = 0; *(uint8_t*)0x200000e7 = 0; *(uint8_t*)0x200000e8 = 0; *(uint8_t*)0x200000e9 = 0; *(uint8_t*)0x200000ea = 0; *(uint8_t*)0x200000eb = 0; *(uint8_t*)0x200000ec = 0; *(uint8_t*)0x200000ed = 0; *(uint8_t*)0x200000ee = 0; *(uint8_t*)0x200000ef = 0; *(uint8_t*)0x200000f0 = 0; *(uint8_t*)0x200000f1 = 0; *(uint8_t*)0x200000f2 = 0; *(uint8_t*)0x200000f3 = 0; syscall(__NR_ioctl, -1, 0x40345410, 0x200000c0); res = syscall(__NR_fcntl, -1, 0x10, 0x20000140); if (res != -1) r[0] = *(uint32_t*)0x20000144; *(uint32_t*)0x20000240 = 2; *(uint32_t*)0x20000244 = 7; *(uint32_t*)0x20000248 = 0; *(uint32_t*)0x2000024c = 0x81; memcpy((void*)0x20000250, "\x73\x79\x7a\x30\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00", 44); *(uint32_t*)0x2000027c = 6; *(uint32_t*)0x20000280 = 5; *(uint32_t*)0x20000284 = 0x24; *(uint32_t*)0x20000288 = 0xfff; *(uint32_t*)0x2000028c = r[0]; *(uint32_t*)0x20000290 = 9; *(uint32_t*)0x20000294 = 0; memcpy((void*)0x20000298, "\x73\x79\x7a\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 64); *(uint64_t*)0x200002d8 = 0x20000180; memcpy((void*)0x20000180, "cgroup", 7); memcpy((void*)0x20000187, "/dev/input/mice", 16); memcpy((void*)0x20000197, "proc", 5); memcpy((void*)0x2000019c, "/dev/snd/controlC#", 19); memcpy((void*)0x200001af, "/dev/zero", 10); memcpy((void*)0x200001b9, "/dev/zero", 10); memcpy((void*)0x200001c3, "eth1", 5); memcpy((void*)0x200001c8, "/dev/input/mice", 16); memcpy((void*)0x200001d8, "/dev/input/mice", 16); *(uint32_t*)0x200002e0 = 0x68; *(uint8_t*)0x200002e4 = 0; *(uint8_t*)0x200002e5 = 0; *(uint8_t*)0x200002e6 = 0; *(uint8_t*)0x200002e7 = 0; *(uint8_t*)0x200002e8 = 0; *(uint8_t*)0x200002e9 = 0; *(uint8_t*)0x200002ea = 0; *(uint8_t*)0x200002eb = 0; *(uint8_t*)0x200002ec = 0; *(uint8_t*)0x200002ed = 0; *(uint8_t*)0x200002ee = 0; *(uint8_t*)0x200002ef = 0; *(uint8_t*)0x200002f0 = 0; *(uint8_t*)0x200002f1 = 0; *(uint8_t*)0x200002f2 = 0; *(uint8_t*)0x200002f3 = 0; *(uint8_t*)0x200002f4 = 0; *(uint8_t*)0x200002f5 = 0; *(uint8_t*)0x200002f6 = 0; *(uint8_t*)0x200002f7 = 0; *(uint8_t*)0x200002f8 = 0; *(uint8_t*)0x200002f9 = 0; *(uint8_t*)0x200002fa = 0; *(uint8_t*)0x200002fb = 0; *(uint8_t*)0x200002fc = 0; *(uint8_t*)0x200002fd = 0; *(uint8_t*)0x200002fe = 0; *(uint8_t*)0x200002ff = 0; *(uint8_t*)0x20000300 = 0; *(uint8_t*)0x20000301 = 0; *(uint8_t*)0x20000302 = 0; *(uint8_t*)0x20000303 = 0; *(uint8_t*)0x20000304 = 0; *(uint8_t*)0x20000305 = 0; *(uint8_t*)0x20000306 = 0; *(uint8_t*)0x20000307 = 0; *(uint8_t*)0x20000308 = 0; *(uint8_t*)0x20000309 = 0; *(uint8_t*)0x2000030a = 0; *(uint8_t*)0x2000030b = 0; *(uint8_t*)0x2000030c = 0; *(uint8_t*)0x2000030d = 0; *(uint8_t*)0x2000030e = 0; *(uint8_t*)0x2000030f = 0; *(uint16_t*)0x20000310 = 0x40; *(uint16_t*)0x20000312 = 6; *(uint16_t*)0x20000314 = 0x800; *(uint16_t*)0x20000316 = 0xfffd; syscall(__NR_ioctl, -1, 0xc1105517, 0x20000240); memcpy((void*)0x20000200, "/dev/input/mice", 16); res = syz_open_dev(0x20000200, 0, 0); if (res != -1) r[1] = res; *(uint64_t*)0x20000100 = 0x20000040; memcpy((void*)0x20000040, "\x02\x00\xa6\xff\xff\xff\x01\x00\x00\x00\xff\x07\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x55\xaa", 64); *(uint64_t*)0x20000108 = 0x40; *(uint64_t*)0x20000110 = 0x1c0; syz_read_part_table(0x1000000000000003, 1, 0x20000100); *(uint32_t*)0x20001680 = 0xe8; syscall(__NR_getsockopt, r[1], 0, 0x10, 0x20001580, 0x20001680); *(uint32_t*)0x20000040 = 0xfffeffff; *(uint32_t*)0x20000044 = 0xe54; *(uint32_t*)0x20000048 = 5; *(uint32_t*)0x2000004c = 0x10000; syscall(__NR_setsockopt, -1, 0x10f, 0x87, 0x20000040, 0x10); memcpy((void*)0x20000080, "./file0", 8); syscall(__NR_openat, 0xffffff9c, 0x20000080, 0x8001a0, 0); } int main(void) { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }