Skip to content

Apply a seccomp system call policy to clickhouse-server at startup - #119545

Merged
alexey-milovidov merged 18 commits into
masterfrom
seccomp-policy
Sep 27, 2026
Merged

alexey-milovidov merged 18 commits into
masterfrom
seccomp-policy

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

clickhouse-server now applies a seccomp system call filter to itself at startup, allowing only
the system calls it is known to use.

The motivation is containment: an attacker who reaches code execution inside the server process
should not also inherit the kernel interfaces that turn that into a host compromise. The policy
refuses everything a healthy server never needs - loading kernel modules, rebooting, mounting and
the whole new mount API, chroot, changing the process identity, creating namespaces, ptrace and
cross-process memory access, eBPF, the kernel keyring, userfaultfd and vmsplice, file handles,
fanotify, swap and quota control, setting the system clock and the host name, System V and POSIX
IPC, and the extended-attribute calls. ioctl is allowed except for TIOCSTI and TIOCLINUX, the
two requests that let a process holding a terminal take over the session that owns it. In every
mode but disabled the server also sets PR_SET_NO_NEW_PRIVS, so neither it nor anything it
starts can gain privileges by running a setuid program.

The allow-list is generous within each group it keeps: an older or newer spelling of a call that
is allowed anyway (open next to openat, fork next to clone, epoll_wait next to
epoll_pwait2) is allowed too, because which one gets used depends on the libc version and on the
running kernel rather than on anything ClickHouse decides. The two largest pieces of surface that
remain are perf_event_open and the io_uring family, and both are there because ClickHouse
genuinely uses them - for metrics_perf_events_enabled and for
local_filesystem_read_method = io_uring. The filter does not see the operations submitted through an io_uring
ring, so the operations io_uring implements stay reachable that way; the documentation says so.

The new seccomp server setting chooses what happens to a call outside the policy: trap turns it
into SIGSYS, which the existing fatal signal handler reports with the system call number and a
stack trace before the server terminates; kill has the kernel kill the process outright; errno
fails the call with EPERM and lets the server run on; log refuses nothing and only records; and
disabled installs no filter at all. The kernel records every refused call in its audit log in all
of the enforcing modes, which is the only evidence left behind under kill.

The default is log, so that this first release enforces nothing: the filter is installed and the
kernel records every system call the policy does not cover, which is how the policy gets checked
against a real workload before anyone has to trust it. log does still set PR_SET_NO_NEW_PRIVS,
because the kernel asks for that before it accepts a filter at all. Turning the setting to trap,
kill or errno is a deliberate step, and an upgrade does not take it for you. Where the kernel cannot install a log filter (older than Linux 4.14, no
CONFIG_SECCOMP_FILTER, or an outer sandbox that refuses the seccomp system call), the log
mode warns with the reason and runs without a filter, since it would have enforced nothing; the
enforcing modes refuse to start instead.

