// https://syzkaller.appspot.com/bug?id=f29750d7805751d874d3c03945040eed4e5cc6a7 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { 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); } exit(sig); } static void install_segv_handler(void) { 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); \ } #ifndef __NR_memfd_create #define __NR_memfd_create 319 #endif uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; 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); install_segv_handler(); intptr_t res = 0; res = syscall(__NR_socket, 2ul, 1ul, 0); if (res != -1) r[0] = res; NONFAILING(memcpy((void*)0x20000140, "-B\325NI\305j\272ppp\360\b\204\242m\000:)" "\000\273\215\254\254va}knh#\313)\017\310\300:" "\234c\020d\356\251\213Cc\255\211\234k\336\305\3516\335U" "\251=\315Jx\252\217~\2710\213\031\352\357\343\253\266\245$" "4\326\3767\017\347\331$\316 " "\253N\256\311\275\323g@\341\'s\016\220\362\315r\270(" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000", 118)); res = syscall(__NR_memfd_create, 0x20000140ul, 0ul); if (res != -1) r[1] = res; NONFAILING(memcpy((void*)0x200004c0, "1", 1)); syscall(__NR_write, r[1], 0x200004c0ul, 1ul); syscall(__NR_mmap, 0x20000000ul, 0x2000ul, 4ul, 0x11ul, r[1], 0ul); NONFAILING(*(uint64_t*)0x20000240 = 0); syscall(__NR_sendfile, r[1], r[1], 0x20000240ul, 0xba8ul); NONFAILING(*(uint32_t*)0x20000040 = 0); syscall(__NR_getsockopt, r[0], 0, 0x50, 0ul, 0x20000040ul); return 0; }