Repository navigation
Fix pure-virtual call in printPipeline for a dangling output peer - #110955
alexey-milovidov merged 10 commits into
Conversation
…dangling output peer printPipeline followed each processor's output port to the peer processor via getInputPort().getProcessor(). A port stays connected (its shared State is ref-counted) and keeps the raw peer pointer even after the peer processor is destroyed, so during streaming-query pipeline teardown the debug-only exception dump dereferenced a freed peer: the node-label loop virtual-dispatched getUniqID() -> pure-virtual getName() (SIGABRT), and the edge loop read the freed peer (heap-use-after-free under ASAN). printPipeline no longer dereferences a processor reachable only through a port: the out-of-collection node-label loop is removed and edges are matched between the passed processors through the shared port-connection identity. Output for well-formed pipelines is unchanged. Related: ClickHouse#110834 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-author-slot-2:20260718-194700 |
Internal second-model review — adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-author-slot-2:20260718-194700 |
|
cc @yariks5s @vdimir — could you review this? It fixes the pure-virtual abort in |
|
Workflow [PR], commit [73d641a] Summary: ✅
AI ReviewSummaryThis PR rewires Findings❌ Blockers
Final Verdict
|
CI finish ledger — b11a3d8Every failure below has an owner (a fixing PR). None are caused by this PR's diff (a debug/CI-only
Session id: cron:our-pr-ci-monitor:20260719-063000 |
…angling-output-peer
| /// Lets diagnostics match an output port to its peer input port without dereferencing the | ||
| /// peer processor, whose lifetime is not guaranteed during pipeline teardown. Opaque on | ||
| /// purpose: only pointer identity is meaningful. | ||
| const void * getConnectionId() const { return state.get(); } |
There was a problem hiding this comment.
printPipeline is safe after this change, but the same dangling-peer dereference is still present in processor-profile collection. ExecutingGraph::removeNode erases finished processors from the shared Processors list and delayed_destruction frees them before the post-execution logging passes run; after that, a surviving output port can still be isConnected() while output.getInputPort().getProcessor() is dangling.
We still call IProcessor::getProcessorsProfileLogInfo on that mutated list from finalizeQueryPipelineBeforeLogging, PreparedSets, and scalar-subquery logging, and that method still does the raw peer dereference. So this patch removes the UAF from printPipeline, but the same shape can still blow up on successful query completion / profile logging. Please switch the parent_ids walk to the same getConnectionId()-based lookup (or otherwise skip peers whose owning input processor is no longer present).
There was a problem hiding this comment.
Verified: this finding is real. IProcessor::getProcessorsProfileLogInfo() (src/Processors/IProcessor.cpp:166-172) does the identical peer deref this PR removed from printPipeline: it walks outputs, checks isConnected(), then port.getInputPort().getProcessor(), and getProcessor() (Port.h:258) reads the peer input port's processor inside a possibly-freed peer. finalizeQueryPipelineBeforeLogging calls it at src/Interpreters/executeQuery.cpp:634, right beside the printPipeline call at :639, over the same getProcessors() list, and unlike dumpPipeline it is not #ifndef NDEBUG and not gated by log_processors_profiles, so it is release-reachable on normal query finish.
This PR stays scoped to the reported debug-only printPipeline/dumpPipeline crash (#110834) and is already approved. The release-reachable profile-log UAF is a distinct, higher-severity issue; folding it in would rebuild an approved PR around a broader change. I will fix it in a separate follow-up PR that switches the parent_ids walk to the same getConnectionId()-based lookup (skip peers whose owning input processor is not in the set). Tracked separately.
There was a problem hiding this comment.
Follow-up opened: #111019. It moves the parent_ids walk into the free getProcessorsProfileLogInfo(const Processors &) and matches ports by getConnectionId() shared-state identity, so the peer processor is never dereferenced. Regression gtest reproduces the release heap-UAF under ASAN without the fix and passes with it.
There was a problem hiding this comment.
Status update on this thread: the follow-up #111019 was closed today by @yariks5s with CHANGES_REQUESTED. The objections there are about the design of the profile-log fix, not about its memory-safety claim — that getProcessorsProfileLogInfo would stop populating parent_ids, that it changes system.processors_profile_log semantics for peers absent from the supplied set, that it adds a hash-map allocation on every successful-query finish path even when processor-profile logging is disabled, and that matching by connection id works around the dangling pointer rather than fixing the port/processor lifetime. @yariks5s noted they will come back to it.
So the release-reachable dereference this thread points at is still real and now has no open PR behind it; it is waiting on a maintainer design call on how to fix it (connection-id lookup vs. fixing the lifetime so a connected port never outlives its peer). Recording that here so the thread is not read as "already handled elsewhere".
This PR stays scoped to the debug-only printPipeline/dumpPipeline path that @alexey-milovidov approved. Folding the profile-log change in here would import exactly the design question that is still open, into an approved and otherwise green PR.
There was a problem hiding this comment.
Tracking issue opened for this finding so it is not lost now that #111019 is closed: #112320. It records the release-reachable path (logQueryFinish -> getProcessorsProfileLogInfo), the confirmation from this thread, and the design objections that closed #111019, so whoever picks it up starts from the open question rather than from the rejected patch.
This pull request stays scoped to the debug-only printPipeline / dumpPipeline fix that was approved here; folding the profile-log fix back in would re-import an unresolved design question into it.
…angling-output-peer
…angling-output-peer
…angling-output-peer
|
@groeneai, investigate the failure: https://github.com/ClickHouse/ClickHouse/actions/runs/30141497100/job/89654934179 — This is unrelated to this PR (the diff only touches I could not find an existing tracking issue for it. Please file one and provide a fix in a separate PR, or link the fix here if it is already in progress. |
|
@alexey-milovidov, the failure is tracked and the fix is in progress: issue #110518, fix PR #111689 ( Your search missed the issue because Signal 6, query The only occurrence of from CIDB shows the same STID under both labels in the same check (7 days, On the cause: the query log entry for the aborting query has The |
CI finish ledger - 1a48aadEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Fast test and Style check are green on this head. Session id: cron:our-pr-ci-monitor:20260726-163000 |
…angling-output-peer
CI finish ledger - 169b823Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
This head is a plain merge of PR-caused gate: ZERO. Session id: cron:our-pr-ci-monitor:20260727-073000 |
|
Discharging the finish-ledger line for the Fixing PR: #112045 (@ alexey-milovidov, open) adds a Root cause, for the record: for the whole-second units the Note for anyone matching this signature later: it is recorded under at least three different STID |
…angling-output-peer
CI finish ledger - 92b763bEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
This head is @alexey-milovidov's plain merge of Cleared versus the Session id: cron:our-pr-ci-monitor:20260728-110000 |
…angling-output-peer
| out << " n" << current_proc_id << " -> n" << get_proc_id(next) << ";\n"; | ||
| /// Only draw the edge if the peer input port belongs to a processor in this set. | ||
| auto it = input_connection_to_id.find(port.getConnectionId()); | ||
| if (it == input_connection_to_id.end()) |
There was a problem hiding this comment.
printPipeline is also used on malformed-but-live processor sets in the PipelineExecutor constructor catch (PipelineExecutor.cpp:128-135), immediately after ExecutingGraph::addEdge throws because a connected peer is missing from processors (ExecutingGraph.cpp:77-86). In that path the peer is not dangling, so the removed unmatched-output rendering was the only place the appended DOT dump kept the missing node and edge. After this continue, the exception still gives only to->getName(), but the graph no longer shows which edge is broken, which becomes ambiguous once several processors share that name.
Can we keep a synthetic node and edge for unmatched getConnectionId() values (or otherwise preserve the missing-peer information in the appended pipeline dump) instead of dropping them entirely?
There was a problem hiding this comment.
Verified the mechanism, and it is partly right, but the requested remedy is not implementable without reintroducing the crash.
Correct: PipelineExecutor.cpp:120-136 is a second caller of the branch I removed, it is not #ifndef NDEBUG, and in that path the peer really is live rather than dangling. ExecutingGraph's constructor adds every node before any edge (ExecutingGraph.cpp:30-36), so when addEdge throws at :77-86 the absent peer is a live processor that is merely outside the collection. And getUniqID is getName()_processor_index with a per-thread counter (IProcessor.h:139, IProcessor.cpp:29), so it does disambiguate same-named processors.
One correction: the exception is not limited to to->getName(). It reads "Processor {to} was found as {input|output} for processor {from}, but not found in list of processors", so both endpoints of the broken edge and its direction are already reported. What the removed loop added on top was the numeric suffix.
Why I cannot keep a synthetic node for unmatched getConnectionId() values: the connection id is safe as a key, because the shared Port::State outlives either side, but it carries no peer identity. Port::State (Port.h:55-152) has exactly one data member, std::atomic<Data *> data, holding a chunk, an exception and three flag bits; grepping its body for IProcessor, InputPort, OutputPort or processor returns nothing. The peer's name is reachable only through port.getInputPort().getProcessor() (Port.h:487, :250), which is precisely the dereference that aborts on a freed peer. So a synthetic node could only be an anonymous placeholder, and it would add nothing beyond what the exception message already prints.
It would also not be free elsewhere. printPipeline has nine callers, and only this one and QueryPipeline.cpp:84 are malformed-set paths. The rest pass well-formed sets, including executeQuery.cpp:651 on successful query finish, ProcessorsProfileLog.cpp:160, and user-facing EXPLAIN PIPELINE graph=1 (InterpreterExplainQuery.cpp:1130, :1148). Emitting placeholder nodes unconditionally would put phantom nodes into EXPLAIN output and into successful-query profile dumps whenever a set legitimately omits a peer.
The useful version of this lives one layer up rather than in the dump: ExecutingGraph::addEdge can print to->getUniqID() instead of to->getName(), which is safe there because the peer is alive and the line already dereferences it. That recovers the suffix for exactly the path you are describing, in one line, without any placeholder rendering. I have filed it as a separate follow-up rather than folding it in here, since it is a different file and a different concern, and this pull request is approved, green and deliberately scoped to the debug-only dump path.
There was a problem hiding this comment.
The follow-up described above is now filed: #112745. It changes the ExecutingGraph::addEdge exception to name both endpoints of the broken edge via getUniqID instead of getName, which restores the numeric disambiguation for the malformed-graph path without any placeholder rendering in the dump.
CI finish ledger - 2b46255Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All 174 check-runs on this head are It is not caused by this diff, which touches Session id: cron:our-pr-ci-monitor:20260730-180000 |
|
Correction to the owner column of my CI finish ledger for The The failing statement is A 14-day settings fingerprint over the non-flaky-check rows, with the host-OOM rows excluded, shows Nothing changes for this PR: the failure is still not caused by its diff, and nothing was pushed. |
…angling-output-peer
CI finish ledger - 9354e30Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260801-003000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 50/52 (96.15%) · Uncovered code |
|
Following up on the I opened #113610 for it, but only for the cost of that failure, not its cause: |
When `ExecutingGraph::addEdge` finds a connected peer that is missing from the list of processors, the thrown `LOGICAL_ERROR` named both endpoints of the broken edge via `getName`, which is ambiguous when several processors share a name. Use `getUniqID` (the name plus the per-thread processor index) for both endpoints instead; both processors are alive at this point, so the call is safe. This recovers the disambiguation previously provided by the out-of-set node rendering that was removed from `printPipeline` in ClickHouse#110955. Related: ClickHouse#110955 Co-Authored-By: Claude Fable 5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Description
Fixes the pure-virtual abort in
printPipeline/dumpPipelinereported in #110834 (found by thetargeted AST fuzzer,
AST fuzzer (amd_debug, targeted)).printPipelinewalked each processor's output ports to the peer processor viaport.getInputPort().getProcessor(). APortstaysisConnected()(its sharedStateisref-counted) and keeps the raw peer
IProcessor*even after the peer processor is destroyed. Whena streaming query's pipeline is expanded/torn down, a downstream processor can be removed and freed
while a survivor still references it through a port. The debug-only exception dump
(
PipelineExecutor::execute->dumpPipeline->printPipeline) then dereferenced that freedpeer: the "outputs not in
processors" loop calledgetUniqID()-> pure-virtualgetName()(the reported
__cxa_pure_virtualabort), and the edge loop readgetInputPort().getProcessor()(heap-use-after-free under ASAN). Release builds do not call
dumpPipeline, so they are unaffected.Fix:
printPipelineno longer dereferences a processor reachable only through a port. Theout-of-collection node-label loop is removed, and edges are now matched between the passed
processors through the shared port-connection identity, so no peer processor is touched. Output for
well-formed pipelines is unchanged.
Added a unit test that reproduces the crash (a survivor whose output port points at a destroyed
peer) and asserts edges are still rendered for a well-formed pipeline.
Version info
26.8.1.619(included in26.8and later)