Skip to content

Cherry pick #117003 to 26.3: Bound the MySQL handshake response - #118073

Merged
robot-clickhouse-ci-2 merged 12 commits into
backport/26.3/117003from
cherrypick/26.3/117003
Sep 7, 2026
Merged

robot-clickhouse-ci-2 merged 12 commits into
backport/26.3/117003from
cherrypick/26.3/117003

Conversation

@robot-ch-test-poll4

Copy link
Copy Markdown
Contributor

Original pull-request #117003

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-pick locally.
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.

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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

On the TLS path the handshake response was read through
`MySQLPacketPayloadReadBuffer`, which follows a chain of maximum-size packets as
one logical message, and the fields inside the response are read up to a
terminator. A peer that completed the TLS handshake could therefore stream data
and make the server grow memory before sending any credentials.

Bound the response on both paths: the plaintext path rejects a declared payload
larger than 64 KiB before reading it, and the TLS path, where the framing is
handled by the packet endpoint, reads through a buffer limited to the same size.
A real handshake response is a few hundred bytes.
…path

Address review: limiting the underlying stream under `PacketEndpoint` was not
enough. `MySQLPacketPayloadReadBuffer` reports end of file as soon as the stream
below it ends, and `IMySQLReadPacket::readPayload` treats that as "the whole
packet was consumed", so a stream cut off exactly at the limit would make a
truncated packet look like a complete one: a peer could declare a payload of
`0xFFFFFF` and have the parsed prefix end at the limit.

Read the packet header on the TLS path as well, reject a declared payload larger
than the bound before reading it, and then read exactly as many bytes as the
header declares, which mirrors the plaintext path. Add a test case for a packet
that declares a maximum-size payload while carrying a complete, parseable prefix.
…ual transport state

`mysql_require_secure_transport` was checked against the client-advertised
`CLIENT_SSL` capability bit. A client can set that bit in a plaintext
`HandshakeResponse` without ever sending an `SSLRequest`: it then stays on the
non-TLS branch of `finishHandshake`, `secure_connection` remains false, and the
gate still lets authentication proceed over cleartext.

Key the check off `secure_connection`, which is set only when the TLS transition
actually happened, and add a focused integration test that drives a plaintext
handshake advertising `CLIENT_SSL` against a server with
`mysql_require_secure_transport`.
The test used the `default` user, which needs a password, so the handshake was
rejected by authentication rather than by the gate. Drive it with a
`no_password` user instead: without the fix the server now replies with an OK
packet on the unencrypted connection, which is exactly the bypass.
…ze-limit

Bound the MySQL handshake response
@robot-ch-test-poll4 robot-ch-test-poll4 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Sep 4, 2026
@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Dear @thevar1able, @alexey-milovidov, this cherry-pick PR has not been updated for 3d0h25m36s. Please resolve the conflicts to backport #117003, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants