// https://syzkaller.appspot.com/bug?id=e2dc9aea0465d1eea101bb24cb463e2a7efe7d17 // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include #include #include #include #include #include #include const int kFailStatus = 67; const int kRetryStatus = 69; static void fail(const char* msg, ...) { int e = errno; va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus); } static void exitf(const char* msg, ...) { int e = errno; va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); doexit(kRetryStatus); } static uint64_t current_time_ms() { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) fail("clock_gettime failed"); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void use_temporary_dir() { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) fail("failed to mkdtemp"); if (chmod(tmpdir, 0777)) fail("failed to chmod"); if (chdir(tmpdir)) fail("failed to chdir"); } static void remove_dir(const char* dir) { DIR* dp; struct dirent* ep; int iter = 0; retry: dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exitf("opendir(%s) failed due to NOFILE, exiting"); } exitf("opendir(%s) failed", dir); } 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)) exitf("lstat(%s) failed", filename); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exitf("unlink(%s) failed", filename); if (umount2(filename, MNT_DETACH)) exitf("umount(%s) failed", filename); } } closedir(dp); int i; for (i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, MNT_DETACH)) exitf("umount(%s) failed", dir); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exitf("rmdir(%s) failed", dir); } } static void test(); void loop() { int iter; for (iter = 0;; iter++) { char cwdbuf[256]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) fail("failed to mkdir"); int pid = fork(); if (pid < 0) fail("loop fork failed"); if (pid == 0) { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); if (chdir(cwdbuf)) fail("failed to chdir"); test(); doexit(0); } int status = 0; uint64_t start = current_time_ms(); for (;;) { int res = waitpid(-1, &status, __WALL | WNOHANG); if (res == pid) break; usleep(1000); if (current_time_ms() - start > 5 * 1000) { kill(-pid, SIGKILL); kill(pid, SIGKILL); while (waitpid(-1, &status, __WALL) != pid) { } break; } } remove_dir(cwdbuf); } } long r[2]; void test() { memset(r, -1, sizeof(r)); syscall(__NR_mmap, 0x20000000, 0xfff000, 0x3, 0x32, 0xffffffff, 0x0); r[0] = syscall(__NR_socket, 0x26, 0x5, 0x0); *(uint16_t*)0x2038c000 = 0x26; memcpy((void*)0x2038c002, "\x73\x6b\x63\x69\x70\x68\x65\x72\x00\x00\x00\x00\x00\x00", 14); *(uint32_t*)0x2038c010 = 0x0; *(uint32_t*)0x2038c014 = 0x0; memcpy((void*)0x2038c018, "\x65\x63\x62\x2d\x74\x77\x6f\x66\x69\x73\x68\x2d\x61\x76\x78" "\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); syscall(__NR_bind, r[0], 0x2038c000, 0x58); memcpy((void*)0x201ec000, "\x0a\x07\x75\xb0\xd5\xe3\x83\xe5\xb3\xb6" "\x0c\xed\x5c\x54\xdb\xb7", 16); syscall(__NR_setsockopt, r[0], 0x117, 0x1, 0x201ec000, 0x10); r[1] = syscall(__NR_accept, r[0], 0x0, 0x0); *(uint64_t*)0x20f74fc8 = 0x0; *(uint32_t*)0x20f74fd0 = 0x0; *(uint64_t*)0x20f74fd8 = 0x20381ff0; *(uint64_t*)0x20f74fe0 = 0x1; *(uint64_t*)0x20f74fe8 = 0x2090efb8; *(uint64_t*)0x20f74ff0 = 0x18; *(uint32_t*)0x20f74ff8 = 0x0; *(uint64_t*)0x20381ff0 = 0x2091c000; *(uint64_t*)0x20381ff8 = 0x280; memcpy( (void*)0x2091c000, "\x5d\xfb\xc3\x3d\xc1\x9c\xb8\x70\x84\x3d\xf3\x02\x73\xb3\x81\xfa" "\xa8\xd6\x2a\x74\xea\xc9\x3d\x92\x5f\x73\x14\x76\x83\xc8\x0e\x60" "\x33\x71\x91\xa5\x8d\xf0\xc2\xc6\xd5\xb8\x70\xca\x6e\x04\xca\xf4" "\x1e\xab\x5e\x60\x6a\x54\x00\xab\x3f\x2b\x56\xcf\xac\x84\x40\x12" "\x00\x88\x5e\x8e\xd0\x98\xaa\x66\x15\xba\x7d\x2e\x3a\x54\x5e\x7c" "\x9e\xbb\x48\x84\x3f\x0a\x66\x11\x47\x64\x42\x88\xac\x33\xc0\x34" "\xe2\x1d\x98\x66\xce\xa3\x16\x44\x1b\x3f\xca\x92\x94\x25\xac\x31" "\xac\x96\xfa\xe3\x8c\x27\x9f\xaa\x18\xcb\xd3\xfc\x29\x2a\xab\x32" "\xde\x88\x5d\x74\x9a\xf3\xdb\x38\x9d\x1e\x12\x8e\x78\x08\x0b\x2c" "\x00\x2a\x5f\xa9\xc8\xab\x59\xac\x3a\xaa\x03\x44\x84\x9a\x06\x16" "\xe8\x11\xf0\x92\xef\x32\xd1\x56\xb4\xdb\x5b\x36\xb9\x68\x94\x37" "\xda\x01\xe8\xf9\x6d\x5a\x7b\x94\x33\x60\x2b\xc3\x59\x98\x91\x12" "\x9d\x5a\xa3\xb8\x84\xcd\x91\x5f\x01\x2b\xf4\x05\x46\x3e\xef\x85" "\x8d\x87\x49\x7d\xf9\x69\x35\xbd\x9f\x53\xc7\x34\xc1\x8b\x29\x8a" "\xd7\xa9\xb3\x78\xe8\xc5\x4c\x28\xa8\x9e\xa5\x7a\x59\x45\xaf\xd1" "\xb2\x3f\x6a\x45\x99\x37\x26\x9a\x10\x6e\x46\x7a\x29\x76\x6c\xbe" "\x0c\xc9\x6f\xd3\x06\xd6\x87\xdb\x2f\x13\x30\x84\x74\x5e\xa5\x73" "\xf3\x26\x39\x19\x88\x12\x34\xd9\x3a\xc5\x4d\xe6\x5e\xc1\x91\x13" "\x12\xfa\x2b\x2a\xfc\x9b\x16\xc6\x5d\x8a\xb8\x67\x82\xef\xf4\xfc" "\xfb\x00\xa1\x23\x63\x86\x28\x3f\x41\xe0\x95\x47\x40\xab\x75\x14" "\xc8\x50\x12\x6c\x40\x7f\xe2\x87\xec\x7a\x91\x76\xf3\xb2\xcc\xdd" "\x5b\x97\x01\x48\x84\x61\x88\xff\x57\xce\x85\xc4\x51\x63\xaf\x7d" "\xab\xcf\x89\x7f\x35\x8a\x20\xe7\x19\xc6\x9c\xd0\xc8\x93\xc3\x61" "\xdd\x8f\x5f\x5d\x86\x5a\xa8\x32\x4b\xe5\x76\xac\xb6\x60\x24\xb4" "\x60\x75\xaf\x67\x42\xd5\xf4\x4b\xf3\x4c\x86\x2f\x4f\xee\x23\x2c" "\x5d\x64\xc5\xbe\x17\x6d\x4f\x7d\x42\x2e\x69\xb7\xe5\xca\x45\xbe" "\x4c\xca\x3e\x6a\xe0\x4d\x90\x2f\x4d\x4f\xbd\x3c\x61\x37\x8d\x03" "\xd7\x84\x8e\x1e\xd6\x65\xf7\xe5\xa7\xcf\xe3\x9c\x7b\xb1\xd8\x50" "\xcf\x18\x88\x92\x30\x5f\xdc\x51\xf3\x2b\xc7\x22\xd2\x2b\x01\xf9" "\x77\x89\xd1\x9f\xcb\x6d\x7b\xf0\x43\xfb\x79\xfe\xde\x42\x7f\x43" "\x39\xc5\xe7\x0f\xb5\x3d\xf8\x15\xed\x0e\xd8\x6c\x29\x5b\xa5\xc8" "\x12\x7b\xe8\x3c\x02\x5f\xc0\x5e\x5f\x2e\x78\x21\x91\x60\x6c\x46" "\x3f\x77\xfc\x5c\xba\xb6\x3d\x19\x78\x71\x85\x58\x23\xc3\xb7\x92" "\x45\xa2\x93\x62\x18\x14\xc7\xc1\x13\x53\x51\x95\x75\xa8\xb9\xb6" "\x5a\x14\x92\x78\xa1\xa4\xa8\xf6\x99\xee\x0f\x7b\x4c\x3a\x29\x4b" "\xa6\x20\x2b\xaf\x49\x4b\x8a\x31\x58\x51\x3f\xab\x94\xb9\x82\xe2" "\x2a\x13\x85\x44\xc9\xdb\x8a\xfd\xf9\xf7\x1a\xb9\x30\x7f\x23\x71" "\x06\x34\xca\x6c\x7f\x7a\x02\x32\x76\xeb\x8f\x95\x30\xa8\x63\x29" "\xd8\x1e\xd4\xc2\xe4\x3d\xd1\x0d\x3d\x4b\xd0\xf9\x78\xd2\x5d\x58" "\x54\xd5\x43\x74\x48\x72\x1d\x7f\x5a\x2e\x3d\x1f\x99\xd7\xf3" "\xf6", 640); *(uint64_t*)0x2090efb8 = 0x18; *(uint32_t*)0x2090efc0 = 0x117; *(uint32_t*)0x2090efc4 = 0x3; *(uint32_t*)0x2090efc8 = 0x1; syscall(__NR_sendmsg, r[1], 0x20f74fc8, 0x0); *(uint64_t*)0x20b2dfc8 = 0x207ebffa; *(uint32_t*)0x20b2dfd0 = 0x6; *(uint64_t*)0x20b2dfd8 = 0x20f75000; *(uint64_t*)0x20b2dfe0 = 0x2; *(uint64_t*)0x20b2dfe8 = 0x20ec7000; *(uint64_t*)0x20b2dff0 = 0x6b; *(uint32_t*)0x20b2dff8 = 0x0; *(uint64_t*)0x20f75000 = 0x2074b000; *(uint64_t*)0x20f75008 = 0x95; *(uint64_t*)0x20f75010 = 0x20f11000; *(uint64_t*)0x20f75018 = 0x1000; syscall(__NR_recvmsg, r[1], 0x20b2dfc8, 0x0); } int main() { use_temporary_dir(); loop(); return 0; }