Skip to content

Backport #108508 to 26.4: Enforce access control for MySQL COM_FIELD_LIST and COM_INIT_DB - #109633

Merged
Algunenano merged 2 commits into
26.4from
backport/26.4/108508
Jul 8, 2026
Merged

Algunenano merged 2 commits into
26.4from
backport/26.4/108508

Conversation

@robot-ch-test-poll3

@robot-ch-test-poll3 robot-ch-test-poll3 commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #108508

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.4.5.112

@robot-ch-test-poll3 robot-ch-test-poll3 added pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default labels Jul 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [533a138]

Summary: ✅

`used_privileges` (and `missing_privileges`) rows in `system.query_log`
could contain privilege strings from completely unrelated earlier queries
of a different user, database, and session that had finished much earlier.

`Context::makeQueryContext` seeded the new query's `QueryPrivilegesInfo`
by copying the contents of the parent context's object:

    query_privileges_info = std::make_shared<QueryPrivilegesInfo>(*query_privileges_info);

The parent is the session (or global) context. Session contexts are
created via `createCopy(global_context)` and never call `makeQueryContext`,
so the session and global contexts share a single `QueryPrivilegesInfo`
object. Any privilege string that ever landed in that shared object — and
partial state observed when the copy raced a concurrent writer — leaked
into the `used_privileges` of unrelated later queries. The one-directional
spread and the 1-2 partial entries per polluted row match a copy-vs-write
race against this shared object.

A new query has checked no privileges yet, so there is nothing legitimate
to inherit. Seed every query with an empty `QueryPrivilegesInfo`. Child
contexts created via `createCopy` still share the query's object, so
sub-operations correctly contribute to the same query's `used_privileges`.

Added a deterministic unit test `MakeQueryContextDoesNotInheritPrivileges`
that pollutes a parent context's privileges, derives a query context, and
asserts the query starts clean and that its checks do not bleed back into
the parent.

Closes: #105983

CI report:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=fa6d98d95368955ee5619a28a21527da7a9b83cb&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20distributed%20plan%2C%20parallel%2C%202%2F2%29

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
(cherry picked from commit 3a3c454)
@Algunenano
Algunenano merged commit 2598958 into 26.4 Jul 8, 2026
35 checks passed
@Algunenano
Algunenano deleted the backport/26.4/108508 branch July 8, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only! pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants