1 Safety
liquibyte edited this page 2026-11-19 16:23:30 -06:00

Safety

Opening a file in Unryu is safe even when you do not trust the file: a source file from the internet, a repository you are reviewing, an attachment. This page explains how Unryu protects your files, your desktop and your unsaved work from such a file, what that means for you in daily use, and what its limits are.

Why Unryu reads files in a jail

To color code, pair braces and know what every name means, a program has to read and take apart everything a file says. The code that does this is large and complicated, and like all such code it can have bugs. A file made on purpose to trigger such a bug could make the program do something it was never meant to do, with all the rights you have: read your private files, change them, or send them away.

Unryu therefore does not take a file's code apart in the editor itself (the few exceptions are listed under Known limitations below). That work is done by separate processes, each locked in a jail: a set of rules, enforced by the Linux kernel, that leaves the process nothing worth stealing and no way to send anything out or change anything. If a hostile file did take over such a process, it would find itself in an empty room. And because a process that a file has taken over could send back anything, the editor treats every answer it gets back as possibly hostile too, and checks it before using it.

The editor, which holds your files, your desktop connection and your unsaved text, talks to four kinds of jailed processes: one analysis process per document, a check process during Suggest Repairs, one worker for a project's flags files, a document's images and the terminal's pictures, and the compiler

Red borders are jails. Each jailed process talks only to the editor, over a private connection the jail leaves open.

One more jailed process reads the whole project: the index process, one for the project in front and one for each project of the open workbench (its plain folders are not read). It reads every file of its project that has a language, to know where each name is defined and used (Go to Definition into any file). It may read its project's folder and nothing else (not your home folder as a whole, nor /: for such a folder there is no index process), and it writes nothing: the index it sends is checked by the editor, and the editor itself keeps it in ~/.cache/unryu/index. On the next start the editor sends that file back to the index process, which reads it in its jail, as it reads everything.

One more reads a git repository, in its Read and Full modes (Git): the git process, one for the repository in front. It takes apart the repository's objects (compressed data from whoever made the repository) in its jail: it may read the repository's folder and nothing else, runs nothing, and writes nothing. What it sends is checked by the editor. In Full mode, Tools > Git runs git itself, outside any jail: only for a repository you trust.

And one runs when you ask for it: Help > Look Up Documentation runs the language's documentation program (man, pydoc3 ...) in a jail of its own, because such a program can run code (pydoc3 imports the module it documents). It may read and run the system's folders (/usr, /bin, /lib, /opt), read /etc, /var/cache/man and the folder of the file in front, and write nothing. It runs without a shell, without your environment, in a session of its own, and it is stopped after 10 seconds (see The Window).

What the jail allows and forbids

The jail is made from two features of the Linux kernel, Landlock and seccomp. They need no administrator rights and nothing to install. The jail is all or nothing: if any part of it cannot be set up, the process does not run at all. There is no weaker fallback and no setting to turn it off, on purpose. What the kernel can enforce depends on its version; older kernels enforce a little less (see Known limitations below).

