// https://syzkaller.appspot.com/bug?id=bda19bf6b14e7fddccf28ac6f0205c7df6d8c32e // 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___realpathat #define SYS___realpathat 574 #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[5] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } res = syscall(SYS_socket, /*domain=*/2ul, /*type=SOCK_STREAM*/ 1ul, /*proto=*/0x84); if (res != -1) r[0] = res; syscall(SYS_setsockopt, /*fd=*/r[0], /*level=*/0x84, /*opt=*/3, /*val=*/0ul, /*len=*/0ul); syscall(SYS_connect, /*fd=*/r[0], /*addr=*/0ul, /*addrlen=*/0ul); *(uint16_t*)0x20000040 = 0; *(uint16_t*)0x20000042 = 0x4720; *(uint32_t*)0x20000044 = 0; *(uint32_t*)0x20000048 = 0; *(uint32_t*)0x2000004c = 0; syscall(SYS_setsockopt, /*fd=*/r[0], /*level=*/0x84, /*opt=*/0x21, /*val=*/0x20000040ul, /*len=*/0x10ul); syscall(SYS_sendto, /*fd=*/r[0], /*buf=*/0ul, /*len=*/0ul, /*f=*/0ul, /*addr=*/0ul, /*addrlen=*/0ul); *(uint8_t*)0x20000140 = 0x10; *(uint8_t*)0x20000141 = 2; *(uint16_t*)0x20000142 = htobe16(0x4e20); *(uint8_t*)0x20000144 = 0xac; *(uint8_t*)0x20000145 = 0x14; *(uint8_t*)0x20000146 = 0; *(uint8_t*)0x20000147 = 0xbb; memset((void*)0x20000148, 0, 8); syscall(SYS_connect, /*fd=*/-1, /*addr=*/0x20000140ul, /*addrlen=*/0x10ul); res = syscall(SYS_dup2, /*oldfd=*/-1, /*newfd=*/-1); if (res != -1) r[1] = res; syscall(SYS_sendto, /*fd=*/-1, /*buf=*/0x20000600ul, /*len=*/0ul, /*f=*/0ul, /*addr=*/0ul, /*addrlen=*/0ul); res = syscall(SYS_kqueue); if (res != -1) r[2] = res; *(uint64_t*)0x20000040 = 0; *(uint16_t*)0x20000048 = 0xfff9; *(uint16_t*)0x2000004a = 9; *(uint32_t*)0x2000004c = 8; *(uint64_t*)0x20000050 = 4; *(uint64_t*)0x20000058 = 0; *(uint64_t*)0x20000060 = 0; *(uint64_t*)0x20000068 = 0; *(uint64_t*)0x20000070 = 7; *(uint64_t*)0x20000078 = 0x40000000000000; syscall(SYS_kevent, /*kqueue=*/r[2], /*changelist=*/0x20000040ul, /*nchanges=*/1ul, /*eventlist=*/0ul, /*nevents=*/0ul, /*timeout=*/0ul); res = syscall(SYS_socket, /*domain=AF_INET*/ 2ul, /*type=SOCK_STREAM*/ 1ul, /*proto=*/0); if (res != -1) r[3] = res; memcpy((void*)0x20000080, "bbr\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000", 32); *(uint32_t*)0x200000a0 = 0; syscall(SYS_setsockopt, /*fd=*/r[3], /*level=*/6, /*optname=*/0x2000, /*optval=*/0x20000080ul, /*optlen=*/0x24ul); syscall(SYS_setsockopt, /*fd=*/r[3], /*level=*/6, /*optname=TCP_NODELAY*/ 1, /*optval=*/0ul, /*optlen=*/0ul); syscall(SYS_sendmsg, /*fd=*/r[3], /*msg=*/0ul, /*f=*/0ul); *(uint32_t*)0x20000000 = 0x1009; syscall(SYS_accept4, /*fd=*/r[3], /*peer=*/0x20001740ul, /*peerlen=*/0x20000000ul, /*flags=*/0ul); *(uint32_t*)0x200001c0 = 4; syscall(SYS_ioctl, /*fd=*/r[1], /*cmd=*/0x8004427cul, /*arg=*/0x200001c0ul); res = syscall(SYS_socket, /*domain=*/0x1cul, /*type=SOCK_SEQPACKET*/ 5ul, /*proto=*/0x84); if (res != -1) r[4] = res; memcpy((void*)0x20000000, "./file0\000", 8); syscall(SYS___realpathat, /*dirfd=*/r[4], /*path=*/0x20000000ul, /*buf=*/0x20000040ul, /*size=*/1ul, /*flags=*/0ul); *(uint8_t*)0x20000300 = 0x1c; *(uint8_t*)0x20000301 = 0x1c; *(uint16_t*)0x20000302 = htobe16(0x4e22); *(uint32_t*)0x20000304 = 0xfffffffe; *(uint64_t*)0x20000308 = htobe64(0); *(uint64_t*)0x20000310 = htobe64(1); *(uint32_t*)0x20000318 = 0x8be; syscall(SYS_connect, /*fd=*/r[4], /*addr=*/0x20000300ul, /*addrlen=*/0x1cul); memcpy((void*)0x20000180, "./file0\000", 8); syscall(SYS_fstatat, /*fd=*/-1, /*path=*/0x20000180ul, /*statbuf=*/0ul, /*flag=AT_SYMLINK_NOFOLLOW*/ 0x200ul); *(uint8_t*)0x20000240 = 0x10; *(uint8_t*)0x20000241 = 2; *(uint16_t*)0x20000242 = htobe16(0x4e22); *(uint8_t*)0x20000244 = 0xac; *(uint8_t*)0x20000245 = 0x14; *(uint8_t*)0x20000246 = 0; *(uint8_t*)0x20000247 = 0xbb; memset((void*)0x20000248, 0, 8); syscall(SYS_connect, /*fd=*/-1, /*addr=*/0x20000240ul, /*addrlen=*/0x10ul); syscall(SYS_rfork, /*flags=RFTSIGZMB|RFSIGSHARE|RFCFDG*/ 0x85000ul); } int main(void) { syscall(SYS_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x1012ul, /*fd=*/-1, /*offset=*/0ul); const char* reason; (void)reason; loop(); return 0; }