Implementation notes:

  • The BPF program is generated rather than written by hand, as a binary search over merged runs of
    allowed numbers, so that it costs about a dozen instructions per system call rather than a few
    hundred - it runs on every system call the server makes. The calls whose fate takes more than
    their number to decide are checked after the search rather than ahead of it, so looking at an
    argument is paid for by the call whose argument it is.
  • Creating a namespace is refused in every form it takes, which takes more than leaving unshare
    and setns out of the list. A clone carrying any of the seven CLONE_NEW* flags is refused by
    its flags - the kernel looks at the low half of that argument only, so matching on the low half
    is exact - while the flags a libc passes for a thread, for fork and for posix_spawn are
    allowed. clone3 cannot be inspected at all, since what it is asked to do lives in a structure
    in the calling process's memory, so it is refused as a whole, with ENOSYS rather than with the
    configured action: ENOSYS is how a libc discovers that the kernel has no clone3 and falls
    back to clone, whose flags the filter can see. A recent glibc asks once and remembers the
    answer, so this costs one refused system call in a process rather than one per thread. docker
    and systemd refuse clone3 the same way in their own policies.
  • Before the kernel is asked to enforce the program, it is run through a small interpreter in
    verifyProgram and checked against the table it was generated from, for every number the kernel
    could produce plus the x32 and foreign-ABI cases, the ioctl requests and the clone flags. A
    mistake in the generator therefore fails loudly at startup instead of either opening a hole or
    taking the server down on the first perfectly ordinary system call.
  • The filter is installed with SECCOMP_FILTER_FLAG_TSYNC, so it covers the threads that already
    exist, and with SECCOMP_FILTER_FLAG_SPEC_ALLOW where the kernel supports it: without that flag
    a seccomp filter makes the kernel force the Speculative Store Bypass mitigation on the process
    for the rest of its life, which costs throughput on every query. Flag support is established with
    the documented null-program probe rather than by trial and error.
  • A filter cannot be removed or relaxed once installed and is inherited across both fork and
    execve, so executable dictionaries and user defined functions, the bridges, and the OOM canary
    run under the same policy. This is asserted by the test.
  • Only x86-64 and AArch64 are covered by a filter, since a policy is a list of
    architecture-specific numbers. Elsewhere the server logs a warning at startup and runs without
    one, but still sets PR_SET_NO_NEW_PRIVS, which does not depend on the architecture.
  • The integrity check of the executable used to tell a debugger apart by whether
    ptrace(PTRACE_TRACEME) failed, and ptrace is outside the policy - so under an enforcing mode
    the check would either take the server down on that call or read the EPERM as a debugger and
    hide a real checksum mismatch. It reads TracerPid from /proc/self/status instead, which no
    mode of the setting can change the answer to.

Changelog category (leave one):

  • Improvement

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

clickhouse-server now applies a seccomp system call filter to itself at startup, allowing only the system calls it uses and refusing the rest - kernel module loading, mounting, chroot, identity changes, namespace creation (including a clone that asks for one; clone3, whose arguments a filter cannot read, is refused with ENOSYS, which sends a libc back to clone), ptrace, eBPF, the kernel keyring, userfaultfd, and others. The new seccomp server setting selects what a refused call does: it defaults to log, which enforces nothing and only has the kernel record the calls outside the policy, so that the policy can be checked against a workload before it is turned on; trap, kill and errno enforce it, and disabled installs no filter.


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

Version info

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

The server installs a seccomp-BPF filter on itself, allowing only the system
calls it is known to use, so that code execution inside the server process does
not come with the kernel interfaces that turn it into a host compromise. The
policy refuses loading kernel modules, rebooting, mounting and the new mount
API, `chroot`, changing the process identity, creating namespaces, `ptrace` and
cross-process memory access, eBPF, the kernel keyring, `userfaultfd` and
`vmsplice`, file handles, `fanotify`, swap and quota control, setting the system
clock and the host name, System V and POSIX IPC, and the extended-attribute
calls. `ioctl` is allowed except for `TIOCSTI` and `TIOCLINUX`, the two requests
that let a process holding a terminal take over the session that owns it. The
server also sets `PR_SET_NO_NEW_PRIVS`, so neither it nor anything it starts can
gain privileges by running a setuid program.

Within each group it keeps, the allow-list is deliberately generous: an older or
a newer spelling of an allowed call (`open` next to `openat`, `clone` next to
`clone3`) is allowed too, because which one is used depends on the libc version
and on the running kernel rather than on anything ClickHouse decides. The two
largest pieces of surface that remain are `perf_event_open` and the `io_uring`
family, and both are there because ClickHouse uses them - for
`metrics_perf_events_enabled` and for `local_filesystem_read_method = io_uring`.

The new `seccomp` server setting chooses what a call outside the policy does:
`trap` (the default) raises `SIGSYS`, which the fatal signal handler reports with
the system call number and a stack trace before the server terminates; `kill`,
`errno` and `log` are also available, and `disabled` installs no filter. `log`
blocks nothing and only records, which is the mode to run first when checking the
policy against an unusual workload.