Area Analysis and check processes, the worker Compiler
Reading files The file's own folder and the folder above it; the project's folders and the folders its build flags name; the folders you named yourself (see below); the system folders /usr, /opt, /srv, /mnt, /media and /nix/store; and the visible part of your home folder (see below). The worker may read no file at all: the editor reads a project's compile_commands.json or compile_flags.txt, an image a Markdown document names, or a picture a program sent to the terminal, and hands the worker its bytes to take apart. The system's headers and libraries, the compiler's own files, and the project: the folders the analysis may read for the project, the folders its flags name, the folders you named yourself, and the private folder with the copies.
Hidden folders in your home Folders whose names start with a dot, such as .ssh, .gnupg, .config and browser profiles, are where secrets are kept. They are not part of the visible home folder the jail lets in, and a link from there into one does not count. A folder that a project's compile_commands.json or compile_flags.txt names (its directory, the folder of that file, or a folder or file given with -I, -isystem, -iquote, -include, -imacros, -idirafter, -isysroot or --sysroot) is never let in when it lies inside a hidden folder of your home. The one exception is a folder inside the same hidden folder as the file you opened. The file you open yourself is read wherever it is, together with its folder and the folder above that, even inside a hidden folder. The folders you name yourself are let in even when hidden: those of check-folders in Preferences > Various (at first ~/.local/include, where a library installed in your home folder keeps its headers), and those of the CPATH, C_INCLUDE_PATH and CPLUS_INCLUDE_PATH environment variables.
Your whole home folder Never let in as a whole, not even when you name it yourself. A folder that contains your home folder (or is it) is never added as a project folder. A file lying directly in your home folder gets the visible folders and the source files beside it instead.
Writing Nothing, anywhere. Nothing can be created, renamed, deleted or emptied. The only thing that can be written to is /dev/null. A file that may be read cannot be emptied either, on any kernel: Unryu refuses truncate and an open that would empty a file, which the kernel's Landlock refuses itself only from Linux 6.2.
Network No connections of any kind: no internet, no local network, and no local sockets, so also no way to reach your desktop (the X server) or D-Bus.
Other programs Cannot start any program, cannot create new processes, and cannot send signals to anything. Can start only the compiler, the parts it needs (such as gcc's cc1) and the system's program loader. Through the loader, a compiler that misbehaves could run another program it can read. Cannot debug or read the memory of other processes. Cannot send a signal to every process or to a group of processes, on any kernel; to a single other process only before Linux 6.12 (see Known limitations).
Kernel features No access to other processes' memory, no new namespaces (neither by unshare nor when a process is made), no mounting, no kernel keyring, no io_uring, no bpf, no loading kernel modules, no rebooting.
Privileges Can never gain rights: starting a setuid program gives it nothing.
Size and time At most 8 GB of memory and 256 open files; it can write no files and leaves no core dump. The analysis process is stopped when nothing passes between it and the editor for two minutes. The check process is stopped with the check, after 60 seconds at most. At most 2 GB of memory and 30 seconds of processor time, runs at lower priority, at most 4 at once in a check (half your processors, at least one), plus one for a running "ask the compiler". Stopped after 15 seconds for one round, 60 seconds for a whole check, and two minutes at most whatever happens.

Each analysis process is a fresh copy of the Unryu program started again, not a copy of the running editor. So it has none of the editor's memory: none of your other documents, no unsaved text, and no connection to your desktop. It enters its jail before it receives the first byte of the file, and before it parses the language file that describes the file's language. A jail can only be made narrower, never wider, and each file needs its own folders, so each document gets its own process.

The worker is one more fresh copy of the program, started the first time something needs it and kept for the rest of the session. It may read no file at all: the editor reads a file and sends it the bytes. It takes apart a project's compile_commands.json and compile_flags.txt, the images a Markdown document names, and every picture file (PNG, JPEG, GIF, BMP), sixel picture and compressed picture a program sends to the terminal; raw pixels need no taking apart and are copied by the editor after a size check. An answer that is too large, too late (5 seconds) or does not add up is thrown away, and the worker is stopped; the next request starts a new one. Unryu stops the worker through a handle to that very process, not by its process number, so the signal can never reach another program that has since been given the same number.

The jail needs Linux 5.13 or newer with Landlock enabled, on an x86-64 or ARM64 processor. Most current distributions have it.

What this means for you

  • Everything you do yourself works as usual. Opening, editing, saving, searching, building and running are done by the editor or by commands you chose, not by the jailed processes, so the jail never stands in your way.
  • Without a jail there is no analysis. On a system where the jail cannot be made, Unryu still opens, edits and saves every file, but as plain text: no colors, no brace answers, no Symbols list, no tooltips. The Details panel says "Off: this system cannot sandbox the code that reads the file". Suggest Repairs and the tooltip's "ask the compiler" refuse to run and say why.
  • Headers in unusual places may not be followed. The analysis can read only the folders listed above. A header in a hidden folder, or in a place that is neither in the project, the system folders nor the visible part of your home folder, is not read, so its names stay unknown.
  • A crash costs nothing. If a file makes an analysis process crash, hang or send nonsense, the editor stops that process, keeps the last good answer on screen, and starts a new process at your next edit. Your text is never affected. When the answer failed the editor's checks, Details warns: "This file may be trying to attack the editor."
  • The window never waits for a jailed process. Sending and receiving never block, so a process that stops reading or answering cannot freeze the window.

What the editor checks in every answer: each count, position and index is compared with the text it sent before it is used, and a size is refused before any memory is set aside for it. The editor never takes the text back from the process; it keeps its own copy and checks the answers against that. The check process has extra limits: it may ask for at most 32 versions of the text at a time, each not much longer than the file, and at most 64 compiles beyond its budget, so a process that a file has taken over cannot keep the compiler busy without end.

The compiler under the jail

A compiler runs only when you ask for it: with Navigate > Suggest Repairs (Ctrl+Shift+B) or with the "ask the compiler" link in the tooltip over a name (Analysis). It never runs when a file opens or while you type, and no setting changes that. It only checks whether code compiles (-fsyntax-only, with warnings off) and never builds anything.

The four steps before a compiler runs: find the project's flags, choose a compiler that may run, keep only safe flags, run it in the jail with limits

A project's files are not trusted, so a project can neither choose a program to run nor widen the jail to your home folder.

  • Where the flags come from. In the file's folder, and then in each folder above it, Unryu looks for compile_commands.json, then build/compile_commands.json, then compile_flags.txt. A compile_commands.json counts only if it has an entry for the file or for a file in the same folder; otherwise the search goes on upward. The editor reads each of these files and hands its bytes to the worker in the jail, which takes them apart; what it sends back is checked before it is used.
  • Which compiler may run. A project's compile_commands.json can name any program as its compiler. Unryu runs it only if it is named like a compiler (cc, gcc, g++, c++, clang, clang++, also with a target before the name and a version after it, such as x86_64-linux-gnu-gcc-14 or clang-19), and if it and its folder belong to the system administrator (owned by root and writable by nobody else). Anything else is refused, and the system's cc (for C) or c++ (for C++) is used instead. Details then says "Will not run:" with the refused program and the file that named it.
  • Compiler wrappers are skipped. A wrapper such as ccache, sccache, distcc, icecc or buildcache starts another program and writes a cache or sends the work away, which the jail does not allow, so it never runs, even when you list it in trusted-compilers. For ccache gcc ... the check runs gcc; for a wrapper's link named like a compiler (/usr/lib/ccache/gcc), it runs the compiler of that name found after it on your PATH. Details says "Wrapper skipped:" with the wrapper's name.
  • Allowing your own compiler. To allow a compiler that does not pass this test, for example one in your home folder, add its full path to trusted-compilers (Preferences > Various, or trusted-compilers = in unryu.conf); separate several paths with colons. A compiler you listed may also be a script; the program its first line names may then run too, and so may the system's own compilers (cc, gcc, c++, g++, clang, clang++), so that a wrapper script of your own can start one.
  • Finding the compiler. Unryu looks the compiler up in the folders of your PATH itself, and only in folders given as full paths, never in the current folder.
  • Which flags are passed. Only flags that decide whether code compiles are passed on: include folders (-I, -isystem, -iquote, -include and similar), macros (-D, -U), the language standard (-std=), the target, and most -f and -m options. Flags that could load code or write files, such as -fplugin, -wrapper, -B, -specs, -Xclang, -mllvm, @file and -fdump-..., are dropped, as are output, dependency, optimization, debugging and warning flags. Any flag Unryu does not know is dropped too. Details counts, under "Flags ignored", the flags that were refused as unsafe or unknown. Output, dependency, warning, debugging and optimization flags, and @file arguments, are dropped without being counted.
  • Your file is not touched. The compiler works on copies in a private temporary folder that only you can reach (in XDG_RUNTIME_DIR, TMPDIR or /tmp), and the folder is removed afterwards. Nothing is ever written next to your source.
  • Your environment stays private. The compiler gets PATH=/usr/bin:/bin and LC_ALL=C, and of your own variables only CPATH, C_INCLUDE_PATH and CPLUS_INCLUDE_PATH, which name folders of headers. Tokens, passwords and other secrets in your environment never reach it.
  • Headers you installed in your home folder. A project's files can come from anyone, so they cannot let a hidden folder of your home into the jail. You can: the folders of check-folders (Preferences > Various, or unryu.conf; folders separated by colons, ~ for your home folder) and of CPATH and the like are let in even when hidden. At first check-folders is ~/.local/include, where make PREFIX=~/.local install puts a library's headers. The compiler searches the check-folders after every other folder, so a library installed there is found without a flags file. Your home folder itself is never let in.
  • It cannot take over the machine. It runs at lower priority, with limited memory, processor time and file size, and without core dumps. A compiler that hangs (for example on an #include of a pipe) is stopped together with everything it started when its time is up, and also when Unryu itself is closed or killed.
  • The analysis does not ask the compiler. Unryu never asks your compiler for its built-in macros or include folders to help the analysis. Doing so made no difference to the brace answers, took eight times as long as the analysis itself, and would have meant running a program for every file you open.

Known limitations of the compiler check

  • The compiler needs the file's headers and flags. For a file outside a set-up project, every copy can fail for that reason alone, whatever the braces look like. Add a compile_flags.txt or compile_commands.json, and name with -I any folder outside the project that the file needs, or add the folder to check-folders. A project that lies directly in your home folder needs a folder of its own, because your whole home folder is never let in. This is on purpose: it keeps your private files out of the jail.
  • Signals on older kernels. On kernels before Linux 6.12 (Landlock version 6), the jail cannot stop the compiler from sending a signal to one of your other programs by its process number. For that to happen, a file would first have to take over the compiler through a bug in it; the compiler could then, say, close one of your programs, but it could still read nothing private, change no file and reach no network. A signal to every process or to a group of processes is refused on every kernel. The analysis and check processes and the worker cannot send signals on any kernel.

Help > Compiler shows a short version of this section in the Details panel.

Other protections

  • Details never loads anything a file names. Text taken from a file, such as a comment shown as documentation or a path, goes into the Details panel with images and raw HTML made into plain characters, so the panel cannot be made to load an image or any other file.
  • Private caches. Unryu's cache folders (~/.cache/unryu/, or under XDG_CACHE_HOME) hold copies of your text, such as recovery copies, so they are made readable by you alone (Files).
  • A project's own build commands need your approval. A settings file in a project's folder can give build commands. Those run as you, with all your rights, so Unryu uses them only after you have seen them and approved them (Tools > Approve Project Build Commands), and asks again whenever they change. Nothing is ever written into your source folders (Build and Run).
  • Commands you set run as you. The Build menu, Execute, the terminal and the custom commands run the commands you set yourself, with your rights and without a jail. That is what they are for; see Build and Run.
  • Desktop errors do not close Unryu. An error reported by the X server does not stop the program, and when the connection to the desktop is lost, your unsaved text is copied first (The Window, Files).

Known limitations

  • Some of a file's content is still handled in the editor itself, outside any jail: the file's encoding and first line (to choose its language), drawing its text, the (escaped) text in Details, and, for Markdown documents, the formatted view's text and the Markdown counts in Details. From the tokens the analysis process sent, and the editor checked, the editor also works out the folds, the other pairs (quotes, tags, block words: plain walks over the tokens), and it looks for the characters that are not what they look like (a scan of the bytes). These are small, plain steps that take nothing apart. A project's compile_commands.json and compile_flags.txt, the images a Markdown document names and the picture files, sixel pictures and compressed pictures a program sends to the terminal are taken apart in the jail.
  • The terminal itself (the control sequences that programs print, which move the cursor, set colors and so on) runs in the editor. Only its pictures go to the worker: moving the whole terminal into a jail would mean running its screen in another process.
  • The jail has been tested on x86-64 only. It has not been tested on ARM64, nor on kernels older than Linux 6.12. This limitation may go away once it has been tested there.
  • On other processors (neither x86-64 nor ARM64) the jail cannot be made, so files open as plain text there. This is on purpose: the jail's rules are written for those two processors.