// https://syzkaller.appspot.com/bug?id=cc48191274be0a9e986e29be2ef06fc176c4aa51 // 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 #include #include #include #include #include #include #include #include #include #include static __thread int clone_ongoing; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { if (__atomic_load_n(&clone_ongoing, __ATOMIC_RELAXED) != 0) { exit(sig); } uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0; int valid = addr < prog_start || addr > prog_end; if (skip && valid) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) ({ int ok = 1; __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); if (_setjmp(segv_env) == 0) { __VA_ARGS__; } else ok = 0; __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); ok; }) static void kill_and_wait(int pid, int* status) { kill(pid, SIGKILL); while (waitpid(-1, status, 0) != pid) { } } 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 void __attribute__((noinline)) remove_dir(const char* dir) { DIR* dp = opendir(dir); if (dp == NULL) { if (errno == EACCES) { if (rmdir(dir)) exit(1); return; } 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); struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } if (unlink(filename)) { exit(1); } } closedir(dp); while (rmdir(dir)) { exit(1); } } #define CAST static void execute_one(void); #define WAIT_FLAGS 0 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); 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[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; NONFAILING(*(uint64_t*)0x20000000 = 0x10); NONFAILING(*(uint64_t*)0x20000008 = 0); NONFAILING(*(uint64_t*)0x20000010 = 0x20ffb000); NONFAILING(*(uint64_t*)0x20000018 = 0x20ffd000); NONFAILING(*(uint64_t*)0x20000020 = 0x1000); NONFAILING(*(uint64_t*)0x20000028 = 0x2002f000); NONFAILING(*(uint64_t*)0x20000030 = 0x20000000); NONFAILING(*(uint64_t*)0x20000038 = 0); NONFAILING(*(uint64_t*)0x20000040 = 0x20060000); NONFAILING(*(uint64_t*)0x20000048 = 0x20298000); NONFAILING(*(uint64_t*)0x20000050 = 0); NONFAILING(*(uint64_t*)0x20000058 = 0); NONFAILING(*(uint64_t*)0x20000060 = 0); NONFAILING(*(uint64_t*)0x20000068 = 0); NONFAILING(*(uint64_t*)0x20000070 = 0x200ba000); NONFAILING(*(uint64_t*)0x20000078 = 0x20ffb000); NONFAILING(*(uint64_t*)0x20000080 = 0); NONFAILING(*(uint64_t*)0x20000088 = 0x20ffd000); NONFAILING(*(uint64_t*)0x20000090 = 0x20fff000); NONFAILING(*(uint64_t*)0x20000098 = 0); NONFAILING(*(uint64_t*)0x200000a0 = 0); NONFAILING(*(uint64_t*)0x200000a8 = 0); NONFAILING(*(uint64_t*)0x200000b0 = 0); NONFAILING(*(uint64_t*)0x200000b8 = 0x20ffd000); NONFAILING(*(uint64_t*)0x200000c0 = 0x20ffe000); NONFAILING(*(uint64_t*)0x200000c8 = 0); NONFAILING(*(uint64_t*)0x200000d0 = 0); NONFAILING(*(uint64_t*)0x200000d8 = 0); NONFAILING(*(uint64_t*)0x200000e0 = 0); NONFAILING(*(uint64_t*)0x200000e8 = 0x20ffc000); NONFAILING(*(uint64_t*)0x200000f0 = 0x20ffc000); NONFAILING(*(uint64_t*)0x200000f8 = 0); NONFAILING(*(uint64_t*)0x20000100 = 0); NONFAILING(*(uint64_t*)0x20000108 = 0x20112000); NONFAILING(*(uint64_t*)0x20000110 = 0); NONFAILING(*(uint64_t*)0x20000118 = 0x20ffb000); NONFAILING(*(uint64_t*)0x20000120 = 0x20ffd000); NONFAILING(*(uint64_t*)0x20000128 = 0); NONFAILING(*(uint64_t*)0x20000130 = 0x20047000); NONFAILING(*(uint64_t*)0x20000138 = 0x20ffd000); NONFAILING(*(uint64_t*)0x20000140 = 0); NONFAILING(*(uint64_t*)0x20000148 = 0x20053000); NONFAILING(*(uint64_t*)0x20000150 = 0x202b7000); NONFAILING(*(uint64_t*)0x20000158 = 0); NONFAILING(*(uint64_t*)0x20000160 = 0x20095000); NONFAILING(*(uint64_t*)0x20000168 = 0); NONFAILING(*(uint64_t*)0x20000170 = 0); NONFAILING(*(uint64_t*)0x20000178 = 0); NONFAILING(*(uint64_t*)0x20000180 = 0x20ffd000); NONFAILING(*(uint64_t*)0x20000188 = 0); NONFAILING(memcpy((void*)0x20000190, "./file0\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 64)); NONFAILING(*(uint32_t*)0x200001d0 = 0); NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t))CAST(ioctl))(/*fd=*/-1, /*cmd=*/0xc5005601, /*arg=*/0x20000000)); NONFAILING(memcpy((void*)0x20000500, "/dev/vmm\000", 9)); res = -1; NONFAILING(res = ((intptr_t(*)(intptr_t,intptr_t,intptr_t,intptr_t))CAST(openat))(/*fd=*/0xffffffffffffff9c, /*file=*/0x20000500, /*flags=*/0, /*mode=*/0)); if (res != -1) r[0] = res; NONFAILING(*(uint32_t*)0x20000000 = 1); NONFAILING(*(uint32_t*)0x20000004 = 0); NONFAILING(*(uint8_t*)0x20000008 = 1); NONFAILING(*(uint16_t*)0x2000000a = 0); NONFAILING(*(uint64_t*)0x20000010 = 0); NONFAILING(*(uint16_t*)0x20000018 = 0); NONFAILING(*(uint8_t*)0x2000001a = 9); NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t))CAST(ioctl))(/*fd=*/r[0], /*cmd=*/0xc2585601, /*arg=*/0x20000000)); NONFAILING(((intptr_t(*)(intptr_t))CAST(shmdt))(/*addr=*/0)); NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t,intptr_t))CAST(shmget))(/*key=*/0x798dd814, /*size=*/0x1000, /*flags=*/0, /*unused=*/0x20fff000)); NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t))CAST(shmctl))(/*shmid=*/0, /*cmd=*/0, 0)); NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t))CAST(ioctl))(/*fd=*/-1, /*cmd=*/0x8020426c, /*arg=*/0)); NONFAILING(((intptr_t(*)())CAST(geteuid))()); NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t))CAST(shmat))(/*shmid=*/0, /*addr=*/0x20ff9000, /*flags=*/0)); NONFAILING(((intptr_t(*)(intptr_t,intptr_t))CAST(getgroups))(/*size=*/0, /*list=*/0)); NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t,intptr_t,intptr_t))CAST(getsockopt))(/*fd=*/-1, /*level=*/0xffff, /*optname=*/0x1022, /*optval=*/0x20000140, /*optlen=*/0)); NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t))CAST(semget))(/*key=*/0x798e2635, /*nsems=*/0, /*flags=IPC_EXCL|IPC_CREAT|0x108*/0x708)); NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t))CAST(open))(/*file=*/0, /*flags=*/0, /*mode=S_IXUSR|S_IWUSR*/0xc0)); NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t,intptr_t,intptr_t))CAST(setsockopt))(/*fd=*/-1, /*level=*/0xffff, /*optname=*/0x1022, /*optval=*/0, /*optlen=*/0)); res = -1; NONFAILING(res = ((intptr_t(*)(intptr_t,intptr_t,intptr_t))CAST(open))(/*file=*/0, /*flags=O_CREAT*/0x200, /*mode=*/0)); if (res != -1) r[1] = res; NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t,intptr_t,intptr_t,intptr_t))CAST(mmap))(/*addr=*/0x20000000, /*len=*/0x200000, /*prot=*/0, /*flags=MAP_FIXED*/0x10, /*fd=*/r[1], /*offset=*/0)); } int main(void) { NONFAILING(((intptr_t(*)(intptr_t,intptr_t,intptr_t,intptr_t,intptr_t,intptr_t))CAST(mmap))(/*addr=*/0x20000000, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ*/3, /*flags=MAP_ANONYMOUS|MAP_FIXED|MAP_PRIVATE*/0x1012, /*fd=*/-1, /*offset=*/0)); install_segv_handler(); use_temporary_dir(); loop(); return 0; }