// https://syzkaller.appspot.com/bug?id=80ffd087a886df22d21a44af2c6809a5d3ff2d9b // 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 #ifndef __NR_getsockname #define __NR_getsockname 204 #endif #ifndef __NR_mmap #define __NR_mmap 222 #endif #ifndef __NR_sendmsg #define __NR_sendmsg 211 #endif #ifndef __NR_socket #define __NR_socket 198 #endif 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_common() { 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); setsid(); 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); setup_common(); sandbox_common(); drop_caps(); if (unshare(CLONE_NEWNET)) { } write_file("/proc/sys/net/ipv4/ping_group_range", "0 65535"); setup_binderfs(); loop(); exit(1); } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0x0}; void loop(void) { intptr_t res = 0; res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0); if (res != -1) r[0] = res; res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/0x803ul, /*proto=*/0); if (res != -1) r[1] = res; *(uint64_t*)0x200004c0 = 0; *(uint32_t*)0x200004c8 = 0; *(uint64_t*)0x200004d0 = 0x20000480; *(uint64_t*)0x20000480 = 0; *(uint64_t*)0x20000488 = 0x92; *(uint64_t*)0x200004d8 = 1; *(uint64_t*)0x200004e0 = 0; *(uint64_t*)0x200004e8 = 0; *(uint32_t*)0x200004f0 = 0; syscall(__NR_sendmsg, /*fd=*/r[1], /*msg=*/0x200004c0ul, /*f=*/0ul); *(uint32_t*)0x20000000 = 0xa; res = syscall(__NR_getsockname, /*fd=*/r[1], /*addr=*/0x20000100ul, /*addrlen=*/0x20000000ul); if (res != -1) r[2] = *(uint32_t*)0x20000104; *(uint64_t*)0x200007c0 = 0; *(uint32_t*)0x200007c8 = 0; *(uint64_t*)0x200007d0 = 0x20000180; *(uint64_t*)0x20000180 = 0x20000580; *(uint32_t*)0x20000580 = 0xdc; *(uint16_t*)0x20000584 = 0x24; *(uint16_t*)0x20000586 = 0xe0b; *(uint32_t*)0x20000588 = 0; *(uint32_t*)0x2000058c = 0; *(uint8_t*)0x20000590 = 0; *(uint8_t*)0x20000591 = 0; *(uint16_t*)0x20000592 = 0; *(uint32_t*)0x20000594 = r[2]; *(uint16_t*)0x20000598 = 0; *(uint16_t*)0x2000059a = 0; *(uint16_t*)0x2000059c = -1; *(uint16_t*)0x2000059e = -1; *(uint16_t*)0x200005a0 = 0; *(uint16_t*)0x200005a2 = 0; *(uint16_t*)0x200005a4 = 0xa; *(uint16_t*)0x200005a6 = 1; memcpy((void*)0x200005a8, "netem\000", 6); *(uint16_t*)0x200005b0 = 0xac; *(uint16_t*)0x200005b2 = 2; *(uint32_t*)0x200005b4 = 0; *(uint32_t*)0x200005b8 = 8; *(uint32_t*)0x200005bc = 0; *(uint32_t*)0x200005c0 = 0; *(uint32_t*)0x200005c4 = 0; *(uint32_t*)0x200005c8 = 0; *(uint16_t*)0x200005cc = 0xc; *(uint16_t*)0x200005ce = 0xa; *(uint64_t*)0x200005d0 = 0xffffffff; *(uint16_t*)0x200005d8 = 0xc; *(uint16_t*)0x200005da = 8; *(uint64_t*)0x200005dc = 0x654534bf5327d02e; *(uint16_t*)0x200005e4 = 0x14; *(uint16_t*)0x200005e6 = 6; *(uint32_t*)0x200005e8 = 0xe49a; *(uint32_t*)0x200005ec = 0; *(uint32_t*)0x200005f0 = 2; *(uint32_t*)0x200005f4 = 0; *(uint16_t*)0x200005f8 = 0x41; *(uint16_t*)0x200005fa = 2; memcpy((void*)0x200005fc, "\x83\xa3\x45\x0b\xf7\x4b\xc0\x40\x64\x2d\xfa\x5e\x6f\x37\xee\x6c\x96" "\xef\xd7\xb1\xfc\x04\x08\xf3\x1d\xee\xe1\x92\xac\xc7\xc3\x8f\xc8\xd4" "\xbd\x50\x3e\xa1\x8e\xc4\xb8\xd3\xd7\x49\xff\x73\x4b\x0d\x10\xb3\xa5" "\x6f\x0b\xee\x67\x9c\xdf\xe4\x34\x3e\x34", 61); *(uint16_t*)0x2000063c = 0xc; *(uint16_t*)0x2000063e = 0xb; *(uint64_t*)0x20000640 = 3; *(uint16_t*)0x20000648 = 0x14; *(uint16_t*)0x2000064a = 6; *(uint32_t*)0x2000064c = 0xff; *(uint32_t*)0x20000650 = 5; *(uint32_t*)0x20000654 = 5; *(uint32_t*)0x20000658 = 3; *(uint64_t*)0x20000188 = 0xdc; *(uint64_t*)0x200007d8 = 1; *(uint64_t*)0x200007e0 = 0; *(uint64_t*)0x200007e8 = 0; *(uint32_t*)0x200007f0 = 0; syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x200007c0ul, /*f=*/0ul); } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=*/7ul, /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=*/0x32ul, /*fd=*/-1, /*offset=*/0ul); do_sandbox_none(); return 0; }