// https://syzkaller.appspot.com/bug?id=12d2a0443c5b41cac2798aa8fcfdfa8632b852b6 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #ifndef __NR_seccomp #define __NR_seccomp 317 #endif static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } struct thread_t { int created, call; event_t ready, done; }; 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 (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void loop(void) { if (write(1, "executing program\n", sizeof("executing program\n") - 1)) { } int i, call, thread; for (call = 0; call < 8; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); if (call == 5) break; event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } uint64_t r[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: // unshare arguments: [ // flags: unshare_flags = 0x22020600 (8 bytes) // ] syscall(__NR_unshare, /*flags=CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWCGROUP|CLONE_FS|0x400*/ 0x22020600ul); break; case 1: // seccomp$SECCOMP_SET_MODE_FILTER_LISTENER arguments: [ // op: const = 0x1 (8 bytes) // flags: seccomp_flags_listener = 0x7 (8 bytes) // arg: nil // ] // returns fd_seccomp syscall(__NR_seccomp, /*op=*/1ul, /*flags=*/7ul, /*arg=*/0ul); break; case 2: // socket$pppl2tp arguments: [ // domain: const = 0x18 (8 bytes) // type: const = 0x1 (8 bytes) // proto: const = 0x1 (4 bytes) // ] // returns sock_pppl2tp res = syscall(__NR_socket, /*domain=*/0x18ul, /*type=*/1ul, /*proto=*/1); if (res != -1) r[0] = res; break; case 3: // socket$inet6_udp arguments: [ // domain: const = 0xa (8 bytes) // type: const = 0x2 (8 bytes) // proto: const = 0x0 (4 bytes) // ] // returns sock_udp6 res = syscall(__NR_socket, /*domain=*/0xaul, /*type=*/2ul, /*proto=*/0); if (res != -1) r[1] = res; break; case 4: // connect$pppl2tp arguments: [ // fd: sock_pppl2tp (resource) // addr: ptr[in, sockaddr_pppl2tp] { // union sockaddr_pppl2tp { // pppol2tp: sockaddr_pppl2tp_t[pppol2tp_addr] { // sa_family: const = 0x18 (2 bytes) // sa_protocol: const = 0x1 (4 bytes) // addr: pppol2tp_addr_t[int16] { // pid: const = 0x0 (4 bytes) // fd: sock (resource) // addr: sockaddr_in { // family: const = 0x2 (2 bytes) // port: int16be = 0x4e24 (2 bytes) // addr: union ipv4_addr { // broadcast: const = 0xffffffff (4 bytes) // } // pad = 0x0 (8 bytes) // } // s_tunnel: int16 = 0x2 (2 bytes) // s_session: int16 = 0x0 (2 bytes) // d_tunnel: int16 = 0x3 (2 bytes) // d_session: int16 = 0x0 (2 bytes) // } // } // } // } // addrlen: len = 0x26 (8 bytes) // ] *(uint16_t*)0x200000000000 = 0x18; *(uint32_t*)0x200000000002 = 1; *(uint32_t*)0x200000000006 = 0; *(uint32_t*)0x20000000000a = r[1]; *(uint16_t*)0x20000000000e = 2; *(uint16_t*)0x200000000010 = htobe16(0x4e24); *(uint32_t*)0x200000000012 = htobe32(-1); *(uint16_t*)0x20000000001e = 2; *(uint16_t*)0x200000000020 = 0; *(uint16_t*)0x200000000022 = 3; *(uint16_t*)0x200000000024 = 0; syscall(__NR_connect, /*fd=*/r[0], /*addr=*/0x200000000000ul, /*addrlen=*/0x26ul); break; case 5: // openat$ppp arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: nil // flags: open_flags = 0x1 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_ppp syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0ul, /*flags=O_WRONLY*/ 1, /*mode=*/0); break; case 6: // openat$ppp arguments: [ // fd: const = 0xffffffffffffff9c (8 bytes) // file: ptr[in, buffer] { // buffer: {2f 64 65 76 2f 70 70 70 00} (length 0x9) // } // flags: open_flags = 0x1 (4 bytes) // mode: const = 0x0 (2 bytes) // ] // returns fd_ppp memcpy((void*)0x2000000000c0, "/dev/ppp\000", 9); res = syscall(__NR_openat, /*fd=*/0xffffffffffffff9cul, /*file=*/0x2000000000c0ul, /*flags=O_WRONLY*/ 1, /*mode=*/0); if (res != -1) r[2] = res; break; case 7: // ioctl$PPPIOCATTCHAN arguments: [ // fd: fd_ppp (resource) // cmd: const = 0x40047438 (4 bytes) // arg: nil // ] syscall(__NR_ioctl, /*fd=*/r[2], /*cmd=*/0x40047438, /*arg=*/0ul); break; } } 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; loop(); return 0; }