// 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___specialfd #define SYS___specialfd 577 #endif #ifndef SYS_copy_file_range #define SYS_copy_file_range 569 #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[9] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 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=*/0x1cul, /*type=SOCK_STREAM*/ 1ul, /*proto=*/0x84); if (res != -1) r[0] = res; *(uint16_t*)0x200000c0 = 0; *(uint16_t*)0x200000c2 = 0xaddd; *(uint32_t*)0x200000c4 = 0; *(uint32_t*)0x200000c8 = 7; *(uint32_t*)0x200000cc = 0; syscall(SYS_setsockopt, /*fd=*/r[0], /*level=*/0x84, /*opt=*/0x21, /*val=*/0x200000c0ul, /*len=*/0x10ul); *(uint64_t*)0x20000100 = 0x20000080; *(uint8_t*)0x20000080 = 0x1c; *(uint8_t*)0x20000081 = 0x1c; *(uint16_t*)0x20000082 = htobe16(0x4e20); *(uint32_t*)0x20000084 = 0; *(uint8_t*)0x20000088 = 0xfe; *(uint8_t*)0x20000089 = 0x80; memset((void*)0x2000008a, 0, 12); *(uint8_t*)0x20000096 = 0; *(uint8_t*)0x20000097 = 0xbb; *(uint32_t*)0x20000098 = 0; *(uint32_t*)0x20000108 = 0x1c; *(uint64_t*)0x20000110 = 0x20001600; *(uint64_t*)0x20001600 = 0x20000340; memset((void*)0x20000340, 247, 1); *(uint64_t*)0x20001608 = 1; *(uint32_t*)0x20000118 = 1; *(uint64_t*)0x20000120 = 0; *(uint32_t*)0x20000128 = 0; *(uint32_t*)0x2000012c = 0; syscall(SYS_sendmsg, /*fd=*/r[0], /*msg=*/0x20000100ul, /*f=*/0ul); res = syscall(SYS_dup2, /*oldfd=*/r[0], /*newfd=*/r[0]); if (res != -1) r[1] = res; syscall(SYS_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0ul, /*flags=*/0ul, /*mode=*/0ul); memcpy((void*)0x200002c0, ".\000", 2); syscall(SYS_open, /*file=*/0x200002c0ul, /*flags=*/0ul, /*mode=*/0ul); res = syscall(SYS_socket, /*domain=*/0x1cul, /*type=SOCK_STREAM*/ 1ul, /*proto=*/0x84); if (res != -1) r[2] = res; syscall(SYS_socket, /*domain=*/2ul, /*type=SOCK_RAW*/ 3ul, /*proto=*/0); res = syscall(SYS_socket, /*domain=AF_INET*/ 2ul, /*type=SOCK_STREAM*/ 1ul, /*proto=*/0); if (res != -1) r[3] = res; memcpy((void*)0x20000240, "./file1\000", 8); syscall(SYS_open, /*file=*/0x20000240ul, /*flags=O_TRUNC*/ 0x400ul, /*mode=S_IXOTH|S_IROTH|S_IRGRP*/ 0x25ul); res = syscall(SYS_kqueue); if (res != -1) r[4] = res; *(uint64_t*)0x200000c0 = 4; *(uint16_t*)0x200000c8 = 0xfffc; *(uint16_t*)0x200000ca = 0x4001; *(uint32_t*)0x200000cc = 2; *(uint64_t*)0x200000d0 = 0x2000000004000000; *(uint64_t*)0x200000d8 = 0; *(uint64_t*)0x200000e0 = 0; *(uint64_t*)0x200000e8 = 0; *(uint64_t*)0x200000f0 = 4; *(uint64_t*)0x200000f8 = 0; syscall(SYS_kevent, /*kqueue=*/r[4], /*changelist=*/0x200000c0ul, /*nchanges=*/1ul, /*eventlist=*/0ul, /*nevents=*/0ul, /*timeout=*/0ul); memcpy((void*)0x20000180, "./file0\000", 8); memcpy( (void*)0x200001c0, "\220\317\243+\000-=\\5\201\262(\214&" "\331D\276\227\307\"\336\"\rZ\004\036C\323\313&\266\311:" "PM\026SU\357\350\326T\\\223\037\316\031\241#Y\034\f\372\\07\021\321=" "\261\305\235\266M|\306@\021H\304\004\256Q\377i\\\246?" "\362\001O\326\314\355[a\370u}\255\232\270\035\021\a\244\364o\316 " "\347\257sZ\261.P\245\306.\351\"w$\017\332\201f\203M&" "\231\317nn\242p\024\225\357\253b9x\\\a\366\312p\277\350?\365D\255@" "\343\023\263\352\354S\0346\264\331\327$/\213U\341\210/" "C\272\264}\210\'+X\362R\341\024\201Q\300\373\017\310n\242\354q\224\317&" "\314\343\021\341\342Q\274\324.4\301\355\254\250\225\270\231\347\034", 208); syscall(SYS_extattr_set_link, /*file=*/0x20000180ul, /*attrnamespace=EXTATTR_NAMESPACE_USER*/ 1ul, /*attrname=*/0x200001c0ul, /*data=*/0ul, /*nbytes=*/0ul); memcpy((void*)0x20000040, "./file0\000", 8); memcpy( (void*)0x200003c0, "\220\317\243+\000-=\\5\201\262(\214&" "\331D\276\227\307\"\336\"\rZ\004\036C\323\313&\266\311:" "PM\026SU\357\350\326T\\\223\037\316\031\241#Y\034\f\372\\07\021\321=" "\261\305\235\266M|\306@\021H\304\004\256Q\377i\\\246?" "\362\001O\326\314\355[a\370u}\255\232\270\035\021\a\244\364o\316 " "\347\257sZ\261.P\245\306.\351\"w$\017\332\201f\203M&" "\231\317n\256\341p\024\225\357\253b9x\\\a\366\312p\277\350?\365D\255@" "\343\023\263\352\354S\0346\264\331\327$/\213U\341\210/" "C\272\264}\210\'+X\362R\341\024\201Q\300\373\017\310n\242\354q\224\317&" "\314\343\021\341\342Q\274\324.4\301\355\254\250\225\270\231\347\034", 208); syscall(SYS_extattr_delete_link, /*file=*/0x20000040ul, /*attrnamespace=EXTATTR_NAMESPACE_USER*/ 1ul, /*attrname=*/0x200003c0ul); memcpy((void*)0x20000040, "/dev/filemon\000", 13); res = syscall(SYS_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x20000040ul, /*flags=*/0ul, /*mode=*/0ul); if (res != -1) r[5] = res; syscall(SYS_sendto, /*fd=*/r[2], /*buf=*/0ul, /*len=*/0ul, /*f=MSG_OOB*/ 1ul, /*addr=*/0ul, /*addrlen=*/0ul); syscall(SYS_sendmsg, /*fd=*/-1, /*msg=*/0ul, /*f=MSG_EOF|MSG_DONTROUTE*/ 0x104ul); *(uint32_t*)0x20000540 = 0; *(uint32_t*)0x20000544 = 0; res = syscall(SYS___specialfd, /*type=*/1ul, /*req=*/0x20000540ul, /*len=*/8ul); if (res != -1) r[6] = res; *(uint32_t*)0x20000000 = r[6]; syscall(SYS_ioctl, /*fd=*/r[5], /*cmd=*/0xc0045301ul, /*arg=*/0x20000000ul); res = syscall(SYS_setsid); if (res != -1) r[7] = res; *(uint32_t*)0x200002c0 = r[7]; syscall(SYS_ioctl, /*fd=*/r[5], /*cmd=*/0xc0045302ul, /*arg=*/0x200002c0ul); memcpy((void*)0x20000240, "./file1\000", 8); syscall(SYS_open, /*file=*/0x20000240ul, /*flags=O_NOCTTY*/ 0x8000ul, /*mode=S_IXGRP|S_IWUSR*/ 0x88ul); memcpy((void*)0x20000840, "./file1\000", 8); res = syscall(SYS_open, /*file=*/0x20000840ul, /*flags=O_SYNC|O_CREAT|FASYNC|O_RDWR|0x4000040000000000*/ 0x40000400000002c2ul, /*mode=*/0ul); if (res != -1) r[8] = res; syscall(SYS_pwritev, /*fd=*/r[8], /*vec=*/0x20000140ul, /*vlen=*/0ul, /*off=*/0ul); syscall(SYS_copy_file_range, /*infd=*/r[3], /*inoffp=*/0ul, /*outfd=*/r[1], /*outoffp=*/0ul, /*len=*/0xfffffffffffffffdul, /*flags=*/0ul); syscall(SYS_vfork); syscall(SYS_rfork, /*flags=*/0ul); } 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; }