// https://syzkaller.appspot.com/bug?id=650f29599f90395d4190195e5b5a3aec7beb7af2 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #ifndef __NR_memfd_create #define __NR_memfd_create 279 #endif #ifndef __NR_mmap #define __NR_mmap 222 #endif #ifndef __NR_setgroups #define __NR_setgroups 159 #endif static __thread int clone_ongoing; static __thread int skip_segv; static __thread jmp_buf segv_env; static void segv_handler(int sig, siginfo_t* info, void* ctx) { if (__atomic_load_n(&clone_ongoing, __ATOMIC_RELAXED) != 0) { exit(sig); } uintptr_t addr = (uintptr_t)info->si_addr; const uintptr_t prog_start = 1 << 20; const uintptr_t prog_end = 100 << 20; int skip = __atomic_load_n(&skip_segv, __ATOMIC_RELAXED) != 0; int valid = addr < prog_start || addr > prog_end; if (skip && valid) { _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(...) \ ({ \ int ok = 1; \ __atomic_fetch_add(&skip_segv, 1, __ATOMIC_SEQ_CST); \ if (_setjmp(segv_env) == 0) { \ __VA_ARGS__; \ } else \ ok = 0; \ __atomic_fetch_sub(&skip_segv, 1, __ATOMIC_SEQ_CST); \ ok; \ }) uint64_t r[1] = {0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; install_segv_handler(); intptr_t res = 0; if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } // memfd_create arguments: [ // name: ptr[in, buffer] { // buffer: {ff 2d 42 d5 4e 49 c5 6a 9a 70 70 70 f0 08 84 a2 6d 00 0b 18 // 00 34 a2 45 79 db d1 a7 b1 53 f1 3a 29 00 bb 8d ac c8 c0 3a 9c 63 02 // 64 ee a9 8f 63 63 ad 89 9c 6b de 05 00 00 00 55 45 c9 38 4d cd fb cc // 97 b4 0b a9 3d cd 4a 78 aa 8f 7e b9 30 61 a9 b2 04 4b 98 93 3d 88 00 // f7 d6 1d a1 ce 8b 19 ea ef e3 ab 00 a5 c2 34 d6 fe 37 0f} (length // 0x6c) // } // flags: memfd_flags = 0x0 (8 bytes) // ] // returns fd_memfd NONFAILING(memcpy( (void*)0x20000140, "\377-" "B\325NI\305j\232ppp\360\b\204\242m\000\v\030\0004\242Ey\333\321\247\261S" "\361:)\000\273\215\254\310\300:" "\234c\002d\356\251\217cc\255\211\234k\336\005\000\000\000UE\3118M\315" "\373\314\227\264\v\251=\315Jx\252\217~\2710a\251\262\004K\230\223=" "\210\000\367\326\035\241\316\213\031\352\357\343\253\000\245\3024\326" "\3767\017", 108)); res = syscall(__NR_memfd_create, /*name=*/0x20000140ul, /*flags=*/0ul); if (res != -1) r[0] = res; // mmap arguments: [ // addr: VMA[0x4000] // len: len = 0x4000 (8 bytes) // prot: mmap_prot = 0x4 (8 bytes) // flags: mmap_flags = 0x11 (8 bytes) // fd: fd (resource) // offset: intptr = 0x0 (8 bytes) // ] syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x4000ul, /*prot=PROT_EXEC*/ 4ul, /*flags=MAP_FIXED|MAP_SHARED*/ 0x11ul, /*fd=*/r[0], /*offset=*/0ul); // setgroups arguments: [ // size: len = 0x1 (8 bytes) // list: ptr[in, array[gid]] { // array[gid] { // gid (resource) // } // } // ] NONFAILING(*(uint32_t*)0x20000200 = 0); syscall(__NR_setgroups, /*size=*/1ul, /*list=*/0x20000200ul); return 0; }