// https://syzkaller.appspot.com/bug?id=f9364472bcbd3cb1738f774dd3711668cb402216 // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #include #include #include #include #include const int kFailStatus = 67; const int kRetryStatus = 69; static void fail(const char* msg, ...) { int e = errno; va_list args; va_start(args, msg); vfprintf(stderr, msg, args); va_end(args); fprintf(stderr, " (errno %d)\n", e); doexit((e == ENOMEM || e == EAGAIN) ? kRetryStatus : kFailStatus); } static uintptr_t syz_open_dev(uintptr_t a0, uintptr_t a1, uintptr_t a2) { if (a0 == 0xc || a0 == 0xb) { char buf[128]; sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2); return open(buf, O_RDWR, 0); } else { char buf[1024]; char* hash; strncpy(buf, (char*)a0, sizeof(buf)); buf[sizeof(buf) - 1] = 0; while ((hash = strchr(buf, '#'))) { *hash = '0' + (char)(a1 % 10); a1 /= 10; } return open(buf, a2, 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 = 128 << 20; setrlimit(RLIMIT_AS, &rlim); rlim.rlim_cur = rlim.rlim_max = 8 << 20; setrlimit(RLIMIT_MEMLOCK, &rlim); rlim.rlim_cur = rlim.rlim_max = 32 << 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); if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(0x02000000)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } } static int do_sandbox_none(void) { if (unshare(CLONE_NEWPID)) { } int pid = fork(); if (pid < 0) fail("sandbox fork failed"); if (pid) return pid; sandbox_common(); if (unshare(CLONE_NEWNET)) { } loop(); doexit(1); } uint64_t r[2] = {0xffffffffffffffff, 0x0}; void loop() { long res = 0; *(uint32_t*)0x200029c0 = 0x80; syscall(__NR_getpeername, -1, 0x20002940, 0x200029c0); memcpy((void*)0x20000540, "/dev/dsp#", 10); res = syz_open_dev(0x20000540, 1, 2); if (res != -1) r[0] = res; *(uint64_t*)0x20000640 = 3; syscall(__NR_ioctl, r[0], 0x800000c004500a, 0x20000640); *(uint8_t*)0x20000380 = 0; syscall(__NR_setsockopt, -1, 0x84, 0x15, 0x20000380, 1); *(uint64_t*)0x20000a40 = 0x20000980; *(uint32_t*)0x20000980 = -1; *(uint32_t*)0x20000984 = -1; *(uint64_t*)0x20000988 = -1; *(uint32_t*)0x20000a48 = -1; *(uint64_t*)0x20000a4c = 0x20000c80; *(uint16_t*)0x20000c80 = -1; *(uint64_t*)0x20000c82 = 0; *(uint16_t*)0x20000c8a = -1; *(uint64_t*)0x20000a54 = 0; *(uint64_t*)0x20000a5c = 0; *(uint64_t*)0x20000a64 = -1; *(uint32_t*)0x20000a6c = -1; syscall(__NR_write, r[0], 0x20000a40, 0x30); syscall(__NR_semctl, 0, 0, 2, 0x20000280); *(uint16_t*)0x20000600 = 0x2c83; *(uint16_t*)0x20000602 = 0; *(uint16_t*)0x20000604 = 9; *(uint32_t*)0x20000608 = 6; *(uint32_t*)0x2000060c = 4; *(uint32_t*)0x20000610 = 0x3da; *(uint32_t*)0x20000614 = 0xfffffffc; *(uint32_t*)0x20000618 = 0xfffffffc; *(uint32_t*)0x2000061c = 0; *(uint32_t*)0x200007c0 = 0x20; res = syscall(__NR_getsockopt, -1, 0x84, 0xa, 0x20000600, 0x200007c0); if (res != -1) r[1] = *(uint32_t*)0x2000061c; *(uint16_t*)0x20000800 = 0x7fff; *(uint16_t*)0x20000802 = 0xa; *(uint32_t*)0x20000804 = 0xf33; *(uint32_t*)0x20000808 = 0xe51c; *(uint32_t*)0x2000080c = r[1]; syscall(__NR_setsockopt, -1, 0x84, 0x22, 0x20000800, 0x10); memcpy((void*)0x20000000, "user.syz", 9); syscall(__NR_fremovexattr, -1, 0x20000000); *(uint64_t*)0x20000340 = 9; *(uint64_t*)0x20000348 = 0; syscall(__NR_ioctl, -1, 0xc010640c, 0x20000340); *(uint16_t*)0x20000740 = 0x26; memcpy((void*)0x20000742, "\x72\x6e\x67\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 14); *(uint32_t*)0x20000750 = 0; *(uint32_t*)0x20000754 = 0; memcpy((void*)0x20000758, "\x64\x72\x62\x67\x5f\x70\x72\x5f\x68\x6d\x61\x63\x5f\x73\x68\x61\x35" "\x31\x32\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 64); syscall(__NR_connect, -1, 0x20000740, 0x80); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); int pid = do_sandbox_none(); int status = 0; while (waitpid(pid, &status, __WALL) != pid) { } return 0; }