// https://syzkaller.appspot.com/bug?id=ab2b76b5454b77fb2249e858b8c74c1f7d552ab5 // 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 #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 __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* uctx) { uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; if (__atomic_load_n(&skip_segv, __ATOMIC_RELAXED) && (addr < prog_start || addr > prog_end)) { _longjmp(segv_env, 1); } doexit(sig); } static void install_segv_handler() { 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(...) \ { \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ } 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; NONFAILING(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 = 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 if (unshare(CLONE_NEWNS)) { } if (unshare(CLONE_NEWIPC)) { } if (unshare(CLONE_NEWCGROUP)) { } if (unshare(CLONE_NEWUTS)) { } if (unshare(CLONE_SYSVSEM)) { } } static int do_sandbox_none(int executor_pid, bool enable_tun) { 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); } 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; } } } } #ifndef __NR_mmap #define __NR_mmap 192 #endif #ifndef __NR_ioctl #define __NR_ioctl 54 #endif #ifndef __NR_poll #define __NR_poll 168 #endif #ifndef __NR_readv #define __NR_readv 145 #endif #undef __NR_mmap #define __NR_mmap __NR_mmap2 long r[1]; void execute_call(int call) { switch (call) { case 0: syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0); break; case 1: NONFAILING(memcpy((void*)0x20061000, "/dev/snd/timer", 15)); r[0] = syz_open_dev(0x20061000, 0, 0); break; case 2: NONFAILING(*(uint32_t*)0x2060c000 = 1); NONFAILING(*(uint32_t*)0x2060c004 = 0); NONFAILING(*(uint32_t*)0x2060c008 = 0); NONFAILING(*(uint32_t*)0x2060c00c = 0); NONFAILING(*(uint32_t*)0x2060c010 = 0); NONFAILING(*(uint8_t*)0x2060c014 = 0); NONFAILING(*(uint8_t*)0x2060c015 = 0); NONFAILING(*(uint8_t*)0x2060c016 = 0); NONFAILING(*(uint8_t*)0x2060c017 = 0); NONFAILING(*(uint8_t*)0x2060c018 = 0); NONFAILING(*(uint8_t*)0x2060c019 = 0); NONFAILING(*(uint8_t*)0x2060c01a = 0); NONFAILING(*(uint8_t*)0x2060c01b = 0); NONFAILING(*(uint8_t*)0x2060c01c = 0); NONFAILING(*(uint8_t*)0x2060c01d = 0); NONFAILING(*(uint8_t*)0x2060c01e = 0); NONFAILING(*(uint8_t*)0x2060c01f = 0); NONFAILING(*(uint8_t*)0x2060c020 = 0); NONFAILING(*(uint8_t*)0x2060c021 = 0); NONFAILING(*(uint8_t*)0x2060c022 = 0); NONFAILING(*(uint8_t*)0x2060c023 = 0); NONFAILING(*(uint8_t*)0x2060c024 = 0); NONFAILING(*(uint8_t*)0x2060c025 = 0); NONFAILING(*(uint8_t*)0x2060c026 = 0); NONFAILING(*(uint8_t*)0x2060c027 = 0); NONFAILING(*(uint8_t*)0x2060c028 = 0); NONFAILING(*(uint8_t*)0x2060c029 = 0); NONFAILING(*(uint8_t*)0x2060c02a = 0); NONFAILING(*(uint8_t*)0x2060c02b = 0); NONFAILING(*(uint8_t*)0x2060c02c = 0); NONFAILING(*(uint8_t*)0x2060c02d = 0); NONFAILING(*(uint8_t*)0x2060c02e = 0); NONFAILING(*(uint8_t*)0x2060c02f = 0); NONFAILING(*(uint8_t*)0x2060c030 = 0); NONFAILING(*(uint8_t*)0x2060c031 = 0); NONFAILING(*(uint8_t*)0x2060c032 = 0); NONFAILING(*(uint8_t*)0x2060c033 = 0); syscall(__NR_ioctl, r[0], 0x40345410, 0x2060c000); break; case 3: syscall(__NR_ioctl, r[0], 0x54a0); break; case 4: NONFAILING(*(uint32_t*)0x204da000 = r[0]); NONFAILING(*(uint16_t*)0x204da004 = 0); NONFAILING(*(uint16_t*)0x204da006 = 0); NONFAILING(*(uint32_t*)0x204da008 = -1); NONFAILING(*(uint16_t*)0x204da00c = 0x2040); NONFAILING(*(uint16_t*)0x204da00e = 0); syscall(__NR_poll, 0x204da000, 2, 0xffffff80); break; case 5: NONFAILING(*(uint32_t*)0x201e1fcc = 2); NONFAILING(*(uint32_t*)0x201e1fd0 = 0); NONFAILING(*(uint32_t*)0x201e1fd4 = 0x257); NONFAILING(*(uint32_t*)0x201e1fd8 = 3); NONFAILING(*(uint32_t*)0x201e1fdc = 5); NONFAILING(*(uint8_t*)0x201e1fe0 = 0); NONFAILING(*(uint8_t*)0x201e1fe1 = 0); NONFAILING(*(uint8_t*)0x201e1fe2 = 0); NONFAILING(*(uint8_t*)0x201e1fe3 = 0); NONFAILING(*(uint8_t*)0x201e1fe4 = 0); NONFAILING(*(uint8_t*)0x201e1fe5 = 0); NONFAILING(*(uint8_t*)0x201e1fe6 = 0); NONFAILING(*(uint8_t*)0x201e1fe7 = 0); NONFAILING(*(uint8_t*)0x201e1fe8 = 0); NONFAILING(*(uint8_t*)0x201e1fe9 = 0); NONFAILING(*(uint8_t*)0x201e1fea = 0); NONFAILING(*(uint8_t*)0x201e1feb = 0); NONFAILING(*(uint8_t*)0x201e1fec = 0); NONFAILING(*(uint8_t*)0x201e1fed = 0); NONFAILING(*(uint8_t*)0x201e1fee = 0); NONFAILING(*(uint8_t*)0x201e1fef = 0); NONFAILING(*(uint8_t*)0x201e1ff0 = 0); NONFAILING(*(uint8_t*)0x201e1ff1 = 0); NONFAILING(*(uint8_t*)0x201e1ff2 = 0); NONFAILING(*(uint8_t*)0x201e1ff3 = 0); NONFAILING(*(uint8_t*)0x201e1ff4 = 0); NONFAILING(*(uint8_t*)0x201e1ff5 = 0); NONFAILING(*(uint8_t*)0x201e1ff6 = 0); NONFAILING(*(uint8_t*)0x201e1ff7 = 0); NONFAILING(*(uint8_t*)0x201e1ff8 = 0); NONFAILING(*(uint8_t*)0x201e1ff9 = 0); NONFAILING(*(uint8_t*)0x201e1ffa = 0); NONFAILING(*(uint8_t*)0x201e1ffb = 0); NONFAILING(*(uint8_t*)0x201e1ffc = 0); NONFAILING(*(uint8_t*)0x201e1ffd = 0); NONFAILING(*(uint8_t*)0x201e1ffe = 0); NONFAILING(*(uint8_t*)0x201e1fff = 0); syscall(__NR_ioctl, r[0], 0x40345410, 0x201e1fcc); break; case 6: NONFAILING(*(uint32_t*)0x20c2bffc = 1); syscall(__NR_ioctl, r[0], 0x40045402, 0x20c2bffc); break; case 7: NONFAILING(*(uint32_t*)0x20690fa0 = 0x204e0000); NONFAILING(*(uint32_t*)0x20690fa4 = 0x4c); NONFAILING(*(uint32_t*)0x20690fa8 = 0x20546000); NONFAILING(*(uint32_t*)0x20690fac = 0x1000); NONFAILING(*(uint32_t*)0x20690fb0 = 0x206c5000); NONFAILING(*(uint32_t*)0x20690fb4 = 3); NONFAILING(*(uint32_t*)0x20690fb8 = 0x20fc3000); NONFAILING(*(uint32_t*)0x20690fbc = 0xe2); NONFAILING(*(uint32_t*)0x20690fc0 = 0x20883000); NONFAILING(*(uint32_t*)0x20690fc4 = 0xa7); NONFAILING(*(uint32_t*)0x20690fc8 = 0x20ef2000); NONFAILING(*(uint32_t*)0x20690fcc = 0x1000); syscall(__NR_readv, r[0], 0x20690fa0, 6); break; } } void loop() { memset(r, -1, sizeof(r)); execute(8); } int main() { install_segv_handler(); int pid = do_sandbox_none(0, false); int status = 0; while (waitpid(pid, &status, __WALL) != pid) { } return 0; }