Repository navigation
Enable -fstack-protector-strong - #119684
alexey-milovidov wants to merge 1 commit into
Conversation
An overflow of a stack local currently corrupts the frame silently: nothing in the build emits a canary, and `_FORTIFY_SOURCE` is not set either, so a `memcpy` with an unchecked length simply writes through its destination and, about two kilobytes further on, through the saved return address. `-fstack-protector-strong` instruments every function with a local array, a local whose address is taken, or a variable-length allocation, which is the shape such bugs actually take. The plain `-fstack-protector` is not enough: it covers only character arrays of at least eight bytes, so it would not have instrumented the `BIT` column overflow fixed in #119680, whose destination was a `UInt64` whose address was taken. Measured on an aarch64 release build, per translation unit, against the real compile commands: Columns/ColumnVector +1.92% text, 28% of functions canaried Interpreters/Aggregator +2.13% text, 72% Parsers/ExpressionElementParsers +2.63% text, 32% Processors/Sources/MySQLSource +3.06% text, 34% A microbenchmark on Neoverse V2 puts the cost at +0.85 ns per instrumented call, which is +78% for a function whose body is four instructions and below the noise floor once a call processes a block of values: summing 65528 elements per call measured -0.04%, i.e. no difference. ClickHouse spends its time in the latter shape, but it has plenty of the former in the parser and the analyzer, which is what the performance tests need to price. Draft: opened to get a performance comparison and a full CI run. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Workflow [PR], commit [e5bcc6f] Summary: ❌
AI ReviewSummaryThis PR enables Tests
Final VerdictStatus: Minimum required action: provide real ClickHouse-level before/after performance evidence for the global LLVM Coverage ReportMeasured on commit e5bcc6f.
Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage). Newly covered: +271 lines in 73 files (-170 lines lost coverage) · Details |
| # address. `-strong` rather than the plain `-fstack-protector`, which covers only character arrays | ||
| # of at least eight bytes and so misses, for instance, a `memcpy` into an integer local whose | ||
| # address was taken. | ||
| set (COMPILER_FLAGS "${COMPILER_FLAGS} -fstack-protector-strong") |
There was a problem hiding this comment.
The rollout contract here is not just "pass the build" but "enable this globally without an unacceptable cost on real ClickHouse workloads." Right now the PR still has no ClickHouse-level before/after data: the dedicated Performance Comparison reports for this commit are empty because the PR is not labeled pr-performance, so the only evidence is a synthetic microbenchmark plus a few translation-unit text-size deltas. Given that the description itself calls out parser/analyzer code as the sensitive call-bound case, please run the standard perf comparison (or attach equivalent focused before/after measurements on those paths) before merging.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. The official master build is compiled with Compile time of recompiled translation units16007 translation units recompiled, 31074 s compile time in total, 15538 of them have a recent master baseline.
|
alexey-milovidov
left a comment
There was a problem hiding this comment.
No significant degradations.
|
Duplicated: #119039 |
An overflow of a stack local currently corrupts the frame silently. Nothing in the build emits a canary, and
_FORTIFY_SOURCEis not set either, so amemcpywith an unchecked length just writes through its destination and, about two kilobytes further on, through the saved return address.-fstack-protector-stronginstruments every function that has a local array, a local whose address is taken, or a variable-length allocation, which is the shape these bugs actually take. The plain-fstack-protectoris not enough: it covers only character arrays of at least eight bytes, so it would not have instrumented theBITcolumn overflow fixed in #119680, whose destination was aUInt64whose address had been taken. I verified both claims by disassembling the real object files.Measured per translation unit on an
aarch64release build, using the actual compile commands:Columns/ColumnVectorInterpreters/AggregatorParsers/ExpressionElementParsersProcessors/Sources/MySQLSourceFor reference,
-fstack-protector-allcosts +10.4% and +12.4% of text on the latter two.Runtime, on Neoverse V2, minimum over five interleaved runs of fifteen repetitions:
-fstack-protector-strongSo the cost is +0.85 ns per instrumented call, invisible in vectorised code and real in call-bound code. ClickHouse spends its time in the former shape but has plenty of the latter in the parser and the analyzer, which is exactly what the performance tests are for - hence this draft.
One consequence to accept deliberately: this converts silent corruption into
SIGABRT, so a latent overflow becomes a server restart rather than continued execution on a corrupted frame.Related: #119680
Related: #119685
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Build with
-fstack-protector-strong, so that an overflow of a stack local aborts immediately instead of silently corrupting the stack frame.Workflow [PR]
Sync PR [sync-upstream/pr/119684]