Repository navigation
Bound the size of the PostgreSQL startup message - #115708
Conversation
|
Workflow [PR], commit [47928ab] Summary: ✅
AI ReviewSummaryThe PR hardens the PostgreSQL startup-message path before authentication by rejecting oversized packets, parsing the declared payload through Final VerdictStatus: ✅ Approve LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 16/20 (80.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units11 translation units recompiled, 45 s compile time in total, 11 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
Bounding the declared size of the startup message is not enough on its own: `StartupMessage::deserialize` reads parameter names and values with `readNullTerminated`, which keeps appending to the string until the next `'\0'` arrives, regardless of the declared size. A client could therefore declare a tiny startup packet and then stream an arbitrarily long unterminated parameter, consuming memory before authentication. Wrap the connection in a `LimitReadBuffer` bounded by the declared payload size in `MessageTransport::receiveWithPayloadSize`, so the parser cannot read past the end of the message. The remaining-size check inside `StartupMessage::deserialize` stays as a consistency check within that bounded payload. Add a socket-level test that declares a small startup message and then streams bytes without a terminator. Address review: #115708
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115708&sha=a201a80e7992e32864d0fa026e4acdd612804788&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29 — It is unrelated to this PR (which only touches the PostgreSQL wire protocol): the same logical error has been hit on many unrelated pull requests over the last two months ( |
|
A fix is already in progress: #115786 ("Do not run the server-side AST fuzzer on a collaborative worker context"), mine, open. No new PR needed. I read this off the report's own server log rather than the message text, because this family has two adjacent guards in the same function that one event can trip. Carrier: query
The discriminator: Breadth over 60 days: 9 hits, all in fuzzer-enabled flavours (6 Stress, 3 AST fuzzer) and none outside them, while test 04649 itself ran 53653 times under On #65043: same assertion, but the reproducers recorded there are |
Backport #115708 to 26.6: Bound the size of the PostgreSQL startup message
Backport #115708 to 26.7: Bound the size of the PostgreSQL startup message
Resolved a conflict in `src/Server/PostgreSQLHandler.cpp`: 26.5 has no `classifyNoOpDriverCommand` anonymous-namespace block and no `UNEXPECTED_PACKET_FROM_CLIENT` error code (both come from unrelated master changes), so only the `UNKNOWN_PACKET_FROM_CLIENT` declaration needed by #115708 was kept. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Cherry pick #115708 to 25.8: Bound the size of the PostgreSQL startup message
Cherry pick #115708 to 26.3: Bound the size of the PostgreSQL startup message
Cherry pick #115708 to 26.5: Bound the size of the PostgreSQL startup message
Backport #115708 to 26.5: Bound the size of the PostgreSQL startup message
Backport #115708 to 26.3: Bound the size of the PostgreSQL startup message
Backport #115708 to 25.8: Bound the size of the PostgreSQL startup message
…startup message
PROTO: PostgreSQL wire startup message before auth -> DoS. Effect in the production build a394e92: its upstream test(s) 05037_postgresql_startup_message_size fail on it and pass on official 26.8.8.8, run on isolated servers (evidence/fix_ci_20260925/upstream_repro/server_triage_PROD263_vs_UP2688.tsv). Upstream patch unchanged, with its test(s): 05037_postgresql_startup_message_size. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The startup message of the PostgreSQL wire protocol carries its own size, which is read from the
socket before any authentication, and the message is read into memory in full. The size was not
bounded, so an unauthenticated peer could make the server hold an arbitrary amount of memory per
connection. Bound it at 10000 bytes, the same limit PostgreSQL itself uses.
Bounding the declared size is not sufficient on its own, because
StartupMessage::deserializereadsparameter names and values with
readNullTerminated, which keeps appending to the string until thenext
'\0'arrives, regardless of the declared size. ThereforeMessageTransport::receiveWithPayloadSizenow parses the message through a
LimitReadBufferbounded by the declared payload size, so the parsercannot read past the end of the message.
The guard inside
StartupMessage::deserializethat was meant to catch a message whose parametersrun past the declared size checked the declared size itself, which is a member that never changes,
instead of the remaining size.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Bound the size of the startup message of the PostgreSQL wire protocol, which is read before authentication.
Workflow [PR]
Sync PR [sync-upstream/pr/115708]
Version info
26.7.6.10,26.6.4.14,26.5.8.26,26.3.24.2,25.8.34.3