// https://syzkaller.appspot.com/bug?id=f98813c9a92c13238b7b643b31b9c7125c2f6b45 // 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 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 (sig == SIGBUS) valid = 1; 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 (;;) { sleep_ms(10); if (waitpid(-1, &status, WNOHANG | WAIT_FLAGS) == pid) break; if (current_time_ms() - start < 5000) continue; kill_and_wait(pid, &status); break; } } } uint64_t r[1] = {0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // openat$netmap arguments: [ // fd: const = 0xffffff9c (4 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 6e 65 74 6d 61 70 00} (length 0xc) // } // flags: open_flags = 0x80000 (4 bytes) // mode: const = 0x0 (4 bytes) // ] // returns fd_netmap NONFAILING(memcpy((void*)0x10000080, "/dev/netmap\000", 12)); res = syscall(SYS_openat, /*fd=*/0xffffff9c, /*file=*/0x10000080, /*flags=O_TTY_INIT*/ 0x80000, /*mode=*/0); if (res != -1) r[0] = res; // ioctl$NIOCREGIF arguments: [ // fd: fd_netmap (resource) // cmd: const = 0xc03c6992 (4 bytes) // arg: ptr[inout, nmreq] { // nmreq { // nr_name: buffer: {1e 5e bf 9f 1e 72 25 62 12 e8 99 6f bd 6f c4 73} // (length 0x10) nr_version: int32 = 0x426d (4 bytes) nr_offset: int32 // = 0x8001 (4 bytes) nr_memsize: int32 = 0x8 (4 bytes) nr_tx_slots: // int32 = 0xfcb (4 bytes) nr_rx_slots: int32 = 0x1000 (4 bytes) // nr_tx_rings: int16 = 0x7 (2 bytes) // nr_rx_rings: int16 = 0x4 (2 bytes) // nr_ringid: nmreq_register_ringid = 0x1ffe (2 bytes) // nr_cmd: nmreq_nr_cmds = 0x6 (2 bytes) // nr_arg1: int16 = 0x6 (2 bytes) // nr_arg2: int16 = 0x8 (2 bytes) // nr_arg3: int32 = 0x7ff (4 bytes) // nr_flags: nmreq_register_modes = 0x3 (4 bytes) // spare2: array[int32] { // int32 = 0x6 (4 bytes) // } // } // } // ] NONFAILING(memcpy( (void*)0x10000000, "\x1e\x5e\xbf\x9f\x1e\x72\x25\x62\x12\xe8\x99\x6f\xbd\x6f\xc4\x73", 16)); NONFAILING(*(uint32_t*)0x10000010 = 0x426d); NONFAILING(*(uint32_t*)0x10000014 = 0x8001); NONFAILING(*(uint32_t*)0x10000018 = 8); NONFAILING(*(uint32_t*)0x1000001c = 0xfcb); NONFAILING(*(uint32_t*)0x10000020 = 0x1000); NONFAILING(*(uint16_t*)0x10000024 = 7); NONFAILING(*(uint16_t*)0x10000026 = 4); NONFAILING(*(uint16_t*)0x10000028 = 0x1ffe); NONFAILING(*(uint16_t*)0x1000002a = 6); NONFAILING(*(uint16_t*)0x1000002c = 6); NONFAILING(*(uint16_t*)0x1000002e = 8); NONFAILING(*(uint32_t*)0x10000030 = 0x7ff); NONFAILING(*(uint32_t*)0x10000034 = 3); NONFAILING(*(uint32_t*)0x10000038 = 6); syscall(SYS_ioctl, /*fd=*/(intptr_t)r[0], /*cmd=*/0xc03c6992, /*arg=*/0x10000000); } int main(void) { syscall(SYS_mmap, /*addr=*/0x10000000, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x1012, /*fd=*/(intptr_t)-1, /*offset=*/0); const char* reason; (void)reason; install_segv_handler(); loop(); return 0; }