Rootless preempt-rt mode (Work in Progress)#918
Draft
dwrobel wants to merge 6 commits intoLinuxCNC:masterfrom
Draft
Rootless preempt-rt mode (Work in Progress)#918dwrobel wants to merge 6 commits intoLinuxCNC:masterfrom
dwrobel wants to merge 6 commits intoLinuxCNC:masterfrom
Conversation
Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
The code tries to unify the codebase of using FIFO_SCHED between root and non-root as being a root is not a prerequisite to set FIFO_SCHED scheduler policy (see capabilities(7)). Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
Temporarily disable executing iptables. Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
Also print out both linuxcnc_debug.txt and linuxcnc_print.txt in case of failure. Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
Contributor
|
Things to make sure of as you work on this:
I don't know what's the point of protecting a system against a setuid binary but allowing a binary with cap_sys_rawio, but linux security decisions are a land of contrasts. |
Collaborator
|
It's been quite a while, but this might still be a good idea. Any comments? |
Collaborator
|
It sound like a great idea to reduce the privileges needed to run linuxcnc. Any hope to get this patch out of draft / work in progress mode? |
Collaborator
|
Is this still a live project? It seems that this work would be good to introduce, but it has been "draft" for 6 years. If this is still something that you are interested in then we can leave it in the PR list, but otherwise it is just going to sit here looking untidy. |
This was referenced Apr 12, 2026
grandixximo
pushed a commit
to grandixximo/linuxcnc
that referenced
this pull request
Apr 24, 2026
PR LinuxCNC#918's SCHED_FIFO unification commit replaced setrlimit(RLIMIT_MEMLOCK, unlimited) + unconditional mlockall() with getrlimit + mlockall only when rlim_max >= 2 * PRE_ALLOC_SIZE. This silently skips mlockall inside Debian-packaging CI containers where the default RLIMIT_MEMLOCK is 64 KiB, because 64 KiB is less than the 64 MiB threshold. Without locked pages, thread scheduling jitter causes tests/threads.0 to miss counter increments. Seen as 'line 3097: got 0, expected 10 or 1' on amd64 trixie and sid. Always call mlockall and log failures. A best-effort setrlimit is still attempted (to raise the soft cap to the hard cap without requiring CAP_SYS_RESOURCE), but the mlockall call itself succeeds on any kernel as long as the process has CAP_IPC_LOCK, regardless of the rlimit.
grandixximo
pushed a commit
to grandixximo/linuxcnc
that referenced
this pull request
Apr 25, 2026
Issue LinuxCNC#3928 reported three bugs in rtapi_is_realtime(): 1. It required a setuid bit on EMC2_BIN_DIR/rtapi_app, ignoring file capabilities that grant the same kernel privileges. 2. It stat()ed a fixed path instead of the running binary, so wrapper-based installs (NixOS /run/wrappers and similar) never saw the check succeed. 3. It ran the setuid test before LINUXCNC_FORCE_REALTIME, silently discarding the environment variable. PR LinuxCNC#918 replaced the whole function with 'return 1', which breaks the sim-vs-rt distinction that GUIs read via hal.is_sim / hal.is_rt and removes the makeApp() sim fallback. Rework rtapi_is_realtime() as a runtime capability probe: briefly set SCHED_FIFO on the calling thread and restore the previous policy, cache the result. LINUXCNC_FORCE_REALTIME short-circuits before the probe, and the RTAI / Xenomai backend detectors still force-true when those environments are present. This matches the convention used by comparable userspace-realtime projects (JACK's jack_is_realtime, PipeWire, rtkit, Xenomai, Klipper): surface observed capability rather than kernel metadata, and let callers who need EPERM visibility use the action API directly. makeApp() drops its own probe and calls rtapi_is_realtime() to choose between SCHED_FIFO and SCHED_OTHER, falling back to POSIX non-realtime with a warning that points at 'make setcap' or 'make setuid'. detect_preempt_rt() is removed -- the probe subsumes it and also works on kernels that no longer expose /sys/kernel/realtime (6.12+).
grandixximo
pushed a commit
to grandixximo/linuxcnc
that referenced
this pull request
Apr 25, 2026
PR LinuxCNC#918's SCHED_FIFO unification commit replaced setrlimit(RLIMIT_MEMLOCK, unlimited) + unconditional mlockall() with getrlimit + mlockall only when rlim_max >= 2 * PRE_ALLOC_SIZE. This silently skips mlockall inside Debian-packaging CI containers where the default RLIMIT_MEMLOCK is 64 KiB, because 64 KiB is less than the 64 MiB threshold. Without locked pages, thread scheduling jitter causes tests/threads.0 to miss counter increments. Seen as 'line 3097: got 0, expected 10 or 1' on amd64 trixie and sid. Always call mlockall and log failures. A best-effort setrlimit is still attempted (to raise the soft cap to the hard cap without requiring CAP_SYS_RESOURCE), but the mlockall call itself succeeds on any kernel as long as the process has CAP_IPC_LOCK, regardless of the rlimit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allows to run linuxcnc in
preempt-rtmode without root (setuid bit).Benefits:
SCHED_FIFOpolicy (on both rt and non-rt kernels),CIflow can use and tests exactly the same code flow as will be used on the production,latency-test(on modern hardware) should return much more reliable results on non-rt kernel,linuxcncin Fedora (see: setuid removal) and maybe other distros wheresetuidbinaries are not welcome.How to run it:
TODO list:
make setcaptarget to set capabilities onrtapi_app,iptablesin hm2_eth.c (it's much easier and more reliable to configure the rules using firewalld/NetworkManager e.g. on Fedora >=32 firewalld switched from iptables to nftables backend),