Unryu: 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 (Unryu) holds your files, your desktop and your unsaved text never takes the file's text apart itself checks every answer before using it runs a compiler only when you ask Analysis process one for each open document reads the code: colors, braces, names may read: project, system may not: write, connect, run Check process only while Suggest Repairs runs works out which repairs to try the same jail as the analysis cannot run the compiler itself Worker flags files, a document's images, the terminal's pictures may read: no file at all may not: write, connect, run Compiler only on Ctrl+Shift+B or "ask the compiler", on copies may read: system, project may not: write, see secrets
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).

AreaAnalysis and check processes, the workerCompiler
Reading filesThe 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 homeFolders 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 folderNever 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.
WritingNothing, 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.
NetworkNo 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 programsCannot 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 featuresNo 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.
PrivilegesCan never gain rights: starting a setuid program gives it nothing.
Size and timeAt 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

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.

1. Find the flags compile_commands.json (also in build/) or compile_flags.txt in the file's folder, or the nearest folder above it nothing runs: files are only read, in a jail 2. Choose the compiler the one the project names, if it is the system's own, or one you listed in trusted-compilers; never a wrapper (ccache ...) otherwise: the system's cc or c++, and Details says why 3. Keep safe flags kept: include folders, macros, language standard, -f and -m dropped: anything that could load code or write files no shell: nothing in a flag can become a command 4. Run it, locked in in the jail, on copies in a private folder low priority, limited memory and time of your environment, sees only the header paths
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.

Known limitations of the compiler check

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

Other protections

Known limitations