// https://syzkaller.appspot.com/bug?id=ae28a692910f2e066889b98c890adc67d88a4fda // 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 #ifndef SYS_inotify_add_watch_at #define SYS_inotify_add_watch_at 593 #endif 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)) { } // rfork arguments: [ // flags: rfork_flags = 0x85000 (8 bytes) // ] syscall(SYS_rfork, /*flags=RFTSIGZMB|RFSIGSHARE|RFCFDG*/ 0x85000ul); // openat$bpf arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 62 70 66 00} (length 0x9) // } // flags: open_flags = 0x1 (8 bytes) // mode: const = 0x0 (8 bytes) // ] // returns fd_bpf memcpy((void*)0x200000000000, "/dev/bpf\000", 9); res = syscall(SYS_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000000ul, /*flags=O_WRONLY*/ 1ul, /*mode=*/0ul); if (res != -1) r[0] = res; // ioctl$BIOCSETF arguments: [ // fd: fd_bpf (resource) // cmd: const = 0x80104267 (8 bytes) // arg: nil // ] syscall(SYS_ioctl, /*fd=*/r[0], /*cmd=*/0x80104267ul, /*arg=*/0ul); // sysarch$I386_GET_IOPERM arguments: [ // cmd: const = 0x3 (8 bytes) // args: nil // ] syscall(SYS_sysarch, /*cmd=*/3ul, /*args=*/0ul); // socket$inet6_udp arguments: [ // domain: const = 0x1c (8 bytes) // type: const = 0x2 (8 bytes) // proto: const = 0x0 (1 bytes) // ] // returns sock_udp6 res = syscall(SYS_socket, /*domain=*/0x1cul, /*type=*/2ul, /*proto=*/0); if (res != -1) r[1] = res; // setsockopt$inet6_IPV6_DSTOPTS arguments: [ // fd: sock_in6 (resource) // level: const = 0x29 (4 bytes) // optname: const = 0x32 (4 bytes) // optval: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // } // } // optlen: len = 0x8 (8 bytes) // ] syscall(SYS_setsockopt, /*fd=*/r[1], /*level=*/0x29, /*optname=*/0x32, /*optval=*/0x200000000300ul, /*optlen=*/8ul); // mprotect arguments: [ // addr: VMA[0x800000] // len: len = 0x800000 (8 bytes) // prot: mmap_prot = 0x5 (8 bytes) // ] syscall(SYS_mprotect, /*addr=*/0x200000000000ul, /*len=*/0x800000ul, /*prot=PROT_READ|PROT_EXEC*/ 5ul); // inotify_add_watch_at arguments: [ // fd: fd_inotify (resource) // dfd: fd_dir (resource) // file: nil // mask: inotify_mask = 0x2000000 (8 bytes) // ] // returns inotifydesc syscall(SYS_inotify_add_watch_at, /*fd=*/(intptr_t)-1, /*dfd=*/(intptr_t)-1, /*file=*/0ul, /*mask=IN_DONT_FOLLOW*/ 0x2000000ul); // getsockopt$inet6_buf arguments: [ // fd: sock_in6 (resource) // level: const = 0x29 (4 bytes) // optname: inet6_option_types_buf = 0x32 (4 bytes) // optval: ptr[out, buffer] { // buffer: (DirOut) // } // optlen: ptr[inout, len] { // len = 0x1000 (4 bytes) // } // ] *(uint32_t*)0x200000000000 = 0x1000; syscall(SYS_getsockopt, /*fd=*/r[1], /*level=*/0x29, /*optname=IPV6_DSTOPTS*/ 0x32, /*optval=*/0x200000001040ul, /*optlen=*/0x200000000000ul); } int main(void) { syscall(SYS_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x1012ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; loop(); return 0; }