fix(runtime): cap H2 control-frame output to stop PING-flood DoS/crash
MOLO-H2-004 (CVE-2019-9511/9512/9515/9518 class): a client that floods PING frames without draining its socket crashed runtime_interop_server after ~100-150k frames. Root cause, confirmed with an ASan build, is a stack overflow, not heap growth: EventLoop::post()/the Task<T> continuation resume synchronously when work is already buffered, so H2Connection::ReadLoop's frame loop never returns to EventLoop::run_once()'s flat dispatch while a burst of already-read frames remains; each frame nests the native stack one level deeper (ReadLoop -> Ensure -> ReadLoop -> ...) until it overflows. ReadLoop now forces a co_await loop().yield() every caps::kH2FramesPerYield frames, unwinding the stack back to run_once() regardless of burst size. Separately, EnqueueControl/EnqueueData/CompleteResponse had no ceiling on out_queued_bytes_ for H2, unlike the H1 path's out_.size() check in runtime/http/connection.cpp. Added EnforceWriteCap(), using a new, tight caps::kH2MaxPendingControlBytes for control output (PING/SETTINGS acks, RST, WINDOW_UPDATE, GOAWAY) and the existing kWriteBufferCeiling for DATA/response output, same as H1. Because the kernel's own TCP send buffer keeps draining small control frames even while the peer never reads, out_queued_bytes_ alone can stay near zero through a flood, so also added a monotonic caps::kH2MaxControlFramesPerConnection rate cap in EnqueueControl as the mechanism that actually bounds this class of abuse; exceeding either cap drops the connection via Fatal(). audit/MOLO-H2-004 now PASSes repeatably: the connection is cut well before all 300k PINGs are accepted, and the server stays up with bounded RSS. All 134 runtime unit tests (including the H2 suite) still pass. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -87,6 +87,13 @@ class H2Connection : public std::enable_shared_from_this<H2Connection> {
|
||||
|
||||
void EnqueueControl(uint32_t stream_id, const std::string& frame_bytes);
|
||||
void EnqueueData(uint32_t stream_id, std::string payload, bool end_stream);
|
||||
// Backpressure floor: a peer that stops draining (e.g. a PING flood that
|
||||
// never reads the socket) must not be allowed to grow out_queue_ without
|
||||
// bound. Checked after every append to out_queued_bytes_; trips Fatal()
|
||||
// once `ceiling` is crossed. Callers pass caps::kH2MaxPendingControlBytes
|
||||
// for control output or caps::kWriteBufferCeiling (shared with the H1
|
||||
// path in runtime/http/connection.cpp) for DATA/response output.
|
||||
void EnforceWriteCap(std::size_t ceiling);
|
||||
void KickWriter();
|
||||
void WakeWriter();
|
||||
void SendSettingsAck();
|
||||
@@ -127,6 +134,9 @@ class H2Connection : public std::enable_shared_from_this<H2Connection> {
|
||||
std::deque<OutItem> out_queue_;
|
||||
// Payload bytes currently queued; bounds file-body streaming.
|
||||
std::size_t out_queued_bytes_ = 0;
|
||||
// Lifetime count of control frames queued to send; see
|
||||
// caps::kH2MaxControlFramesPerConnection.
|
||||
std::size_t control_frames_sent_ = 0;
|
||||
void UnqueueBytes(std::size_t n) {
|
||||
out_queued_bytes_ -=
|
||||
n > out_queued_bytes_ ? out_queued_bytes_ : n;
|
||||
|
||||
Reference in New Issue
Block a user