// https://syzkaller.appspot.com/bug?id=4f75167210501e91853d8baa350eb70278006d91 // 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*)0x10000040, "/dev/netmap\000", 12)); res = syscall(SYS_openat, /*fd=*/0xffffff9c, /*file=*/0x10000040, /*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: {20 b5 40 c2 ca 25 6f b2 34 40 ec 5d db b9 1f 24} // (length 0x10) nr_version: int32 = 0x80000000 (4 bytes) nr_offset: // int32 = 0x5 (4 bytes) nr_memsize: int32 = 0xfffffffe (4 bytes) // nr_tx_slots: int32 = 0x20000001 (4 bytes) // nr_rx_slots: int32 = 0x100 (4 bytes) // nr_tx_rings: int16 = 0x8 (2 bytes) // nr_rx_rings: int16 = 0xfffe (2 bytes) // nr_ringid: nmreq_register_ringid = 0x1000 (2 bytes) // nr_cmd: nmreq_nr_cmds = 0x0 (2 bytes) // nr_arg1: int16 = 0x7 (2 bytes) // nr_arg2: int16 = 0x1 (2 bytes) // nr_arg3: int32 = 0x3 (4 bytes) // nr_flags: nmreq_register_modes = 0x5 (4 bytes) // spare2: array[int32] { // int32 = 0x1000 (4 bytes) // } // } // } // ] NONFAILING(memcpy( (void*)0x10000180, "\x20\xb5\x40\xc2\xca\x25\x6f\xb2\x34\x40\xec\x5d\xdb\xb9\x1f\x24", 16)); NONFAILING(*(uint32_t*)0x10000190 = 0x80000000); NONFAILING(*(uint32_t*)0x10000194 = 5); NONFAILING(*(uint32_t*)0x10000198 = 0xfffffffe); NONFAILING(*(uint32_t*)0x1000019c = 0x20000001); NONFAILING(*(uint32_t*)0x100001a0 = 0x100); NONFAILING(*(uint16_t*)0x100001a4 = 8); NONFAILING(*(uint16_t*)0x100001a6 = 0xfffe); NONFAILING(*(uint16_t*)0x100001a8 = 0x1000); NONFAILING(*(uint16_t*)0x100001aa = 0); NONFAILING(*(uint16_t*)0x100001ac = 7); NONFAILING(*(uint16_t*)0x100001ae = 1); NONFAILING(*(uint32_t*)0x100001b0 = 3); NONFAILING(*(uint32_t*)0x100001b4 = 5); NONFAILING(*(uint32_t*)0x100001b8 = 0x1000); syscall(SYS_ioctl, /*fd=*/(intptr_t)r[0], /*cmd=*/0xc03c6992, /*arg=*/0x10000180); } 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; }