// https://syzkaller.appspot.com/bug?id=124373f67ef703d44990a3cf4dacd2510b0fc1fc // 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 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; } #define CAST 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; } static void execute_one(void); #define WAIT_FLAGS 0 static void loop(void) { int iter = 0; for (;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { 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; } } } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; res = -1; res = syz_open_pts(); if (res != -1) r[0] = res; *(uint16_t*)0x20000040 = 0; *(uint16_t*)0x20000042 = 0; *(uint64_t*)0x20000048 = 0; *(uint64_t*)0x20000050 = 0x1000110000405; *(uint32_t*)0x20000058 = 0; ((intptr_t(*)(intptr_t,intptr_t,intptr_t))CAST(fcntl))(/*fd=*/r[0], /*cmd=F_SETLKW*/9, /*lock=*/0x20000040); res = -1; res = ((intptr_t(*)(intptr_t,intptr_t))CAST(dup2))(/*oldfd=*/r[0], /*newfd=*/r[0]); if (res != -1) r[1] = res; ((intptr_t(*)(intptr_t,intptr_t))CAST(flock))(/*fd=*/r[1], /*op=LOCK_SH*/1); ((intptr_t(*)(intptr_t))CAST(close))(/*fd=*/r[1]); syz_open_pts(); syz_open_pts(); syz_open_pts(); } int main(void) { ((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); for (procid = 0; procid < 8; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }