// https://syzkaller.appspot.com/bug?id=72694209890020e9d0ee063dd10d889d8da0fa03 // 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 #ifndef SYS_accept #define SYS_accept 30 #endif #ifndef SYS_bind #define SYS_bind 104 #endif #ifndef SYS_connect #define SYS_connect 98 #endif #ifndef SYS_dup3 #define SYS_dup3 454 #endif #ifndef SYS_listen #define SYS_listen 106 #endif #ifndef SYS_mmap #define SYS_mmap 197 #endif #ifndef SYS_socket #define SYS_socket 394 #endif static unsigned long long procid; 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 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[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; res = syscall(SYS_socket, /*domain=*/1ul, /*type=*/1ul, /*proto=*/0); if (res != -1) r[0] = res; res = syscall(SYS_socket, /*domain=*/1ul, /*type=*/1ul, /*proto=*/0); if (res != -1) r[1] = res; NONFAILING( memcpy((void*)0x20000000, "\x01\x00\xe9\x1f\x71\x89\x59\x1e\x92\x33\x61\x4b\x00\x24\xc6\xb7" "\x9b\x6d\xa8\x42\x4f\xb8\x48\x4e\x0d\x84\x3a\xa4\xb7\xce\xdd\x64" "\xdf\xc8\x94\x7b\x1d\x60\x74\x9d\x43\x4f\x01\x2a\x72\x1e\x2b\xcf", 48)); syscall(SYS_bind, /*fd=*/r[1], /*addr=*/0x20000000ul, /*addrlen=*/0x6eul); syscall(SYS_listen, /*fd=*/r[1], /*backlog=*/0); NONFAILING(*(uint16_t*)0x20000280 = 1); NONFAILING(memcpy((void*)0x20000282, "\351\037q\211Y\036\2223aK\000", 11)); syscall(SYS_connect, /*fd=*/r[0], /*addr=*/0x20000280ul, /*addrlen=*/0x6eul); res = syscall(SYS_dup3, /*oldfd=*/r[1], /*newfd=*/r[0], /*flags=*/0ul); if (res != -1) r[2] = res; res = syscall(SYS_accept, /*s=*/r[2], /*addr=*/0ul, /*addrlen=*/0ul); if (res != -1) r[3] = res; NONFAILING(*(uint16_t*)0x20000300 = 1); NONFAILING(memcpy((void*)0x20000302, "\351\037q\211Y\036\2223aK\000", 11)); syscall(SYS_connect, /*fd=*/r[3], /*addr=*/0x20000300ul, /*addrlen=*/0x6eul); syscall(SYS_accept, /*s=*/r[2], /*addr=*/0ul, /*addrlen=*/0ul); } int main(void) { syscall(SYS_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=*/3ul, /*flags=*/0x1012ul, /*fd=*/-1, /*pad=*/0ul, /*offset=*/0ul); install_segv_handler(); for (procid = 0; procid < 6; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }