Skip to content

Crash (use-after-free) in EnvoyQuicServerStream

Moderate
phlax published GHSA-hww5-43gv-35jv Jun 4, 2024

Package

QUIC (Envoyproxy)

Affected versions

< 1.30.2

Patched versions

1.30.2, 1.29.5, 1.28.4, 1.27.6

Description

Summary

There is a use-after-free in HttpConnectionManager (HCM) with EnvoyQuicServerStream that can crash Envoy.

Details

EnvoyQuicServerStream doesn't run reset callbacks upon incoming RESET_STREAM if no STOP_SENDING is received before or afterwards.

If a client sends a request without FIN and then a RESET_STREAM frame, OnStreamReset() will not call runResetCallbacks() because the write side is not closed yet and Envoy is supposed to be able to send any response. Such a stream will not receive any more request payload and thus will hit stream idle timeout in HCM and send a local reply.

Upon FIN being written to the codec, ConnectionManagerImpl::doEndStream() will call resetStream() on the EnvoyQuicServerStream because HCM hasn't received FIN yet, nor does it know about the RESET_STREAM received on QUIC stream.

The resetStream() implementation will call ResetWithError() to send both STOP_SENDING and RESET_STREAM because reading has been stopped. ResetWithError() also won't call runResetCallbacks() because local_end_stream_ is already true.

After this point, the QUIC stream is both read and write closed and thus legitimate to be destroyed from QUICHE's perspective, but ActiveStream in HCM is still referencing the QUIC stream as the response encoder.

Accessing the response encoder after this can lead to a use-after-free, triggering the following crash stack:

Envoy::Http::ConnectionManagerImpl::resetAllStreams
Envoy::Http::ConnectionManagerImpl::doConnectionClose
Envoy::Http::ConnectionManagerImpl::onEvent
Envoy::Network::ConnectionImplBase::raiseConnectionEvent
Envoy::Quic::QuicFilterManagerConnectionImpl::onConnectionCloseEvent
Envoy::Quic::EnvoyQuicServerSession::OnConnectionClosed
external_quiche_quic::QuicConnection::TearDownLocalConnectionState
external_quiche_quic::QuicConnection::OnIdleNetworkDetected
external_quiche_quic::QuicAlarm::Fire
event_process_active_single_queue
event_process_active
event_base_loop
Envoy::Server::WorkerImpl::threadRoutine

PoC

Use a QUIC client to send a request without FIN and then a RESET_STREAM frame. After receiving the response, close the connection.

Impact

All HTTP/3 downstream users

Severity

Moderate

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
High
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
None
Integrity
None
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H

CVE ID

CVE-2024-34362

Weaknesses

Credits