// https://syzkaller.appspot.com/bug?id=44f63704b28fe02f0ea1185bce77908b623b8f20 // 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 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 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 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)) { } if (symlink("/dev/binderfs", "./binderfs")) { } } 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); } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void loop(void) { intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } NONFAILING(memcpy((void*)0x200000000500, "/dev/ashmem\000", 12)); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000500ul, /*flags=*/0, /*mode=*/0); if (res != -1) r[0] = res; syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x40087703, /*arg=*/8ul); syscall(__NR_mmap, /*addr=*/0x200000701000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_PRIVATE*/ 0x12ul, /*fd=*/r[0], /*offset=*/0ul); NONFAILING(memcpy((void*)0x2000000002c0, "/selinux/policy\000", 16)); res = syscall(__NR_openat, /*fd=*/0xffffff9cul, /*file=*/0x2000000002c0ul, /*flags=*/0, /*mode=*/0); if (res != -1) r[1] = res; syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0xb36000ul, /*prot=PROT_GROWSDOWN|PROT_SEM|PROT_WRITE*/ 0x100000aul, /*flags=MAP_FIXED|MAP_PRIVATE*/ 0x12ul, /*fd=*/r[1], /*offset=*/0ul); NONFAILING(memcpy( (void*)0x200000002600, "\000\000\003\006\000\000\000\005\000x\222\022\254\006^" "\276wV\363\"\304\004\273\00642\234\032\321\313{" "\260\326\036\000gQ\312\016U\367\'\214\301\306\273\305\034\367\257\225" "\203=" "\t7\226\032\255\320\320\356\234\2262\bu\272\374\256\302\031\353\221\311" "\t\274\301\313\272\343\216\366\211\302\'\337n(Q=v-<\r\321?$" "\213\027Bn\027h\033\254\374\202\034\364\320\365\325\200`4/" "\351\025\232\237\360:\375$\255\273\232|" "c\374\"\356\304\223Q\202\026\277\343c\215 \017\261\351\362o " "\000\000\000\000\000\000\000H\257\t\030\310\033\036\276\330>\354\237~" "\247\367\257dd\361\333jE\001\321sD\211\224&\\U\f\030\231]" "\253a\3513\001\2423\311hP1\334-\'\320\236}\211\377\214\354^\204\031\237_" "D\275t/" "\'\366\303\214\270\vS\200\255\370\277\242\240\231\302\026=" "\314\260\0337\343-" "\'\002\026\365\346\223\002E\n\350\000\000\214\355\021\367\362J\366\220A@" "\001\023\307`g\313\327\333\036\262\311\375\367\251\226\370/" "0Xd\317\271\242\035\023\217C\322&" "\330\235\213\340E\322\306\032\363\250\016\272\354Ov$" "\310\"\a\327T\373\374\372uT\370\236\206\357.\366<\277B\347\200\032\a\t+" "x_B=\347\245\211\373\242\306\227\353\336cY{" "\016\302\000\000\000\000\000\000\000\a\364\210\006\343\313\310\340\314\v" "E\030\"\207\240\251:\316Y\360\242\340\235\214\216\021\267\230\245\332$" "\224D\264\362>\001\000+\372\251 " "\341\023Y\206\330\277H\306\234\214s4\r\315\321\203JT\371\242\203?" "\263\017\306&\035\243\304\303\322\375\255\2435o\350\315^/" "\330\026\\n\237J\364\n\222c\252\335T&L<+\031R\a\374\362\027\270$\251]" "\302\\\332<\310d.w\234\2574\273\350Co\263\330\202\222\272+" "\231PXB\334\272y\240s<\222k\vJTRW\3026\006\020\222\307\2455\237Z\377*" "ir\036\350\a\000\000\000\000\000\000\000\210\031\367\335\250\357\240\230" "\315\201\020>\307{\204\271\300B\341\t\000\272Qj\201\310\370\0246%" "Z\203H\253F\030<\206h\001=\003i\304\t\216/" "\022\a\337\347zU\035\025\016\301?\352u\264\204\004;\305[\nja\271\'\311#" "\374x\000\000X\364\351\037\315\005\017z_\215,^" "\336\375\321\276d\355\241\365\306(p\264;\016\030\367/" "A\375\222\320}ur\252g\333&e$\f\rrT\330\210~" "\023\3022t\366\364Fs\301\005\372\231\025\207\024\023$\t\250?" "\356\224W\216\341\314\303U\204\306]:\232|" "W\354\204\030\bb\202\217\300\253\343a\231\027\205\232\005\261\022K\\\362" "\325\b^[D~~\204\\\344\000B\005\324\352\352\177=\306:" "\\N\303\267Vw\306\234\226s\252HL\226\3072\n\030Ynj\316TS\373l\017\2378M" "\f\211\241\322Hs`\213p\212\304%\370\0353\nV\232\257\037\3716^" "\223\301\257)\rg\206\326\352\251\017\232\361V\033\277\213\'-" "\253\216\t7\323\367\251v\373Y\346\233^d\214\261\335", 822)); syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x40087708, /*arg=*/0x200000002600ul); } 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; install_segv_handler(); do_sandbox_none(); return 0; }