Skip to content

Build with -fstack-clash-protection and -z separate-code - #123073

Merged
Algunenano merged 3 commits into
ClickHouse:masterfrom
Algunenano:harden-stack-clash-separate-code
Oct 1, 2026
Merged

Algunenano merged 3 commits into
ClickHouse:masterfrom
Algunenano:harden-stack-clash-separate-code

Conversation

@Algunenano

@Algunenano Algunenano commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

Two more hardening flags for the binary, following PIE, -fstack-protector-strong and full RELRO.

-fstack-clash-protection makes the compiler touch every page of a large stack allocation, so it cannot skip past a thread's guard page into another mapping. Only functions with frames larger than a page get the extra probes.

-Wl,-z,separate-code places read-only data in segments that are not executable, so those bytes cannot be used as ROP gadgets. lld does not do this by default.

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Build the clickhouse binary with -fstack-clash-protection and -Wl,-z,separate-code to make exploiting memory bugs harder.


Workflow [PR]
Sync PR [sync-upstream/pr/123073]

Version info

  • Merged into: 26.10.1.1154-master (included in 26.10 and later)

`-fstack-clash-protection` probes every page of a large stack allocation so it
cannot jump over a thread's guard page. `-Wl,-z,separate-code` keeps read-only
data out of executable segments, removing it as a source of ROP gadgets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6ecd3f0]

Summary: ✅


AI Review

Summary

This PR hardens executable builds by enabling -fstack-clash-protection on the supported Clang/architecture combinations and -Wl,-z,separate-code on non-Darwin, non-WebAssembly executable links. The current diff already addresses the earlier RISC-V64 concern by removing ARCH_RISCV64 from the -fstack-clash-protection allowlist, and I did not find any remaining correctness, safety, or contract issues in the updated change.

Final Verdict

Status: ✅ Approve

LLVM Coverage Report

Measured on commit 6ecd3f0.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Uncovered code analysis did not run: No coverable C/C++ source files changed (contrib/ is excluded from coverage).

Newly covered: +169 lines in 59 files (-83 lines lost coverage) · Details

Full report

@clickhouse-gh clickhouse-gh Bot added pr-build Pull request with build/testing/packaging improvement comp-build-system Build system (CMake, compilation, platform builds). labels Sep 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6ecd3f09b with master 253f06071 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

16117 translation units recompiled, 32786 s compile time in total, 15608 of them have a recent master baseline.

Translation unit Master PR Δ vs median
contrib/grpc-cmake/__/grpc/src/core/filter/fused_filters.cc 7.0 s 12.5 s +5.3 s (+73%)

Job report

…ed targets

Clang ignores `-fstack-clash-protection` on Darwin, WebAssembly and LoongArch, which fails the `-Werror` builds. Skip `-z separate-code` on WebAssembly.

CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123073&sha=ca5ce5576b7fed321f83f1e30fc9b779158feb15&name_0=PR

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Comment thread CMakeLists.txt Resolved
@alexey-milovidov alexey-milovidov self-assigned this Oct 1, 2026
@Algunenano
Algunenano added this pull request to the merge queue Oct 1, 2026
Merged via the queue into ClickHouse:master with commit adfa48c Oct 1, 2026
150 checks passed
@Algunenano
Algunenano deleted the harden-stack-clash-separate-code branch October 1, 2026 10:49
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-build-system Build system (CMake, compilation, platform builds). pr-build Pull request with build/testing/packaging improvement pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants