// https://syzkaller.appspot.com/bug?id=be49c2247d07ad4a4faa018ebea0432f6f0c1a82 // 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 386 #endif #ifndef __NR_mmap #define __NR_mmap 192 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 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"); } 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 < 15000) continue; kill_and_wait(pid, &status); break; } } } void execute_one(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // bpf$PROG_LOAD arguments: [ // cmd: const = 0x5 (4 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 = 0x6 (4 bytes) // ninsn: bytesize8 = 0x5 (4 bytes) // insns: ptr[inout, array[ANYUNION]] { // array[ANYUNION] { // union ANYUNION { // ANYBLOB: buffer: {18 02 00 00 00 80 00 00 00 00 00 00 00 00 00 // 00 85 00 00 00 36 00 00 00 85 00 00 00 2a 00 00 00 95 00 00 00 // 00 00 00 00 91 0f 00 10 83 f7 b8 03 31 57 ad 3a 9e c3 e0 a1 54 // dd e8 e5 16 b3 3d 49 cd 6d 8e a1 ef 44 e2 6a 96 89 04 7d c8 10 // 52 3b b6 cb 64 6e da c6 90 57 13 1e 1b e7 16 2e ed 1f 07 ba 5e // 28 f6 fe 1c b9 39 67 ef 2f 0e f2 d0 df 01 ab 65 f8 f7 30 d2 85 // 12 51 b7 cd a3 3d 6e 31 16 f5 66 92 77 44 a6 e2 35 59 db 48 c0 // 3d 56 7c 61 c6 8d 40 95 f6 39 c7 dd aa 0d 10 b9 b3 f0 d1 f2 0b // d1 b7 20 12 aa aa 70 b8 45 45 5e c5 2e 27 fd b0} (length 0xb2) // } // } // } // license: ptr[in, buffer] { // buffer: {73 79 7a 6b 61 6c 6c 65 72 00} (length 0xa) // } // loglev: int32 = 0x0 (4 bytes) // logsize: len = 0x0 (4 bytes) // log: nil // kern_version: bpf_kern_version = 0x0 (4 bytes) // flags: bpf_prog_load_flags = 0x0 (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 { // xdp: xdp_attach_types = 0x0 (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 = 0x49 (4 bytes) // ] // returns fd_bpf_prog *(uint32_t*)0x20000100 = 6; *(uint32_t*)0x20000104 = 5; *(uint64_t*)0x20000108 = 0x200001c0; memcpy( (void*)0x200001c0, "\x18\x02\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x85\x00" "\x00\x00\x36\x00\x00\x00\x85\x00\x00\x00\x2a\x00\x00\x00\x95\x00\x00\x00" "\x00\x00\x00\x00\x91\x0f\x00\x10\x83\xf7\xb8\x03\x31\x57\xad\x3a\x9e\xc3" "\xe0\xa1\x54\xdd\xe8\xe5\x16\xb3\x3d\x49\xcd\x6d\x8e\xa1\xef\x44\xe2\x6a" "\x96\x89\x04\x7d\xc8\x10\x52\x3b\xb6\xcb\x64\x6e\xda\xc6\x90\x57\x13\x1e" "\x1b\xe7\x16\x2e\xed\x1f\x07\xba\x5e\x28\xf6\xfe\x1c\xb9\x39\x67\xef\x2f" "\x0e\xf2\xd0\xdf\x01\xab\x65\xf8\xf7\x30\xd2\x85\x12\x51\xb7\xcd\xa3\x3d" "\x6e\x31\x16\xf5\x66\x92\x77\x44\xa6\xe2\x35\x59\xdb\x48\xc0\x3d\x56\x7c" "\x61\xc6\x8d\x40\x95\xf6\x39\xc7\xdd\xaa\x0d\x10\xb9\xb3\xf0\xd1\xf2\x0b" "\xd1\xb7\x20\x12\xaa\xaa\x70\xb8\x45\x45\x5e\xc5\x2e\x27\xfd\xb0", 178); *(uint64_t*)0x20000110 = 0x200000c0; memcpy((void*)0x200000c0, "syzkaller\000", 10); *(uint32_t*)0x20000118 = 0; *(uint32_t*)0x2000011c = 0; *(uint64_t*)0x20000120 = 0; *(uint32_t*)0x20000128 = 0; *(uint32_t*)0x2000012c = 0; memset((void*)0x20000130, 0, 16); *(uint32_t*)0x20000140 = 0; *(uint32_t*)0x20000144 = 0; *(uint32_t*)0x20000148 = -1; *(uint32_t*)0x2000014c = 0; *(uint64_t*)0x20000150 = 0; *(uint32_t*)0x20000158 = 0; *(uint32_t*)0x2000015c = 0; *(uint64_t*)0x20000160 = 0; *(uint32_t*)0x20000168 = 0; *(uint32_t*)0x2000016c = 0; *(uint32_t*)0x20000170 = 0; *(uint32_t*)0x20000174 = 0; *(uint64_t*)0x20000178 = 0; *(uint64_t*)0x20000180 = 0; *(uint32_t*)0x20000188 = 0x10; *(uint32_t*)0x2000018c = 0; *(uint32_t*)0x20000190 = 0; syscall(__NR_bpf, /*cmd=*/5, /*arg=*/0x20000100, /*size=*/0x49); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000, /*len=*/0x1000, /*prot=*/0, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32, /*fd=*/(intptr_t)-1, /*offset=*/0); syscall(__NR_mmap, /*addr=*/0x20000000, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32, /*fd=*/(intptr_t)-1, /*offset=*/0); syscall(__NR_mmap, /*addr=*/0x21000000, /*len=*/0x1000, /*prot=*/0, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32, /*fd=*/(intptr_t)-1, /*offset=*/0); const char* reason; (void)reason; loop(); return 0; }