// https://syzkaller.appspot.com/bug?id=a133db4b32d89957481e21b5080f9edfa3bf4359 // 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 #include #include 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 void use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } #define FS_IOC_SETFLAGS _IOW('f', 2, long) static void remove_dir(const char* dir) { int iter = 0; DIR* dp = 0; retry: while (umount2(dir, MNT_DETACH | UMOUNT_NOFOLLOW) == 0) { } dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exit(1); } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); while (umount2(filename, MNT_DETACH | UMOUNT_NOFOLLOW) == 0) { } struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EPERM) { int fd = open(filename, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exit(1); if (umount2(filename, MNT_DETACH | UMOUNT_NOFOLLOW)) exit(1); } } closedir(dp); for (int i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EPERM) { int fd = open(dir, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, MNT_DETACH | UMOUNT_NOFOLLOW)) exit(1); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exit(1); } } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); for (int 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) { } } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); write_file("/proc/self/oom_score_adj", "1000"); if (symlink("/dev/binderfs", "./binderfs")) { } } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); setup_test(); execute_one(); 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 < 5000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; memcpy((void*)0x20000000, "./file0\000", 8); syscall(__NR_mkdir, 0x20000000ul, 0ul); res = syscall(__NR_pipe2, 0x20000180ul, 0ul); if (res != -1) { r[0] = *(uint32_t*)0x20000180; r[1] = *(uint32_t*)0x20000184; } memcpy( (void*)0x20000400, "\x15\x09\x00\x00\x00\xff\xff\x5e\x32\xf8\x02\xdc\x53\xb2\x70\x95\xf3\x89" "\x88\x57\x3f\x3c\xe4\x38\x33\x3a\xb5\x45\xca\xc7\xf9\x6f\xa6\x53\xd0\x65" "\x96\x49\xe9\x58\x34\x4a\x9f\x9b\xca\xca\xa8\x6e\x70\x98\xc5\x58\x60\xbc" "\xf6\xb1\x28\x2d\xe1\x2c\xcf\x18\x91\x5f\x0f\xb7\x2b\x13\x1c\xc6\x7d\x73" "\x6f\xfb\x5c\xfa\x0a\x5f\x06\xbf\x12\x05\xc7\xca\x5f\xc2\x36\x73\x0b\xba" "\xaf\x50\xab\x86\x2e\xc3\xc8\x9e\x86\x7e\x4b\xc3\x3e\x4d\x3a\xb3\x8c\xb5" "\x25\x59\x5a\x1b\xfd\x6f\xcf\x70\xa1\x82\x25\xd7\x97\x9b\x90\xa7\x83\xea" "\x84\x0f\xde\xc8\x7e\xdd\x9e\x7a\x16\x5f\x29\xbd\x35\x8c\x93\xdb\x38\xc3" "\x5e\xb3\xc3\xc7\xf6\x82\xf9\xbf\x75\xfd\x1c\x23\x4c\x7c\xdf\xc0\x65\xfe" "\x2b\xa8\xb5\xbe\x8d\xb2\x26\x67\x17\xc3\x23\xa9\xda\xc8\x3e\x89\x51\x4d" "\x2c\xc3\x8b\x31\x55\x01\x11\x5d\xea\x6c\x9e\x9c\x30\x9f\x16\x87\xaf\x95" "\x3a\xdf\x68\xff\x40\x49\xdc\xab\x44\x04\xc8\xe7\x2b\x59\x51\xc1\x77\x32" "\x40\xd9\xc9\xf1\x6f\x89\x22\x5d\x51\x95\x6d\x2c\x72\x7c\x5f\x50\x53\x80" "\xed\x56\x82\x1e\x9d\x9c\xf3\x03\x3a\xb6\x76\xfd\xf6\x10\xa1\x36\xaf\x2c" "\xb3\xd3\x75\x14\x2e\xb7\x13\x48\x4d\x01\x1a\x9a\xb5\x6d\xb8\x74\xe5\x58" "\x41\xb3\xcb\xa1\x8e\xc2\xd1\x3b\xd6\xc5\xd0\x35\xe6\xf5\x4d\xaf\x78\x00" "\xf8\x19\x08\xca\x1f\xf2\x1d\x95\x21\x67\x24\x8d\xa3\xb4\x75\x6e\x3b\x97" "\xf9\xf4\x1a\xd0\x36\x28\xfc\xa3\xaa\x27\x30\x9b\x7d\x34\xbd\x78\x2b\x44" "\xd2\x0a\x90\x3b\x07\x76\xe7\x13\xf6\x20\x0c\xd9\xf8\x55\x50\x50\x48\x27" "\x1d\x68\x5e\x12\xff\x90\x64\xa5\x91\x65\xea\x5a\x6c\x84\xd2\x4b\x28\xde" "\x3b\x7b\x70\xb8\xb5\x41\xa7\x6b\xab\x2a\x85\x03\xae\x10\xe4\x54\x5d\x16" "\x44\x0c\x93\x9a\x67\xe6\x31\x6d\xe5\x0f\xdb\x0a\x25\x4a\xf2\xd1\x18\xa6" "\x49\x52\xec\xdd\x65\xc7\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\xd4\x49\x50\x3c\x3d\xb5\xcf\x8a\x25\x4e\x21\x59\xd3\x97\x9b\x2a\x3e\xa6" "\xce\xdb\xa2\xd0\x00\x51\x10\xa1\xb8\x01\x87\x4b\x0b\x2b\xed\x87\x88\x0c" "\xcd\x99\x89", 453); syscall(__NR_write, r[1], 0x20000400ul, 0x15ul); res = syscall(__NR_dup, r[1]); if (res != -1) r[2] = res; memcpy((void*)0x20000040, "./file0\000", 8); memcpy((void*)0x200001c0, "9p\000", 3); memcpy((void*)0x20000080, "trans=fd,rfdno=", 15); sprintf((char*)0x2000008f, "0x%016llx", (long long)r[0]); memcpy((void*)0x200000a1, ",wfdno=", 7); sprintf((char*)0x200000a8, "0x%016llx", (long long)r[2]); syscall(__NR_mount, 0ul, 0x20000040ul, 0x200001c0ul, 0ul, 0x20000080ul); } 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); use_temporary_dir(); loop(); return 0; }