// https://syzkaller.appspot.com/bug?id=d5f63be97bcf572595613d19f9b82475e37c9026 // 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 #include #include #include #include #include #ifndef __NR_bpf #define __NR_bpf 321 #endif 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 use_temporary_dir(void) { char tmpdir_template[] = "./syzkaller.XXXXXX"; char* tmpdir = mkdtemp(tmpdir_template); if (!tmpdir) exit(1); if (chmod(tmpdir, 0777)) exit(1); if (chdir(tmpdir)) exit(1); } 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); } #define BITMASK(bf_off, bf_len) (((1ull << (bf_len)) - 1) << (bf_off)) #define STORE_BY_BITMASK(type, htobe, addr, val, bf_off, bf_len) \ *(type*)(addr) = \ htobe((htobe(*(type*)(addr)) & ~BITMASK((bf_off), (bf_len))) | \ (((type)(val) << (bf_off)) & BITMASK((bf_off), (bf_len)))) 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; } #define MAX_FDS 30 static void setup_gadgetfs(); static void setup_binderfs(); static void setup_fusectl(); static void sandbox_common_mount_tmpfs(void) { write_file("/proc/sys/fs/mount-max", "100000"); if (mkdir("./syz-tmp", 0777)) exit(1); if (mount("", "./syz-tmp", "tmpfs", 0, NULL)) exit(1); if (mkdir("./syz-tmp/newroot", 0777)) exit(1); if (mkdir("./syz-tmp/newroot/dev", 0700)) exit(1); unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE; if (mount("/dev", "./syz-tmp/newroot/dev", NULL, bind_mount_flags, NULL)) exit(1); if (mkdir("./syz-tmp/newroot/proc", 0700)) exit(1); if (mount("syz-proc", "./syz-tmp/newroot/proc", "proc", 0, NULL)) exit(1); if (mkdir("./syz-tmp/newroot/selinux", 0700)) exit(1); const char* selinux_path = "./syz-tmp/newroot/selinux"; if (mount("/selinux", selinux_path, NULL, bind_mount_flags, NULL)) { if (errno != ENOENT) exit(1); if (mount("/sys/fs/selinux", selinux_path, NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); } if (mkdir("./syz-tmp/newroot/sys", 0700)) exit(1); if (mount("/sys", "./syz-tmp/newroot/sys", 0, bind_mount_flags, NULL)) exit(1); if (mount("/sys/kernel/debug", "./syz-tmp/newroot/sys/kernel/debug", NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); if (mount("/sys/fs/smackfs", "./syz-tmp/newroot/sys/fs/smackfs", NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); if (mount("/proc/sys/fs/binfmt_misc", "./syz-tmp/newroot/proc/sys/fs/binfmt_misc", NULL, bind_mount_flags, NULL) && errno != ENOENT) exit(1); if (mkdir("./syz-tmp/newroot/syz-inputs", 0700)) exit(1); if (mount("/syz-inputs", "./syz-tmp/newroot/syz-inputs", NULL, bind_mount_flags | MS_RDONLY, NULL) && errno != ENOENT) exit(1); if (mkdir("./syz-tmp/pivot", 0777)) exit(1); if (syscall(SYS_pivot_root, "./syz-tmp", "./syz-tmp/pivot")) { if (chdir("./syz-tmp")) exit(1); } else { if (chdir("/")) exit(1); if (umount2("./pivot", MNT_DETACH)) exit(1); } if (chroot("./newroot")) exit(1); if (chdir("/")) exit(1); setup_gadgetfs(); setup_binderfs(); setup_fusectl(); } static void setup_gadgetfs() { if (mkdir("/dev/gadgetfs", 0777)) { } if (mount("gadgetfs", "/dev/gadgetfs", "gadgetfs", 0, NULL)) { } } static void setup_fusectl() { if (mount(0, "/sys/fs/fuse/connections", "fusectl", 0, 0)) { } } static void setup_binderfs() { if (mkdir("/dev/binderfs", 0777)) { } if (mount("binder", "/dev/binderfs", "binder", 0, NULL)) { } } static void loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); if (getppid() == 1) exit(1); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = (200 << 20); setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 136 << 20; setrlimit(RLIMIT_FSIZE, &rlim); rlim.rlim_cur = rlim.rlim_max = 1 << 20; setrlimit(RLIMIT_STACK, &rlim); rlim.rlim_cur = rlim.rlim_max = 128 << 20; setrlimit(RLIMIT_CORE, &rlim); rlim.rlim_cur = rlim.rlim_max = 256; setrlimit(RLIMIT_NOFILE, &rlim); if (unshare(CLONE_NEWNS)) { } if (mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } typedef struct { const char* name; const char* value; } sysctl_t; static const sysctl_t sysctls[] = { {"/proc/sys/kernel/shmmax", "16777216"}, {"/proc/sys/kernel/shmall", "536870912"}, {"/proc/sys/kernel/shmmni", "1024"}, {"/proc/sys/kernel/msgmax", "8192"}, {"/proc/sys/kernel/msgmni", "1024"}, {"/proc/sys/kernel/msgmnb", "1024"}, {"/proc/sys/kernel/sem", "1024 1048576 500 1024"}, }; unsigned i; for (i = 0; i < sizeof(sysctls) / sizeof(sysctls[0]); i++) write_file(sysctls[i].name, sysctls[i].value); } static int wait_for_loop(int pid) { if (pid < 0) exit(1); int status = 0; while (waitpid(-1, &status, __WALL) != pid) { } return WEXITSTATUS(status); } static void drop_caps(void) { struct __user_cap_header_struct cap_hdr = {}; struct __user_cap_data_struct cap_data[2] = {}; cap_hdr.version = _LINUX_CAPABILITY_VERSION_3; cap_hdr.pid = getpid(); if (syscall(SYS_capget, &cap_hdr, &cap_data)) exit(1); const int drop = (1 << CAP_SYS_PTRACE) | (1 << CAP_SYS_NICE); cap_data[0].effective &= ~drop; cap_data[0].permitted &= ~drop; cap_data[0].inheritable &= ~drop; if (syscall(SYS_capset, &cap_hdr, &cap_data)) exit(1); } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid != 0) return wait_for_loop(pid); sandbox_common(); drop_caps(); if (unshare(CLONE_NEWNET)) { } write_file("/proc/sys/net/ipv4/ping_group_range", "0 65535"); sandbox_common_mount_tmpfs(); loop(); exit(1); } #define FS_IOC_SETFLAGS _IOW('f', 2, long) static void remove_dir(const char* dir) { int iter = 0; DIR* dp = 0; const int umount_flags = MNT_FORCE | UMOUNT_NOFOLLOW; retry: while (umount2(dir, umount_flags) == 0) { } dp = opendir(dir); if (dp == NULL) { if (errno == EMFILE) { exit(1); } exit(1); } struct dirent* ep = 0; while ((ep = readdir(dp))) { if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0) continue; char filename[FILENAME_MAX]; snprintf(filename, sizeof(filename), "%s/%s", dir, ep->d_name); while (umount2(filename, umount_flags) == 0) { } struct stat st; if (lstat(filename, &st)) exit(1); if (S_ISDIR(st.st_mode)) { remove_dir(filename); continue; } int i; for (i = 0;; i++) { if (unlink(filename) == 0) break; if (errno == EPERM) { int fd = open(filename, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno != EBUSY || i > 100) exit(1); if (umount2(filename, umount_flags)) exit(1); } } closedir(dp); for (int i = 0;; i++) { if (rmdir(dir) == 0) break; if (i < 100) { if (errno == EPERM) { int fd = open(dir, O_RDONLY); if (fd != -1) { long flags = 0; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == 0) { } close(fd); continue; } } if (errno == EROFS) { break; } if (errno == EBUSY) { if (umount2(dir, umount_flags)) exit(1); continue; } if (errno == ENOTEMPTY) { if (iter < 100) { iter++; goto retry; } } } exit(1); } } 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"); if (symlink("/dev/binderfs", "./binderfs")) { } } static void close_fds() { for (int fd = 3; fd < MAX_FDS; fd++) close(fd); } 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 < 4; 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); close_fds(); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); 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; } remove_dir(cwdbuf); } } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: // bpf$MAP_CREATE_TAIL_CALL arguments: [ // cmd: const = 0x0 (8 bytes) // arg: ptr[in, bpf_map_create_arg_t[const[BPF_MAP_TYPE_PROG_ARRAY, // int32], const[4, int32], const[4, int32], const[10, int32], const[0, // int32], const[0, int64]]] { // bpf_map_create_arg_t[const[BPF_MAP_TYPE_PROG_ARRAY, int32], const[4, // int32], const[4, int32], const[10, int32], const[0, int32], const[0, // int64]] { // type: const = 0x3 (4 bytes) // ksize: const = 0x4 (4 bytes) // vsize: const = 0x4 (4 bytes) // max: const = 0xa (4 bytes) // flags: const = 0x0 (4 bytes) // inner: fd_bpf_map (resource) // node: int32 = 0x0 (4 bytes) // map_name: buffer: {00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00} (length 0x10) map_ifindex: ifindex (resource) btf_fd: fd_btf // (resource) btf_key_type_id: int32 = 0x0 (4 bytes) // btf_value_type_id: int32 = 0x0 (4 bytes) // btf_vmlinux_type_id: int32 = 0x0 (4 bytes) // map_extra: const = 0x0 (8 bytes) // value_type_btf_obj_fd: union // _bpf_map_create_arg_t[const[BPF_MAP_TYPE_PROG_ARRAY, int32], // const[4, int32], const[4, int32], const[10, int32], const[0, // int32], const[0, int64]]_value_type_btf_obj_fd_wrapper { // void: buffer: {} (length 0x0) // } // pad1: union _bpf_map_create_arg_t[const[BPF_MAP_TYPE_PROG_ARRAY, // int32], const[4, int32], const[4, int32], const[10, int32], // const[0, int32], const[0, int64]]_pad1_wrapper { // value: const = 0x0 (4 bytes) // } // map_token_fd: union // _bpf_map_create_arg_t[const[BPF_MAP_TYPE_PROG_ARRAY, int32], // const[4, int32], const[4, int32], const[10, int32], const[0, // int32], const[0, int64]]_map_token_fd_wrapper { // void: buffer: {} (length 0x0) // } // pad2: union _bpf_map_create_arg_t[const[BPF_MAP_TYPE_PROG_ARRAY, // int32], const[4, int32], const[4, int32], const[10, int32], // const[0, int32], const[0, int64]]_pad2_wrapper { // value: const = 0x0 (4 bytes) // } // } // } // size: len = 0x48 (8 bytes) // ] // returns tail_call_map_fd *(uint32_t*)0x200000000540 = 3; *(uint32_t*)0x200000000544 = 4; *(uint32_t*)0x200000000548 = 4; *(uint32_t*)0x20000000054c = 0xa; *(uint32_t*)0x200000000550 = 0; *(uint32_t*)0x200000000554 = 0; *(uint32_t*)0x200000000558 = 0; memset((void*)0x20000000055c, 0, 16); *(uint32_t*)0x20000000056c = 0; *(uint32_t*)0x200000000570 = 0; *(uint32_t*)0x200000000574 = 0; *(uint32_t*)0x200000000578 = 0; *(uint32_t*)0x20000000057c = 0; *(uint64_t*)0x200000000580 = 0; *(uint32_t*)0x200000000588 = 0; *(uint32_t*)0x20000000058c = 0; res = syscall(__NR_bpf, /*cmd=*/0ul, /*arg=*/0x200000000540ul, /*size=*/0x48ul); if (res != -1) r[0] = res; break; case 1: // 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 = 0x3 (4 bytes) // ninsn: bytesize8 = 0x8 (4 bytes) // insns: ptr[in, bpf_instructions] { // union bpf_instructions { // framed: bpf_framed_program { // initr0: bpf_insn_init_r0 { // code: const = 0x18 (1 bytes) // dst: const = 0x0 (0 bytes) // src: const = 0x0 (1 bytes) // off: const = 0x0 (2 bytes) // imm: int32 = 0x0 (4 bytes) // code2: const = 0x0 (1 bytes) // regs2: const = 0x0 (1 bytes) // off2: const = 0x0 (2 bytes) // imm2: int32 = 0x0 (4 bytes) // } // body: array[bpf_insn] { // union bpf_insn { // tail_call: bpf_insn_tail_call { // insn1: bpf_insn_map_fd_t[const[BPF_REG_2, int8:4], // tail_call_map] { // code: const = 0x18 (1 bytes) // dst: const = 0x2 (0 bytes) // src: const = 0x1 (1 bytes) // off: const = 0x0 (2 bytes) // imm: tail_call_map (resource) // code2: const = 0x0 (1 bytes) // regs2: const = 0x0 (1 bytes) // off2: const = 0x0 (2 bytes) // imm2: const = 0x0 (4 bytes) // } // insn2: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_MOV0, // const[BPF_REG_3, int8:4], const[0, int8:4], const[0, // int16], const[0, int32]] { // code_class: int8 = 0x7 (0 bytes) // code_s: int8 = 0x0 (0 bytes) // code_op: int8 = 0xb (1 bytes) // dst: const = 0x3 (0 bytes) // src: const = 0x0 (1 bytes) // off: const = 0x0 (2 bytes) // imm: const = 0x0 (4 bytes) // } // insn3: // bpf_insn_call_helper_t[const[BPF_FUNC_tail_call, // int32]] { // code: const = 0x85 (1 bytes) // regs: const = 0x0 (1 bytes) // off: const = 0x0 (2 bytes) // func: const = 0xc (4 bytes) // } // insn4: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_MOV0, // const[BPF_REG_0, int8:4], const[0, int8:4], const[0, // int16], const[0, int32]] { // code_class: int8 = 0x7 (0 bytes) // code_s: int8 = 0x0 (0 bytes) // code_op: int8 = 0xb (1 bytes) // dst: const = 0x0 (0 bytes) // src: const = 0x0 (1 bytes) // off: const = 0x0 (2 bytes) // imm: const = 0x0 (4 bytes) // } // } // } // } // exit: bpf_insn_exit { // code: const = 0x95 (1 bytes) // regs: const = 0x0 (1 bytes) // off: const = 0x0 (2 bytes) // imm: const = 0x0 (4 bytes) // } // } // } // } // license: ptr[in, buffer] { // buffer: {47 50 4c 00} (length 0x4) // } // 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 { // sched_cls: sched_cls_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 = 0x0 (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 = 0xa0 (8 bytes) // ] // returns fd_bpf_prog *(uint32_t*)0x200000000680 = 3; *(uint32_t*)0x200000000684 = 8; *(uint64_t*)0x200000000688 = 0x200000000740; *(uint8_t*)0x200000000740 = 0x18; STORE_BY_BITMASK(uint8_t, , 0x200000000741, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000741, 0, 4, 4); *(uint16_t*)0x200000000742 = 0; *(uint32_t*)0x200000000744 = 0; *(uint8_t*)0x200000000748 = 0; *(uint8_t*)0x200000000749 = 0; *(uint16_t*)0x20000000074a = 0; *(uint32_t*)0x20000000074c = 0; *(uint8_t*)0x200000000750 = 0x18; STORE_BY_BITMASK(uint8_t, , 0x200000000751, 2, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000751, 1, 4, 4); *(uint16_t*)0x200000000752 = 0; *(uint32_t*)0x200000000754 = r[0]; *(uint8_t*)0x200000000758 = 0; *(uint8_t*)0x200000000759 = 0; *(uint16_t*)0x20000000075a = 0; *(uint32_t*)0x20000000075c = 0; STORE_BY_BITMASK(uint8_t, , 0x200000000760, 7, 0, 3); STORE_BY_BITMASK(uint8_t, , 0x200000000760, 0, 3, 1); STORE_BY_BITMASK(uint8_t, , 0x200000000760, 0xb, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000761, 3, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000761, 0, 4, 4); *(uint16_t*)0x200000000762 = 0; *(uint32_t*)0x200000000764 = 0; *(uint8_t*)0x200000000768 = 0x85; *(uint8_t*)0x200000000769 = 0; *(uint16_t*)0x20000000076a = 0; *(uint32_t*)0x20000000076c = 0xc; STORE_BY_BITMASK(uint8_t, , 0x200000000770, 7, 0, 3); STORE_BY_BITMASK(uint8_t, , 0x200000000770, 0, 3, 1); STORE_BY_BITMASK(uint8_t, , 0x200000000770, 0xb, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000771, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000771, 0, 4, 4); *(uint16_t*)0x200000000772 = 0; *(uint32_t*)0x200000000774 = 0; *(uint8_t*)0x200000000778 = 0x95; *(uint8_t*)0x200000000779 = 0; *(uint16_t*)0x20000000077a = 0; *(uint32_t*)0x20000000077c = 0; *(uint64_t*)0x200000000690 = 0x200000000780; memcpy((void*)0x200000000780, "GPL\000", 4); *(uint32_t*)0x200000000698 = 0; *(uint32_t*)0x20000000069c = 0; *(uint64_t*)0x2000000006a0 = 0; *(uint32_t*)0x2000000006a8 = 0; *(uint32_t*)0x2000000006ac = 0; memset((void*)0x2000000006b0, 0, 16); *(uint32_t*)0x2000000006c0 = 0; *(uint32_t*)0x2000000006c4 = 0; *(uint32_t*)0x2000000006c8 = 0; *(uint32_t*)0x2000000006cc = 0; *(uint64_t*)0x2000000006d0 = 0; *(uint32_t*)0x2000000006d8 = 0; *(uint32_t*)0x2000000006dc = 0; *(uint64_t*)0x2000000006e0 = 0; *(uint32_t*)0x2000000006e8 = 0; *(uint32_t*)0x2000000006ec = 0; *(uint32_t*)0x2000000006f0 = 0; *(uint32_t*)0x2000000006f4 = 0; *(uint64_t*)0x2000000006f8 = 0; *(uint64_t*)0x200000000700 = 0; *(uint32_t*)0x200000000708 = 0; *(uint32_t*)0x20000000070c = 0; *(uint32_t*)0x200000000710 = 0; res = syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x200000000680ul, /*size=*/0xa0ul); if (res != -1) r[1] = res; break; case 2: // 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 = 0x3 (4 bytes) // ninsn: bytesize8 = 0x8 (4 bytes) // insns: ptr[in, bpf_instructions] { // union bpf_instructions { // framed: bpf_framed_program { // initr0: bpf_insn_init_r0 { // code: const = 0x18 (1 bytes) // dst: const = 0x0 (0 bytes) // src: const = 0x0 (1 bytes) // off: const = 0x0 (2 bytes) // imm: int32 = 0x0 (4 bytes) // code2: const = 0x0 (1 bytes) // regs2: const = 0x0 (1 bytes) // off2: const = 0x0 (2 bytes) // imm2: int32 = 0xfffffffe (4 bytes) // } // body: array[bpf_insn] { // union bpf_insn { // tail_call: bpf_insn_tail_call { // insn1: bpf_insn_map_fd_t[const[BPF_REG_2, int8:4], // tail_call_map] { // code: const = 0x18 (1 bytes) // dst: const = 0x2 (0 bytes) // src: const = 0x1 (1 bytes) // off: const = 0x0 (2 bytes) // imm: tail_call_map (resource) // code2: const = 0x0 (1 bytes) // regs2: const = 0x0 (1 bytes) // off2: const = 0x0 (2 bytes) // imm2: const = 0x0 (4 bytes) // } // insn2: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_MOV0, // const[BPF_REG_3, int8:4], const[0, int8:4], const[0, // int16], const[0, int32]] { // code_class: int8 = 0x7 (0 bytes) // code_s: int8 = 0x0 (0 bytes) // code_op: int8 = 0xb (1 bytes) // dst: const = 0x3 (0 bytes) // src: const = 0x0 (1 bytes) // off: const = 0x0 (2 bytes) // imm: const = 0x0 (4 bytes) // } // insn3: // bpf_insn_call_helper_t[const[BPF_FUNC_tail_call, // int32]] { // code: const = 0x85 (1 bytes) // regs: const = 0x0 (1 bytes) // off: const = 0x0 (2 bytes) // func: const = 0xc (4 bytes) // } // insn4: bpf_insn_alu_t[BPF_ALU64, BPF_K0, BPF_MOV0, // const[BPF_REG_0, int8:4], const[0, int8:4], const[0, // int16], const[0, int32]] { // code_class: int8 = 0x7 (0 bytes) // code_s: int8 = 0x0 (0 bytes) // code_op: int8 = 0xb (1 bytes) // dst: const = 0x0 (0 bytes) // src: const = 0x0 (1 bytes) // off: const = 0x0 (2 bytes) // imm: const = 0x0 (4 bytes) // } // } // } // } // exit: bpf_insn_exit { // code: const = 0x95 (1 bytes) // regs: const = 0x0 (1 bytes) // off: const = 0x0 (2 bytes) // imm: const = 0x0 (4 bytes) // } // } // } // } // license: ptr[in, buffer] { // buffer: {47 50 4c 00} (length 0x4) // } // 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 { // sched_cls: sched_cls_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 = 0x0 (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*)0x200000000c80 = 3; *(uint32_t*)0x200000000c84 = 8; *(uint64_t*)0x200000000c88 = 0x200000000bc0; *(uint8_t*)0x200000000bc0 = 0x18; STORE_BY_BITMASK(uint8_t, , 0x200000000bc1, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000bc1, 0, 4, 4); *(uint16_t*)0x200000000bc2 = 0; *(uint32_t*)0x200000000bc4 = 0; *(uint8_t*)0x200000000bc8 = 0; *(uint8_t*)0x200000000bc9 = 0; *(uint16_t*)0x200000000bca = 0; *(uint32_t*)0x200000000bcc = 0xfffffffe; *(uint8_t*)0x200000000bd0 = 0x18; STORE_BY_BITMASK(uint8_t, , 0x200000000bd1, 2, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000bd1, 1, 4, 4); *(uint16_t*)0x200000000bd2 = 0; *(uint32_t*)0x200000000bd4 = r[0]; *(uint8_t*)0x200000000bd8 = 0; *(uint8_t*)0x200000000bd9 = 0; *(uint16_t*)0x200000000bda = 0; *(uint32_t*)0x200000000bdc = 0; STORE_BY_BITMASK(uint8_t, , 0x200000000be0, 7, 0, 3); STORE_BY_BITMASK(uint8_t, , 0x200000000be0, 0, 3, 1); STORE_BY_BITMASK(uint8_t, , 0x200000000be0, 0xb, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000be1, 3, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000be1, 0, 4, 4); *(uint16_t*)0x200000000be2 = 0; *(uint32_t*)0x200000000be4 = 0; *(uint8_t*)0x200000000be8 = 0x85; *(uint8_t*)0x200000000be9 = 0; *(uint16_t*)0x200000000bea = 0; *(uint32_t*)0x200000000bec = 0xc; STORE_BY_BITMASK(uint8_t, , 0x200000000bf0, 7, 0, 3); STORE_BY_BITMASK(uint8_t, , 0x200000000bf0, 0, 3, 1); STORE_BY_BITMASK(uint8_t, , 0x200000000bf0, 0xb, 4, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000bf1, 0, 0, 4); STORE_BY_BITMASK(uint8_t, , 0x200000000bf1, 0, 4, 4); *(uint16_t*)0x200000000bf2 = 0; *(uint32_t*)0x200000000bf4 = 0; *(uint8_t*)0x200000000bf8 = 0x95; *(uint8_t*)0x200000000bf9 = 0; *(uint16_t*)0x200000000bfa = 0; *(uint32_t*)0x200000000bfc = 0; *(uint64_t*)0x200000000c90 = 0x200000000c40; memcpy((void*)0x200000000c40, "GPL\000", 4); *(uint32_t*)0x200000000c98 = 0; *(uint32_t*)0x200000000c9c = 0; *(uint64_t*)0x200000000ca0 = 0; *(uint32_t*)0x200000000ca8 = 0; *(uint32_t*)0x200000000cac = 0; memset((void*)0x200000000cb0, 0, 16); *(uint32_t*)0x200000000cc0 = 0; *(uint32_t*)0x200000000cc4 = 0; *(uint32_t*)0x200000000cc8 = 0; *(uint32_t*)0x200000000ccc = 0; *(uint64_t*)0x200000000cd0 = 0; *(uint32_t*)0x200000000cd8 = 0; *(uint32_t*)0x200000000cdc = 0; *(uint64_t*)0x200000000ce0 = 0; *(uint32_t*)0x200000000ce8 = 0; *(uint32_t*)0x200000000cec = 0; *(uint32_t*)0x200000000cf0 = 0; *(uint32_t*)0x200000000cf4 = 0; *(uint64_t*)0x200000000cf8 = 0; *(uint64_t*)0x200000000d00 = 0; *(uint32_t*)0x200000000d08 = 0; *(uint32_t*)0x200000000d0c = 0; *(uint32_t*)0x200000000d10 = 0; syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x200000000c80ul, /*size=*/0x94ul); for (int i = 0; i < 64; i++) { syscall(__NR_bpf, /*cmd=*/5ul, /*arg=*/0x200000000c80ul, /*size=*/0x94ul); } break; case 3: // bpf$MAP_UPDATE_ELEM_TAIL_CALL arguments: [ // cmd: const = 0x2 (8 bytes) // arg: ptr[inout, bpf_map_update_tail_call_arg] { // bpf_map_update_tail_call_arg { // map: tail_call_map_update { // in: tail_call_map_fd (resource) // out: tail_call_map (resource) // } // pad = 0x0 (4 bytes) // key: ptr[in, const[0, const]] { // const = 0x0 (4 bytes) // } // val: ptr[in, fd_bpf_prog] { // fd_bpf_prog (resource) // } // flags: const = 0x0 (8 bytes) // } // } // size: len = 0x20 (8 bytes) // ] *(uint32_t*)0x2000000000c0 = r[0]; *(uint64_t*)0x2000000000c8 = 0x200000000000; *(uint32_t*)0x200000000000 = 0; *(uint64_t*)0x2000000000d0 = 0x200000000080; *(uint32_t*)0x200000000080 = r[1]; *(uint64_t*)0x2000000000d8 = 0; syscall(__NR_bpf, /*cmd=*/2ul, /*arg=*/0x2000000000c0ul, /*size=*/0x20ul); break; } } 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; for (procid = 0; procid < 5; procid++) { if (fork() == 0) { use_temporary_dir(); do_sandbox_none(); } } sleep(1000000); return 0; }