// https://syzkaller.appspot.com/bug?id=2212d848f78d472dfeaec7a3cc9f5a31e2a44f42 // 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 static unsigned long long procid; 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[3] = {0xffffffffffffffff, 0x0, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // open$dir arguments: [ // file: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8) // } // flags: open_flags = 0x200 (8 bytes) // mode: open_mode = 0x19c (8 bytes) // ] // returns fd_dir memcpy((void*)0x200000000040, "./file0\000", 8); syscall(SYS_open, /*file=*/0x200000000040ul, /*flags=O_CREAT*/ 0x200ul, /*mode=S_IROTH|S_IXGRP|S_IWGRP|S_IWUSR|S_IRUSR*/ 0x19cul); // setreuid arguments: [ // ruid: uid (resource) // euid: uid (resource) // ] syscall(SYS_setreuid, /*ruid=*/0xee00, /*euid=*/0); // chown arguments: [ // file: nil // uid: uid (resource) // gid: gid (resource) // ] syscall(SYS_chown, /*file=*/0ul, /*uid=*/0, /*gid=*/0); // kqueue arguments: [ // ] // returns kqueue res = syscall(SYS_kqueue); if (res != -1) r[0] = res; // kevent arguments: [ // kqueue: kqueue (resource) // changelist: ptr[in, array[kevent]] { // array[kevent] { // kevent { // ident: intptr = 0x0 (8 bytes) // filter: filters = 0xfffffffffffffff9 (2 bytes) // flags: evflags = 0x8009 (2 bytes) // fflags: fflags = 0x8 (4 bytes) // data: int64 = 0xe8c5 (8 bytes) // udata: intptr = 0x0 (8 bytes) // ext: array[int64] { // int64 = 0x7ffffffffc (8 bytes) // int64 = 0xfffffffffffffffc (8 bytes) // int64 = 0x7 (8 bytes) // int64 = 0x40000000000000 (8 bytes) // } // } // } // } // nchanges: len = 0x1 (8 bytes) // eventlist: nil // nevents: len = 0x0 (8 bytes) // timeout: nil // ] *(uint64_t*)0x200000000040 = 0; *(uint16_t*)0x200000000048 = 0xfff9; *(uint16_t*)0x20000000004a = 0x8009; *(uint32_t*)0x20000000004c = 8; *(uint64_t*)0x200000000050 = 0xe8c5; *(uint64_t*)0x200000000058 = 0; *(uint64_t*)0x200000000060 = 0x7ffffffffc; *(uint64_t*)0x200000000068 = 0xfffffffffffffffc; *(uint64_t*)0x200000000070 = 7; *(uint64_t*)0x200000000078 = 0x40000000000000; syscall(SYS_kevent, /*kqueue=*/r[0], /*changelist=*/0x200000000040ul, /*nchanges=*/1ul, /*eventlist=*/0ul, /*nevents=*/0ul, /*timeout=*/0ul); // extattr_delete_fd arguments: [ // fd: fd (resource) // attrnamespace: attrnamespace_flags = 0x0 (8 bytes) // attrname: ptr[in, buffer] { // buffer: {27 17 2e 29 23 00} (length 0x6) // } // ] memcpy((void*)0x2000000001c0, "\'\027.)#\000", 6); syscall(SYS_extattr_delete_fd, /*fd=*/r[0], /*attrnamespace=*/0ul, /*attrname=*/0x2000000001c0ul); // freebsd11_mknod arguments: [ // file: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8) // } // mod: mknod_mode = 0x1000 (8 bytes) // dev: int32 = 0x0 (4 bytes) // ] memcpy((void*)0x2000000000c0, "./file0\000", 8); syscall(SYS_freebsd11_mknod, /*file=*/0x2000000000c0ul, /*mod=S_IFIFO*/ 0x1000ul, /*dev=*/0); // freebsd10_pipe arguments: [ // pipefd: nil // ] syscall(SYS_freebsd10_pipe, /*pipefd=*/0ul); // ksem_init arguments: [ // idp: ptr[out, semid] { // semid (resource) // } // value: int32 = 0x0 (4 bytes) // ] res = syscall(SYS_ksem_init, /*idp=*/0x200000000100ul, /*value=*/0); if (res != -1) r[1] = *(uint64_t*)0x200000000100; // ksem_post arguments: [ // id: semid (resource) // ] syscall(SYS_ksem_post, /*id=*/r[1]); // 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 = 0x40 (8 bytes) // mode: const = 0x0 (8 bytes) // ] // returns fd_bpf memcpy((void*)0x200000000040, "/dev/bpf\000", 9); syscall(SYS_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000040ul, /*flags=FASYNC*/ 0x40ul, /*mode=*/0ul); // kqueue arguments: [ // ] // returns kqueue res = syscall(SYS_kqueue); if (res != -1) r[2] = res; // kevent arguments: [ // kqueue: kqueue (resource) // changelist: nil // nchanges: len = 0x0 (8 bytes) // eventlist: nil // nevents: len = 0x0 (8 bytes) // timeout: nil // ] syscall(SYS_kevent, /*kqueue=*/r[2], /*changelist=*/0ul, /*nchanges=*/0ul, /*eventlist=*/0ul, /*nevents=*/0ul, /*timeout=*/0ul); // ktrace arguments: [ // path: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8) // } // ops: ktrace_ops = 0x4 (8 bytes) // trpoints: ktrace_trpoints = 0x94659db2cce5c9d8 (8 bytes) // pid: pid (resource) // ] memcpy((void*)0x2000000000c0, "./file0\000", 8); syscall( SYS_ktrace, /*path=*/0x2000000000c0ul, /*ops=KTRFLAG_DESCEND*/ 4ul, /*trpoints=KTRFAC_INHERIT|KTRFAC_FAULTEND|KTRFAC_PROCDTOR|KTRFAC_STRUCT|KTRFAC_USER|KTRFAC_CSW|KTRFAC_GENIO|0x94659db28ce58008*/ 0x94659db2cce5c9d8ul, /*pid=*/0); // rfork arguments: [ // flags: rfork_flags = 0x96014 (8 bytes) // ] syscall(SYS_rfork, /*flags=RFLINUXTHPN|RFTSIGZMB|RFSIGSHARE|RFTHREAD|RFFDG|RFPROC*/ 0x96014ul); // ktrace arguments: [ // path: ptr[in, buffer] { // buffer: {2e 2f 66 69 6c 65 30 00} (length 0x8) // } // ops: ktrace_ops = 0x2 (8 bytes) // trpoints: ktrace_trpoints = 0x180 (8 bytes) // pid: pid (resource) // ] memcpy((void*)0x200000000000, "./file0\000", 8); syscall(SYS_ktrace, /*path=*/0x200000000000ul, /*ops=KTROP_CLEARFILE*/ 2ul, /*trpoints=KTRFAC_STRUCT|KTRFAC_USER*/ 0x180ul, /*pid=*/0); } 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; for (procid = 0; procid < 4; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }