// https://syzkaller.appspot.com/bug?id=b53d789b93ee44038efb6c5619d323e9ea8df76a // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include 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; \ }) const int kInitNetNsFd = 201; static long syz_open_pts(volatile long a0, volatile long a1) { int ptyno = 0; if (ioctl(a0, TIOCGPTN, &ptyno)) return -1; char buf[128]; sprintf(buf, "/dev/pts/%d", ptyno); return open(buf, a1, 0); } static long syz_init_net_socket(volatile long domain, volatile long type, volatile long proto) { return syscall(__NR_socket, domain, type, proto); } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000, /*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=*/0x200001000000ul, /*len=*/0x1000, /*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)) { } // openat$ptmx arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 70 74 6d 78 00} (length 0xa) // } // flags: open_flags = 0x2 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_tty NONFAILING(memcpy((void*)0x200000000040, "/dev/ptmx\000", 10)); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x200000000040ul, /*flags=O_RDWR*/ 2, /*mode=*/0); if (res != -1) r[0] = res; // ioctl$TIOCSPTLCK arguments: [ // fd: fd_tty (resource) // cmd: const = 0x40045431 (4 bytes) // arg: ptr[in, int32] { // int32 = 0x0 (4 bytes) // } // ] NONFAILING(*(uint32_t*)0x200000000080 = 0); syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0x40045431, /*arg=*/0x200000000080ul); // syz_open_pts arguments: [ // fd: fd_tty (resource) // flags: open_flags = 0x2 (8 bytes) // ] // returns fd_tty res = -1; NONFAILING(res = syz_open_pts(/*fd=*/r[0], /*flags=O_RDWR*/ 2)); if (res != -1) r[1] = res; // ioctl$TIOCSETD arguments: [ // fd: fd_tty (resource) // cmd: const = 0x5423 (4 bytes) // arg: ptr[in, int32] { // int32 = 0x11 (4 bytes) // } // ] NONFAILING(*(uint32_t*)0x200000000100 = 0x11); syscall(__NR_ioctl, /*fd=*/r[1], /*cmd=*/0x5423, /*arg=*/0x200000000100ul); // syz_init_net_socket$llc arguments: [ // domain: const = 0x1a (8 bytes) // type: llc_socket_type = 0x2 (8 bytes) // proto: const = 0x0 (8 bytes) // ] // returns sock_llc res = -1; NONFAILING(res = syz_init_net_socket(/*domain=*/0x1a, /*type=SOCK_DGRAM*/ 2, /*proto=*/0)); if (res != -1) r[2] = res; // ioctl arguments: [ // fd: fd (resource) // cmd: int32 = 0x8914 (4 bytes) // arg: ptr[in, buffer] { // buffer: {63 61 6e 30 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00} (length // 0x28) // } // ] NONFAILING(memcpy((void*)0x200000000200, "\x63\x61\x6e\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 40)); syscall(__NR_ioctl, /*fd=*/r[2], /*cmd=*/0x8914, /*arg=*/0x200000000200ul); // write arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {65 31 61 0d} (length 0x4) // } // count: len = 0x4 (8 bytes) // ] NONFAILING(memcpy((void*)0x200000000300, "e1a\r", 4)); syscall(__NR_write, /*fd=*/r[0], /*buf=*/0x200000000300ul, /*count=*/4ul); return 0; }