Repository navigation
Cherry pick #118588 to 26.3: Do not deserialize a Data packet that arrives before any query - #119693
Conversation
TCPHandler::receivePacketsExpectQuery() handles the packets that arrive
before any Query has been received. Its Data/Scalar case called
processUnexpectedData() and only then threw UNEXPECTED_PACKET_FROM_CLIENT.
That call builds a headerless NativeReader and reads a block, so the
column type name comes off the wire and is handed to DataTypeFactory.
Entering interserver mode requires only the name of a cluster that has a
non-empty <secret>, never the secret itself, and the secret is verified
only inside processQuery(), which this loop never reaches. So an
unauthenticated peer decided which type the server constructed and which
deserializer ran.
The read had no consumer for any peer either: its return value was
discarded, and the exception thrown right after is caught where
"if (!query_state) return;" exits runImpl, so the exception is never
sent, the connection is closed, and no further byte is read from the
socket. runImpl's exception handler already documents that policy ("the
server should not try to skip (parse, decompress) the remaining packets
sent by the client, as it will lead to additional work and unneeded
exposure to unauthenticated connections"); the parse it forbids had
already happened one frame earlier. The adjacent case of the same
switch, processObsoleteIgnoredPartUUIDs(), was given exactly this shape
in #99398.
No setting gates the rejection, deliberately. The TablesStatusRequest
path needed an operator opt-out when it was hardened in #99854 because
it was a served path, and rejecting it broke rolling upgrades (#113602).
Data before Query has always thrown, so there is no working flow to
preserve, and nothing a client can observe changes: the connection
closes with nothing written back, before and after.
The regression test completes an accepted interserver handshake over a
raw socket and then sends a Data packet declaring a column type that
does not exist. Without this change the server logs "Unknown data type
family: NoSuchTypeGroeneAI", which is the proof that a wire-supplied
type name reached DataTypeFactory before authentication. It is extended
into the existing pre-authentication interserver test module rather than
added as a new one, because that module already provides the cluster
with a <secret> and a handshake pinned below the chunked-packets
revision, which is what makes a hand-built packet feasible.
Requested by @ nikitamikhaylov, relayed via OranjeAI.
Co-Authored-By: Claude Opus 5 <[email protected]>
The regression test sent the complete Data packet and then asserted only that no data type had been constructed. That is a subset of what the change claims: a handler that read the external table name and only then threw would touch peer-supplied payload bytes and still pass the test. The test function now opens a second connection that sends the Data packet type alone, one byte, and shuts down its write side. On a server without the fix the external-table-name length varint inside processUnexpectedData() hits end of stream, so UNEXPECTED_PACKET_FROM_CLIENT is never constructed and the rejection is never logged; measured, that arm fails with "Attempt to read after eof" raised from readStringBinary one frame below processUnexpectedData(). With the fix the rejection is immediate, because no payload byte is required. The handshake and the bounded log barrier are factored into helpers so the second connection reuses them; both are used by the new test only, and the two pre-existing tests keep their own inlined handshake unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
The native protocol spec describes READY as the state where the client may send Ping, Query or close, and, unlike the handshake, ping and query phases, it gives no outcome for anything else. A client author reading it cannot learn what happens if they send a Data packet there, which is precisely the packet this change stops the server from decoding. State the three facts: it is a protocol violation and the connection is terminated, no Exception packet is sent first so the client observes a silent close, and the body is not decoded. The silent close is general rather than interserver-specific: query_state is always null in the loop that reads pre-query packets, so runImpl's handler returns before any send for every peer. Scalar is named alongside Data because both share the same case label. The sentence is deliberately not written as "anything other than Ping or Query", which would be wrong: TablesStatusRequest is served from READY and Cancel is accepted and ignored. Co-Authored-By: Claude Opus 5 <[email protected]>
The module comment stated that a packet arriving before the Query must neither disclose anything nor have its payload deserialized. Two pre-query paths contradict that by design, not by omission: processTablesStatusRequest reads the request body before validating the hash, because the hash is computed over that body, and Ping is answered with Pong. A reader who takes the sentence as the module's invariant concludes the hardened TablesStatusRequest path is buggy. Scope the claim to the packets the server rejects. The legitimately served pre-query packets are not enumerated here; the protocol spec carries that. Co-Authored-By: Claude Opus 5 <[email protected]>
The module comment claimed that a packet the server rejects before the Query must disclose nothing and must not have its payload deserialized. The second half is false for two pre-query paths, one of which this very comment enumerates: processTablesStatusRequest() deserializes the request body at TCPHandler.cpp:1711 before comparing digests at :1738, because the digest binds request.getAuthDigest(), so a wrong-secret request is rejected only after its payload has been read. processUnexpectedHello() likewise drains seven bounded fields and then throws. A reader who checks the module's second bullet, a TablesStatusRequest signed with the wrong cluster secret, against the sentence above it finds them contradictory. Only a rejected Data or Scalar packet leaves its payload untouched, so the payload clause now names Data. The disclosure clause holds for every rejected packet and is unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
The READY row of the protocol spec said the client "observes a silent close". The server rejects the packet without reading its body, so unconsumed bytes can still be queued when the socket closes and the client can see a TCP reset instead. The sibling reject-before-read path behaves the same way on master, which is why its test accepts ConnectionResetError. Stating the reset outcome keeps a client author from treating it as a protocol bug.
Both comments said the cluster secret is only verified while the Query packet is processed. That is not true: a new-protocol TablesStatusRequest validates a secret-derived hash of its own before any Query, which the module's wrong-secret test exercises. What stays unauthenticated until the Query packet is the connection, which is what is_interserver_authenticated tracks and what makes an early Data packet peer-controlled input.
…ation failure Not reading the payload is the point of the previous commit, but throwing `UNEXPECTED_PACKET_FROM_CLIENT` for it also renames the case: an interserver connection that has not reached its `Query` packet is unauthenticated, and `runImpl` has a dedicated answer for `AUTHENTICATION_FAILED` in interserver mode. Throw that instead, and keep `UNEXPECTED_PACKET_FROM_CLIENT` for an ordinary client. `CH Inc sync` found this: a test there asserts the guard's log line for exactly this shape, and it stopped appearing once the packet was rejected earlier. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A Data packet arriving before any Query on an unauthenticated interserver connection is now reported as AUTHENTICATION_FAILED, so "Unexpected packet Data received from client" is no longer logged on the path this test drives: both log barriers waited out their 60s timeout and the test failed even with the guard working. Measured here, the old needle never appears at all (assert 0 > 0 after 84s); the new one appears within the barrier, and the test passes 50/50. Matching the interserver wording rather than a signal shared by both exception codes keeps the assertion tied to the unauthenticated case: a connection that stopped reaching interserver mode would otherwise still satisfy it. With src/Server/TCPHandler.cpp reverted to master the test still reddens on the deserialization assertion (assert 1 == 0), so the oracle is no weaker than before. Co-Authored-By: Claude Opus 5 <[email protected]>
…ket-unread Do not deserialize a Data packet that arrives before any query
|
I authored #118588, so here is what I measured on this cherry-pick. I cannot resolve it myself: hand-authoring a backport or pushing to a robot branch is off-limits for me under the standing rule from @ pufit, and I hold The conflict is structural, not textual. The diff touches 3 paths and 2 of them do not exist on
The module arrived on master in The source hunk itself would apply. Its pre-image is byte-identical on every branch ( One timing fact before this lapses. The dispositions I see are: resolve these two by hand, or close them and accept the fix on |
Resolve the two modify/delete conflicts by dropping the paths that do not exist on 26.3: the `NativeProtocol` spec page (no such page in the 26.3 tree) and the `test_interserver_tables_status_auth` integration test module (added on master after 26.3 was cut). The backport is source-only: the `TCPHandler.cpp` hunk applied cleanly and everything it relies on (`is_interserver_mode`, `is_interserver_authenticated`, `ErrorCodes::AUTHENTICATION_FAILED`) is present on 26.3. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Resolved by hand as a source-only backport, as you laid out: the two modify/delete conflicts (the |
Original pull-request #118588
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job