// https://syzkaller.appspot.com/bug?id=8aa6edf73efcad3a97b234016a4328792eea9f5c // 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 #include #include #include #include #include #include static unsigned long long procid; 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 thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } static bool write_file(const char* file, const char* what, ...) { char buf[1024]; va_list args; va_start(args, what); vsnprintf(buf, sizeof(buf), what, args); va_end(args); buf[sizeof(buf) - 1] = 0; int len = strlen(buf); int fd = open(file, O_WRONLY | O_CLOEXEC); if (fd == -1) return false; if (write(fd, buf, len) != len) { int err = errno; close(fd); errno = err; return false; } close(fd); return true; } static void kill_and_wait(int pid, int* status) { kill(-pid, SIGKILL); kill(pid, SIGKILL); for (int i = 0; i < 100; i++) { if (waitpid(-1, status, WNOHANG | __WALL) == pid) return; usleep(1000); } DIR* dir = opendir("/sys/fs/fuse/connections"); if (dir) { for (;;) { struct dirent* ent = readdir(dir); if (!ent) break; if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) continue; char abort[300]; snprintf(abort, sizeof(abort), "/sys/fs/fuse/connections/%s/abort", ent->d_name); int fd = open(abort, O_WRONLY); if (fd == -1) { continue; } if (write(fd, abort, 1) < 0) { } close(fd); } closedir(dir); } else { } while (waitpid(-1, status, __WALL) != pid) { } } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); write_file("/proc/self/oom_score_adj", "1000"); } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void execute_one(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; for (call = 0; call < 10; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter = 0; for (;; iter++) { int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { setup_test(); 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_call(int call) { intptr_t res = 0; switch (call) { case 0: // socket$inet_tcp arguments: [ // domain: const = 0x2 (8 bytes) // type: const = 0x1 (8 bytes) // proto: const = 0x0 (4 bytes) // ] // returns sock_tcp res = syscall(__NR_socket, /*domain=*/2ul, /*type=*/1ul, /*proto=*/0); if (res != -1) r[0] = res; break; case 1: // bind$inet arguments: [ // fd: sock_in (resource) // addr: ptr[in, sockaddr_in] { // sockaddr_in { // family: const = 0x2 (2 bytes) // port: int16be = 0x4e20 (2 bytes) // addr: union ipv4_addr { // loopback: const = 0x7f000001 (4 bytes) // } // pad = 0x0 (8 bytes) // } // } // addrlen: len = 0x10 (8 bytes) // ] *(uint16_t*)0x200000000000 = 2; *(uint16_t*)0x200000000002 = htobe16(0x4e20); *(uint32_t*)0x200000000004 = htobe32(0x7f000001); syscall(__NR_bind, /*fd=*/r[0], /*addr=*/0x200000000000ul, /*addrlen=*/0x10ul); break; case 2: // listen arguments: [ // fd: sock (resource) // backlog: int32 = 0x10 (4 bytes) // ] syscall(__NR_listen, /*fd=*/r[0], /*backlog=*/0x10); break; case 3: // mkdirat arguments: [ // fd: fd_dir (resource) // path: ptr[in, buffer] { // buffer: {2e 2f 63 69 66 73 00} (length 0x7) // } // mode: open_mode = 0x1ff (8 bytes) // ] memcpy((void*)0x200000000100, "./cifs\000", 7); syscall( __NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x200000000100ul, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/ 0x1fful); break; case 4: // mount arguments: [ // src: ptr[in, blockdev_filename] { // union blockdev_filename { // filename: buffer: {5c 5c 31 32 37 2e 30 2e 30 2e 31 5c 73 68 61 72 // 65 00} (length 0x12) // } // } // dst: ptr[in, buffer] { // buffer: {2e 2f 63 69 66 73 00} (length 0x7) // } // type: ptr[in, buffer] { // buffer: {63 69 66 73 00} (length 0x5) // } // flags: mount_flags = 0x0 (8 bytes) // data: ptr[in, buffer] { // buffer: {75 6e 63 3d 2f 2f 31 32 37 2e 30 2e 30 2e 31 2f 73 68 61 72 // 65 2c 69 70 3d 31 32 37 2e 30 2e 30 2e 31 2c 70 6f 72 74 3d 32 30 30 // 30 30 2c 75 73 65 72 3d 72 6f 6f 74 2c 70 61 73 73 3d 72 6f 6f 74 2c // 76 65 72 73 3d 33 2e 30 2c 6e 6f 64 66 73 00} (length 0x51) // } // ] memcpy((void*)0x200000000500, "\\\\127.0.0.1\\share\000", 18); memcpy((void*)0x200000000100, "./cifs\000", 7); memcpy((void*)0x200000000200, "cifs\000", 5); memcpy( (void*)0x200000000300, "unc=//127.0.0.1/" "share,ip=127.0.0.1,port=20000,user=root,pass=root,vers=3.0,nodfs\000", 81); syscall(__NR_mount, /*src=*/0x200000000500ul, /*dst=*/0x200000000100ul, /*type=*/0x200000000200ul, /*flags=*/0ul, /*data=*/0x200000000300ul); break; case 5: // accept arguments: [ // fd: sock (resource) // peer: nil // peerlen: nil // ] // returns sock res = syscall(__NR_accept, /*fd=*/r[0], /*peer=*/0ul, /*peerlen=*/0ul); if (res != -1) r[1] = res; break; case 6: // sendto$inet arguments: [ // fd: sock_in (resource) // buf: ptr[in, buffer] { // buffer: {00 00 00 80 fe 53 4d 42 40 00 01 00 00 00 00 00 00 00 01 00 // 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 41 00 01 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 10 00 00 00 10 00 00 00 10 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 00} // (length 0x86) // } // len: len = 0x84 (8 bytes) // f: send_flags = 0x0 (8 bytes) // addr: nil // addrlen: len = 0x0 (8 bytes) // ] memcpy( (void*)0x200000002000, "\x00\x00\x00\x80\xfe\x53\x4d\x42\x40\x00\x01\x00\x00\x00\x00\x00\x00" "\x00\x01\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x41\x00\x01\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00" "\x10\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00", 134); syscall(__NR_sendto, /*fd=*/r[1], /*buf=*/0x200000002000ul, /*len=*/0x84ul, /*f=*/0ul, /*addr=*/0ul, /*addrlen=*/0ul); break; case 7: // sendto$inet arguments: [ // fd: sock_in (resource) // buf: ptr[in, buffer] { // buffer: {} (length 0x0) // } // len: len = 0x0 (8 bytes) // f: send_flags = 0x0 (8 bytes) // addr: nil // addrlen: len = 0x0 (8 bytes) // ] syscall(__NR_sendto, /*fd=*/r[1], /*buf=*/0x200000002100ul, /*len=*/0ul, /*f=*/0ul, /*addr=*/0ul, /*addrlen=*/0ul); break; case 8: // ioctl$CEC_ADAP_S_LOG_ADDRS arguments: [ // fd: fd_cec (resource) // cmd: const = 0xc05c6104 (4 bytes) // arg: ptr[inout, cec_log_addrs] { // cec_log_addrs { // log_addr: buffer: {44 97 ac f4} (length 0x4) // log_addr_mask: int16 = 0xb (2 bytes) // cec_version: int8 = 0x4 (1 bytes) // num_log_addrs: int8 = 0x0 (1 bytes) // vendor_id: int32 = 0x3 (4 bytes) // flags: int32 = 0x1000006 (4 bytes) // osd_name: buffer: {55 00 57 8e a5 f4 ff ff ff eb 00 00 10 00 00} // (length 0xf) primary_device_type: buffer: {15 75 b8 59} (length // 0x4) log_addr_type: buffer: {00 00 00 00} (length 0x4) // all_device_types: buffer: {27 71 36 4f} (length 0x4) // features: array[buffer] { // buffer: {aa be 84 59 c6 22 24 47 57 93 e8 a7} (length 0xc) // buffer: {7f 9c e2 d2 c4 f4 39 ff 80 e1 d1 c8} (length 0xc) // buffer: {fa 07 00 f2 2b 42 a3 02 3b e5 16 d1} (length 0xc) // buffer: {00 00 00 00 00 00 00 00 00 00 00 00} (length 0xc) // } // pad = 0x0 (1 bytes) // } // } // ] memcpy((void*)0x200000000140, "\x44\x97\xac\xf4", 4); *(uint16_t*)0x200000000144 = 0xb; *(uint8_t*)0x200000000146 = 4; *(uint8_t*)0x200000000147 = 0; *(uint32_t*)0x200000000148 = 3; *(uint32_t*)0x20000000014c = 0x1000006; memcpy((void*)0x200000000150, "\x55\x00\x57\x8e\xa5\xf4\xff\xff\xff\xeb\x00\x00\x10\x00\x00", 15); memcpy((void*)0x20000000015f, "\x15\x75\xb8\x59", 4); memset((void*)0x200000000163, 0, 4); memcpy((void*)0x200000000167, "\'q6O", 4); memcpy((void*)0x20000000016b, "\xaa\xbe\x84\x59\xc6\x22\x24\x47\x57\x93\xe8\xa7", 12); memcpy((void*)0x200000000177, "\x7f\x9c\xe2\xd2\xc4\xf4\x39\xff\x80\xe1\xd1\xc8", 12); memcpy((void*)0x200000000183, "\xfa\x07\x00\xf2\x2b\x42\xa3\x02\x3b\xe5\x16\xd1", 12); memset((void*)0x20000000018f, 0, 12); syscall(__NR_ioctl, /*fd=*/(intptr_t)-1, /*cmd=*/0xc05c6104, /*arg=*/0x200000000140ul); break; case 9: // close arguments: [ // fd: fd (resource) // ] syscall(__NR_close, /*fd=*/r[1]); break; } } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; for (procid = 0; procid < 5; procid++) { if (fork() == 0) { loop(); } } sleep(1000000); return 0; }