// https://syzkaller.appspot.com/bug?id=ffb3b968582af45169155ae8f13d408eef7673bd // 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$pass arguments: [ // fd: const = 0xffffffffffffff9c (4 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 70 61 73 73 30 00} (length 0xb) // } // flags: open_flags = 0x2 (4 bytes) // mode: const = 0x0 (4 bytes) // ] // returns fd_pass NONFAILING(memcpy((void*)0x10000040, "/dev/pass0\000", 11)); res = syscall(SYS_openat, /*fd=*/0xffffff9c, /*file=*/0x10000040, /*flags=O_RDWR*/ 2, /*mode=*/0); if (res != -1) r[0] = res; // ioctl$CAMIOCOMMAND arguments: [ // fd: fd_pass (resource) // cmd: const = 0xc4e01a02 (4 bytes) // arg: ptr[inout, ccb] { // union ccb { // ccg: ccb_calc_geometry { // ccb_h: ccb_hdr { // pinfo: cam_pinfo { // priority: int32 = 0x5 (4 bytes) // generation: int32 = 0xde7 (4 bytes) // index: int32 = 0xe00 (4 bytes) // } // xpt_links: union camq_entry { // prev: const = 0x0 (4 bytes) // } // sim_links: union camq_entry { // next: const = 0x0 (4 bytes) // } // periph_links: union camq_entry { // prev: const = 0x0 (4 bytes) // } // retry_count: int16 = 0xcc6d (2 bytes) // alloc_flags: int16 = 0x81 (2 bytes) // cbfcnp: intptr = 0x7ffffffe (4 bytes) // func_code: ccb_hdr_func_codes = 0x18 (4 bytes) // status: int32 = 0x7fff (4 bytes) // path: const = 0x0 (4 bytes) // path_id: int32 = 0x2 (4 bytes) // target_id: int32 = 0x401 (4 bytes) // target_lun: int64 = 0x2 (8 bytes) // flags: int32 = 0x7 (4 bytes) // xflags: int32 = 0x222 (4 bytes) // periph_priv: union ccb_ppriv_area { // entries: array[ccb_priv_entry] { // union ccb_priv_entry { // field: intptr = 0x5 (4 bytes) // } // union ccb_priv_entry { // field: intptr = 0x100000001 (4 bytes) // } // } // } // sim_priv: union ccb_spriv_area { // entries: array[ccb_priv_entry] { // union ccb_priv_entry { // field: intptr = 0xff (4 bytes) // } // union ccb_priv_entry { // field: intptr = 0x91d (4 bytes) // } // } // } // qos: union ccb_qos_area { // etime: nil // } // timeout: int32 = 0x8 (4 bytes) // softtimeout: timeval { // sec: intptr = 0x2 (4 bytes) // usec: intptr = 0x6fc (4 bytes) // } // } // block_size: int32 = 0xffffff4f (4 bytes) // volume_size: int64 = 0x7 (8 bytes) // cylinders: int32 = 0x7a6 (4 bytes) // heads: int8 = 0x4 (1 bytes) // secs_per_track: int8 = 0x8 (1 bytes) // pad = 0x0 (2 bytes) // } // } // } // ] NONFAILING(*(uint32_t*)0x10000080 = 5); NONFAILING(*(uint32_t*)0x10000084 = 0xde7); NONFAILING(*(uint32_t*)0x10000088 = 0xe00); NONFAILING(*(uint32_t*)0x1000008c = 0); NONFAILING(*(uint32_t*)0x10000090 = 0); NONFAILING(*(uint32_t*)0x10000094 = 0); NONFAILING(*(uint16_t*)0x10000098 = 0xcc6d); NONFAILING(*(uint16_t*)0x1000009a = 0x81); NONFAILING(*(uint32_t*)0x1000009c = 0x7ffffffe); NONFAILING(*(uint32_t*)0x100000a0 = 0x18); NONFAILING(*(uint32_t*)0x100000a4 = 0x7fff); NONFAILING(*(uint32_t*)0x100000a8 = 0); NONFAILING(*(uint32_t*)0x100000ac = 2); NONFAILING(*(uint32_t*)0x100000b0 = 0x401); NONFAILING(*(uint64_t*)0x100000b4 = 2); NONFAILING(*(uint32_t*)0x100000bc = 7); NONFAILING(*(uint32_t*)0x100000c0 = 0x222); NONFAILING(*(uint32_t*)0x100000c4 = 5); NONFAILING(*(uint32_t*)0x100000c8 = 1); NONFAILING(*(uint32_t*)0x100000cc = 0xff); NONFAILING(*(uint32_t*)0x100000d0 = 0x91d); NONFAILING(*(uint32_t*)0x100000d4 = 0); NONFAILING(*(uint32_t*)0x100000d8 = 8); NONFAILING(*(uint32_t*)0x100000dc = 2); NONFAILING(*(uint32_t*)0x100000e0 = 0x6fc); NONFAILING(*(uint32_t*)0x100000e4 = 0xffffff4f); NONFAILING(*(uint64_t*)0x100000e8 = 7); NONFAILING(*(uint32_t*)0x100000f0 = 0x7a6); NONFAILING(*(uint8_t*)0x100000f4 = 4); NONFAILING(*(uint8_t*)0x100000f5 = 8); syscall(SYS_ioctl, /*fd=*/(intptr_t)r[0], /*cmd=*/0xc4e01a02, /*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; }