// https://syzkaller.appspot.com/bug?id=fd0f9041cf7c93c445cf121b545df960b1a315b6 // 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_fsconfig #define __NR_fsconfig 431 #endif #ifndef __NR_fsopen #define __NR_fsopen 430 #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 < 9; 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[3] = {0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: // socket$inet arguments: [ // domain: const = 0x2 (8 bytes) // type: socket_type = 0x1 (8 bytes) // proto: int32 = 0x0 (4 bytes) // ] // returns sock_in res = syscall(__NR_socket, /*domain=*/2ul, /*type=SOCK_STREAM*/ 1ul, /*proto=*/0); if (res != -1) r[0] = res; break; case 1: // bind$inet arguments: [ // fd: sock_in (resource) // addr: ptr[in, sockaddr_in] { // sockaddr_in { // family: const = 0x2 (2 bytes) // port: int16be = 0x1a0a (2 bytes) // addr: union ipv4_addr { // empty: const = 0x0 (4 bytes) // } // pad = 0x0 (8 bytes) // } // } // addrlen: len = 0x10 (8 bytes) // ] *(uint16_t*)0x200000000000 = 2; *(uint16_t*)0x200000000002 = htobe16(0x1a0a); *(uint32_t*)0x200000000004 = htobe32(0); syscall(__NR_bind, /*fd=*/r[0], /*addr=*/0x200000000000ul, /*addrlen=*/0x10ul); break; case 2: // listen arguments: [ // fd: sock (resource) // backlog: int32 = 0x5 (4 bytes) // ] syscall(__NR_listen, /*fd=*/r[0], /*backlog=*/5); break; case 3: // fsopen arguments: [ // type: ptr[in, buffer] { // buffer: {63 65 70 68 00} (length 0x5) // } // flags: fsopen_flags = 0x0 (8 bytes) // ] // returns fd_fscontext memcpy((void*)0x200000000100, "ceph\000", 5); res = syscall(__NR_fsopen, /*type=*/0x200000000100ul, /*flags=*/0ul); if (res != -1) r[1] = res; break; case 4: // fsconfig$FSCONFIG_SET_STRING arguments: [ // fd: fd_fscontext (resource) // cmd: const = 0x1 (8 bytes) // key: ptr[in, buffer] { // buffer: {73 6f 75 72 63 65 00} (length 0x7) // } // value: ptr[in, buffer] { // buffer: {31 32 37 2e 30 2e 30 2e 31 3a 36 36 36 36 3a 2f 70 61 74 68 // 00} (length 0x15) // } // aux: const = 0x0 (8 bytes) // ] memcpy((void*)0x200000000200, "source\000", 7); memcpy((void*)0x200000000300, "127.0.0.1:6666:/path\000", 21); syscall(__NR_fsconfig, /*fd=*/r[1], /*cmd=*/1ul, /*key=*/0x200000000200ul, /*value=*/0x200000000300ul, /*aux=*/0ul); break; case 5: // fsconfig$FSCONFIG_CMD_CREATE arguments: [ // fd: fd_fscontext (resource) // cmd: const = 0x6 (8 bytes) // key: const = 0x0 (8 bytes) // value: const = 0x0 (8 bytes) // aux: const = 0x0 (8 bytes) // ] syscall(__NR_fsconfig, /*fd=*/r[1], /*cmd=*/6ul, /*key=*/0ul, /*value=*/0ul, /*aux=*/0ul); break; case 6: // accept$inet arguments: [ // fd: sock_in (resource) // peer: nil // peerlen: nil // ] // returns sock_in res = syscall(__NR_accept, /*fd=*/r[0], /*peer=*/0ul, /*peerlen=*/0ul); if (res != -1) r[2] = res; break; case 7: // write arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {63 65 70 68 20 76 30 32 37 00 00 00 00 00 00 00 00 02 00 1a // 0a 7f 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 // 1a 0a 7f 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00} (length 0x3d) // } // count: len = 0x41 (8 bytes) // ] memcpy((void*)0x200000000800, "\x63\x65\x70\x68\x20\x76\x30\x32\x37\x00\x00\x00\x00\x00\x00\x00" "\x00\x02\x00\x1a\x0a\x7f\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x1a\x0a\x7f\x00\x00" "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 61); syscall(__NR_write, /*fd=*/r[2], /*buf=*/0x200000000800ul, /*count=*/0x41ul); break; case 8: // write arguments: [ // fd: fd (resource) // buf: ptr[in, buffer] { // buffer: {04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 // 00 00 00 00 04 00 00 00 00 00 00 00 00 00 00 00 12 00 00 00 5d 9e 5b // 72 01 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 01 00 00 00 01 // 00 00 00 02 00 1a 0a 7f 00 00 01 00 00 00 00 00 00 00 00 5d 9e 5b // 72} (length 0x70) // } // count: len = 0x55 (8 bytes) // ] memcpy((void*)0x200000000b00, "\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x12\x00\x00\x00\x5d\x9e\x5b\x72\x01\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x02\x00\x1a\x0a" "\x7f\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x5d\x9e\x5b\x72", 112); syscall(__NR_write, /*fd=*/r[2], /*buf=*/0x200000000b00ul, /*count=*/0x55ul); 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; }