// https://syzkaller.appspot.com/bug?id=dbcb39beb96c35c5b1f579ec77a4c121d60d21a0 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include 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 < 6; 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); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } uint64_t r[2] = {0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: // socket$alg arguments: [ // domain: const = 0x26 (8 bytes) // type: const = 0x5 (8 bytes) // proto: const = 0x0 (4 bytes) // ] // returns sock_alg res = syscall(__NR_socket, /*domain=*/0x26ul, /*type=*/5ul, /*proto=*/0); if (res != -1) r[0] = res; break; case 1: // bind$alg arguments: [ // fd: sock_alg (resource) // addr: ptr[in, sockaddr_alg] { // sockaddr_alg { // family: const = 0x26 (2 bytes) // type: buffer: {73 6b 63 69 70 68 65 72 00 00 00 00 00 00} (length // 0xe) feat: af_alg_type = 0x0 (4 bytes) mask: af_alg_type = 0x0 (4 // bytes) name: buffer: {65 63 62 28 64 65 73 33 5f 65 64 65 29 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 00} (length 0x40) // } // } // addrlen: len = 0x58 (8 bytes) // ] *(uint16_t*)0x200000000000 = 0x26; memcpy((void*)0x200000000002, "skcipher\000\000\000\000\000\000", 14); *(uint32_t*)0x200000000010 = 0; *(uint32_t*)0x200000000014 = 0; memcpy( (void*)0x200000000018, "ecb(des3_ede)" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000" "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", 64); syscall(__NR_bind, /*fd=*/r[0], /*addr=*/0x200000000000ul, /*addrlen=*/0x58ul); break; case 2: // setsockopt$ALG_SET_KEY arguments: [ // fd: sock_alg (resource) // level: const = 0x117 (4 bytes) // opt: const = 0x1 (4 bytes) // key: ptr[in, buffer] { // buffer: {ad 56 b6 c5 82 0f ae 9d 6d cd 32 92 ea 54 c7 be ef 91 5d 56 // 4c 90 c2 00} (length 0x18) // } // keylen: len = 0x18 (8 bytes) // ] memcpy((void*)0x200000c18000, "\xad\x56\xb6\xc5\x82\x0f\xae\x9d\x6d\xcd\x32\x92\xea\x54\xc7\xbe" "\xef\x91\x5d\x56\x4c\x90\xc2\x00", 24); syscall(__NR_setsockopt, /*fd=*/r[0], /*level=*/0x117, /*opt=*/1, /*key=*/0x200000c18000ul, /*keylen=*/0x18ul); break; case 3: // accept4 arguments: [ // fd: sock (resource) // peer: nil // peerlen: nil // flags: accept_flags = 0x0 (8 bytes) // ] // returns sock res = syscall(__NR_accept4, /*fd=*/r[0], /*peer=*/0ul, /*peerlen=*/0ul, /*flags=*/0ul); if (res != -1) r[1] = res; break; case 4: // sendmmsg$alg arguments: [ // fd: sock_algconn (resource) // mmsg: ptr[in, array[msghdr_alg]] { // array[msghdr_alg] { // msghdr_alg { // addr: const = 0x20000000 (8 bytes) // addrlen: const = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // vec: ptr[in, array[iovec[in, array[int8]]]] { // array[iovec[in, array[int8]]] { // iovec[in, array[int8]] { // addr: ptr[in, buffer] { // buffer: {f7 8d 9c a3 8f ff 48 f3 be 52 16 34 48 41 2b // a8} (length 0x10) // } // len: len = 0xfffffe1a (8 bytes) // } // } // } // vlen: len = 0x1 (8 bytes) // ctrl: ptr[in, array[cmsghdr_alg]] { // array[cmsghdr_alg] { // union cmsghdr_alg { // op: cmsghdr_alg_op { // len: len = 0x18 (8 bytes) // level: const = 0x117 (4 bytes) // type: const = 0x3 (4 bytes) // op: alg_op_op = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // } // } // } // } // ctrllen: bytesize = 0x18 (8 bytes) // f: send_flags = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // } // } // } // vlen: len = 0x4924924924924b9 (8 bytes) // f: send_flags = 0x0 (8 bytes) // ] *(uint64_t*)0x200000000400 = 0x20000000; *(uint32_t*)0x200000000408 = 0; *(uint64_t*)0x200000000410 = 0x2000000002c0; *(uint64_t*)0x2000000002c0 = 0x200000000080; memcpy((void*)0x200000000080, "\xf7\x8d\x9c\xa3\x8f\xff\x48\xf3\xbe\x52\x16\x34\x48\x41\x2b\xa8", 16); *(uint64_t*)0x2000000002c8 = 0xfffffe1a; *(uint64_t*)0x200000000418 = 1; *(uint64_t*)0x200000000420 = 0x200000000380; *(uint64_t*)0x200000000380 = 0x18; *(uint32_t*)0x200000000388 = 0x117; *(uint32_t*)0x20000000038c = 3; *(uint32_t*)0x200000000390 = 0; *(uint64_t*)0x200000000428 = 0x18; *(uint32_t*)0x200000000430 = 0; syscall(__NR_sendmmsg, /*fd=*/r[1], /*mmsg=*/0x200000000400ul, /*vlen=*/0x4924924924924b9ul, /*f=*/0ul); break; case 5: // recvmsg$can_raw arguments: [ // fd: sock_can_raw (resource) // msg: ptr[inout, recv_msghdr] { // recv_msghdr { // msg_name: nil // msg_namelen: len = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // msg_iov: ptr[in, array[iovec[out, array[int8]]]] { // array[iovec[out, array[int8]]] { // iovec[out, array[int8]] { // addr: ptr[out, buffer] { // buffer: (DirOut) // } // len: len = 0x1000 (8 bytes) // } // } // } // msg_iovlen: len = 0x1 (8 bytes) // msg_control: nil // msg_controllen: bytesize = 0x0 (8 bytes) // msg_flags: const = 0x0 (4 bytes) // pad = 0x0 (4 bytes) // } // } // f: recv_flags = 0x40000003 (8 bytes) // ] *(uint64_t*)0x200000000600 = 0; *(uint32_t*)0x200000000608 = 0; *(uint64_t*)0x200000000610 = 0x200000000540; *(uint64_t*)0x200000000540 = 0x200000000780; *(uint64_t*)0x200000000548 = 0x1000; *(uint64_t*)0x200000000618 = 1; *(uint64_t*)0x200000000620 = 0; *(uint64_t*)0x200000000628 = 0; *(uint32_t*)0x200000000630 = 0; syscall(__NR_recvmsg, /*fd=*/r[1], /*msg=*/0x200000000600ul, /*f=MSG_PEEK|MSG_OOB|MSG_CMSG_CLOEXEC*/ 0x40000003ul, 0); break; } } int main(void) { syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*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=*/0x200001000000ul, /*len=*/0x1000ul, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul); const char* reason; (void)reason; loop(); return 0; }