The BPF program is generated as a binary search over merged runs of allowed
numbers, so it costs about a dozen instructions per system call rather than a few
hundred. Before the kernel is asked to enforce it, `verifyProgram` runs the
program through a small interpreter and checks it against the table it was
generated from, for every number the kernel could produce plus the x32 and
foreign-ABI cases, so a mistake in the generator fails loudly at startup instead
of opening a hole or taking the server down on an ordinary system call.

The filter is installed with `SECCOMP_FILTER_FLAG_TSYNC`, so it covers the
threads that already exist, and with `SECCOMP_FILTER_FLAG_SPEC_ALLOW` where the
kernel supports it: without that flag a seccomp filter makes the kernel force the
Speculative Store Bypass mitigation on the process for the rest of its life,
which costs throughput on every query. Flag support is established with the
documented null-program probe rather than by trial and error.

A filter cannot be removed or relaxed once installed and is inherited across both
`fork` and `execve`, so executable dictionaries and user defined functions, the
bridges, and the OOM canary run under the same policy. Only x86-64 and AArch64
are covered; elsewhere the server logs a warning at startup and runs without a
filter.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [931446c]

Summary: ✅


AI Review

Summary

This PR adds a self-installed seccomp policy for clickhouse-server, the seccomp server setting, and focused coverage around startup, subprocess inheritance, ZooKeeper-backed configuration, and config reloads. The remaining issue is that the new runtime introspection still reports the requested seccomp mode as if it were active on startup paths where no filter could be installed.

Findings

⚠️ Majors

  • [src/Core/ServerSettings.cpp:3823] system.server_settings now uses getInstalledSeccompMode as "the policy in force", but that value is recorded before installSeccompFilter knows whether a filter was actually installed. In log mode under an outer sandbox / old kernel, or on unsupported architectures, the table will still report log / trap / errno even though the process is running without a seccomp filter and only PR_SET_NO_NEW_PRIVS was applied. This recreates the same false-security-state bug the PR just fixed for config reloads.
    Suggested fix: store/report filter installation success separately from the requested mode, and have system.server_settings reflect the actual installed state.
Final Verdict

⚠️ Needs changes before merge.

LLVM Coverage Report

Measured on commit 931446c.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.70% 91.80% +0.10%
Branches 79.50% 79.60% +0.10%

