Repository navigation
Bound the collections read from the Native protocol - #117015
Conversation
Several fields of the protocol are allocated at a size the peer declares before the data behind them arrives, and the collections among them had no bound that the data can plausibly have. In interserver mode `ClientInfo`, the settings and the externally granted roles of a query are deserialized before its secret hash is checked. - The settings and the query parameters of a query are read in a loop that ends on an empty name, with no bound on the number of pairs. - The strings of `ClientInfo` are short metadata - a user name, a host name, a quota key, a user agent, a URL - but were allowed a gigabyte each, and the number of current roles was allowed a billion entries, which is resized before the names are read. The `Hello` packet already bounds its fields. - The same for the externally granted roles. - `TablesStatusRequest` and `TablesStatusResponse` allowed a billion tables. - The obsolete `PartUUIDs` packet let a server make a client read sixteen gigabytes off the socket. `readVectorBinary` now takes the bound as an argument, so a caller that reads from an untrusted peer can pass what the data can plausibly hold.
|
Workflow [PR], commit [67236f3] Summary: ✅
AI ReviewSummaryThis PR hardens Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 67236f3.
Changed lines: Changed C/C++ lines covered: 132/147 (89.80%) · Uncovered code |
`MAX_EXTRA_ROLES` is used in the interserver branch, which is compiled out when ClickHouse is built without SSL, so `-Wunused-const-variable` fails the build.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1963 translation units recompiled, 12034 s compile time in total, 1963 of them have a recent master baseline. |
…rotocol-collection-limits
A bound on the number of elements is not enough: a `String` element is resized to its declared size before its value arrives in the same way the collection is, so a peer can declare a single role name or table identifier of a gigabyte and force the allocation on the same pre-authentication path. - `readVectorBinary` now takes a bound for the element as well, and `ClientInfo::read` and the externally granted roles of `TCPHandler` pass the identifier bound to it. - `TablesStatusRequest::read` and `TablesStatusResponse::read` bound the database and the table name. - The receiver-side limits are documented in the `NativeProtocol` specification. - The test covers the table-status paths, and is renumbered to avoid colliding with the tests merged into master.
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
…rotocol-collection-limits
… protocol The count bound on a settings or parameters sequence does not cover a single pair: a peer could declare a gigabyte-long setting or parameter name and never send it, forcing the allocation before the interserver hash is checked. A name is an identifier, so `BaseSettingsHelpers::readName` bounds it by the same 64 KiB as the strings of the `Hello` packet. The values keep the generic 1 GiB bound: a parameter is query-sized data, and the query text itself has to be read at that bound before the `auth_hash` covering it can be checked, so a tighter bound on values would break large parameters without lowering what a peer can make the server allocate. The test now speaks protocol revision 54459 so it can send a `Parameter` entry, and covers both names. The spec lists the new limit. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
There is one Native-protocol collection this PR does not cover, and I would rather ask than open a parallel PR next to it.
The legitimate content is at most 4 elements: Two measured details that may affect how you want it bounded:
Would you prefer this bounded inside #117015, or should I open a separate PR touching only |
…rotocol-collection-limits Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…gtest Master switched `BaseSettingsHelpers::readString` to `readStringBinaryGrowing` and added `Settings.ADeclaredLengthOnTheSettingsWireIsNotAnAllocation`, which expects a 64 MiB declared name to run out of buffer. With the name bound of this PR the name is refused up front with `TOO_LARGE_STRING_SIZE` instead, so the case now expects that code. `readName` also reads growing, like `readString`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
All three have a fix; the two merged ones are in your master merge
|
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Backport #117015 to 26.9: Bound the collections read from the Native protocol
Backport #117015 to 26.8: Bound the collections read from the Native protocol
…e conflicts The conflicts come from prerequisites that are not on 26.7: the valueless setting helpers (`throwValuelessSettingIsNotBool`, `throwValuelessSettingHasValue`, `formatValueForErrorMessage`), the `http_handler_name` / `http_request_url` fields of `ClientInfo` and the `setClientVersionFromConnectionIfUnknown` tests. Kept the 26.7 code and applied only the changes of #117015 on top of it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflicts of the cherry-pick of #117015 to 26.3 by keeping the 26.3 code and applying only the bounds introduced by the PR: - `Connection.cpp`: 26.3 still reads `part_uuids` with `readVectorBinary`; the obsolete-packet skip path the PR changes does not exist there, so keep the 26.3 code. - `BaseSettings`: add `MAX_SETTINGS_IN_A_SEQUENCE`, `MAX_SETTING_NAME_SIZE`, `readName` and `throwTooManySettings` without the valueless-settings helpers that 26.3 lacks. - `Settings.cpp`: 26.3 has no `readQueryParameters`; query parameters are read through `Settings::read`, which is bounded by the change in `BaseSettings`. Likewise keep `skip_settings.read` for the parameters in `TCPHandler::processUnexpectedQuery`. - `ReadHelpers.h`: add `max_element_size` to the 26.3 `readVectorBinary` signature. - `ClientInfo.cpp`: read the strings with `readStringBinaryGrowing`; 26.3 has no trailing fields and no `current_roles`, so their bounds are dropped. - `TablesStatus.cpp`: add the bounds without the `getAuthDigest` that 26.3 lacks. - `gtest_settings.cpp`: keep the 26.3 peak-memory measurement and check `expected_code`. - Drop `gtest_client_info_read.cpp` and the native protocol doc, which do not exist in 26.3. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #117015 to 26.3: Bound the collections read from the Native protocol
Cherry pick #117015 to 26.7: Bound the collections read from the Native protocol
Backport #117015 to 26.3: Bound the collections read from the Native protocol
Backport #117015 to 26.7: Bound the collections read from the Native protocol
…he Native protocol
Closes: https://github.com/ClickHouse/clickhouse-private/issues/71255
Related: #117011
Several fields of the Native protocol are allocated at a size the peer declares before the data behind them arrives, and the collections among them had no bound that the data can plausibly have. In interserver mode
ClientInfo, the settings and the externally granted roles of a query are deserialized before its secret hash is checked.ClientInfoare short metadata — a user name, a host name, a quota key, a user agent, a URL — but were allowed a gigabyte each, and the number of current roles was allowed a billion entries. TheHellopacket already bounds its fields the same way.TablesStatusRequestandTablesStatusResponseallowed a billion tables.PartUUIDspacket let a server make a client read sixteen gigabytes off the socket.readVectorBinarynow takes the bound as an argument, so a caller that reads from an untrusted peer can pass what the data can plausibly hold. It also takes a bound for aStringelement, because an element is resized to its declared size before its value arrives in the same way the collection is: a single role name or table identifier of a gigabyte would otherwise force the allocation on the same path.The receiver-side limits are documented in the
NativeProtocolspecification.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The collections of the Native protocol — the settings and the query parameters of a query, the client information, the granted roles and the table-status lists — are now bounded, so a small packet can no longer make the server allocate memory for data that has not arrived.
Workflow [PR]
Sync PR [sync-upstream/pr/117015]
Version info
26.10.1.2158-master(included in26.10and later)26.9.17.5,26.8.25.8,26.7.29.11,26.3.50.8