// https://syzkaller.appspot.com/bug?id=3e60a26f8743c540eb99e5ea5b404d0346c6a325 // 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[2] = {0xffffffffffffffff, 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 = 0x8 (4 bytes) // mode: const = 0x0 (4 bytes) // ] // returns fd_netmap NONFAILING(memcpy((void*)0x10000480, "/dev/netmap\000", 12)); res = syscall(SYS_openat, /*fd=*/0xffffff9c, /*file=*/0x10000480, /*flags=O_APPEND*/ 8, /*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: {22 83 92 e9 00 00 00 00 81 00 00 00 00 00 f0 00} // (length 0x10) nr_version: int32 = 0x7fffffff (4 bytes) nr_offset: // int32 = 0x5 (4 bytes) nr_memsize: int32 = 0x6 (4 bytes) nr_tx_slots: // int32 = 0x3 (4 bytes) nr_rx_slots: int32 = 0x1 (4 bytes) // nr_tx_rings: int16 = 0x2 (2 bytes) // nr_rx_rings: int16 = 0xb (2 bytes) // nr_ringid: nmreq_register_ringid = 0x9fff (2 bytes) // nr_cmd: nmreq_nr_cmds = 0x0 (2 bytes) // nr_arg1: int16 = 0xd (2 bytes) // nr_arg2: int16 = 0x1 (2 bytes) // nr_arg3: int32 = 0x2068734c (4 bytes) // nr_flags: nmreq_register_modes = 0x6 (4 bytes) // spare2: array[int32] { // int32 = 0xfffffffe (4 bytes) // } // } // } // ] NONFAILING(memcpy( (void*)0x100004c0, "\x22\x83\x92\xe9\x00\x00\x00\x00\x81\x00\x00\x00\x00\x00\xf0\x00", 16)); NONFAILING(*(uint32_t*)0x100004d0 = 0x7fffffff); NONFAILING(*(uint32_t*)0x100004d4 = 5); NONFAILING(*(uint32_t*)0x100004d8 = 6); NONFAILING(*(uint32_t*)0x100004dc = 3); NONFAILING(*(uint32_t*)0x100004e0 = 1); NONFAILING(*(uint16_t*)0x100004e4 = 2); NONFAILING(*(uint16_t*)0x100004e6 = 0xb); NONFAILING(*(uint16_t*)0x100004e8 = 0x9fff); NONFAILING(*(uint16_t*)0x100004ea = 0); NONFAILING(*(uint16_t*)0x100004ec = 0xd); NONFAILING(*(uint16_t*)0x100004ee = 1); NONFAILING(*(uint32_t*)0x100004f0 = 0x2068734c); NONFAILING(*(uint32_t*)0x100004f4 = 6); NONFAILING(*(uint32_t*)0x100004f8 = 0xfffffffe); syscall(SYS_ioctl, /*fd=*/(intptr_t)r[0], /*cmd=*/0xc03c6992, /*arg=*/0x100004c0); // 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*)0x10000480, "/dev/netmap\000", 12)); res = syscall(SYS_openat, /*fd=*/0xffffff9c, /*file=*/0x10000480, /*flags=O_TTY_INIT*/ 0x80000, /*mode=*/0); if (res != -1) r[1] = res; // ioctl$NIOCREGIF arguments: [ // fd: fd_netmap (resource) // cmd: const = 0xc03c6992 (4 bytes) // arg: ptr[inout, nmreq] { // nmreq { // nr_name: buffer: {22 83 92 e9 00 00 00 00 81 00 00 00 00 00 f0 00} // (length 0x10) nr_version: int32 = 0x7fffffff (4 bytes) nr_offset: // int32 = 0x800 (4 bytes) nr_memsize: int32 = 0x6 (4 bytes) // nr_tx_slots: int32 = 0x1 (4 bytes) // nr_rx_slots: int32 = 0xc (4 bytes) // nr_tx_rings: int16 = 0x1 (2 bytes) // nr_rx_rings: int16 = 0x13 (2 bytes) // nr_ringid: nmreq_register_ringid = 0x1fff (2 bytes) // nr_cmd: nmreq_nr_cmds = 0x0 (2 bytes) // nr_arg1: int16 = 0x19 (2 bytes) // nr_arg2: int16 = 0x1 (2 bytes) // nr_arg3: int32 = 0x9 (4 bytes) // nr_flags: nmreq_register_modes = 0x1 (4 bytes) // spare2: array[int32] { // int32 = 0xfffffffd (4 bytes) // } // } // } // ] NONFAILING(memcpy( (void*)0x10000080, "\x22\x83\x92\xe9\x00\x00\x00\x00\x81\x00\x00\x00\x00\x00\xf0\x00", 16)); NONFAILING(*(uint32_t*)0x10000090 = 0x7fffffff); NONFAILING(*(uint32_t*)0x10000094 = 0x800); NONFAILING(*(uint32_t*)0x10000098 = 6); NONFAILING(*(uint32_t*)0x1000009c = 1); NONFAILING(*(uint32_t*)0x100000a0 = 0xc); NONFAILING(*(uint16_t*)0x100000a4 = 1); NONFAILING(*(uint16_t*)0x100000a6 = 0x13); NONFAILING(*(uint16_t*)0x100000a8 = 0x1fff); NONFAILING(*(uint16_t*)0x100000aa = 0); NONFAILING(*(uint16_t*)0x100000ac = 0x19); NONFAILING(*(uint16_t*)0x100000ae = 1); NONFAILING(*(uint32_t*)0x100000b0 = 9); NONFAILING(*(uint32_t*)0x100000b4 = 1); NONFAILING(*(uint32_t*)0x100000b8 = 0xfffffffd); syscall(SYS_ioctl, /*fd=*/(intptr_t)r[1], /*cmd=*/0xc03c6992, /*arg=*/0x10000080); } 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; }