// https://syzkaller.appspot.com/bug?id=3c27eae7bdba97293b68e79c9700ac110f977eed // autogenerated by syzkaller (http://github.com/google/syzkaller) #define _GNU_SOURCE #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 #define BITMASK_LEN(type, bf_len) (type)((1ull << (bf_len)) - 1) #define BITMASK_LEN_OFF(type, bf_off, bf_len) \ (type)(BITMASK_LEN(type, (bf_len)) << (bf_off)) #define STORE_BY_BITMASK(type, addr, val, bf_off, bf_len) \ if ((bf_off) == 0 && (bf_len) == 0) { \ *(type*)(addr) = (type)(val); \ } else { \ type new_val = *(type*)(addr); \ new_val &= ~BITMASK_LEN_OFF(type, (bf_off), (bf_len)); \ new_val |= ((type)(val)&BITMASK_LEN(type, (bf_len))) << (bf_off); \ *(type*)(addr) = new_val; \ } 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); \ } 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_userfaultfd #define __NR_userfaultfd 323 #endif uint64_t r[8] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { long res; switch (call) { case 0: res = syscall(__NR_socket, 0xd, 1, 0); if (res != -1) r[0] = res; break; case 1: NONFAILING(memcpy((void*)0x200000c0, "/dev/rfkill", 12)); res = syscall(__NR_openat, 0xffffffffffffff9c, 0x200000c0, 0, 0); if (res != -1) r[1] = res; break; case 2: NONFAILING(memcpy((void*)0x20000100, "./file0", 8)); syscall(__NR_openat, r[1], 0x20000100, 0x800, 1); break; case 3: res = syscall(__NR_socket, 2, 2, 0); if (res != -1) r[2] = res; break; case 4: NONFAILING(*(uint32_t*)0x20000080 = htobe32(0xe0000001)); NONFAILING(*(uint8_t*)0x20000084 = 0xac); NONFAILING(*(uint8_t*)0x20000085 = 0x14); NONFAILING(*(uint8_t*)0x20000086 = 0x14); NONFAILING(*(uint8_t*)0x20000087 = 0xd); NONFAILING(*(uint32_t*)0x20000088 = htobe32(0)); syscall(__NR_setsockopt, r[2], 0, 0x27, 0x20000080, 0xc); break; case 5: syscall(__NR_ioctl, r[0], 0x8912, 0x20000240); break; case 6: NONFAILING(*(uint32_t*)0x20000200 = 0x80); res = syscall(__NR_getsockname, r[1], 0x20000280, 0x20000200); if (res != -1) NONFAILING(r[3] = *(uint32_t*)0x20000284); break; case 7: NONFAILING(*(uint8_t*)0x20000300 = 0xfe); NONFAILING(*(uint8_t*)0x20000301 = 0x80); NONFAILING(*(uint8_t*)0x20000302 = 0); NONFAILING(*(uint8_t*)0x20000303 = 0); NONFAILING(*(uint8_t*)0x20000304 = 0); NONFAILING(*(uint8_t*)0x20000305 = 0); NONFAILING(*(uint8_t*)0x20000306 = 0); NONFAILING(*(uint8_t*)0x20000307 = 0); NONFAILING(*(uint8_t*)0x20000308 = 0); NONFAILING(*(uint8_t*)0x20000309 = 0); NONFAILING(*(uint8_t*)0x2000030a = 0); NONFAILING(*(uint8_t*)0x2000030b = 0); NONFAILING(*(uint8_t*)0x2000030c = 0); NONFAILING(*(uint8_t*)0x2000030d = 0); NONFAILING(*(uint8_t*)0x2000030e = 0); NONFAILING(*(uint8_t*)0x2000030f = 0x16); NONFAILING(*(uint32_t*)0x20000310 = 3); NONFAILING(*(uint32_t*)0x20000314 = r[3]); syscall(__NR_ioctl, r[0], 0x8936, 0x20000300); break; case 8: res = syscall(__NR_socket, 2, 2, 0); if (res != -1) r[4] = res; break; case 9: NONFAILING(*(uint32_t*)0x20000040 = htobe32(0xe0000002)); NONFAILING(*(uint8_t*)0x20000044 = 0xac); NONFAILING(*(uint8_t*)0x20000045 = 0x14); NONFAILING(*(uint8_t*)0x20000046 = 0x14); NONFAILING(*(uint8_t*)0x20000047 = 0xd); NONFAILING(*(uint32_t*)0x20000048 = htobe32(0)); syscall(__NR_setsockopt, r[4], 0, 0x27, 0x20000040, 0xc); break; case 10: NONFAILING(*(uint32_t*)0x20b5a000 = 2); NONFAILING(*(uint32_t*)0x20b5a004 = 0x70); NONFAILING(*(uint8_t*)0x20b5a008 = 0xe2); NONFAILING(*(uint8_t*)0x20b5a009 = 0); NONFAILING(*(uint8_t*)0x20b5a00a = 0); NONFAILING(*(uint8_t*)0x20b5a00b = 0); NONFAILING(*(uint32_t*)0x20b5a00c = 0); NONFAILING(*(uint64_t*)0x20b5a010 = 0); NONFAILING(*(uint64_t*)0x20b5a018 = 0); NONFAILING(*(uint64_t*)0x20b5a020 = 0); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 0, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 1, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 2, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 3, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 4, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0xffff, 5, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 6, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 7, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 8, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 9, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 10, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 11, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 12, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 13, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 14, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 15, 2)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 17, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 18, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 19, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 20, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 21, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 22, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 23, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 24, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 25, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 26, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 27, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 28, 1)); NONFAILING(STORE_BY_BITMASK(uint64_t, 0x20b5a028, 0, 29, 35)); NONFAILING(*(uint32_t*)0x20b5a030 = 0); NONFAILING(*(uint32_t*)0x20b5a034 = 0); NONFAILING(*(uint64_t*)0x20b5a038 = 0x20000000); NONFAILING(*(uint64_t*)0x20b5a040 = 0); NONFAILING(*(uint64_t*)0x20b5a048 = 0x400); NONFAILING(*(uint64_t*)0x20b5a050 = 0); NONFAILING(*(uint32_t*)0x20b5a058 = 0); NONFAILING(*(uint32_t*)0x20b5a05c = 0); NONFAILING(*(uint64_t*)0x20b5a060 = 0); NONFAILING(*(uint32_t*)0x20b5a068 = 0); NONFAILING(*(uint16_t*)0x20b5a06c = 0); NONFAILING(*(uint16_t*)0x20b5a06e = 0); syscall(__NR_perf_event_open, 0x20b5a000, 0, -1, -1, 0); break; case 11: NONFAILING(*(uint32_t*)0x200001c0 = 0x48); syscall(__NR_accept4, r[0], 0x20000140, 0x200001c0, 0x80000); break; case 12: res = syscall(__NR_userfaultfd, 0x80000); if (res != -1) r[5] = res; break; case 13: NONFAILING(*(uint64_t*)0x20fcdfe8 = 0xaa); NONFAILING(*(uint64_t*)0x20fcdff0 = 0); NONFAILING(*(uint64_t*)0x20fcdff8 = 0); syscall(__NR_ioctl, r[5], 0xc018aa3f, 0x20fcdfe8); break; case 14: syscall(__NR_mmap, 0x20000000, 0xfff000, 3, 0x32, -1, 0); break; case 15: syscall(__NR_socket, 0x18, 1, 1); break; case 16: syscall(__NR_socket, 0x10, 3, 0x15); break; case 17: res = syscall(__NR_socket, 2, 2, 0); if (res != -1) r[6] = res; break; case 18: res = syscall(__NR_socket, 0x18, 1, 1); if (res != -1) r[7] = res; break; case 19: NONFAILING(*(uint16_t*)0x20e92000 = 0x18); NONFAILING(*(uint32_t*)0x20e92002 = 1); NONFAILING(*(uint32_t*)0x20e92006 = 0); NONFAILING(*(uint32_t*)0x20e9200a = r[6]); NONFAILING(*(uint16_t*)0x20e9200e = 2); NONFAILING(*(uint16_t*)0x20e92010 = htobe16(1)); NONFAILING(*(uint8_t*)0x20e92012 = 0xac); NONFAILING(*(uint8_t*)0x20e92013 = 0x14); NONFAILING(*(uint8_t*)0x20e92014 = 0); NONFAILING(*(uint8_t*)0x20e92015 = 0xbb); NONFAILING(*(uint8_t*)0x20e92016 = 0); NONFAILING(*(uint8_t*)0x20e92017 = 0); NONFAILING(*(uint8_t*)0x20e92018 = 0); NONFAILING(*(uint8_t*)0x20e92019 = 0); NONFAILING(*(uint8_t*)0x20e9201a = 0); NONFAILING(*(uint8_t*)0x20e9201b = 0); NONFAILING(*(uint8_t*)0x20e9201c = 0); NONFAILING(*(uint8_t*)0x20e9201d = 0); NONFAILING(*(uint32_t*)0x20e9201e = 2); NONFAILING(*(uint32_t*)0x20e92022 = 0); NONFAILING(*(uint32_t*)0x20e92026 = 4); NONFAILING(*(uint32_t*)0x20e9202a = 0); syscall(__NR_connect, r[7], 0x20e92000, 0x2e); break; case 20: syscall(__NR_close, r[6]); break; case 21: syscall(__NR_close, r[7]); break; } } void loop() { execute(22); } int main() { syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); install_segv_handler(); loop(); return 0; }