// https://syzkaller.appspot.com/bug?id=28daec4f11514873dfde8de4742143259b443ece // 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 #include #include #ifndef __NR_memfd_create #define __NR_memfd_create 319 #endif static unsigned long long procid; static __thread int clone_ongoing; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { if (__atomic_load_n(&clone_ongoing, __ATOMIC_RELAXED) != 0) { exit(sig); } uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0; int valid = addr < prog_start || addr > prog_end; if (skip && valid) { _longjmp(segv_env, 1); } exit(sig); } static void install_segv_handler(void) { struct sigaction sa; memset(&sa, 0, sizeof(sa)); sa.sa_handler = SIG_IGN; syscall(SYS_rt_sigaction, 0x20, &sa, NULL, 8); syscall(SYS_rt_sigaction, 0x21, &sa, NULL, 8); memset(&sa, 0, sizeof(sa)); sa.sa_sigaction = segv_handler; sa.sa_flags = SA_NODEFER | SA_SIGINFO; sigaction(SIGSEGV, &sa, NULL); sigaction(SIGBUS, &sa, NULL); } #define NONFAILING(...) \ ({ \ int ok = 1; \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } else \ ok = 0; \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ ok; \ }) 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 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 //% This code is derived from puff.{c,h}, found in the zlib development. The //% original files come with the following copyright notice: //% Copyright (C) 2002-2013 Mark Adler, all rights reserved //% version 2.3, 21 Jan 2013 //% This software is provided 'as-is', without any express or implied //% warranty. In no event will the author be held liable for any damages //% arising from the use of this software. //% Permission is granted to anyone to use this software for any purpose, //% including commercial applications, and to alter it and redistribute it //% freely, subject to the following restrictions: //% 1. The origin of this software must not be misrepresented; you must not //% claim that you wrote the original software. If you use this software //% in a product, an acknowledgment in the product documentation would be //% appreciated but is not required. //% 2. Altered source versions must be plainly marked as such, and must not be //% misrepresented as being the original software. //% 3. This notice may not be removed or altered from any source distribution. //% Mark Adler madler@alumni.caltech.edu //% BEGIN CODE DERIVED FROM puff.{c,h} #define MAXBITS 15 #define MAXLCODES 286 #define MAXDCODES 30 #define MAXCODES (MAXLCODES + MAXDCODES) #define FIXLCODES 288 struct puff_state { unsigned char* out; unsigned long outlen; unsigned long outcnt; const unsigned char* in; unsigned long inlen; unsigned long incnt; int bitbuf; int bitcnt; jmp_buf env; }; static int puff_bits(struct puff_state* s, int need) { long val = s->bitbuf; while (s->bitcnt < need) { if (s->incnt == s->inlen) longjmp(s->env, 1); val |= (long)(s->in[s->incnt++]) << s->bitcnt; s->bitcnt += 8; } s->bitbuf = (int)(val >> need); s->bitcnt -= need; return (int)(val & ((1L << need) - 1)); } static int puff_stored(struct puff_state* s) { s->bitbuf = 0; s->bitcnt = 0; if (s->incnt + 4 > s->inlen) return 2; unsigned len = s->in[s->incnt++]; len |= s->in[s->incnt++] << 8; if (s->in[s->incnt++] != (~len & 0xff) || s->in[s->incnt++] != ((~len >> 8) & 0xff)) return -2; if (s->incnt + len > s->inlen) return 2; if (s->outcnt + len > s->outlen) return 1; for (; len--; s->outcnt++, s->incnt++) { if (s->in[s->incnt]) s->out[s->outcnt] = s->in[s->incnt]; } return 0; } struct puff_huffman { short* count; short* symbol; }; static int puff_decode(struct puff_state* s, const struct puff_huffman* h) { int first = 0; int index = 0; int bitbuf = s->bitbuf; int left = s->bitcnt; int code = first = index = 0; int len = 1; short* next = h->count + 1; while (1) { while (left--) { code |= bitbuf & 1; bitbuf >>= 1; int count = *next++; if (code - count < first) { s->bitbuf = bitbuf; s->bitcnt = (s->bitcnt - len) & 7; return h->symbol[index + (code - first)]; } index += count; first += count; first <<= 1; code <<= 1; len++; } left = (MAXBITS + 1) - len; if (left == 0) break; if (s->incnt == s->inlen) longjmp(s->env, 1); bitbuf = s->in[s->incnt++]; if (left > 8) left = 8; } return -10; } static int puff_construct(struct puff_huffman* h, const short* length, int n) { int len; for (len = 0; len <= MAXBITS; len++) h->count[len] = 0; int symbol; for (symbol = 0; symbol < n; symbol++) (h->count[length[symbol]])++; if (h->count[0] == n) return 0; int left = 1; for (len = 1; len <= MAXBITS; len++) { left <<= 1; left -= h->count[len]; if (left < 0) return left; } short offs[MAXBITS + 1]; offs[1] = 0; for (len = 1; len < MAXBITS; len++) offs[len + 1] = offs[len] + h->count[len]; for (symbol = 0; symbol < n; symbol++) if (length[symbol] != 0) h->symbol[offs[length[symbol]]++] = symbol; return left; } static int puff_codes(struct puff_state* s, const struct puff_huffman* lencode, const struct puff_huffman* distcode) { static const short lens[29] = {3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258}; static const short lext[29] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0}; static const short dists[30] = { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; static const short dext[30] = {0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; int symbol; do { symbol = puff_decode(s, lencode); if (symbol < 0) return symbol; if (symbol < 256) { if (s->outcnt == s->outlen) return 1; if (symbol) s->out[s->outcnt] = symbol; s->outcnt++; } else if (symbol > 256) { symbol -= 257; if (symbol >= 29) return -10; int len = lens[symbol] + puff_bits(s, lext[symbol]); symbol = puff_decode(s, distcode); if (symbol < 0) return symbol; unsigned dist = dists[symbol] + puff_bits(s, dext[symbol]); if (dist > s->outcnt) return -11; if (s->outcnt + len > s->outlen) return 1; while (len--) { if (dist <= s->outcnt && s->out[s->outcnt - dist]) s->out[s->outcnt] = s->out[s->outcnt - dist]; s->outcnt++; } } } while (symbol != 256); return 0; } static int puff_fixed(struct puff_state* s) { static int virgin = 1; static short lencnt[MAXBITS + 1], lensym[FIXLCODES]; static short distcnt[MAXBITS + 1], distsym[MAXDCODES]; static struct puff_huffman lencode, distcode; if (virgin) { lencode.count = lencnt; lencode.symbol = lensym; distcode.count = distcnt; distcode.symbol = distsym; short lengths[FIXLCODES]; int symbol; for (symbol = 0; symbol < 144; symbol++) lengths[symbol] = 8; for (; symbol < 256; symbol++) lengths[symbol] = 9; for (; symbol < 280; symbol++) lengths[symbol] = 7; for (; symbol < FIXLCODES; symbol++) lengths[symbol] = 8; puff_construct(&lencode, lengths, FIXLCODES); for (symbol = 0; symbol < MAXDCODES; symbol++) lengths[symbol] = 5; puff_construct(&distcode, lengths, MAXDCODES); virgin = 0; } return puff_codes(s, &lencode, &distcode); } static int puff_dynamic(struct puff_state* s) { static const short order[19] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; int nlen = puff_bits(s, 5) + 257; int ndist = puff_bits(s, 5) + 1; int ncode = puff_bits(s, 4) + 4; if (nlen > MAXLCODES || ndist > MAXDCODES) return -3; short lengths[MAXCODES]; int index; for (index = 0; index < ncode; index++) lengths[order[index]] = puff_bits(s, 3); for (; index < 19; index++) lengths[order[index]] = 0; short lencnt[MAXBITS + 1], lensym[MAXLCODES]; struct puff_huffman lencode = {lencnt, lensym}; int err = puff_construct(&lencode, lengths, 19); if (err != 0) return -4; index = 0; while (index < nlen + ndist) { int symbol; int len; symbol = puff_decode(s, &lencode); if (symbol < 0) return symbol; if (symbol < 16) lengths[index++] = symbol; else { len = 0; if (symbol == 16) { if (index == 0) return -5; len = lengths[index - 1]; symbol = 3 + puff_bits(s, 2); } else if (symbol == 17) symbol = 3 + puff_bits(s, 3); else symbol = 11 + puff_bits(s, 7); if (index + symbol > nlen + ndist) return -6; while (symbol--) lengths[index++] = len; } } if (lengths[256] == 0) return -9; err = puff_construct(&lencode, lengths, nlen); if (err && (err < 0 || nlen != lencode.count[0] + lencode.count[1])) return -7; short distcnt[MAXBITS + 1], distsym[MAXDCODES]; struct puff_huffman distcode = {distcnt, distsym}; err = puff_construct(&distcode, lengths + nlen, ndist); if (err && (err < 0 || ndist != distcode.count[0] + distcode.count[1])) return -8; return puff_codes(s, &lencode, &distcode); } static int puff(unsigned char* dest, unsigned long* destlen, const unsigned char* source, unsigned long sourcelen) { struct puff_state s = { .out = dest, .outlen = *destlen, .outcnt = 0, .in = source, .inlen = sourcelen, .incnt = 0, .bitbuf = 0, .bitcnt = 0, }; int err; if (setjmp(s.env) != 0) err = 2; else { int last; do { last = puff_bits(&s, 1); int type = puff_bits(&s, 2); err = type == 0 ? puff_stored(&s) : (type == 1 ? puff_fixed(&s) : (type == 2 ? puff_dynamic(&s) : -1)); if (err != 0) break; } while (!last); } *destlen = s.outcnt; return err; } //% END CODE DERIVED FROM puff.{c,h} #define ZLIB_HEADER_WIDTH 2 static int puff_zlib_to_file(const unsigned char* source, unsigned long sourcelen, int dest_fd) { if (sourcelen < ZLIB_HEADER_WIDTH) return 0; source += ZLIB_HEADER_WIDTH; sourcelen -= ZLIB_HEADER_WIDTH; const unsigned long max_destlen = 132 << 20; void* ret = mmap(0, max_destlen, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0); if (ret == MAP_FAILED) return -1; unsigned char* dest = (unsigned char*)ret; unsigned long destlen = max_destlen; int err = puff(dest, &destlen, source, sourcelen); if (err) { munmap(dest, max_destlen); errno = -err; return -1; } if (write(dest_fd, dest, destlen) != (ssize_t)destlen) { munmap(dest, max_destlen); return -1; } return munmap(dest, max_destlen); } static int setup_loop_device(unsigned char* data, unsigned long size, const char* loopname, int* loopfd_p) { int err = 0, loopfd = -1; int memfd = syscall(__NR_memfd_create, "syzkaller", 0); if (memfd == -1) { err = errno; goto error; } if (puff_zlib_to_file(data, size, memfd)) { err = errno; goto error_close_memfd; } loopfd = open(loopname, O_RDWR); if (loopfd == -1) { err = errno; goto error_close_memfd; } if (ioctl(loopfd, LOOP_SET_FD, memfd)) { if (errno != EBUSY) { err = errno; goto error_close_loop; } ioctl(loopfd, LOOP_CLR_FD, 0); usleep(1000); if (ioctl(loopfd, LOOP_SET_FD, memfd)) { err = errno; goto error_close_loop; } } close(memfd); *loopfd_p = loopfd; return 0; error_close_loop: close(loopfd); error_close_memfd: close(memfd); error: errno = err; return -1; } static void reset_loop_device(const char* loopname) { int loopfd = open(loopname, O_RDWR); if (loopfd == -1) { return; } if (ioctl(loopfd, LOOP_CLR_FD, 0)) { } close(loopfd); } static long syz_mount_image(volatile long fsarg, volatile long dir, volatile long flags, volatile long optsarg, volatile long change_dir, volatile unsigned long size, volatile long image) { unsigned char* data = (unsigned char*)image; int res = -1, err = 0, need_loop_device = !!size; char* mount_opts = (char*)optsarg; char* target = (char*)dir; char* fs = (char*)fsarg; char* source = NULL; char loopname[64]; if (need_loop_device) { int loopfd; memset(loopname, 0, sizeof(loopname)); snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid); if (setup_loop_device(data, size, loopname, &loopfd) == -1) return -1; close(loopfd); source = loopname; } mkdir(target, 0777); char opts[256]; memset(opts, 0, sizeof(opts)); if (strlen(mount_opts) > (sizeof(opts) - 32)) { } strncpy(opts, mount_opts, sizeof(opts) - 32); if (strcmp(fs, "iso9660") == 0) { flags |= MS_RDONLY; } else if (strncmp(fs, "ext", 3) == 0) { bool has_remount_ro = false; char* remount_ro_start = strstr(opts, "errors=remount-ro"); if (remount_ro_start != NULL) { char after = *(remount_ro_start + strlen("errors=remount-ro")); char before = remount_ro_start == opts ? '\0' : *(remount_ro_start - 1); has_remount_ro = ((before == '\0' || before == ',') && (after == '\0' || after == ',')); } if (strstr(opts, "errors=panic") || !has_remount_ro) strcat(opts, ",errors=continue"); } else if (strcmp(fs, "xfs") == 0) { strcat(opts, ",nouuid"); } res = mount(source, target, fs, flags, opts); if (res == -1) { err = errno; goto error_clear_loop; } res = open(target, O_RDONLY | O_DIRECTORY); if (res == -1) { err = errno; goto error_clear_loop; } if (change_dir) { res = chdir(target); if (res == -1) { err = errno; } } error_clear_loop: if (need_loop_device) reset_loop_device(loopname); errno = err; return res; } static void mount_cgroups(const char* dir, const char** controllers, int count) { if (mkdir(dir, 0777)) { return; } char enabled[128] = {0}; int i = 0; for (; i < count; i++) { if (mount("none", dir, "cgroup", 0, controllers[i])) { continue; } umount(dir); strcat(enabled, ","); strcat(enabled, controllers[i]); } if (enabled[0] == 0) { if (rmdir(dir) && errno != EBUSY) exit(1); return; } if (mount("none", dir, "cgroup", 0, enabled + 1)) { if (rmdir(dir) && errno != EBUSY) exit(1); } if (chmod(dir, 0777)) { } } static void mount_cgroups2(const char** controllers, int count) { if (mkdir("/syzcgroup/unified", 0777)) { return; } if (mount("none", "/syzcgroup/unified", "cgroup2", 0, NULL)) { if (rmdir("/syzcgroup/unified") && errno != EBUSY) exit(1); return; } if (chmod("/syzcgroup/unified", 0777)) { } int control = open("/syzcgroup/unified/cgroup.subtree_control", O_WRONLY); if (control == -1) return; int i; for (i = 0; i < count; i++) if (write(control, controllers[i], strlen(controllers[i])) < 0) { } close(control); } static void setup_cgroups() { const char* unified_controllers[] = {"+cpu", "+io", "+pids"}; const char* net_controllers[] = {"net", "net_prio", "devices", "blkio", "freezer"}; const char* cpu_controllers[] = {"cpuset", "cpuacct", "hugetlb", "rlimit", "memory"}; if (mkdir("/syzcgroup", 0777)) { return; } mount_cgroups2(unified_controllers, sizeof(unified_controllers) / sizeof(unified_controllers[0])); mount_cgroups("/syzcgroup/net", net_controllers, sizeof(net_controllers) / sizeof(net_controllers[0])); mount_cgroups("/syzcgroup/cpu", cpu_controllers, sizeof(cpu_controllers) / sizeof(cpu_controllers[0])); write_file("/syzcgroup/cpu/cgroup.clone_children", "1"); write_file("/syzcgroup/cpu/cpuset.memory_pressure_enabled", "1"); } static void setup_cgroups_loop() { int pid = getpid(); char file[128]; char cgroupdir[64]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/pids.max", cgroupdir); write_file(file, "32"); snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); snprintf(file, sizeof(file), "%s/memory.soft_limit_in_bytes", cgroupdir); write_file(file, "%d", 299 << 20); snprintf(file, sizeof(file), "%s/memory.limit_in_bytes", cgroupdir); write_file(file, "%d", 300 << 20); snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (mkdir(cgroupdir, 0777)) { } snprintf(file, sizeof(file), "%s/cgroup.procs", cgroupdir); write_file(file, "%d", pid); } static void setup_cgroups_test() { char cgroupdir[64]; snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/unified/syz%llu", procid); if (symlink(cgroupdir, "./cgroup")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/cpu/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.cpu")) { } snprintf(cgroupdir, sizeof(cgroupdir), "/syzcgroup/net/syz%llu", procid); if (symlink(cgroupdir, "./cgroup.net")) { } } static void initialize_cgroups() { if (mkdir("./syz-tmp/newroot/syzcgroup", 0700)) exit(1); if (mkdir("./syz-tmp/newroot/syzcgroup/unified", 0700)) exit(1); if (mkdir("./syz-tmp/newroot/syzcgroup/cpu", 0700)) exit(1); if (mkdir("./syz-tmp/newroot/syzcgroup/net", 0700)) exit(1); unsigned bind_mount_flags = MS_BIND | MS_REC | MS_PRIVATE; if (mount("/syzcgroup/unified", "./syz-tmp/newroot/syzcgroup/unified", NULL, bind_mount_flags, NULL)) { } if (mount("/syzcgroup/cpu", "./syz-tmp/newroot/syzcgroup/cpu", NULL, bind_mount_flags, NULL)) { } if (mount("/syzcgroup/net", "./syz-tmp/newroot/syzcgroup/net", NULL, bind_mount_flags, NULL)) { } } 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); initialize_cgroups(); 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_loop() { setup_cgroups_loop(); } static void reset_loop() { char buf[64]; snprintf(buf, sizeof(buf), "/dev/loop%llu", procid); int loopfd = open(buf, O_RDWR); if (loopfd != -1) { ioctl(loopfd, LOOP_CLR_FD, 0); close(loopfd); } } static void setup_test() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); setup_cgroups_test(); 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); } static void execute_one(void); #define WAIT_FLAGS __WALL static void loop(void) { setup_loop(); int iter = 0; for (;; iter++) { char cwdbuf[32]; sprintf(cwdbuf, "./%d", iter); if (mkdir(cwdbuf, 0777)) exit(1); reset_loop(); int pid = fork(); if (pid < 0) exit(1); if (pid == 0) { if (chdir(cwdbuf)) exit(1); setup_test(); execute_one(); close_fds(); 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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_one(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } NONFAILING(memcpy((void*)0x200000000f00, "udf\000", 4)); NONFAILING(memcpy((void*)0x2000000000c0, "./file0\000", 8)); NONFAILING(memcpy((void*)0x200000000280, "adinicb", 7)); NONFAILING(*(uint8_t*)0x200000000287 = 0x2c); NONFAILING(memcpy((void*)0x200000000288, "iocharset", 9)); NONFAILING(*(uint8_t*)0x200000000291 = 0x3d); NONFAILING(memcpy((void*)0x200000000292, "cp1255", 6)); NONFAILING(*(uint8_t*)0x200000000298 = 0x2c); NONFAILING(memcpy((void*)0x200000000299, "utf8", 4)); NONFAILING(*(uint8_t*)0x20000000029d = 0x2c); NONFAILING(memcpy((void*)0x20000000029e, "uid", 3)); NONFAILING(*(uint8_t*)0x2000000002a1 = 0x3d); NONFAILING(sprintf((char*)0x2000000002a2, "%020llu", (long long)0)); NONFAILING(*(uint8_t*)0x2000000002b6 = 0x2c); NONFAILING(memcpy((void*)0x2000000002b7, "novrs", 5)); NONFAILING(*(uint8_t*)0x2000000002bc = 0x2c); NONFAILING(memcpy((void*)0x2000000002bd, "iocharset", 9)); NONFAILING(*(uint8_t*)0x2000000002c6 = 0x3d); NONFAILING(memcpy((void*)0x2000000002c7, "macinuit", 8)); NONFAILING(*(uint8_t*)0x2000000002cf = 0x2c); NONFAILING(memcpy((void*)0x2000000002d0, "mode", 4)); NONFAILING(*(uint8_t*)0x2000000002d4 = 0x3d); NONFAILING(sprintf((char*)0x2000000002d5, "%023llo", (long long)8)); NONFAILING(*(uint8_t*)0x2000000002ec = 0x2c); NONFAILING(memcpy((void*)0x2000000002ed, "iocharset", 9)); NONFAILING(*(uint8_t*)0x2000000002f6 = 0x3d); NONFAILING(memcpy((void*)0x2000000002f7, "iso8859-5", 9)); NONFAILING(*(uint8_t*)0x200000000300 = 0x2c); NONFAILING(memcpy((void*)0x200000000301, "adinicb", 7)); NONFAILING(*(uint8_t*)0x200000000308 = 0x2c); NONFAILING(memcpy((void*)0x200000000309, "gid=forget", 10)); NONFAILING(*(uint8_t*)0x200000000313 = 0x2c); NONFAILING(memcpy((void*)0x200000000314, "lastblock", 9)); NONFAILING(*(uint8_t*)0x20000000031d = 0x3d); NONFAILING(sprintf((char*)0x20000000031e, "%020llu", (long long)7)); NONFAILING(*(uint8_t*)0x200000000332 = 0x2c); NONFAILING(memcpy((void*)0x200000000333, "gid=forget", 10)); NONFAILING(*(uint8_t*)0x20000000033d = 0x2c); NONFAILING(memcpy((void*)0x20000000033e, "uid", 3)); NONFAILING(*(uint8_t*)0x200000000341 = 0x3d); NONFAILING(sprintf((char*)0x200000000342, "%020llu", (long long)0)); NONFAILING(*(uint8_t*)0x200000000356 = 0x2c); NONFAILING(*(uint8_t*)0x200000000357 = 0); NONFAILING(memcpy( (void*)0x200000000f40, "\x78\x9c\xec\xdd\x4f\x6c\x1c\xd7\x7d\x07\xf0\xdf\x1b\x2d\xc5\x95\xdc\x56" "\x4c\x9c\x2a\x4e\x1a\x07\x9b\xb6\x48\x65\xc6\x72\xf5\x2f\xa6\x62\x15\xee" "\xaa\xa6\xd9\x06\x90\x65\x22\x14\x73\x0b\xc0\x95\x48\xa9\x0b\x53\x24\x41" "\x52\x8d\x6c\xa4\x05\xd3\x4b\x0f\x3d\x04\x28\x8a\x1e\x72\x22\xd0\x1a\x05" "\x52\x34\x30\x9a\x22\xe8\x91\x69\x5d\x20\xb9\xf8\x50\xe4\xd4\x13\xd1\xc2" "\x46\x50\xf4\xc0\x16\x01\x02\x14\x30\x58\xcc\xec\x5b\x71\x49\x91\xb6\x2c" "\x92\x12\x25\x7f\x3e\x36\xf5\x9d\x9d\x79\x6f\xe6\xbd\x99\xf5\x8c\x2c\xe8" "\xcd\x0b\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\x20\xe2\xf7" "\x5e\xbe\x78\xea\x74\xda\x66\xc3\xa1\x87\xd0\x18\x00\xe0\x81\xb8\x3c\xf6" "\xb5\x53\x67\xb6\x7b\xfe\x03\x00\x8f\xad\x2b\x3b\xfd\xff\x3f\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x70\x50\xa4\x28\xe2\xc9\x48\x31\x77\x79" "\x2d\x4d\x54\x9f\x3b\xea\x97\xda\x7d\xb7\x6e\x8f\x0f\x8f\x6c\x5f\xed\x48" "\xaa\x6a\x1e\xaa\xca\x97\x3f\xf5\xd3\x67\xce\x9e\xfb\xf2\xf3\x43\xe7\xbb" "\x79\xa9\x3d\xf3\x01\xf5\xf7\xda\x67\xe3\xd5\xb1\x2b\x17\x1b\x2f\xcd\xde" "\x9c\x9b\x9f\x5a\x58\x98\x9a\x6c\x8c\xcf\xb4\xaf\xcd\x4e\x4e\xdd\xf3\x1e" "\x76\x5b\x7f\xab\xc1\xea\x04\x34\x6e\xbe\x76\x6b\xf2\xfa\xf5\x85\xc6\x99" "\xe7\xce\x6e\xda\x7c\x7b\xe0\xbd\xfe\x27\x8e\x0f\x5c\x18\x7a\xe6\xe4\xd3" "\xdd\xb2\xe3\xc3\x23\x23\x63\x1b\x45\xea\xbd\xe5\x6b\xf7\xdd\x90\x8e\x9d" "\x46\x78\x1c\x8e\x22\x4e\x46\x8a\x67\xbf\xff\xb3\xd4\x8a\x88\x22\x76\x7f" "\x2e\xea\x0f\xf6\xda\x6f\x75\xa4\xea\xc4\x60\xd5\x89\xf1\xe1\x91\xaa\x23" "\xd3\xed\xd6\xcc\x62\xb9\x71\xb4\x7b\x22\x8a\x88\x46\x4f\xa5\x66\xf7\x1c" "\x6d\x7f\x2d\xa2\xd6\xf7\x40\xfb\xb0\xb3\x66\xc4\x52\xd9\xfc\xb2\xc1\x83" "\x65\xf7\xc6\xe6\x5a\xf3\xad\xab\xd3\x53\x8d\xd1\xd6\xfc\x62\x7b\xb1\x3d" "\x3b\x33\x9a\x3a\xad\x2d\xfb\xd3\x88\x22\xce\xa7\x88\xe5\x88\x58\xed\xbf" "\x7b\x77\x7d\x51\x44\x2d\x52\x7c\xf7\xd8\x5a\xba\x9a\xdf\xfa\x51\x9d\x87" "\x2f\x55\x03\x83\x77\x6e\x47\xb1\x8f\x7d\xbc\x07\x65\x3b\x1b\x7d\x11\xcb" "\xc5\x23\x70\xcd\x0e\xb0\xfe\x28\xe2\x95\x48\xf1\xf3\xb7\x4f\xc4\xb5\x7c" "\x9f\xa9\xee\x35\x5f\x8c\x78\xa5\xcc\x1f\x46\xbc\x59\xe6\x8b\x11\xa9\xfc" "\x62\x9c\x8b\x78\x77\x9b\xef\x11\x8f\xa6\x5a\x14\xf1\xe7\xe5\xf5\xbf\xb0" "\x96\x26\xab\xfb\x41\xf7\xbe\x72\xe9\xeb\x8d\xaf\xce\x5c\x9f\xed\x29\xdb" "\xbd\xaf\x7c\xc4\xe7\xc3\x5d\x77\x8a\x87\xf4\x7c\x38\xb2\x25\x1f\x8c\x03" "\x7e\x6f\xaa\x47\x11\xad\xea\x8e\xbf\x96\xee\xff\x37\x3b\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\xec\xb5\x23\x51\xc4\x67\x22\xc5\xcb" "\xff\xf6\x47\xd5\xb8\xe2\xa8\xc6\xa5\x1f\xbb\x30\xf4\xfb\x03\xbf\xdc\x3b" "\x66\xfc\xa9\x0f\xd9\x4f\x59\xf6\xb9\x88\x58\x2a\xee\x6d\x4c\xee\xe1\x3c" "\x30\x70\x34\x8d\xa6\xf4\x90\xc7\x12\x7f\x9c\xd5\xa3\x88\x3f\xce\xe3\xff" "\xbe\xfd\xb0\x1b\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\xf0\xb1\x56\xc4\x4f\x23\xc5\x0b\xef\x9c\x48\xcb\xd1\x3b\xa7\x78\x7b" "\xe6\x46\xe3\x4a\xeb\xea\x74\x67\x56\xd8\xee\xdc\xbf\xdd\x39\xd3\xd7\xd7" "\xd7\xd7\x1b\xa9\x93\xcd\x9c\x13\x39\x97\x72\x2e\xe7\x5c\xc9\xb9\x9a\x33" "\x8a\x5c\x3f\x67\x33\xe7\x44\xce\xa5\x9c\xcb\x39\x57\x72\xae\xe6\x8c\x43" "\xb9\x7e\xce\x66\xce\x89\x9c\x4b\x39\x97\x73\xae\xe4\x5c\xcd\x19\xb5\x5c" "\x3f\x67\x33\xe7\x44\xce\xa5\x9c\xcb\x39\x57\x72\xae\xe6\x8c\x03\x32\x77" "\x2f\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\xc0\xe3\xa4\x88\x22\xde\x8f" "\x14\xdf\xf9\xe6\x5a\x8a\x14\x11\xcd\x88\x89\xe8\xe4\x4a\xff\xc3\x6e\x1d" "\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\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\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\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\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\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\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\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\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\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\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\x00\x00\x00\x00\x00" "\x00\x50\xea\x4f\x45\xfc\x20\x52\x34\xfe\xa0\x79\x67\x5d\x2d\x22\x52\xf5" "\x6f\xc7\x89\xf2\x97\x73\xd1\x3c\x5c\xe6\x27\xa3\x39\x54\xe6\x8b\xd1\xbc" "\x98\xb3\x55\x65\xad\xf9\xed\x87\xd0\x7e\x76\xa7\x2f\x15\xf1\x93\x48\xd1" "\x5f\x7f\xeb\xce\x05\xcf\xd7\xbf\xaf\xf3\xe9\xce\xd7\x20\xde\xfc\xd6\xc6" "\xa7\xcf\xd6\x3a\x79\xa8\xbb\x71\xe0\xbd\xfe\x27\x8e\x1f\xbb\x30\x34\xf2" "\xf9\xa7\x76\x5a\x4e\xdb\x35\x60\xf0\x52\x7b\xe6\xd6\xed\xc6\xf8\xf0\xc8" "\xc8\x58\xcf\xea\x5a\x3e\xfa\x27\x7b\xd6\x0d\xe4\xe3\x16\x7b\xd3\x75\x22" "\x62\xe1\xf5\x37\x5e\x6b\x4d\x4f\x4f\xcd\xdf\xff\x42\xf9\x15\xb8\xcf\xea" "\xdd\x2b\xb9\x8b\xa3\x3f\xc8\x85\x54\x7b\x64\x9a\x6a\x61\x2f\x16\xa2\x76" "\x20\x9a\xf1\x70\xfa\xbe\x49\xfd\x61\xdc\x9c\xd8\x77\xe5\xf3\xff\xdd\x48" "\xf1\xdb\xef\xfc\x7b\xf7\x81\xdf\x79\xfe\xd7\xe3\x97\x3a\x9f\xee\x3c\xe1" "\xe3\x17\x7f\xb2\xf1\xfc\x7f\x61\xeb\x8e\xee\xf1\xf9\x5f\xdb\x5a\x2f\x3f" "\xff\xcb\x27\xc1\x76\xcf\xff\x27\x7b\xd6\xbd\x90\x7f\x37\xd2\x57\x8b\xa8" "\x2f\xde\x9c\xeb\x3b\x1e\x51\x5f\x78\xfd\x8d\x93\xed\x9b\xad\x1b\x53\x37" "\xa6\x66\xce\x9d\x3a\xf5\x95\xa1\xa1\xaf\x9c\x3d\xd5\x77\x38\xa2\x7e\xbd" "\x3d\x3d\xd5\xb3\xb4\x27\xa7\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\xe0\xc1\x49\x45\xfc\x6e\xa4\x68\xfd\x64\x2d\x35\x22\xe2\x76\x35" "\x5e\x6b\xe0\xc2\xd0\x33\x27\x9f\x3e\x14\x87\xaa\xf1\x56\x9b\xc6\x6d\xbf" "\x3a\x76\xe5\x62\xe3\xa5\xd9\x9b\x73\xf3\x53\x0b\x0b\x53\x93\x8d\xf1\x99" "\xf6\xb5\xd9\xc9\xa9\x7b\x3d\x5c\xbd\x1a\xee\x35\x3e\x3c\xb2\x2f\x9d\xf9" "\x50\x47\xf6\xb9\xfd\x47\xea\x2f\xcd\xce\xbd\x3e\xdf\xbe\xf1\x87\x8b\xdb" "\x6e\x3f\x5a\xbf\x78\x75\x61\x71\xbe\x75\x6d\xfb\xcd\x71\x24\x8a\x88\x66" "\xef\x9a\xc1\xaa\xc1\xe3\xc3\x23\x55\xa3\xa7\xdb\xad\x99\xaa\xea\xe8\xb6" "\x83\xe9\x3f\xba\xbe\x54\xc4\x7f\x44\x8a\x6b\xe7\x1a\xe9\x0b\x79\x5d\x1e" "\xff\xbf\x75\x84\xff\xa6\xf1\xff\x4b\x5b\x77\xb4\x87\xe3\xff\x3f\x7f\x74" "\x63\xfc\xdf\x27\x7a\x8a\x96\xc7\x4c\xa9\x88\x5f\x44\x8a\xdf\xfa\x8b\xa7" "\xe2\x0b\x55\x3b\x8f\xc6\x5d\xe7\x2c\x97\xfb\x9b\x48\x31\x78\xfe\x73\xb9" "\x5c\x1c\x2e\xcb\x75\xdb\xd0\x79\xaf\x40\x67\x64\x60\x59\xf6\x7f\x22\xc5" "\x3f\xbc\xbf\xb9\x6c\x77\x3c\xe4\x93\x1b\x65\x4f\x7f\xa4\x93\xfb\x08\x28" "\xaf\xff\xb1\x48\xf1\x83\x3f\xfb\x5e\xfc\x7a\x5e\xb7\xf9\xfd\x0f\xdb\x5f" "\xff\xa3\x5b\x77\xb4\x4f\xef\x7f\xf8\x54\xcf\xba\xa3\x9b\xde\x57\xb0\xeb" "\xae\x93\xaf\xff\xc9\x48\xf1\xe2\x93\x6f\xc5\x6f\x54\x6b\xfe\xef\x03\xdf" "\xff\xd1\x7d\x63\xc3\x89\x4e\xe1\x8d\xf7\x73\xec\xd3\xf5\xff\xd5\x9e\x75" "\x03\xf9\xb8\xbf\xb9\x57\x9d\x07\x00\x00\x00\x00\x00\x00\x00\x00\x78\x84" "\xf5\xa5\x22\xfe\x36\x52\xfc\x68\xa4\x96\x9e\xcf\xeb\xee\xe5\xef\xff\x4d" "\x6e\xdd\xd1\x3e\xfd\xfd\xaf\x4f\xf7\xac\x9b\xdc\x9b\xf9\x8a\x3e\x74\x61" "\xd7\x27\x15\x00\x00\x00\x00\x0e\x88\xbe\x54\xc4\x4f\x23\xc5\x8d\xc5\xb7" "\xee\x8c\xa1\xde\x3c\xfe\xbb\x67\xfc\xe7\xef\x6c\x8c\xff\x1c\x4e\x5b\xb6" "\x56\x7f\xce\xf7\x2b\xd5\x7b\x03\xf6\xf2\xcf\xff\x7a\x0d\xe4\xe3\x4e\xec" "\xbe\xdb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70" "\xa0\xa4\x54\xc4\xf3\x79\x3e\xf5\x89\x6a\x3c\xff\xe4\x8e\xf3\xa9\xaf\x44" "\x8a\x97\xff\xeb\xd9\x5c\x2e\x1d\x2f\xcb\x75\xe7\x81\x1f\xa8\x7e\xad\x5f" "\x9e\x9d\x39\x79\x71\x7a\x7a\xb6\x1e\x8b\xad\xab\xd3\x53\x8d\xb1\xb9\xd6" "\xb5\xa9\xb2\xee\xa7\x22\xc5\xda\x5f\x7f\x2e\xd7\x2d\xaa\xf9\xd5\xbb\xf3" "\xcd\x77\xe6\x78\xdf\x98\x8b\x7d\x3e\x52\x8c\xfc\x5d\xb7\x6c\x67\x2e\xf6" "\xee\xdc\xe4\x9d\xf9\xc0\xeb\xeb\xeb\x11\xa7\xcb\xb2\x9f\x88\x14\xff\xf9" "\xf7\x9b\xcb\xe6\xa9\xa9\xf3\xdc\xd1\xd5\x7e\xcf\x94\x65\xff\x2a\x52\x7c" "\xe3\x9f\xb6\x2f\x7b\x7c\xa3\xec\xd9\xb2\xec\xf7\x22\xc5\x8f\xbf\xd1\xe8" "\x96\x3d\x5a\x96\xed\xbe\x1f\xf5\xd3\x1b\x65\x9f\xbb\x36\x5b\xec\xc3\x55" "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0\xe3\xa6" "\x2f\x15\xf1\xa7\x91\xe2\xbf\x6f\x2e\xdf\x19\xcb\x9f\xe7\xff\xef\xeb\xf9" "\x58\x79\xf3\x5b\x3d\xf3\xfd\x6f\x71\xbb\x9a\xe7\x7f\xa0\x9a\xff\x7f\xa7" "\xe5\xfb\x99\xff\xbf\x7a\xaf\xc0\xd2\x4e\x47\x05\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\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\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\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\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\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\x80\xc7\x53\x8a\x22\xde\x88\x14" "\x73\x97\xd7\xd2\x4a\x7f\xf9\xb9\xa3\x7e\xa9\x3d\x73\xeb\xf6\xf8\xf0\xc8" "\xf6\xd5\x8e\xa4\xaa\xe6\xa1\xaa\x7c\xf9\x53\x3f\x7d\xe6\xec\xb9\x2f\x3f" "\x3f\x74\xbe\x9b\x1f\x5c\x7f\xaf\x7d\x26\x5e\x1d\xbb\x72\xb1\xf1\xd2\xec" "\xcd\xb9\xf9\xa9\x85\x85\xa9\xc9\xc6\xf8\x4c\xfb\xda\xec\xe4\xd4\x3d\xef" "\x61\xb7\xf5\xb7\x1a\xac\x4e\x40\xe3\xe6\x6b\xb7\x26\xaf\x5f\x5f\x68\x9c" "\x79\xee\xec\xa6\xcd\xb7\x07\xde\xeb\x7f\xe2\xf8\xc0\x85\xa1\x67\x4e\x3e" "\xdd\x2d\x3b\x3e\x3c\x32\x32\xd6\x53\xa6\xd6\x77\xdf\x47\xbf\x4b\xda\x61" "\xfd\xe1\x28\xe2\x2f\x23\xc5\xb3\xdf\xff\x59\xfa\x51\x7f\x44\x11\xbb\x3f" "\x17\x1f\xf2\xdd\xd9\x6f\x47\xaa\x4e\x0c\x56\x9d\x18\x1f\x1e\xa9\x3a\x32" "\xdd\x6e\xcd\x2c\x96\x1b\x47\xbb\x27\xa2\x88\x68\xf4\x54\x6a\x76\xcf\xd1" "\x03\xb8\x16\xbb\xd2\x8c\x58\x2a\x9b\x5f\x36\x78\xb0\xec\xde\xd8\x5c\x6b" "\xbe\x75\x75\x7a\xaa\x31\xda\x9a\x5f\x6c\x2f\xb6\x67\x67\x46\x53\xa7\xb5" "\x65\x7f\x1a\x51\xc4\xf9\x14\xb1\x1c\x11\xab\xfd\x77\xef\xae\x2f\x8a\x78" "\x2d\x52\x7c\xf7\xd8\x5a\xfa\xe7\xfe\x88\x43\xdd\xf3\xf0\xa5\xcb\x63\x5f" "\x3b\x75\x66\xe7\x76\x14\xfb\xd8\xc7\x7b\x50\xb6\xb3\xd1\x17\xb1\x5c\x3c" "\x02\xd7\xec\x00\xeb\x8f\x22\xfe\x31\x52\xfc\xfc\xed\x13\xf1\x2f\xfd\x11" "\xb5\xe8\xfc\xc4\x17\x23\x5e\x29\xf3\x87\x11\x6f\x46\xe7\x7a\xa7\xf2\x8b" "\x71\x2e\xe2\xdd\x6d\xbe\x47\x3c\x9a\x6a\x51\xc4\xff\x96\xd7\xff\xc2\x5a" "\x7a\xbb\xbf\xbc\x1f\x74\xef\x2b\x97\xbe\xde\xf8\xea\xcc\xf5\xd9\x9e\xb2" "\xdd\xfb\xca\x23\xff\x7c\x78\x90\x0e\xf8\xbd\xa9\x1e\x45\xfc\xb8\xba\xe3" "\xaf\xa5\x7f\xf5\xdf\x35\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\xc0\x01\x52\xc4\xaf\x45\x8a\x17\xde\x39\x91\xaa\xf1\xc1\x77\xc6\x14\xb7" "\x67\x6e\x34\xae\xb4\xae\x4e\x77\x86\xf5\x75\xc7\xfe\x75\xc7\x4c\xaf\xaf" "\xaf\xaf\x37\x52\x27\x9b\x39\x27\x72\x2e\xe5\x5c\xce\xb9\x92\x73\x35\x67" "\x14\xb9\x7e\xce\x66\x99\xf5\xf5\xf5\x89\xfc\x79\x29\xe7\x72\xce\x95\x9c" "\xab\x39\xe3\x50\xae\x9f\xb3\x99\x73\x22\xe7\x52\xce\xe5\x9c\x2b\x39\x57" "\x73\x46\x2d\xd7\xcf\xd9\xcc\x39\x91\x73\x29\xe7\x72\xce\x95\x9c\xab\x39" "\xe3\x80\x8c\xdd\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x1e\x2f\x45\xf5\x4f\x8a\xef\x7c\x73\x2d\xad\xf7\x77\xe6\x97\x9e\x88" "\x4e\xae\x98\x0f\xf4\xb1\xf7\xff\x01\x00\x00\xff\xff\xd9\x20\xf6\x0d", 3149)); NONFAILING( syz_mount_image(/*fs=*/0x200000000f00, /*dir=*/0x2000000000c0, /*flags=MS_I_VERSION|MS_RELATIME|MS_NODEV*/ 0xa00004, /*opts=*/0x200000000280, /*chdir=*/1, /*size=*/0xc4d, /*img=*/0x200000000f40)); NONFAILING(memcpy((void*)0x200000000180, "./bus\000", 6)); syscall(__NR_open, /*file=*/0x200000000180ul, /*flags=O_TRUNC|O_SYNC|O_NOATIME|O_LARGEFILE|O_CREAT|O_RDWR|0x3c*/ 0x14927eul, /*mode=*/0ul); NONFAILING(memcpy((void*)0x200000000380, "/dev/loop", 9)); NONFAILING(*(uint8_t*)0x200000000389 = 0x30); NONFAILING(*(uint8_t*)0x20000000038a = 0); NONFAILING(memcpy((void*)0x200000000140, "./bus\000", 6)); syscall(__NR_mount, /*src=*/0x200000000380ul, /*dst=*/0x200000000140ul, /*type=*/0ul, /*flags=MS_BIND*/ 0x1000ul, /*data=*/0ul); res = syscall(__NR_socket, /*domain=*/0x26ul, /*type=*/5ul, /*proto=*/0); if (res != -1) r[0] = res; NONFAILING(*(uint16_t*)0x2000000004c0 = 0x26); NONFAILING( memcpy((void*)0x2000000004c2, "skcipher\000\000\000\000\000\000", 14)); NONFAILING(*(uint32_t*)0x2000000004d0 = 0); NONFAILING(*(uint32_t*)0x2000000004d4 = 0); NONFAILING( memcpy((void*)0x2000000004d8, "cbc-camellia-" "aesni\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 64)); syscall(__NR_bind, /*fd=*/r[0], /*addr=*/0x2000000004c0ul, /*addrlen=*/0x58ul); NONFAILING(memcpy((void*)0x200000000280, "\xad\x56\xb6\xc5\x82\x0f\xae\x9d\x6d\xcd\x32\x92\xea\x54" "\xc7\xbe\xef\x91\x5d\x56\x4c\x90\xc2\x00", 24)); syscall(__NR_setsockopt, /*fd=*/r[0], /*level=*/0x117, /*opt=*/1, /*key=*/0x200000000280ul, /*keylen=*/0x18ul); res = syscall(__NR_accept4, /*fd=*/r[0], /*peer=*/0ul, /*peerlen=*/0ul, /*flags=SOCK_NONBLOCK*/ 0x800ul); if (res != -1) r[1] = res; NONFAILING(*(uint64_t*)0x200000000040 = 0); NONFAILING(*(uint32_t*)0x200000000048 = 0); NONFAILING(*(uint64_t*)0x200000000050 = 0x200000000000); NONFAILING(*(uint64_t*)0x200000000000 = 0x200000000080); NONFAILING(memcpy( (void*)0x200000000080, "\xf7\x8d\x9c\xa3\x8f\xff\x48\xf3\xbe\x52\x16\x34\x48\x41\x2b\xa8", 16)); NONFAILING(*(uint64_t*)0x200000000008 = 0xfffffe3f); NONFAILING(*(uint64_t*)0x200000000010 = 0x200000000140); NONFAILING( memcpy((void*)0x200000000140, "\xeb\xe3\xa0\xe9\x79\x6c\xfd\x16\x47\xe2\x99\xf4\xe3\x76\xfd\xba" "\x12\x82\x80\xb3\x72\x21\x9d\x20\x5e\x81\xf4\xa7\xf7\x1c\x19\x26" "\xaa\xe1\xef\xd7\xe0\x05\x4a\x86\x3f\x3d\x5c\xfe\x6c\xb5\x5b\x5b" "\xb9\xfa\x69\x35\x84\x9e\x60\x98\xed\x88\x4e\x7c\xb5\x17\x26\xb3" "\x60\xfb\xb3\x7b\x4f\xe0\x35\xbb\xb0\x95\x87\x30\x48", 77)); NONFAILING(*(uint64_t*)0x200000000018 = 0); NONFAILING(*(uint64_t*)0x200000000020 = 0x2000000003c0); NONFAILING(memcpy( (void*)0x2000000003c0, "\xe8\x70\x0e\x44\x4d\x50\xa9\x69\xff\x67\x34\x7c\xff\x61\x27\xe6\xef\x12" "\xee\x38\x19\x27\x14\x82\xa4\x97\x5a\x52\xc1\xab\x9b\x8b\x4d\xb3\x94\x5d" "\x10\x32\x00\x5e\xab\xe9\x7b\x4d\xc3\x3a\x47\xd3\xa1\x58\xda\x98\x84\x56" "\xd3\x00\x26\xb4\x33\x18\x6f\x53\xcd\xcd\xb9\x3a\x47\x22\xbf\x30\x6a\x10" "\x47\x0d\x50\xf5\xcb\x1e\xce\x9e\xad\x34\x59\xba\xb1\xcf\x15\x38\xcd\x0b" "\x15\x76\x53\xc5\xe8\x92\x96\x2c\x80\xf1\x58\xc4\x43\xe9\xc6\xad\x7d\x2a" "\x81\x03\xef\x2f\x4b\x93\x76\x6b\x9a\x21\x50\x1f\x94\xc1\x56\x8b\x13\x75" "\x6b\x66\xf7\x4f\x46\xcf\x80\x17\x04\xd2\xda\x8b\x96\xc3\x40\x70\xb2\x33" "\xaf\x0a\xfc\xc4\x36\x71\x2e\x58\xed\x25\xe7\x21\x19\x3a\xf0\x5a\x04\x5a" "\xd3\xfd\xc9\x28\xf0\x2f\x3d\xba\xd1\x9d\x3e\x66\xee\xbd\xa2\xe6\x3f\x3f" "\x46\xef\x45\x11\xce\xe2\x6d\x7b\x48\x24\x18\x47\xbf\x9e\x34\x3e\xf4\x67" "\x4c\x45\xe2\xa0\x85\x06\x0f\x11", 206)); NONFAILING(*(uint64_t*)0x200000000028 = 0); NONFAILING(*(uint64_t*)0x200000000058 = 1); NONFAILING(*(uint64_t*)0x200000000060 = 0x200000000380); NONFAILING(*(uint64_t*)0x200000000380 = 0x18); NONFAILING(*(uint32_t*)0x200000000388 = 0x117); NONFAILING(*(uint32_t*)0x20000000038c = 3); NONFAILING(*(uint32_t*)0x200000000390 = 1); NONFAILING(*(uint64_t*)0x200000000068 = 0x18); NONFAILING(*(uint32_t*)0x200000000070 = 0); syscall(__NR_sendmmsg, /*fd=*/r[1], /*mmsg=*/0x200000000040ul, /*vlen=*/1ul, /*f=MSG_BATCH|MSG_CONFIRM*/ 0x40800ul); NONFAILING(*(uint64_t*)0x2000000005c0 = 0); NONFAILING(*(uint32_t*)0x2000000005c8 = 0); NONFAILING(*(uint64_t*)0x2000000005d0 = 0x2000000001c0); NONFAILING(*(uint64_t*)0x2000000001c0 = 0x2000000000c0); NONFAILING(*(uint64_t*)0x2000000001c8 = 0x7ffff000); NONFAILING(*(uint64_t*)0x2000000001d0 = 0x200000000200); NONFAILING(*(uint64_t*)0x2000000001d8 = 0x20000253); NONFAILING(*(uint64_t*)0x2000000005d8 = 2); NONFAILING(*(uint64_t*)0x2000000005e0 = 0); NONFAILING(*(uint64_t*)0x2000000005e8 = 0); NONFAILING(*(uint32_t*)0x2000000005f0 = 0); syscall(__NR_recvmsg, /*fd=*/r[1], /*msg=*/0x2000000005c0ul, /*f=*/0ul, 0); NONFAILING(memcpy((void*)0x200000000180, "./bus\000", 6)); res = syscall( __NR_open, /*file=*/0x200000000180ul, /*flags=O_SYNC|O_NOCTTY|O_NOATIME|O_RDWR|0x3c*/ 0x14113eul, /*mode=S_IXOTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IWUSR|S_IRUSR|0x6ceac77f206eaa00*/ 0x6ceac77f206eabb9ul); if (res != -1) r[2] = res; NONFAILING(memcpy((void*)0x200000000080, "#! ", 3)); NONFAILING(*(uint8_t*)0x200000000083 = 0xa); syscall(__NR_write, /*fd=*/r[2], /*data=*/0x200000000080ul, /*len=*/0x208e24bul); } 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); setup_cgroups(); const char* reason; (void)reason; install_segv_handler(); use_temporary_dir(); do_sandbox_none(); return 0; }