// https://syzkaller.appspot.com/bug?id=37eefadff13665da133828ad3344b1d2b20d7837 // 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 __attribute__((noreturn)) static void doexit(int status) { volatile unsigned i; syscall(__NR_exit_group, status); for (i = 0;; i++) { } } #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 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 = 1 << 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); #define CLONE_NEWCGROUP 0x02000000 unshare(CLONE_NEWNS); unshare(CLONE_NEWIPC); unshare(CLONE_NEWCGROUP); unshare(CLONE_NEWNET); unshare(CLONE_NEWUTS); unshare(CLONE_SYSVSEM); } static int do_sandbox_none(int executor_pid, bool enable_tun) { unshare(CLONE_NEWPID); int pid = fork(); if (pid < 0) fail("sandbox fork failed"); if (pid) return pid; sandbox_common(); loop(); doexit(1); } static void test(); void loop() { while (1) { test(); } } struct thread_t { int created, running, call; pthread_t th; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { while (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &th->running, FUTEX_WAIT, 0, 0); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 0, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); } return 0; } static void execute(int num_calls) { int call, thread; running = 0; for (call = 0; call < num_calls; call++) { for (thread = 0; thread < sizeof(threads) / sizeof(threads[0]); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); pthread_create(&th->th, &attr, thr, th); } if (!__atomic_load_n(&th->running, __ATOMIC_ACQUIRE)) { th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); __atomic_store_n(&th->running, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &th->running, FUTEX_WAKE); struct timespec ts; ts.tv_sec = 0; ts.tv_nsec = 20 * 1000 * 1000; syscall(SYS_futex, &th->running, FUTEX_WAIT, 1, &ts); if (running) usleep((call == num_calls - 1) ? 10000 : 1000); break; } } } } long r[5]; uint64_t procid; void execute_call(int call) { switch (call) { case 0: syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0); break; case 1: r[0] = syscall(__NR_socket, 2, 0x80a, 0); break; case 2: memcpy((void*)0x208a3fe0, "\x6c\x6f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); *(uint16_t*)0x208a3ff0 = 0xfffd; syscall(__NR_ioctl, r[0], 0x8914, 0x208a3fe0); break; case 3: r[1] = syscall(__NR_socket, 0x10, 3, 0); break; case 4: memcpy((void*)0x208a3fe0, "\x6c\x6f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); *(uint16_t*)0x208a3ff0 = 2; *(uint16_t*)0x208a3ff2 = 0; *(uint32_t*)0x208a3ff4 = htobe32(0); *(uint8_t*)0x208a3ff8 = 0; *(uint8_t*)0x208a3ff9 = 0; *(uint8_t*)0x208a3ffa = 0; *(uint8_t*)0x208a3ffb = 0; *(uint8_t*)0x208a3ffc = 0; *(uint8_t*)0x208a3ffd = 0; *(uint8_t*)0x208a3ffe = 0; *(uint8_t*)0x208a3fff = 0; syscall(__NR_ioctl, r[1], 0x8914, 0x208a3fe0); break; case 5: r[2] = syscall(__NR_socket, 0xa, 0x1000000000003, 4); break; case 6: memcpy((void*)0x202bf000, "\x73\x69\x74\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); *(uint32_t*)0x202bf010 = 0; *(uint8_t*)0x202bf014 = 0; *(uint8_t*)0x202bf015 = 0; *(uint8_t*)0x202bf016 = 0; *(uint8_t*)0x202bf017 = 0; *(uint8_t*)0x202bf018 = 0; *(uint8_t*)0x202bf019 = 0; *(uint8_t*)0x202bf01a = 0; *(uint8_t*)0x202bf01b = 0; *(uint8_t*)0x202bf01c = 0; *(uint8_t*)0x202bf01d = 0; *(uint8_t*)0x202bf01e = 0; *(uint8_t*)0x202bf01f = 0; *(uint8_t*)0x202bf020 = 0; *(uint8_t*)0x202bf021 = 0; *(uint8_t*)0x202bf022 = 0; *(uint8_t*)0x202bf023 = 0; *(uint8_t*)0x202bf024 = 0; *(uint8_t*)0x202bf025 = 0; *(uint8_t*)0x202bf026 = 0; *(uint8_t*)0x202bf027 = 0; if (syscall(__NR_ioctl, r[2], 0x8933, 0x202bf000) != -1) r[3] = *(uint32_t*)0x202bf010; break; case 7: *(uint8_t*)0x20d03fb0 = 0; *(uint8_t*)0x20d03fb1 = 0; *(uint8_t*)0x20d03fb2 = 0; *(uint8_t*)0x20d03fb3 = 0; *(uint8_t*)0x20d03fb4 = 0; *(uint8_t*)0x20d03fb5 = 0; *(uint8_t*)0x20d03fb6 = 0; *(uint8_t*)0x20d03fb7 = 0; *(uint8_t*)0x20d03fb8 = 0; *(uint8_t*)0x20d03fb9 = 0; *(uint8_t*)0x20d03fba = 0; *(uint8_t*)0x20d03fbb = 0; *(uint8_t*)0x20d03fbc = 0; *(uint8_t*)0x20d03fbd = 0; *(uint8_t*)0x20d03fbe = 0; *(uint8_t*)0x20d03fbf = 0; *(uint8_t*)0x20d03fc0 = 0; *(uint8_t*)0x20d03fc1 = 0; *(uint8_t*)0x20d03fc2 = 0; *(uint8_t*)0x20d03fc3 = 0; *(uint8_t*)0x20d03fc4 = 0; *(uint8_t*)0x20d03fc5 = 0; *(uint8_t*)0x20d03fc6 = 0; *(uint8_t*)0x20d03fc7 = 0; *(uint8_t*)0x20d03fc8 = 0; *(uint8_t*)0x20d03fc9 = 0; *(uint8_t*)0x20d03fca = 0; *(uint8_t*)0x20d03fcb = 0; *(uint8_t*)0x20d03fcc = 0; *(uint8_t*)0x20d03fcd = 0; *(uint8_t*)0x20d03fce = 0; *(uint8_t*)0x20d03fcf = 0; *(uint8_t*)0x20d03fd0 = 0xfe; *(uint8_t*)0x20d03fd1 = 0x80; *(uint8_t*)0x20d03fd2 = 0; *(uint8_t*)0x20d03fd3 = 0; *(uint8_t*)0x20d03fd4 = 0; *(uint8_t*)0x20d03fd5 = 0; *(uint8_t*)0x20d03fd6 = 0; *(uint8_t*)0x20d03fd7 = 0; *(uint8_t*)0x20d03fd8 = 0; *(uint8_t*)0x20d03fd9 = 0; *(uint8_t*)0x20d03fda = 0; *(uint8_t*)0x20d03fdb = 0; *(uint8_t*)0x20d03fdc = 0; *(uint8_t*)0x20d03fdd = 0; *(uint8_t*)0x20d03fde = 0; *(uint8_t*)0x20d03fdf = 0xaa; *(uint32_t*)0x20d03fe0 = 0; *(uint16_t*)0x20d03fe4 = 0; *(uint16_t*)0x20d03fe6 = 0; *(uint32_t*)0x20d03fe8 = 0; *(uint64_t*)0x20d03ff0 = 4; *(uint32_t*)0x20d03ff8 = 0xc100bf; *(uint32_t*)0x20d03ffc = r[3]; syscall(__NR_ioctl, r[2], 0x890b, 0x20d03fb0); break; case 8: r[4] = syscall(__NR_socket, 0xa, 1, 0); break; case 9: *(uint64_t*)0x20fd7000 = htobe64(0); *(uint64_t*)0x20fd7008 = htobe64(1); *(uint8_t*)0x20fd7010 = 0xfe; *(uint8_t*)0x20fd7011 = 0x80; *(uint8_t*)0x20fd7012 = 0; *(uint8_t*)0x20fd7013 = 0; *(uint8_t*)0x20fd7014 = 0; *(uint8_t*)0x20fd7015 = 0; *(uint8_t*)0x20fd7016 = 0; *(uint8_t*)0x20fd7017 = 0; *(uint8_t*)0x20fd7018 = 0; *(uint8_t*)0x20fd7019 = 0; *(uint8_t*)0x20fd701a = 0; *(uint8_t*)0x20fd701b = 0; *(uint8_t*)0x20fd701c = 0; *(uint8_t*)0x20fd701d = 0; *(uint8_t*)0x20fd701e = 0; *(uint8_t*)0x20fd701f = 0xbb; *(uint8_t*)0x20fd7020 = -1; *(uint8_t*)0x20fd7021 = 1; *(uint8_t*)0x20fd7022 = 0; *(uint8_t*)0x20fd7023 = 0; *(uint8_t*)0x20fd7024 = 0; *(uint8_t*)0x20fd7025 = 0; *(uint8_t*)0x20fd7026 = 0; *(uint8_t*)0x20fd7027 = 0; *(uint8_t*)0x20fd7028 = 0; *(uint8_t*)0x20fd7029 = 0; *(uint8_t*)0x20fd702a = 0; *(uint8_t*)0x20fd702b = 0; *(uint8_t*)0x20fd702c = 0; *(uint8_t*)0x20fd702d = 0; *(uint8_t*)0x20fd702e = 0; *(uint8_t*)0x20fd702f = 1; *(uint32_t*)0x20fd7030 = 0; *(uint16_t*)0x20fd7034 = 0; *(uint16_t*)0x20fd7036 = 0x40; *(uint32_t*)0x20fd7038 = 0; *(uint64_t*)0x20fd7040 = 0; *(uint32_t*)0x20fd7048 = 0; *(uint32_t*)0x20fd704c = 1; syscall(__NR_ioctl, r[4], 0x890b, 0x20fd7000); break; } } void test() { memset(r, -1, sizeof(r)); execute(10); } int main() { for (procid = 0; procid < 8; procid++) { if (fork() == 0) { for (;;) { int pid = do_sandbox_none(procid, false); int status = 0; while (waitpid(pid, &status, __WALL) != pid) { } } } } sleep(1000000); return 0; }