Skip to content

proxy SIGBUS (use-after-free) in QuicConnection::OnCanWrite when CDS removes a QUIC twin cluster with a live client connection (proving soak w01, 03:25:59Z) #1074

Closed

Description

@bpalermo

Observed — #979 proving soak, talos-main, chart 1.0.12-33ff5e9 (Envoy 1.40.0-dev a1bcf05 + carried aether1050/1054/1054b/1054c)

main-worker-01, #1073 burst 2 (one fetch window after the TRIPLE's agent roll):

  1. 03:25:59.398Z agent: pruned persisted east-west QUIC pairs with no on-demand fetch since agent start count=10
  2. 03:25:59.586 Envoy: cds: ... 10 removed cluster(s) — the twins were removed while k6/prober traffic was still on them
  3. 03:25:59.646 Envoy: Caught Bus error, suspect faulting address 0x6f72702f747365 (the address bytes read "est/pro" in ASCII — a freed object whose memory now holds string data → use-after-free)
  4. Stack, worker thread 42: quic::QuicConnection::OnCanWrite ← EnvoyQuicClientConnection::OnCanWrite ← WriteIfNotBlocked ← EnvoyQuicClientConnection::onFileEvent ← FileEventImpl::mergeInjectedEventsAndRunCb
  5. Supervisor: envoy epoch 96 exited unexpectedly: signal: bus error; aether-proxy-9rghc proxy container exit 1 at 03:26:00, restarted 03:26:01 (restartCount 1)

Impact: ~10 s node outage on w01 — prober 51 × liveness connection refused (03:26:00–:10) + 99 mesh_dns timeouts + 4 conn_err; AetherProberLivenessErrors fired 03:32:55–03:37:55Z; k6 on w01 stalled (534 iterations dropped). This is the soak's only crash (fleet-wide Caught|exited unexpectedly returns only these lines). #1073 burst 1 (23:37Z, same prune on all nodes) did not crash → intermittent.

Reading: removing an upstream QUIC cluster while one of its client connections has a pending write (a file event already injected/queued) frees the connection or its writer, and the queued onFileEvent then runs OnCanWrite on freed memory. Fixing #1073 (don't prune live twins) removes this trigger, but the crash is an Envoy lifetime bug in its own right — any legitimate removal of a QUIC cluster under load (demand-set shrink, destination leaving the dependency set, the 1 h prune of a truly idle pair that just got a request) can hit it.

Ask: reproduce on kind (CDS-remove a quic: twin cluster while an h3 client connection on it is mid-write under load; ASan build of the proxy if feasible), then fix — likely deferred deletion of the client connection / cancelling its injected write event on cluster teardown. Upstream shape for the owner; a carried patch in the meantime. Full crash log: session scratchpad w01-proxy-prev.log. Related: #1073, #1067 carried patches, #979.

Activity

  1. added
    bug
    on Sep 30, 2026
  2. bpalermo commented on Sep 30, 2026

    @bpalermo
    OwnerAuthor

    Root cause (envoy session; confirmed by symbolizing the crashed a1bcf05 binary)

    Fault site: quic::QuicConnection::OnCanWrite+0x154 is the return address of bl QuicConnection::CanWrite(HasRetransmittableData); the fault is clock_->Now() at the end of CanWrite (quic_connection.cc ~3491), the first clock read on that path. The writer call at the top of OnCanWrite worked because the writer is owned by the connection; the clock is not.

    Ownership bug (upstream Envoy since #19862, 2022-03): the clock lives in Quic::PersistentQuicInfoImpl (conn_helper_ with EnvoyQuicClock, alarm factory, quic config, crypto stream factory, writer factory), which is a unique_ptr MEMBER of the worker's thread-local ClusterEntry (cluster_manager_impl.h:719 quic_info_). Http3ConnPoolImpl holds it by reference (conn_pool.h:200) and every upstream QUIC connection holds raw pointers into it (QuicConnection::clock_, each EnvoyQuicAlarm's clock).

    Sequence on a CDS removal: worker TLS update → thread_local_clusters_.erase(name) (cluster_manager_impl.cc:899) → ~ClusterEntry (:2135) → drainConnPools() → drainOrCloseConnPools(host, DrainAndDelete): pools with in-flight streams keep their busy clients → ~ClusterEntry then destroys quic_info_ → the pools live on in host_http_conn_pool_map_ with connections pointing into freed memory → the next write-ready event (our stack) or alarm dereferences the clock. Needs streams in flight at removal, hence intermittent; the w01 access log shows 71–74 rps on the removed twins right up to the removal.

    Fix: make the info shared — PersistentQuicInfoPtr becomes a shared_ptr; Http3ConnPoolImpl and ConnectivityGrid hold a shared_ptr instead of a reference, so it outlives every pool using it (connections are torn down before their pool, so their raw pointers stay valid). No behaviour change on the healthy path. Test: the http3 conn_pool_test drops the creator's ownership of the info and then creates a client connection — UAF under ASan before, clean after. To be carried as envoy-aether1074 on proxy/1074-quic-client-teardown-uaf pending the owner's go; upstream bug-fix PR on the owner's word.

    Mitigation in place: #1073 (PR #1076) stops the agent from removing live twins; this also protects HTTP/3 clusters from the other CDS removal paths only to the extent they don't remove clusters with streams in flight — the carried patch is the real fix.

  3. bpalermo commented on Oct 1, 2026

    @bpalermo
    OwnerAuthor

    Closing: fixed by the carried patch envoy-aether1074-quic-persistent-info-lifetime (#1077) and proven on talos — 0 Envoy crashes across the 2026-09-30 re-soak (6 hot restarts per node) and the 2026-10-01 soak (30 handoffs, twin removals included). The upstream fix is envoyproxy/envoy#47893 (open); dropping the carried patch once it merges is tracked in #980.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions