// https://syzkaller.appspot.com/bug?id=39ad32bbb48e3263ebf3c03db7a3dfee377c0106 // 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 #ifndef __NR_bpf #define __NR_bpf 321 #endif #ifndef __NR_io_uring_enter #define __NR_io_uring_enter 426 #endif #ifndef __NR_io_uring_setup #define __NR_io_uring_setup 425 #endif 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 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"); } #define KMEMLEAK_FILE "/sys/kernel/debug/kmemleak" static const char* setup_leak() { if (!write_file(KMEMLEAK_FILE, "scan=off")) { if (errno == EBUSY) return "KMEMLEAK disabled: increase CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE" " or unset CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF"; return "failed to write(kmemleak, \"scan=off\")"; } if (!write_file(KMEMLEAK_FILE, "scan")) return "failed to write(kmemleak, \"scan\")"; sleep(5); if (!write_file(KMEMLEAK_FILE, "scan")) return "failed to write(kmemleak, \"scan\")"; if (!write_file(KMEMLEAK_FILE, "clear")) return "failed to write(kmemleak, \"clear\")"; return NULL; } static void check_leaks(void) { int fd = open(KMEMLEAK_FILE, O_RDWR); if (fd == -1) exit(1); uint64_t start = current_time_ms(); if (write(fd, "scan", 4) != 4) exit(1); sleep(1); while (current_time_ms() - start < 4 * 1000) sleep(1); if (write(fd, "scan", 4) != 4) exit(1); static char buf[128 << 10]; ssize_t n = read(fd, buf, sizeof(buf) - 1); if (n < 0) exit(1); int nleaks = 0; if (n != 0) { sleep(1); if (write(fd, "scan", 4) != 4) exit(1); if (lseek(fd, 0, SEEK_SET) < 0) exit(1); n = read(fd, buf, sizeof(buf) - 1); if (n < 0) exit(1); buf[n] = 0; char* pos = buf; char* end = buf + n; while (pos < end) { char* next = strstr(pos + 1, "unreferenced object"); if (!next) next = end; char prev = *next; *next = 0; fprintf(stderr, "BUG: memory leak\n%s\n", pos); *next = prev; pos = next; nleaks++; } } if (write(fd, "clear", 5) != 5) exit(1); close(fd); if (nleaks) exit(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; } check_leaks(); } } uint64_t r[1] = {0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // prctl$PR_SET_MM_MAP arguments: [ // option: const = 0x23 (8 bytes) // opt: const = 0xe (8 bytes) // arg: ptr[in, prctl_mm_map] { // prctl_mm_map { // start_code: VMA[0x1000] // end_code: VMA[0xf000] // start_data: VMA[0x4000] // end_data: VMA[0x3000] // start_brk: VMA[0x3000] // brk: VMA[0x3000] // start_stack: VMA[0x3000] // arg_start: VMA[0x3000] // arg_end: VMA[0x1000] // env_start: VMA[0x3000] // env_end: VMA[0x2000] // auxv: nil // auxv_size: bytesize = 0x0 (4 bytes) // exe_fd: fd (resource) // } // } // len: bytesize = 0x68 (8 bytes) // ] *(uint64_t*)0x200000000080 = 0x200000ff7000; *(uint64_t*)0x200000000088 = 0x200000ff1000; *(uint64_t*)0x200000000090 = 0x200000ffc000; *(uint64_t*)0x200000000098 = 0x200000ffc000; *(uint64_t*)0x2000000000a0 = 0x200000ffd000; *(uint64_t*)0x2000000000a8 = 0x200000ff8000; *(uint64_t*)0x2000000000b0 = 0x200000ffb000; *(uint64_t*)0x2000000000b8 = 0x200000ffb000; *(uint64_t*)0x2000000000c0 = 0x200000ff5000; *(uint64_t*)0x2000000000c8 = 0x200000ff9000; *(uint64_t*)0x2000000000d0 = 0x200000ffa000; *(uint64_t*)0x2000000000d8 = 0; *(uint32_t*)0x2000000000e0 = 0; *(uint32_t*)0x2000000000e4 = -1; syscall(__NR_prctl, /*option=*/0x23ul, /*opt=*/0xeul, /*arg=*/0x200000000080ul, /*len=*/0x68ul, 0); // sendmsg$NFT_BATCH arguments: [ // fd: sock_nl_netfilter (resource) // msg: ptr[in, msghdr_netlink[nft_batch_msg]] { // msghdr_netlink[nft_batch_msg] { // addr: nil // addrlen: len = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // vec: nil // vlen: const = 0x1 (8 bytes) // ctrl: const = 0x0 (8 bytes) // ctrllen: const = 0x0 (8 bytes) // f: send_flags = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // } // } // f: send_flags = 0x24004045 (8 bytes) // ] *(uint64_t*)0x200000000080 = 0; *(uint32_t*)0x200000000088 = 0; *(uint64_t*)0x200000000090 = 0; *(uint64_t*)0x200000000098 = 1; *(uint64_t*)0x2000000000a0 = 0; *(uint64_t*)0x2000000000a8 = 0; *(uint32_t*)0x2000000000b0 = 0; syscall( __NR_sendmsg, /*fd=*/(intptr_t)-1, /*msg=*/0x200000000080ul, /*f=MSG_ZEROCOPY|MSG_FASTOPEN|MSG_OOB|MSG_NOSIGNAL|MSG_DONTWAIT|MSG_DONTROUTE*/ 0x24004045ul); // io_uring_setup arguments: [ // entries: int32 = 0x9f9 (4 bytes) // params: ptr[inout, io_uring_params] { // io_uring_params { // sq_entries: int32 = 0x0 (4 bytes) // cq_entries: int32 = 0xc89f (4 bytes) // flags: io_uring_setup_flags = 0x1c800 (4 bytes) // sq_thread_cpu: int32 = 0x3 (4 bytes) // sq_thread_idle: int32 = 0x20002f7 (4 bytes) // features: int32 = 0x0 (4 bytes) // wq_fd: fd_io_uring (resource) // resv: buffer: {00 00 00 00 00 00 00 00 00 00 00 00} (length 0xc) // sq_off: array[int32] { // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // } // cq_off: array[int32] { // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // int32 = 0x0 (4 bytes) // } // } // } // ] // returns fd_io_uring *(uint32_t*)0x200000000044 = 0xc89f; *(uint32_t*)0x200000000048 = 0x1c800; *(uint32_t*)0x20000000004c = 3; *(uint32_t*)0x200000000050 = 0x20002f7; *(uint32_t*)0x200000000058 = -1; memset((void*)0x20000000005c, 0, 12); res = syscall(__NR_io_uring_setup, /*entries=*/0x9f9, /*params=*/0x200000000040ul); if (res != -1) r[0] = res; // bpf$PROG_LOAD arguments: [ // cmd: const = 0x5 (8 bytes) // arg: ptr[in, bpf_prog_t[flags[bpf_prog_type, int32], // bpf_prog_attach_types, bpf_btf_id[opt], fd_bpf_prog[opt]]] { // bpf_prog_t[flags[bpf_prog_type, int32], bpf_prog_attach_types, // bpf_btf_id[opt], fd_bpf_prog[opt]] { // type: bpf_prog_type = 0x12 (4 bytes) // ninsn: bytesize8 = 0x3 (4 bytes) // insns: nil // license: ptr[in, buffer] { // buffer: {73 79 7a 6b 61 6c 6c 65 72 00} (length 0xa) // } // loglev: int32 = 0x80000000 (4 bytes) // logsize: len = 0xfffffffffffffda2 (4 bytes) // log: nil // kern_version: bpf_kern_version = 0x0 (4 bytes) // flags: bpf_prog_load_flags = 0x1000000 (4 bytes) // prog_name: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} // (length 0x10) prog_ifindex: ifindex (resource) expected_attach_type: // union bpf_prog_attach_types { // fallback: bpf_attach_types = 0x2e (4 bytes) // } // btf_fd: fd_btf (resource) // func_info_rec_size: const = 0x0 (4 bytes) // func_info: nil // func_info_cnt: len = 0x0 (4 bytes) // line_info_rec_size: const = 0x0 (4 bytes) // line_info: nil // line_info_cnt: len = 0x0 (4 bytes) // attach_btf_id: bpf_btf_id (resource) // attach_prog_fd: fd_bpf_prog (resource) // core_relo_cnt: len = 0x0 (4 bytes) // fd_array: nil // core_relos: nil // core_relo_rec_size: const = 0x10 (4 bytes) // log_true_size: int32 = 0x0 (4 bytes) // prog_token_fd: union _bpf_prog_t[flags[bpf_prog_type, int32], // bpf_prog_attach_types, bpf_btf_id[opt], // fd_bpf_prog[opt]]_prog_token_fd_wrapper { // void: buffer: {} (length 0x0) // } // pad: union _bpf_prog_t[flags[bpf_prog_type, int32], // bpf_prog_attach_types, bpf_btf_id[opt], // fd_bpf_prog[opt]]_pad_wrapper { // value: const = 0x0 (4 bytes) // } // } // } // size: len = 0x94 (8 bytes) // ] // returns fd_bpf_prog *(uint32_t*)0x200000000000 = 0x12; *(uint32_t*)0x200000000004 = 3; *(uint64_t*)0x200000000008 = 0; *(uint64_t*)0x200000000010 = 0x200000000240; memcpy((void*)0x200000000240, "syzkaller\000", 10); *(uint32_t*)0x200000000018 = 0x80000000; *(uint32_t*)0x20000000001c = 0xfffffda2; *(uint64_t*)0x200000000020 = 0; *(uint32_t*)0x200000000028 = 0; *(uint32_t*)0x20000000002c = 0x1000000; memset((void*)0x200000000030, 0, 16); *(uint32_t*)0x200000000040 = 0; *(uint32_t*)0x200000000044 = 0x2e; *(uint32_t*)0x200000000048 = 0; *(uint32_t*)0x20000000004c = 0; *(uint64_t*)0x200000000050 = 0; *(uint32_t*)0x200000000058 = 0; *(uint32_t*)0x20000000005c = 0; *(uint64_t*)0x200000000060 = 0; *(uint32_t*)0x200000000068 = 0; *(uint32_t*)0x20000000006c = 0; *(uint32_t*)0x200000000070 = 0; *(uint32_t*)0x200000000074 = 0; *(uint64_t*)0x200000000078 = 0; *(uint64_t*)0x200000000080 = 0; *(uint32_t*)0x200000000088 = 0x10; *(uint32_t*)0x20000000008c = 0; *(uint32_t*)0x200000000090 = 0; syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x200000000000ul, /*size=*/0x94ul); // io_uring_enter arguments: [ // fd: fd_io_uring (resource) // to_submit: int32 = 0x2219 (4 bytes) // min_complete: int32 = 0x7721 (4 bytes) // flags: io_uring_enter_flags = 0x16 (8 bytes) // sigmask: nil // size: len = 0x0 (8 bytes) // ] syscall( __NR_io_uring_enter, /*fd=*/r[0], /*to_submit=*/0x2219, /*min_complete=*/0x7721, /*flags=IORING_ENTER_REGISTERED_RING|IORING_ENTER_SQ_WAIT|IORING_ENTER_SQ_WAKEUP*/ 0x16ul, /*sigmask=*/0ul, /*size=*/0ul); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000ul, /*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=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; if ((reason = setup_leak())) printf("the reproducer may not work as expected: leak checking setup " "failed: %s\n", reason); loop(); return 0; }