Skip to content

HTTP/2 memory leak in nghttp2 codec

High
phlax published GHSA-jfxv-29pc-x22r Jul 12, 2023

Package

Envoy

Affected versions

< 1.27.0

Patched versions

1.26.3, 1.25.8, 1.24.9, 1.23.11

Description

Summary

Envoy’s HTTP/2 codec may leak a header map and bookkeeping structures upon receiving RST_STREAM immediately followed by the GOAWAY frames from an upstream server.

Affected Component

HTTP/2 codec

Details

In nghttp2, cleanup of pending requests due to receipt of the GOAWAY frame skips de-allocation of the bookkeeping structure and pending compressed header.

The error return code path is taken if connection is already marked for not sending more requests due to GOAWAY frame.

The clean-up code is right after the return statement, causing memory leak.

PoC

  • From H/2 server accept the connection from Envoy.
  • Send MAX CONCURRENT STREAMS = 1
  • After receiving request
  • Send RST_STREAM for the request
  • Send GO_AWAY with max stream is = 0.

Envoy needs a steady stream of requests from a client.

Upon receiving RST_STREAM Envoy frees up stream capacity on a connection and submits headers for the next request.
In the same I/O operation it also processes GOAWAY and marks connection to not send any more requests.
When processing outbound request queue nghttp2 enters the error handling branch due to connection marked for not sending more requests. In this branch there is no clean-up for the outbound request.

Impact

Denial of service through memory exhaustion.

Attack vector(s)

Specifically crafter response from an untrusted upstream service.

Mitigation

None, apart from disabling HTTP/2 protocol for upstream services.

Detection

Process termination due to out of memory conditions. If collection of memory profile is allowed, the profile will show memory consumed from the submit_headers_shared function in the nghttp2_submit.c file.

Credits

Yan Avlasov [email protected]

Severity

High

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
Low
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:L/PR:N/UI:N/S:U/C:N/I:N/A:H

CVE ID

CVE-2023-35945

Weaknesses

No CWEs

Credits