Changed lines: Changed C/C++ lines covered: 360/428 (84.11%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 11, 2026
Comment thread src/Common/SeccompFilter.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... label Sep 11, 2026
`clang-tidy`'s `google-runtime-int` refuses the `long` that `syscall` returns.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread src/Common/SeccompFilter.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 931446c4f with master e5b8853ba (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.

Object file sizes

11 object files changed (+202.75 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/clickhouse_common_io.dir/Common/SeccompFilter.cpp.o new 144.32 KiB +144.32 KiB
src/CMakeFiles/dbms.dir/Core/SettingsEnums.cpp.o 2.16 MiB 2.18 MiB +22.49 KiB (+1.02%)
programs/server/CMakeFiles/clickhouse-server-lib.dir/Server.cpp.o 1.51 MiB 1.53 MiB +22.48 KiB (+1.46%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

1913 translation units recompiled, 11455 s compile time in total, 1912 of them have a recent master baseline.

Job report

…t cover

The loongarch64 sysroot has no `linux/audit.h`, and the includes sat outside
the architecture condition, so the build failed there instead of compiling the
stub. Both branches now compile under `-Weverything -Werror`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread src/Core/ServerSettings.cpp Resolved

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Sep 12, 2026
alexey-milovidov and others added 4 commits September 12, 2026 21:29
Address review: the policy said it refuses namespace creation, but it only
refused `unshare` and `setns`. `clone` creates one just as well, by naming it
among its flags, so a compromised server could still reach a user namespace -
the usual step from code execution inside a process to the kernel.

`clone` is now decided by its flags rather than by its number alone: a call
carrying any of the seven `CLONE_NEW*` bits is refused, and everything a libc
passes for a thread, for `fork` and for `posix_spawn` is allowed. The kernel
takes only the low half of that argument, so matching on the low half - which
comes first on a little-endian machine - is exact.

`clone3` cannot be inspected at all: what it is asked to do lives in a
structure in the calling process's memory, which a filter cannot read, so a
namespace cannot be told from a thread. It is therefore refused as a whole,
with `ENOSYS` rather than with the configured action. `ENOSYS` is how a libc
discovers that the kernel it runs on has no `clone3` and falls back to `clone`,
whose flags the filter can see; a recent glibc asks once and remembers the
answer, so this costs one refused system call in a process rather than one per
thread. `docker` and `systemd` refuse `clone3` the same way in their own
policies. In the `log` mode, where nothing is refused, `clone3` gets that
mode's own action like everything else outside the policy.

The two checks that need an argument now sit after the binary search instead of
ahead of it, next to the `ioctl` one, so that looking at an argument is paid
for by the call whose argument it is rather than by every system call the
server makes. Measured on AArch64 with the program the policy generates: an
allowed `read` takes 16 instructions and `futex` 14, against 15 and 15 before,
and `clone` and `ioctl` 19.

The test asserts through the executable user defined function that already
probes the policy from a forked process that a `clone` asking for a user
namespace is refused, that `clone3` answers `ENOSYS`, and that making a thread
still works. The flags it passes name a combination the kernel rejects on its
own with `EINVAL`, so the probe creates nothing when the policy does not refuse
it.
Address review, two ways in which the setting did not do what it said.

On a Linux architecture other than x86-64 or AArch64 there is no policy to
install, and `installSeccompFilter` did nothing at all there - including
`prctl(PR_SET_NO_NEW_PRIVS)`, which the setting documents as part of the
feature and which does not depend on the architecture. Executable user defined
functions and dictionaries, the bridges and the OOM canary could still gain
privileges through a setuid binary or one carrying file capabilities on those
builds. It is now applied there as well, in every mode but `disabled`, and only
the filter itself is left to the architectures that have a policy. The warning
at startup says so.

The `log` mode said it enforces no policy at all, while it did set
`PR_SET_NO_NEW_PRIVS` - the kernel asks for that before it accepts a filter,
and a filter is what `log` installs, so it cannot be skipped. The setting
documentation and the comments now say that `log` refuses no system call but
does set `PR_SET_NO_NEW_PRIVS`, which is the one thing it has in common with
the enforcing modes.

The test gets a `log` node and asserts both halves of that: the filter and
`NoNewPrivs` are there, and the probe from a forked process sees exactly what
it sees without a filter - a missing extended attribute rather than `EPERM`,
and a `clone3` the kernel gets to look at rather than `ENOSYS`.
The probe prints a tab-separated row, and the test unpacks it into five names,
so a message with a space in it would fail the test with a confusing unpacking
error rather than with the assertion that means something.
The two architecture branches each declared `SYSTEM_ERROR`. The
duplicate-`ErrorCodes` style check reads the file as text and has no idea
that the branches are mutually exclusive, so it reported a duplicate
declaration. Declare both codes once, above the branches.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Comment thread programs/server/Server.cpp Resolved
Comment thread src/Core/ServerSettings.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added comp-authentication Identity verification: users, credentials, auth methods, external auth providers. and removed comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... labels Sep 18, 2026
alexey-milovidov and others added 3 commits September 19, 2026 00:31
…y denies

The seccomp filter is installed early in startup, well before the integrity
check of the executable, and `ptrace` is outside the policy. The debugger probe
of that check therefore stopped working in every enforcing mode: `trap` and
`kill` take the server down on the `ptrace` itself, and `errno` turns it into
`EPERM`, which the check reads as "running under debugger" - so a real checksum
mismatch was reported as a modified binary under a debugger instead of raising
`CORRUPTED_DATA`.

Read `TracerPid` from `/proc/self/status` instead. It is a plain read of a file
the server may open anyway, so it answers the same way whatever the `seccomp`
setting denies.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Defaulting a brand-new process-wide deny-list to `trap` would start enforcing
`SIGSYS` on upgrade, before an operator has had any chance to run their workload
under the policy. The `log` mode exists exactly for that validation, so make it
the default: the filter is installed, the kernel records every system call the
policy does not cover, and nothing is refused. Turning the setting to `trap`,
`kill` or `errno` stays a deliberate step.

The integration test gains a `trap_node` so the enforcing mode keeps its
coverage, and a test that the integrity check of the executable runs to the end
under the filter in every mode.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Both reds on 5c1fba37 are unrelated to this PR and both already have a fix in flight:

@groeneai, neither has landed on master yet, so this branch cannot clear them by merging — could you push #120932 along?

The branch has since been brought up to master and carries the two review fixes (TracerPid instead of the ptrace debugger probe, and log as the default mode), so the next run starts from a current base.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 On the AArch64 coverage point from the AI review: there is already AArch64 runtime evidence for this policy. tests/integration/test_seccomp runs in the ordinary integration suite, and the suite has four required AArch64 jobs — Integration tests (arm_binary, distributed plan, 1..4/4), defined in integration_test_jobs_required in ci/defs/job_configs.py and running on RunnerLabels.ARM_MEDIUM. All four were green on 5c1fba37.

That is the interesting configuration for the hard-coded generic numbers the review lists (pidfd_open, clone3, openat2, futex_waitv, map_shadow_stack, mseal): arm_binary is a release build, so SECCOMP_ALLOWED_SYSCALLS_SANITIZER is not in effect and the policy is the real one. A wrong number there would show up as the AArch64 errno_node returning EPERM from an ordinary call, or the trap_node losing the connection — which is exactly what test_server_works_under_the_filter watches for, and it now covers trap_node as well.

On top of that, verifyProgram runs the generated BPF through an interpreter at startup and checks it against the table it was generated from, for every number the kernel can produce — so a number that does not match the table fails loudly on the architecture it is wrong on, rather than quietly.

Comment thread src/Core/ServerSettings.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

#120932 is green and ready. Its PR workflow on head c57699f945b0 finished at 02:06Z: 25 jobs success, 0 failures, including the check it fixes (Upgrade check (amd_release), 01:27:20Z to 01:52:40Z, all 12 sub-results OK). The cancelled jobs and the Finish Workflow red that show on that sha come from a superseded first workflow start at 23:20Z, not from this run. A review is requested and nothing is pending on my side, so what remains is an approve and a merge.

You do not have to wait for it to land to get a clean run on this branch, though: configure() re-rolls the flags on every run, so the red is not sticky on a head. Of the 250 Upgrade check (amd_release) runs since the first sighting at 2026-09-18 12:03:19Z, 15 carried this message (15 distinct PRs), so a fresh run on 16b22d2c misses it about 19 times in 20.

Comment thread src/Common/SeccompFilter.cpp Resolved

lukaszszafranski commented Sep 21, 2026 •

Copy link
Copy Markdown

Thanks @alexey-milovidov for letting us continue reviewing active ClickHouse changes.

Veridical.dev reviewed the change

  • Merge readiness — 🟠 Needs work
  • Correctness — No separate correctness defect identified
  • Security — 🟡 One medium containment gap
  • Tests — Add an enforcing-mode regression for restricted io_uring opcodes
  • Reviewed revision — 4165cf5f33ff6717555c67d17948305a89288087

2 surfaced items · 2 with source evidence

Supported defect

Severity Where Issue
🟡 Medium src/Common/SeccompFilter.cpp:174 Unrestricted io_uring preserves operations that the direct-syscall allowlist intends to remove.

The policy permits io_uring_setup, io_uring_enter, and io_uring_register without restricting SQE opcodes. Seccomp sees the outer io_uring_enter syscall, not the operation stored in each SQE, so code already executing in clickhouse-server can still submit operations such as IORING_OP_SETXATTR, IORING_OP_FSETXATTR, or a supported IORING_OP_URING_CMD, even though the corresponding direct interfaces are outside the policy.

Normal file/device permissions, capabilities, and LSM policy still apply. This is a containment gap, not an independent privilege escalation.

🔍 Evidence and suggested direction

The allowlist admits the full io_uring syscall family, while the PR's security boundary is expressed in terms of individual direct syscalls. The kernel executes the SQE operation after the allowed io_uring_enter call, beyond the filter's view.

Register a minimal opcode set with IORING_REGISTER_RESTRICTIONS before enabling a ring and prevent creation of unrestricted additional rings. If that is not practical, remove io_uring from enforcing modes or narrow the documented containment claim.

Existing bot finding corrected

The clickhouse-gh[bot] finding that TSYNC leaves pre-existing threads with NoNewPrivs=0 does not match the Linux implementation. seccomp_sync_threads() explicitly calls task_set_no_new_privs(thread) for every non-exiting sibling when the caller has no_new_privs. That blocker does not appear valid.


Review scope

Source-only Ultra review of the exact revision above. Existing bot and human discussion was included for deduplication. No build or runtime execution was performed.


Reviewed by Veridical · ultra depth · source-only, no build

alexey-milovidov and others added 3 commits September 22, 2026 21:22
`test_binary_integrity_check_survives_the_filter` failed in every
integration job: the common configuration of the integration tests sets
`skip_binary_checksum_checks`, so the check never ran and neither of the
two log lines the test waits for was written. The nodes it looks at now
turn the setting back off.

Also assert `NoNewPrivs: 1` on every thread, not only `Seccomp: 2`: the
review worried that `PR_SET_NO_NEW_PRIVS` stays on the installing thread,
but `TSYNC` carries it over together with the filter (`seccomp_sync_threads`
calls `task_set_no_new_privs` for every sibling), and the test now pins it.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119545&sha=4165cf5f33ff6717555c67d17948305a89288087&name_0=PR
#119545

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…m starting

With `seccomp` defaulting to `log`, a server that used to start on a kernel
older than Linux 4.14, one built without `CONFIG_SECCOMP_FILTER`, or inside a
container runtime whose own policy refuses the `seccomp` system call, would
now fail at startup with `Cannot install the seccomp filter` - an outage
caused by a mode that enforces nothing.

`installSeccompFilter` now asks up front whether the requested action is
implemented (`/proc/sys/kernel/seccomp/actions_avail`) and whether a filter
can be installed at all (the null-program probe, which gives `EFAULT` only
when it can). If not, the `log` mode sets `PR_SET_NO_NEW_PRIVS`, returns the
reason, and the server logs a warning and runs without a filter. The
enforcing modes still refuse to start, now with the reason in the message.
The function returns a `SeccompFilterStatus` instead of a bare count, so the
warning names the actual reason rather than always blaming the architecture.

The new `test_log_mode_starts_where_seccomp_is_unavailable` starts a second
server under an outer filter that refuses `seccomp` with `EPERM`, the way a
restrictive runtime does. Checked locally on AArch64 with the binary of the
previous head (fails to start with `Code: 425`) and with this change
(starts with the warning, answers queries, `NoNewPrivs: 1` on all 169
threads); `errno` under the same outer filter still refuses to start.

#119545

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…o_uring`

The `io_uring` system calls are allowed for `local_filesystem_read_method =
io_uring`, and a ring lets whoever can make one reach the operations
`io_uring` implements - the extended-attribute ones, for example - even
though their system calls are refused. `IORING_REGISTER_RESTRICTIONS` on our
own ring would not close that, since a second, unrestricted ring can be made;
refusing `io_uring_setup` would, at the price of the read method. State the
gap in the setting documentation and next to the policy instead of claiming
more containment than there is.

Raised in the review at #119545

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 8d8318d with a merge of master and the following changes:

  • test_binary_integrity_check_survives_the_filter (red in every integration job). tests/integration/helpers/0_common_instance_config.xml sets skip_binary_checksum_checks, so the check never ran and neither of the log lines the test waits for was written. The nodes the test inspects now turn the setting back off (a4cd9b1).
  • AI review, the log default blocker. Fixed with probe-and-skip for log only, with a test that runs under an outer filter refusing seccomp (dd4ea09). Details are in the thread.
  • AI review, the NoNewPrivs blocker. Not valid: TSYNC propagates no_new_privs, all 169 threads measured NoNewPrivs: 1, and the test now asserts it.
  • Veridical, io_uring. The gap is real, but IORING_REGISTER_RESTRICTIONS on our own ring would not close it, because code already running in the process can make a second, unrestricted ring. Only refusing io_uring_setup would close it, and that would remove local_filesystem_read_method = io_uring. So the setting documentation and the policy comment now state the gap instead of claiming it is contained (8d8318d).
  • Upgrade check. The Keeper feature-flag message was fixed in Stop randomizing the Keeper feature flags that transactions require in the stress and upgrade checks #120932, which is now in master and in this branch.
  • Build profile diff. This fails on every PR at the moment and is tracked in Build profile diff fails fleet-wide with No connection to LogCluster #120462.

Comment thread programs/server/Server.cpp Resolved
Comment thread src/Common/SeccompFilter.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=119545&sha=8d8318d32e2bee7975d30d270a261708319966ba&name_0=PR&name_1=Stress%20test%20(arm_release) and provide a fix in a separate PR. If the fix is already in progress, link it here.

Logical error: offsets_column has data inconsistent with nested_column. Data size: A, last offset: B (STID: 2632-398f) from ExactSetRuntimeFilter<false>::insert ← RuntimeFilter::merge ← RuntimeFilterLookup::add ← BuildRuntimeFilterTransform::prepare. This is the same defect as the one #120940 addressed (closed without merging); CIDB shows it on about a dozen unrelated PRs and on master since 2026-08. Your last comment there proposed the checkpoint/rollback of set_elements in Set::appendSetElements - please open that.

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. Nothing to link yet: #120940 was closed unmerged, so no fixing PR is open for this.

Opening the change you named: checkpoint/rollback of set_elements in Set::appendSetElements (src/Interpreters/Set.cpp:287, the bare insertRangeFrom into the retained column), in the shape of StorageBuffer::appendBlock (checkpoints before the loop, rollback under LockMemoryExceptionInThread). I will post the PR link here.

…se device nodes in `mknod`

The filter was installed from the local configuration, before
`loadConfigWithZooKeeperIncludes` and the reload of the server settings that
follows it. A `seccomp` value from `from_zk` then showed in
`system.server_settings` while the filter in force was the one for the local
value - and a filter cannot be replaced afterwards. The filter is now
installed right after that reload.

`mknodat` (and the legacy `mknod` on x86-64) were allowed unconditionally,
which also allows making character and block device nodes; with `CAP_MKNOD`
that reaches any device through the allowed `openat` and `ioctl`. The filter
now looks at the `S_IFMT` bits of the mode and refuses `S_IFCHR` and `S_IFBLK`.
FIFOs, which executable user defined functions use, regular files and sockets
are still allowed - the server can make those with `openat` and `bind` anyway.
`verifyProgram` checks both, including junk in the ignored bits of the mode.

`test_seccomp` gets a node whose `seccomp` setting comes from ZooKeeper and
must end up enforcing, and the probe script checks that `mknod` of a device
is refused while `mkfifo` works.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Comment thread programs/server/Server.cpp Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

#121898, as instructed: checkpoint/rollback of set_elements in Set::appendSetElements, in the shape of StorageBuffer::appendBlock. This replaces the transform-level guard of the closed #120940. One function, one include, no setting, plus a deterministic gtest that reproduces the inconsistent offsets without the fix and passes with it.

The description carries one question for you: the collected values are now consistent, but the filter can still be partial through paths this change does not touch. I left that fence out, since it is what #120940 attempted.

alexey-milovidov and others added 2 commits September 27, 2026 05:59
…n force after a config reload

The filter is installed once at startup and cannot be installed, removed or
relaxed afterwards, but `SYSTEM RELOAD CONFIG` and the automatic reload rebuild
`system.server_settings` from the new configuration, so a changed `seccomp`
there was reported as if it were in force.

`installSeccompFilter` now remembers the mode it was called with, and
`collectChangeableServerSettings` reports that mode for `seccomp` (with
`changeable_without_restart = No`) instead of the configured one. A reload that
changes the setting logs a warning that it takes effect only after a restart.
`test_reloaded_setting_does_not_replace_the_one_in_force` covers both
directions (`disabled` -> `errno` and `errno` -> `disabled`).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Pushed 931446c on top of a merge of master (b17afa5):

  • AI review, the config-reload Major. Fixed. system.server_settings now reports the seccomp mode installed at startup instead of the reloaded configuration, and a reload that changes the setting logs a warning. A new reload test covers both directions. Details are in the thread.
  • test_replicated_database_active_node_taken (amd_asan_ubsan, db disk, 3/8 and amd_llvm_coverage, 3/8). Not caused by this PR. The flakiness was fixed on master by a2ff290 ("Make the taken-active-node test claim the replica one host at a time"), and the merge brings that fix into this branch.
  • Stress test (arm_tsan), Logical error: Duplicate announcement received for replica number. Also not caused by this PR: it comes from the parallel-replicas coordinator. It is tracked in Correlated subquery with subquery-scoped parallel replicas throws LOGICAL_ERROR #121105, and Do not use task-based parallel replicas for a recursive CTE or a correlated subquery enabled by a nested SETTINGS clause #115916 (open) fixes it.
  • Performance Comparison (arm_release, master_head, 5/6). One query regressed, json_to_string #0 (+17% client_time), and the job also reports "3 too long". No other query on this or any other shard changed, and the default log filter costs every system call the same small amount, so a per-syscall overhead would not show up on a single JSON-formatting query only. I expect it to clear on the next run.


/// The seccomp filter is installed once at startup and cannot be changed afterwards, so a reloaded
/// configuration that says otherwise does not describe the policy in force.
if (const auto seccomp_mode = getInstalledSeccompMode())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collectChangeableServerSettings now treats getInstalledSeccompMode as "the policy in force", but that value is set before installSeccompFilter knows whether a filter was actually installed. On the startup fallback paths (log where the seccomp system call is unavailable, or any unsupported architecture), system.server_settings will still report seccomp = log|trap|... even though the process is running without a seccomp filter and only PR_SET_NO_NEW_PRIVS was applied. That recreates the same false-security-state bug the PR just fixed for SYSTEM RELOAD CONFIG, only on the startup-unavailable path.

Can we preserve/report installation success here instead of only the requested mode?

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 27, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Next step: set it to trap by default in the standalone server configuration. But it likely does not work in Docker - check that. In that case, we can disable it in our Docker image.

Merged via the queue into master with commit 69ea8da Sep 27, 2026
173 checks passed
@alexey-milovidov
alexey-milovidov deleted the seccomp-policy branch September 27, 2026 21:11
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 27, 2026
nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Oct 9, 2026
The setting keeps its `log` default, but the `config.xml` shipped with the
packages and the Docker image now enforces the policy. It works in Docker with
the default seccomp profile: the server's filter stacks on top of the runtime's.

Related: ClickHouse#119545 (comment)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-authentication Identity verification: users, credentials, auth methods, external auth providers. pr-improvement Pull request with some product improvements 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.

4 participants