// https://syzkaller.appspot.com/bug?id=8aae379cf9a320aa0d7b7d94a5332c886867c623 // 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 unsigned long long procid; 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 remove_dir(const char* dir) { DIR* dp; struct dirent* ep; dp = opendir(dir); if (dp == NULL) exit(1); 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); if (rmdir(dir)) exit(1); } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i; for (i = 0; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { pthread_mutex_t mu; pthread_cond_t cv; int state; } event_t; static void event_init(event_t* ev) { if (pthread_mutex_init(&ev->mu, 0)) exit(1); if (pthread_cond_init(&ev->cv, 0)) exit(1); ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { pthread_mutex_lock(&ev->mu); if (ev->state) exit(1); ev->state = 1; pthread_mutex_unlock(&ev->mu); pthread_cond_broadcast(&ev->cv); } static void event_wait(event_t* ev) { pthread_mutex_lock(&ev->mu); while (!ev->state) pthread_cond_wait(&ev->cv, &ev->mu); pthread_mutex_unlock(&ev->mu); } static int event_isset(event_t* ev) { pthread_mutex_lock(&ev->mu); int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; pthread_mutex_lock(&ev->mu); for (;;) { if (ev->state) break; uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; pthread_cond_timedwait(&ev->cv, &ev->mu, &ts); now = current_time_ms(); if (now - start > timeout) break; } int res = ev->state; pthread_mutex_unlock(&ev->mu); return res; } #define __syscall syscall static uintptr_t syz_open_pts(void) { int master, slave; if (openpty(&master, &slave, NULL, NULL, NULL) == -1) return -1; if (dup2(master, master + 100) != -1) close(master); return slave; } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { int i, call, thread; for (call = 0; call < 87; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 45); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter; for (iter = 0;; 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 < 5 * 1000) continue; kill_and_wait(pid, &status); break; } remove_dir(cwdbuf); } } uint64_t r[10] = {0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0x0, 0x0, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0}; void execute_call(int call) { long res; switch (call) { case 0: memcpy((void*)0x20000080, "./bus\000", 6); syscall(SYS_mknod, 0x20000080, 0x3a0914c44f7b202c, 0x501); break; case 1: memcpy((void*)0x20000040, "./bus\000", 6); syscall(SYS_openat, 0xffffff9c, 0x20000040, 0, 0); break; case 2: memcpy((void*)0x20000000, "./bus\000", 6); syscall(SYS_unlink, 0x20000000); break; case 3: syscall(SYS_mknod, 0, 0x3a0914c44f7b202c, 0x501); break; case 4: syscall(SYS_ioctl, -1, 0x80104267, 0); break; case 5: syscall(SYS_openat, 0xffffffffffffff9c, 0, 0, 0); break; case 6: syz_open_pts(); break; case 7: syscall(SYS_write, -1, 0, 0); break; case 8: res = syz_open_pts(); if (res != -1) r[0] = res; break; case 9: syscall(SYS_close, r[0]); break; case 10: syscall(SYS_ioctl, -1, 0x802c7414, 0); break; case 11: syscall(SYS_write, r[0], 0, 0); break; case 12: syscall(SYS_readv, -1, 0, 0); break; case 13: syscall(SYS_write, -1, 0, 0); break; case 14: syscall(SYS_mknod, 0, 0x2000, 0x1000); break; case 15: res = syscall(SYS_socket, 0x18, 2, 0); if (res != -1) r[1] = res; break; case 16: syscall(SYS_getsockopt, r[1], 0x29, 0x2b, 0, 0); break; case 17: syscall(SYS_socketpair, 1, 2, 0, 0); break; case 18: syscall(SYS_mprotect, 0x20000000, 0x3000, 0); break; case 19: syscall(SYS_open, 0, 0, 0); break; case 20: syscall(SYS_clock_settime, 2, 0); break; case 21: syscall(SYS_getpgid, 0); break; case 22: syscall(SYS_setitimer, 0, -1, 0); break; case 23: syscall(SYS_ioctl, -1, 0x802c7415, 0); break; case 24: syscall(SYS_mknod, 0, 0x80002005, 0x4300); break; case 25: syscall(SYS_open, 0, 0x381, 0); break; case 26: syscall(SYS_ioctl, -1, 0x80047410, 0); break; case 27: syscall(SYS_kevent, -1, 0, 0, 0, 0, 0); break; case 28: syscall(SYS_kevent, -1, 0, 0x66, 0, 0, 0); break; case 29: syscall(SYS_read, -1, 0, 0); break; case 30: syz_open_pts(); break; case 31: break; case 32: syscall(SYS_ioctl, -1, 0x802c7414, 0); break; case 33: syscall(SYS_getsockopt, 0xffffff9c, 0xffff, 0x1022, 0, 0); break; case 34: syscall(SYS_open, 0, 0, 0); break; case 35: syscall(SYS_select, 0, 0, 0, 0, 0); break; case 36: syscall(SYS_open, 0, 0x60e, 0); break; case 37: syz_open_pts(); break; case 38: memcpy((void*)0x20000040, "./file0\000", 8); syscall(SYS_open, 0x20000040, 0x611, 0); break; case 39: syscall(SYS_utimes, 0, -1); break; case 40: syscall(SYS_dup, -1); break; case 41: syscall(SYS_readv, -1, 0, 0); break; case 42: syscall(SYS_ioctl, -1, 0x802c7416, 0); break; case 43: *(uint32_t*)0x20000000 = 4; *(uint32_t*)0x20000004 = 2; syscall(SYS_ioctl, -1, 0x80085754, 0x20000000); break; case 44: *(uint32_t*)0x20000080 = 3; *(uint64_t*)0x20000088 = 0x20000000; *(uint16_t*)0x20000000 = 0x20; *(uint8_t*)0x20000002 = 0; *(uint8_t*)0x20000003 = 0; *(uint32_t*)0x20000004 = 0; *(uint16_t*)0x20000008 = 0; *(uint8_t*)0x2000000a = 0; *(uint8_t*)0x2000000b = 0; *(uint32_t*)0x2000000c = 0; *(uint16_t*)0x20000010 = 6; *(uint8_t*)0x20000012 = 0; *(uint8_t*)0x20000013 = 0; *(uint32_t*)0x20000014 = 0; syscall(SYS_ioctl, -1, 0x80104267, 0x20000080); break; case 45: *(uint32_t*)0x20000040 = 1; *(uint32_t*)0x20000044 = 0; syscall(SYS_ioctl, -1, 0x80085762, 0x20000040); break; case 46: syscall(SYS_minherit, 0x2069c000, 0x2000, 2); break; case 47: syscall(SYS_dup, -1); break; case 48: syscall(SYS_socket, 0x18, 1, 0); break; case 49: syscall(SYS_ioctl, -1, 0x802c7416, 0); break; case 50: syscall(SYS_minherit, 0x2069c000, 0x2000, 2); break; case 51: syscall(SYS_flock, -1, 0); break; case 52: syscall(SYS_mprotect, 0x20000000, 0x800000, 5); break; case 53: syscall(SYS_ioctl, -1, 0x80104267, 0); break; case 54: syscall(SYS_clock_gettime, 0, 0); break; case 55: res = syscall(SYS_getuid); if (res != -1) r[2] = res; break; case 56: syscall(SYS_setuid, r[2]); break; case 57: syscall(SYS_getgid); break; case 58: syscall(SYS_setsockopt, -1, 3, 0xa, 0, 0x37488252adb8a56b); break; case 59: res = syscall(SYS_semget, 0, 6, 0x8c); if (res != -1) r[3] = res; break; case 60: syscall(SYS_socket, 0x18, 2, 0); break; case 61: res = syscall(SYS_shmget, 0x798dd814 + procid * 4, 0x3000, 0, 0x20ffb000); if (res != -1) r[4] = res; break; case 62: syscall(SYS_shmctl, r[4], 2, 0x20000500); break; case 63: syscall(SYS_shmget, 0, 0x2000, 0x20, 0x20ffd000); break; case 64: *(uint16_t*)0x200003c0 = 3; *(uint16_t*)0x200003c2 = 0; *(uint16_t*)0x200003c4 = 0x1000; *(uint16_t*)0x200003c6 = 3; *(uint16_t*)0x200003c8 = 0x8001; *(uint16_t*)0x200003ca = 0; *(uint16_t*)0x200003cc = 0; *(uint16_t*)0x200003ce = 0x4ca; *(uint16_t*)0x200003d0 = 0x1000; *(uint16_t*)0x200003d2 = 0; *(uint16_t*)0x200003d4 = 2; *(uint16_t*)0x200003d6 = 0x1000; *(uint16_t*)0x200003d8 = 7; *(uint16_t*)0x200003da = 6; *(uint16_t*)0x200003dc = 0x1000; *(uint16_t*)0x200003de = 0; *(uint16_t*)0x200003e0 = 1; *(uint16_t*)0x200003e2 = 0x800; *(uint16_t*)0x200003e4 = 4; *(uint16_t*)0x200003e6 = 2; *(uint16_t*)0x200003e8 = 0x1000; syscall(SYS_semop, r[3], 0x200003c0, 7); break; case 65: syscall(SYS_clock_gettime, 0, 0); break; case 66: res = syscall(SYS_getgid); if (res != -1) r[5] = res; break; case 67: syscall(SYS_fchown, -1, 0, r[5]); break; case 68: res = syscall(SYS_openat, 0xffffffffffffff9c, 0, 0x4000002, 0); if (res != -1) r[6] = res; break; case 69: memcpy( (void*)0x200018c0, "\xb1\xce\x74\x44\xd8\xb6\xd1\xd6\xa8\x42\xca\xdb\x90\xf0\xff\xe2\xbf" "\xfc\xb3\xfc\x16\xf2\x4f\xe6\xe4\xb4\xaf\x01\x4d\xd6\x3f\x1f\xba\xc6" "\xc9\x1a\x88\xbf\xae\x81\xf0\x31\xf7\x07\xe8\x42\x7f\xf0\x29\xb7\x5a" "\xe1\x67\xe9\x36\x00\x64\xde\x2e\x3e\x9d\xea\xd9\xb2\xd6\x43\xf6\xda" "\xe9\x40\x36\xd0\xad\x86\x80\x12\x04\x9d\x83\x5a\xbe\x80\xe4\xb1\x7f" "\xea\x7a\xcb\x81\x61\xac\xf7\xd1\x8e\x4f\x47\xf0\x1e\x25\xbb\x23\xdc" "\x14\x17\x07\x4c\x92\xd2\x1e\xbb\xc2\x1b\x27\x04\x44\x5a\x7a\xa0\x01" "\x83\xea\xba\x76\x85\xd2\xf6\x04\xb8\xac\x31\xd5\xb1\x1c\x11\x71\xdb" "\x51\xb9\xa1\x72\x15\xfc\xcf\x2c\x26\x59\x52\x54\x15\x92\x44\x3b\xab" "\x67\xfc\xfc\x1e\xc6\x5d\x50\xd4\xee\x3a\xfc\xc0\x6a\x9d\x37\xff\x46" "\xbd\x5e\x00\xe2\xb3\x89\x94\xc4\x9a\x0b\xda\x7f\x59\xfb\x82\x87\xf4" "\x57\x06\xe9\x51\xed\x2d\x47\x57\xfd\x86\x2e\xe4\x73\xda\x42\xcb\xea" "\x8e\x77\x5e\xf6\xca\x29\xe6\x0e\xf7\xf5\x8d\x85\xb9\xe4\x11\x4b\xed" "\xe1\x64\x87\xfe\x74\xff\xad\x24\x5d\x23\x27\x86\xcf\x1f\xd0\x35\x74" "\x52\xb0\x19\x5f\xf7\x08\x93\xf5\xa2\xaf\xa0\x6e\x05\x16\x5a\x79\x1b" "\x0c\x97\x29\x4e\x80\x27\xfe\x1b\xdd\xde\xc7\x9f\x3f\x37\x8f\x6e\xa5" "\xd9\x04\xf7\xea\x3f\x82\x73\x7e\x7c\x71\xb6\xed\x9d\xee\x9e\xca\x0a" "\x8d\x49\x0c\xb3\xff\x37\xc0\xbb\xa0\xe8\xa7\x77\xef\xa7\xec\x79\x69" "\xcd\xef\x6f\x89\x22\x1c\x51\x0c\x8e\x29\xe6\x70\x5c\x86\x28\xa6\x07" "\x33\xd2\x6b\x9c\xf8\x28\xea\xd7", 331); syscall(SYS_setsockopt, -1, 0, 0x1000400000000008, 0x200018c0, 0x14b); break; case 70: syscall(SYS_write, -1, 0x200002c0, 0); break; case 71: syscall(SYS_sendmsg, r[6], 0, 0x400); break; case 72: syscall(SYS_fchown, -1, 0, 0); break; case 73: memcpy((void*)0x20000000, "/dev/null\000", 10); res = syscall(SYS_openat, 0xffffffffffffff9c, 0x20000000, 0x4000002, 0); if (res != -1) r[7] = res; break; case 74: syscall(SYS_ioctl, r[7], 0x2000746e, 0); break; case 75: syscall(SYS_semget, 0, 6, 0x8c); break; case 76: syscall(SYS_getsockopt, -1, 0x29, 0x2a, 0, 0); break; case 77: syscall(SYS_shmctl, 0, 2, 0x20000500); break; case 78: syscall(SYS_clock_gettime, 0, 0); break; case 79: syscall(SYS_fcntl, -1, 1, 0); break; case 80: memcpy((void*)0x20000000, "/dev/null\000", 10); res = syscall(SYS_openat, 0xffffffffffffff9c, 0x20000000, 0x4000002, 0); if (res != -1) r[8] = res; break; case 81: syscall(SYS_setsockopt, -1, 3, 0xa, 0, 0x37488252adb8a56b); break; case 82: syscall(SYS_ioctl, r[8], 0x2000746e, 0); break; case 83: res = syscall(SYS_semget, 0, 6, 0x8c); if (res != -1) r[9] = res; break; case 84: syscall(SYS_getsockopt, -1, 0x29, 0x2a, 0, 0); break; case 85: syscall(SYS_semop, r[9], 0, 0); break; case 86: syscall(SYS_getgid); break; } } int main(void) { syscall(SYS_mmap, 0x20000000, 0x1000000, 3, 0x1012, -1, 0, 0); for (procid = 0; procid < 2; procid++) { if (fork() == 0) { use_temporary_dir(); loop(); } } sleep(1000000); return 0; }