// https://syzkaller.appspot.com/bug?id=601bbf0903e004c31e34feaba541b625a7bd3cf6 // 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 #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)))) 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 loop(); static void sandbox_common() { prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0); setpgrp(); 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 = 0; 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)) { } loop(); exit(1); } uint64_t r[4] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0}; void loop(void) { intptr_t res = 0; *(uint64_t*)0x20000180 = 0; *(uint32_t*)0x20000188 = 0; *(uint64_t*)0x20000190 = 0x200000c0; *(uint64_t*)0x200000c0 = 0; *(uint64_t*)0x200000c8 = 0x34; *(uint64_t*)0x20000198 = 1; *(uint64_t*)0x200001a0 = 0; *(uint64_t*)0x200001a8 = 0; *(uint32_t*)0x200001b0 = 0; syscall(__NR_sendmsg, -1, 0x20000180ul, 0ul); res = syscall(__NR_socket, 0x4000000000010ul, 0x1000000000080002ul, 0); if (res != -1) r[0] = res; res = syscall(__NR_socket, 0x10ul, 3ul, 0); if (res != -1) r[1] = res; res = syscall(__NR_socket, 0x10ul, 0x803ul, 0); if (res != -1) r[2] = res; *(uint64_t*)0x200001c0 = 0; *(uint32_t*)0x200001c8 = 0; *(uint64_t*)0x200001d0 = 0x20000180; *(uint64_t*)0x20000180 = 0; *(uint64_t*)0x20000188 = 0; *(uint64_t*)0x200001d8 = 1; *(uint64_t*)0x200001e0 = 0; *(uint64_t*)0x200001e8 = 0; *(uint32_t*)0x200001f0 = 0; syscall(__NR_sendmsg, r[2], 0x200001c0ul, 0ul); *(uint32_t*)0x20000200 = 0x14; res = syscall(__NR_getsockname, r[2], 0x20000100ul, 0x20000200ul); if (res != -1) r[3] = *(uint32_t*)0x20000104; syscall(__NR_sendmsg, r[1], 0ul, 0ul); *(uint64_t*)0x200007c0 = 0; *(uint32_t*)0x200007c8 = 0; *(uint64_t*)0x200007d0 = 0x200000c0; *(uint64_t*)0x200000c0 = 0x20000240; *(uint32_t*)0x20000240 = 0x170; *(uint16_t*)0x20000244 = 0x24; *(uint16_t*)0x20000246 = 0xd0b; *(uint32_t*)0x20000248 = 0; *(uint32_t*)0x2000024c = 0; *(uint8_t*)0x20000250 = 0; *(uint8_t*)0x20000251 = 0; *(uint16_t*)0x20000252 = 0; *(uint32_t*)0x20000254 = r[3]; *(uint16_t*)0x20000258 = 0; *(uint16_t*)0x2000025a = 0; *(uint16_t*)0x2000025c = -1; *(uint16_t*)0x2000025e = -1; *(uint16_t*)0x20000260 = 0; *(uint16_t*)0x20000262 = 0; *(uint16_t*)0x20000264 = 0xa; *(uint16_t*)0x20000266 = 1; memcpy((void*)0x20000268, "choke\000", 6); *(uint16_t*)0x20000270 = 0x11c; *(uint16_t*)0x20000272 = 2; *(uint16_t*)0x20000274 = 0x104; *(uint16_t*)0x20000276 = 2; memcpy((void*)0x20000278, "\x55\x15\x8e\x77\x70\x58\x1e\x2f\xee\xcf\xdb\x21\x01\x51\x67\x14\xa1" "\x53\x7d\xba\x35\x1e\xec\x9b\x0e\x70\x4e\x32\x82\xf0\xc9\x39\x95\x4f" "\x30\x1a\x92\x27\xee\xbf\xb7\x76\x02\x3c\xe7\x54\x14\x85\x3e\xbe\x9e" "\xbc\x00\xeb\x74\x4c\xf4\xa5\x6f\x74\x01\x0d\xa4\xe8\xd5\x04\x37\x38" "\xe0\x9d\x08\x81\x7e\x2d\x3b\xde\xb0\x5f\xcf\x78\x07\x34\x9d\xa9\x2d" "\x8c\xac\x9a\xe1\xa4\x1c\x83\x15\x8c\x24\xa9\x89\xfc\xf1\x8c\x1e\x55" "\x89\x59\x14\xb7\xef\x59\x5c\x64\x2c\x13\x0d\xf1\x8e\xa3\x29\x35\x7b" "\x38\x49\x79\xe7\x52\xc2\x81\x49\x4f\x20\x1c\x2e\x66\x21\x63\x29\x75" "\xda\xb8\xed\x80\x5f\x3e\x96\xd8\xd9\x3e\x6a\x3f\xf5\x7b\x17\x97\xcd" "\xac\x3a\x50\x21\x6d\x8c\x8d\x9a\xb9\x04\xbf\x82\xd5\x34\x37\xac\x9b" "\xf2\x0d\xcf\x91\x21\xee\x30\x74\xe1\x82\xe6\xeb\x3a\x11\xa9\x2c\x14" "\xce\x00\x5a\xea\xc2\xc1\x3b\x83\xbb\xd0\x6b\x83\xbe\x3d\xb1\x65\x16" "\xd2\x9b\xff\xc9\xba\x25\x09\x0d\xa7\x00\x18\xf0\xaf\x9f\xc8\xd1\x57" "\xe7\xbf\x23\x6a\x14\x89\x53\xed\x71\x8c\xc8\xd6\x9d\xa7\x4a\xa7\x84" "\x27\x45\xdb\x8b\x97\x9f\x36\x33\xb9\x81\x86\xa3\xa7\x00\x00\x00\x00" "\x00", 256); *(uint16_t*)0x20000378 = 0x14; *(uint16_t*)0x2000037a = 1; *(uint32_t*)0x2000037c = 2; *(uint32_t*)0x20000380 = 0; *(uint32_t*)0x20000384 = 0; *(uint8_t*)0x20000388 = 0; *(uint8_t*)0x20000389 = 0; *(uint8_t*)0x2000038a = 0xfd; *(uint8_t*)0x2000038b = 0; *(uint16_t*)0x2000038c = 0x24; STORE_BY_BITMASK(uint16_t, , 0x2000038e, 8, 0, 14); STORE_BY_BITMASK(uint16_t, , 0x2000038f, 0, 6, 1); STORE_BY_BITMASK(uint16_t, , 0x2000038f, 1, 7, 1); *(uint16_t*)0x20000390 = 0x1c; *(uint16_t*)0x20000392 = 1; *(uint8_t*)0x20000394 = 0; *(uint8_t*)0x20000395 = 0; *(uint16_t*)0x20000396 = 0; *(uint32_t*)0x20000398 = 0; *(uint32_t*)0x2000039c = 0; *(uint32_t*)0x200003a0 = 0; *(uint32_t*)0x200003a4 = 0; *(uint32_t*)0x200003a8 = 0; *(uint16_t*)0x200003ac = 4; *(uint16_t*)0x200003ae = 2; *(uint64_t*)0x200000c8 = 0x170; *(uint64_t*)0x200007d8 = 1; *(uint64_t*)0x200007e0 = 0; *(uint64_t*)0x200007e8 = 0; *(uint32_t*)0x200007f0 = 0; syscall(__NR_sendmsg, -1, 0x200007c0ul, 0ul); syscall(__NR_sendmmsg, r[0], 0x20000140ul, 3ul, 0ul); } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); do_sandbox_none(); return 0; }