// https://syzkaller.appspot.com/bug?id=1ab62601ed8e2b3db0de34985bff9933341f57fa // 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 = 0xffffffffffffff9c (4 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 6e 65 74 6d 61 70 00} (length 0xc) // } // flags: open_flags = 0x246 (4 bytes) // mode: const = 0x0 (4 bytes) // ] // returns fd_netmap NONFAILING(memcpy((void*)0x10000100, "/dev/netmap\000", 12)); res = syscall(SYS_openat, /*fd=*/0xffffff9c, /*file=*/0x10000100, /*flags=O_NONBLOCK|O_CREAT|FASYNC|O_RDWR*/ 0x246, /*mode=*/0); if (res != -1) r[0] = res; // ioctl$NIOCCTRL arguments: [ // fd: fd_netmap (resource) // cmd: const = 0xc0586997 (4 bytes) // arg: ptr[inout, nmreq_header] { // nmreq_header { // nr_version: const = 0xe (2 bytes) // nr_reqtype: netmap_req_types = 0x5 (2 bytes) // nr_reserved: const = 0x0 (4 bytes) // nr_name: buffer: {00 00 00 00 2b 73 02 5a 03 b4 64 df 9d 78 f4 9e 00 // ea 71 d0 12 f3 e6 b4 66 9a b0 76 3d 5a cb 05 00 f1 ff 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00} (length 0x40) nr_options: nil nr_body: ptr[inout, nmreq_body] { // union nmreq_body { // vale_list: nmreq_vale_list { // nr_bridge_idx: int16 = 0x4 (2 bytes) // pad1: const = 0x0 (2 bytes) // nr_port_idx: int32 = 0xffff3518 (4 bytes) // } // } // } // } // } // ] NONFAILING(*(uint16_t*)0x10000280 = 0xe); NONFAILING(*(uint16_t*)0x10000282 = 5); NONFAILING(*(uint32_t*)0x10000284 = 0); NONFAILING( memcpy((void*)0x10000288, "\x00\x00\x00\x00\x2b\x73\x02\x5a\x03\xb4\x64\xdf\x9d\x78\xf4\x9e" "\x00\xea\x71\xd0\x12\xf3\xe6\xb4\x66\x9a\xb0\x76\x3d\x5a\xcb\x05" "\x00\xf1\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 64)); NONFAILING(*(uint64_t*)0x100002c8 = 0); NONFAILING(*(uint64_t*)0x100002d0 = 0x10000040); NONFAILING(*(uint16_t*)0x10000040 = 4); NONFAILING(*(uint16_t*)0x10000042 = 0); NONFAILING(*(uint32_t*)0x10000044 = 0xffff3518); syscall(SYS_ioctl, /*fd=*/(intptr_t)r[0], /*cmd=*/0xc0586997, /*arg=*/0x10000280); } 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; }