Repository navigation
CI: add weekly Control-Flow Integrity (CFI) build and test job - #100419
Conversation
|
Workflow [PR], commit [1e59c64] Summary: ✅
AI ReviewSummaryThis PR adds Final Verdict✅ No remaining blocker or major findings. |
|
Let's run it weekly |
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
|
The test |
|
The MSan stress test failure (MemorySanitizer: use-of-uninitialized-value, STID 4179-5154 or 4148-3044) is a known pre-existing issue unrelated to this PR. Fix: #102158 |
Adds support for building ClickHouse with Clang CFI (`-fsanitize=cfi-vcall,cfi-derived-cast`) and a monthly CI workflow that builds with CFI and runs the stateless functional test suite. **Why:** CFI detects vtable type confusion bugs (wrong virtual dispatch target, bad `static_cast` downcast) that ASan/TSan miss. ClickHouse release builds already use ThinLTO (`-flto=thin`) and `-fwhole-program-vtables`, so CFI adds minimal compile overhead — the LTO pass is already paid for. Runtime overhead is ~2–5% on virtual-call-heavy paths. `cfi-icall` is intentionally omitted for now to avoid false positives from C function pointers in contrib libraries compiled without CFI instrumentation. **Changes:** - `cmake/sanitize.cmake`: new `ENABLE_CFI` option; errors if combined with `SANITIZE=` (which would disable ThinLTO) - `CMakeLists.txt`: CFI flags appended to the `RelWithDebInfo` ThinLTO block when `ENABLE_CFI=ON` - `ci/defs/defs.py`: new `BuildTypes.AMD_CFI` and `ArtifactNames.CH_AMD_CFI` - `ci/jobs/build_clickhouse.py`: cmake command for `amd_cfi` (release + ThinLTO + CFI) - `ci/defs/job_configs.py`: `cfi_build_job` and `cfi_stateless_jobs` job configs - `ci/workflows/monthly_cfi.py`: new `MonthlyCFI` workflow (cron: 1st of each month, 06:00 UTC) - `.github/workflows/monthly_cfi.yml`: generated by `praktika yaml` Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
The bot correctly identified that -DENABLE_CFI=ON -DENABLE_THINLTO=OFF would silently succeed with cmake but never apply CFI flags (they are gated by the `if (ENABLE_THINLTO ...)` block in CMakeLists.txt). Add an explicit `FATAL_ERROR` when `ENABLE_THINLTO` is explicitly set to OFF while `ENABLE_CFI` is ON, so the misconfiguration is caught at cmake time rather than silently producing a non-CFI binary. Note: `DEFINED ENABLE_THINLTO AND NOT ENABLE_THINLTO` is used rather than `NOT ENABLE_THINLTO` alone because `ENABLE_THINLTO` is only defined by its `option()` call when certain conditions are met (not in sanitizer builds, not with tests enabled). When the variable is undefined it defaults OFF internally but no explicit -DENABLE_THINLTO=OFF was passed, so we only error on an explicit override. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
… option() declaration The previous fix used `DEFINED ENABLE_THINLTO AND NOT ENABLE_THINLTO` in `cmake/sanitize.cmake`, which the bot correctly identified as still having a gap: `ENABLE_THINLTO` is not yet declared when `sanitize.cmake` is included (line 123), so the check always evaluated false and never fired. The root cause: `sanitize.cmake` is included at CMakeLists.txt line 123, but `option(ENABLE_THINLTO ...)` is declared at line 342. Any check in `sanitize.cmake` sees `ENABLE_THINLTO` as undefined at include time. Fix: remove the premature check from `sanitize.cmake` and add the validation to `CMakeLists.txt` immediately after the `option(ENABLE_THINLTO ...)` block where the variable is fully resolved. The check `if (ENABLE_CFI AND NOT ENABLE_THINLTO)` now fires correctly in all cases — explicit `-DENABLE_THINLTO=OFF`, conditions that prevent the option from being set (tests, sanitizers, non-Linux), and undefined (treated as false by CMake). Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Adds pull_request event so CI runs the CFI build + stateless tests against the ci/cfi-monthly-job branch without waiting for the 1st-of-month schedule. Also adds the PR-mode env vars (DISABLE_CI_MERGE_COMMIT, CHECKOUT_REF) that Praktika needs when triggered from a pull_request event. This trigger must be reverted to schedule-only before merging. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Fixes the 'Check Workflows' CI failure caused by manual edits to the YAML (temporary pull_request trigger and PR-mode env vars added in the previous commit). Regenerated with `PYTHONPATH=ci:. python3 -m praktika yaml`. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Changes event to PULL_REQUEST and switches from branches to base_branches so the CFI build and stateless test jobs run on this PR. Must be reverted to SCHEDULE before merge. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…hlyCFI Clang 21 rejects -fsanitize=cfi-vcall,cfi-derived-cast without an explicit -fvisibility= flag. Add -fvisibility=hidden to CFI_FLAGS in CMakeLists.txt. Also add 4-batch integration test jobs (amd_cfi) to the MonthlyCFI workflow so that CFI violations in replication, Keeper, and storage abstraction layers are caught in addition to the stateless functional test coverage. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
-fvisibility=hidden caused -Wunique-object-duplication errors on inline static members (Context::global_context_instance, BaseSettings::unknown_settings, etc.) which are treated as -Werror in ClickHouse builds. -fvisibility=default satisfies Clang 21's requirement that -fvisibility= be explicitly specified alongside -fsanitize=cfi-*. CFI vtable visibility is already handled by -fwhole-program-vtables and -Wl,--lto-whole-program-visibility. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Add `DEB_AMD_CFI` artifact so the CFI build produces a `.deb` package required by the stress test runner (`stress_runner.sh` uses `dpkg -i`) - Add `BuildTypes.AMD_CFI: "cfi"` to `BUILD_TYPE_TO_DEB_PACKAGE_TYPE` in `build_clickhouse.py` so package generation is triggered for CFI builds - Add `+cfi` version postfix in `packages/build` for the `cfi` build type - Add `cfi_stress_job` parametrized config in `job_configs.py` - Include `cfi_stress_job` and `clickhouse_debians` artifacts in `monthly_cfi.py` and regenerate `monthly_cfi.yml` Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Rename MonthlyCFI → WeeklyCFI and switch the schedule from pull_request (temporary trigger used for validation) to a weekly cron schedule running every Monday at 03:00 UTC. Regenerate .github/workflows/weekly_cfi.yml from the Praktika source.
cfi-vcall and cfi-derived-cast are C++ type-safety checks — they have no meaning for C compilation. Remove the CMAKE_C_FLAGS_RELWITHDEBINFO line; keep CFI flags on CMAKE_CXX_FLAGS_RELWITHDEBINFO and the linker.
…TS guard - Fix ci/workflows/weekly_cfi.py: use `branches` instead of `base_branches` for SCHEDULE workflows (Praktika requires this) - Fix comment to mention integration and stress tests, not just stateless - Add FATAL_ERROR in CMakeLists.txt when ENABLE_CFI=ON and ENABLE_TESTS=ON, since ThinLTO is disabled when building tests, making CFI silently no-op - Regenerate .github/workflows/weekly_cfi.yml
045d410 to
cb7581e
Compare
Three failures in the first PR validation run (https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115036&sha=30c47a7d9420ba1e86365979016e7765cbc080da&name_0=WeeklyCFI): - BuzzHouse (amd_cfi) failed with "Clickhouse was compiled without BuzzHouse enabled": add -DENABLE_BUZZHOUSE=1 to the amd_cfi build, matching the other fuzzer-carrying builds. - 03150_trace_log_add_build_id / 03150_trace_log_source_lines fail deterministically: symbols and lines in system.trace_log are all-empty in the ThinLTO+CFI build, while build_id resolves. This is a regression since the 2026-07-14 validation runs of ClickHouse#100419 (toolchain update ClickHouse#109864 is the prime suspect), tracked in ClickHouse#115122. Tag both tests no-cfi until it is fixed. The third failure, a probabilistic server SIGSEGV in gRPC response compression under test_grpc_protocol, is a real bug filed as ClickHouse#115121 - no test change, it passed on retry. Co-Authored-By: Claude Fable 5 <[email protected]>
The 03150 tests never passed under the amd_cfi profile (they failed in the 2026-07-13 validation run of ClickHouse#100419 even after SPLIT_DEBUG_SYMBOLS was added, before the toolchain update), so issue ClickHouse#115122 is a longstanding property of the profile, not a regression. See ClickHouse#115122 for the corrected analysis. Co-Authored-By: Claude Fable 5 <[email protected]>
The pull_request trigger was temporary, to validate the new stateless, AST fuzzer and BuzzHouse jobs on this PR (same approach as in ClickHouse#100419). Validation completed green on baf56e5: all ten amd_cfi jobs passed, including Stateless tests (parallel + sequential) with the no-cfi tags, AST fuzzer, and BuzzHouse after -DENABLE_BUZZHOUSE=1. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115036&sha=baf56e50335c45adf2afb691d0a1ef72f49c8bc6&name_0=WeeklyCFI Co-Authored-By: Claude Fable 5 <[email protected]>
…cation Address review comment on `CMakeLists.txt:419` (May 8): `-fvisibility=default` makes the CFI configuration much weaker than intended, because Clang CFI's vtable type-confusion checks are scoped to classes with non-default linkage — with `default` visibility, CFI silently skips most classes and the weekly job gives a false sense of coverage. Switch back to `-fvisibility=hidden` (the Clang-documented requirement for CFI) and locally suppress `-Wunique-object-duplication`, which is what blocked the original `hidden` attempt. The warning flags inline static members whose addresses may diverge across DSOs under hidden visibility; since ClickHouse is statically linked into a single binary, address duplication across DSOs does not apply and the warning has no bearing on correctness for this build. Comment thread: ClickHouse#100419 (comment) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Without -fno-sanitize-trap=cfi, Clang CFI stays in trap mode: a violation dies with a bare SIGSEGV instead of the UBSan-style type/location report the WeeklyCFI job promises, making failures hard to triage. Add the flag so hits print a diagnostic; the existing -fno-sanitize-recover=cfi then aborts after the report. Addresses review comment on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
CFI flags are only appended to CMAKE_*_FLAGS_RELWITHDEBINFO, so building with -DENABLE_CFI=ON and CMAKE_BUILD_TYPE=Release/Debug configured successfully and printed the CFI status message while silently producing a non-CFI binary. Add an explicit check next to the existing ENABLE_THINLTO/ENABLE_TESTS guards so the misconfiguration fails loudly instead of no-opping. Addresses review comment on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
A schedule workflow's auto-generated workflow_dispatch checks out only base-repo refs, so it cannot exercise this fork PR head (zlareb1/ClickHouse, b9bfe01). Temporarily switch WeeklyCFI to event=PULL_REQUEST so PR CI wires CHECKOUT_REF to the PR head and runs the amd_cfi build + stateless/integration/ stress tests against the code under review. MUST be reverted to event=SCHEDULE with branches=[BASE_BRANCH] and cron_schedules=["0 3 * * 1"] before merge, so it runs weekly on cron and not on every PR. Addresses review comment on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
The diagnostic-mode flag added earlier makes Clang link the UBSan standalone
runtime (libclang_rt.ubsan_standalone[_cxx].a) at every RelWithDebInfo link.
This toolchain does not ship that runtime (only select compiler-rt libs are
built from contrib), so even the host tool `protoc` fails to link:
ld.lld-21: error: cannot open .../libclang_rt.ubsan_standalone.a: No such file or directory
ninja: build stopped: subcommand failed.
Validated by WeeklyCFI run 28943752776 (Build (amd_cfi) failed at link).
Drop -fno-sanitize-trap=cfi and keep CFI in the runtime-free default trap mode.
A violation traps with SIGILL and CI's core-dump handler produces a stack trace
at the offending vcall/cast, so failures stay triageable without the runtime.
Run: https://github.com/ClickHouse/ClickHouse/actions/runs/28943752776
Addresses review comment on ClickHouse#100419
Co-Authored-By: Claude Opus 4.8 <[email protected]>
WeeklyCFI run 29106994231 was green everywhere (build, stress, all 4 integration shards) except one stateless test: 03150_trace_log_add_build_id. It is a reference diff, not a CFI trap -- the server runs fine, but the profiler's symbolized `lines` lack file:line:column frames because cfi-vcall routes indirect calls through jump-table thunks that carry no source line info. This test passes on every build type on master (0 failures / 21 days), including the plain release amd_binary build, so CFI is the delta. It is already excluded from sanitizer builds for the same class of stack-trace sensitivity. clickhouse-test cannot tell the CFI binary from a plain release build (same BUILD_TYPE, no sanitizer), so add a `cfi` build flag detected from CXX_FLAGS -- kept out of SANITIZERS and RELEASE_NON_SANITIZED so it does not skip unrelated tests -- and tag the test no-cfi. Run: https://github.com/ClickHouse/ClickHouse/actions/runs/29106994231 Addresses review comment on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Revert the temporary pull_request trigger (used to validate the CFI build+test path against the fork PR head) back to the intended weekly cron: event=SCHEDULE, branches=[BASE_BRANCH], cron_schedules=["0 3 * * 1"] (Mon 03:00 UTC). So the job runs weekly, not on every PR. This commit changes only the workflow trigger; the CFI build inputs and tests are unchanged, so the green validation run stands as evidence: WeeklyCFI run https://github.com/ClickHouse/ClickHouse/actions/runs/29140420948 on 83a5f26 -- build (amd_cfi) + stress + 4 integration shards + stateless all passed, no CFI violations. Addresses review comments on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Drop the no-cfi tag on 03150 and the cfi build-flag detection in clickhouse-test that were added to skip 03150 under the CFI build. Keeps this PR scoped to the CI job and leaves the shared test runner and the stateless test unmodified. Note: 03150's third assertion checks the query profiler's symbolized stack lines (file:line:column). Under CFI (cfi-vcall) those frames route through jump-table thunks with no source-line info, so the assertion fails deterministically. Without this tag the weekly CFI stateless job will report 03150 as failing when it runs on master; how to handle that (skip, non-blocking, or narrow the CFI test scope) is left as a follow-up. Addresses review comment on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…tion) The amd_cfi build is "amd_release + CFI" but was missing -DSPLIT_DEBUG_SYMBOLS=ON that amd_release/arm_release set. ThinLTO release builds need it to preserve DWARF line tables through BUILD_STRIPPED_BINARY; without it the query profiler's system.trace_log.lines lose file:line:column frames, which is what makes 03150_trace_log_add_build_id fail under amd_cfi -- not CFI itself. Evidence: 03150 passes on amd_binary (ThinLTO off) and amd_release (ThinLTO + SPLIT on), and failed only on amd_cfi (ThinLTO, SPLIT missing). Add -DSPLIT_DEBUG_SYMBOLS=ON so amd_cfi matches the release ThinLTO profile; this should let 03150 pass without a no-cfi tag (reverted earlier). Temporarily flip WeeklyCFI to event=PULL_REQUEST to validate the full amd_cfi stateless suite on this fork head; revert to SCHEDULE + cron_schedules before merge. Addresses review comments on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
…kly cron CFI's purpose is to catch control-flow / type-confusion violations (cfi-vcall, cfi-derived-cast), which manifest as a trap (SIGILL) + abort -- never as a reference-output diff. Running the full stateless functional suite under CFI therefore adds no CFI signal but does add non-CFI false positives: - 03150_trace_log_add_build_id: deterministic profiler-symbolization diff under the CFI build (not fixed by -DSPLIT_DEBUG_SYMBOLS=ON; server healthy, no trap). - 01010_pmj_right_table_memory_limits: borderline memory-threshold flake. - 02346_text_index_bug108519_qcc_skip_index: ~27% flaky on master, all builds. A blocking stateless job would be red for these non-CFI reasons and drown the real signal. Stress + integration already exercise the full server under CFI, so a genuine violation still surfaces as a crash. Drop cfi_stateless_jobs (and its now-unused definition); adding stateless back later would need a curated no-cfi skip set, as asan/tsan/msan carry. Keep -DSPLIT_DEBUG_SYMBOLS=ON: it did not fix 03150, but it makes a real CFI trap's core-dump stack trace point at the offending vcall/cast. Restore the intended weekly cron: event=SCHEDULE, branches=[BASE_BRANCH], cron_schedules=["0 3 * * 1"]. Addresses review comments on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Flip WeeklyCFI to event=PULL_REQUEST to validate the final CFI job config on this fork PR head: build + stress + integration, with the stateless suite now dropped. Expected fully green (stateless was the only red across prior runs). Revert to event=SCHEDULE with branches=[BASE_BRANCH] and cron_schedules before merge. Addresses review comments on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Revert the temporary pull_request trigger back to the intended weekly cron: event=SCHEDULE, branches=[BASE_BRANCH], cron_schedules=["0 3 * * 1"]. The final CFI job config (build + stress + integration, stateless dropped) was validated fully green on the PR head: WeeklyCFI run https://github.com/ClickHouse/ClickHouse/actions/runs/29271080059 on 27a7baa -- build (amd_cfi) + stress + 4 integration shards all passed, no CFI violations. This commit changes only the trigger, so that run stands as evidence for the merged config. Addresses review comments on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
… merge) Re-validate the CFI job (build + stress + integration) on the PR head after merging latest master. Revert to event=SCHEDULE with branches=[BASE_BRANCH] and cron_schedules before merge. Addresses review comments on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Revert the temporary pull_request trigger back to the weekly cron: event=SCHEDULE, branches=[BASE_BRANCH], cron_schedules=["0 3 * * 1"]. Re-validated fully green on latest master (July-14): WeeklyCFI run https://github.com/ClickHouse/ClickHouse/actions/runs/29308856219 on 7d1d7c9 -- build (amd_cfi) + stress + 4 integration shards all passed. This commit changes only the trigger, so that run stands as evidence. Addresses review comments on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
Address review: amd_cfi omits -DBUILD_STANDALONE_KEEPER=1 (which amd_release sets), so it does not build the standalone clickhouse-keeper executable, and the integration jobs (requires=[CH_AMD_CFI], the self-extracting clickhouse binary) exercise Keeper via `clickhouse keeper` mode rather than the standalone binary. Rather than claim full release-artifact coverage, state the scope explicitly: the job covers the monolithic clickhouse binary only; Keeper coordination code is still CFI-covered through `clickhouse keeper` mode. Standalone-keeper coverage would need -DBUILD_STANDALONE_KEEPER=1 plus surfacing that artifact to the jobs; that is out of scope for this weekly bug-finding job. Addresses review comment on ClickHouse#100419 Co-Authored-By: Claude Opus 4.8 <[email protected]>
CI: add weekly Control-Flow Integrity (CFI) build and test job
ClickHouse release builds already use ThinLTO (`-flto=thin`) and `-fwhole-program-vtables`. These are the two prerequisites for Clang CFI, so adding CFI on top requires almost no extra compile cost — the LTO pass is already paid for.
This PR adds:
What CFI detects:
`cfi-icall` is intentionally omitted: C function pointers in contrib libraries compiled without CFI instrumentation would cause false positives.
Runtime overhead: ~2–5% on virtual-call-heavy paths — negligible for a weekly correctness job.
This PR should only be merged if CI confirms there are no false positives (clean test run).
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
Documentation entry for user-facing changes
Version info
26.7.1.1009(included in26.7and later)