LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.
C cdebiandesktop-environmentebpffirewalllandlocklinuxlinux-distributionopen-sourceprivacyquickjsraspberry-pi-5reactsecuritywaylandwayland-compositor
Launcher: no-files apps get their working directory inside the view, private shm and terminals, read-only shared caches, no writable grant over protected folders, the opened file re-checked without symlinks; never run outside the app's scope in a session
Federico Pereirac15a50e6f3ae
diff --git a/server/src/apps.c b/server/src/apps.cindex 21db01a..50f7432 100644--- a/server/src/apps.c+++ b/server/src/apps.c@@ -237,11 +237,16 @@ static void find_icon(const char *name, char *out, size_t n) {/* ---- list ---- */+/* A desktop id the launcher can run: it must also make a valid app scope name+ * ("app-lordos-<id>.scope", cgroup_scope_name_ok: no '+', at most 62 characters, no "..") and+ * never one that reads as a .lpk package's scope ("lpk-...": that would be lpk:<rest>'s identity,+ * rules and restrictions). */+#define DESKTOP_ID_MAX 62static int valid_id(const char *id) {size_t n = strlen(id);- if (!n || n >= sizeof apps[0].id) return 0;- for (const char *p = id; *p; p++) if (!isalnum((unsigned char)*p) && !strchr("._-+", *p)) return 0;- return id[0] != '.' && id[0] != '-';+ if (!n || n >= sizeof apps[0].id || n > DESKTOP_ID_MAX) return 0;+ for (const char *p = id; *p; p++) if (!isalnum((unsigned char)*p) && !strchr("._-", *p)) return 0;+ return id[0] != '.' && id[0] != '-' && !strstr(id, "..") && strncmp(id, "lpk-", 4);}static void app_dirs(char dirs[2][PATH_MAX]) {@@ -403,7 +408,7 @@ static void open_log(void) {typedef struct {SandboxFilesCfg cfg;- char home[PATH_MAX], runtime[PATH_MAX], wayland[64];+ char home[PATH_MAX], runtime[PATH_MAX], wayland[64], opened[PATH_MAX], cwd[PATH_MAX];char buf[2 * SANDBOX_FILES_MAX][PATH_MAX];int nbuf, nrw, nro;} FilesPlan;@@ -430,11 +435,18 @@ static void plan_add(FilesPlan *p, int rw, const char *fmt, const char *a, const* if it can't name a folder that belongs to someone else's startup, keys or settings. The id is* the only name used: Exec, StartupWMClass and Name are free text of the .desktop file. */static int own_dir_ok(const char *id) {+ /* folders another program reads to run something, or that hold someone else's keys or data */static const char *const deny[] = { "lordos", "ssh", "gnupg", "autostart", "applications", "systemd", "environment.d","keyrings", "dconf", "git", "trash", "mime", "fontconfig", "pulse", "pipewire","wireplumber", "user-dirs.dirs", "mimeapps.list", "gtk-3.0", "gtk-4.0", "fish","bash", "zsh", "nvim", "vim", "emacs", "nano", "mc", "flatpak", "containers",- "thumbnails", "recently-used.xbel", "icons", "themes", "fonts", NULL };+ "thumbnails", "recently-used.xbel", "icons", "themes", "fonts", "dbus-1",+ "user-tmpfiles.d", "xdg-desktop-portal", "menus", "kio", "plasma-workspace",+ "tmux", "kitty", "alacritty", "foot", "wezterm", "mozilla", "chromium",+ "google-chrome", "BraveSoftware", "Code", "keepassxc", "evolution", "Electron",+ "gstreamer-1.0", "mesa_shader_cache", "mesa_shader_cache_db", "radv_builtin_shaders",+ "bin", "applications-merged", "desktop-directories", "kservices5", "kservices6",+ "speech-dispatcher", "environment", "profile.d", NULL };size_t n = strlen(id);if (!n || n > 100 || id[0] == '.' || id[0] == '-') return 0;for (const char *q = id; *q; q++) if (!isalnum((unsigned char)*q) && !strchr("._-+", *q)) return 0;@@ -445,21 +457,45 @@ static int own_dir_ok(const char *id) {/* A writable grant must never land on a folder the system reads to start or install something,* or that holds a security decision (fsops_protected), nor on the shell's startup files. */+/* Folders of the home that make the session run something or hold keys: no writable grant inside+ * them, and none on a folder that contains one (opening ~/.config with an app must not hand it+ * ~/.config/autostart). fsops_protected's list counts the same way. */+static const char *const sensitive[] = { "/.ssh", "/.gnupg", "/.config/systemd", "/.local/share/systemd",+ "/.local/share/dbus-1", "/.config/environment.d", "/.config/user-tmpfiles.d",+ "/.local/bin", "/bin", "/.config/autostart", "/.local/share/applications",+ "/.config/lordos", "/.local/share/lordos", NULL };++static int path_under(const char *path, const char *dir) {+ size_t n = strlen(dir);+ return n && !strncmp(path, dir, n) && (path[n] == '/' || !path[n]);+}+static int grant_ok(const char *path) {if (fsops_protected(path)) return 0;+ const char *h = getenv("HOME");+ char home[PATH_MAX], full[PATH_MAX + 64];+ if (!h || !realpath(h, home)) return 0;+ if (!strcmp(path, home)) return 0; /* the whole home: never writable */+ for (int i = 0; sensitive[i]; i++) {+ snprintf(full, sizeof full, "%s%s", home, sensitive[i]);+ if (path_under(path, full) || path_under(full, path)) return 0;+ }const char *base = strrchr(path, '/');base = base ? base + 1 : path;- static const char *const startup[] = { ".bashrc", ".bash_profile", ".bash_login", ".profile", ".zshrc", ".zprofile",- ".zshenv", ".zlogin", ".xprofile", ".xsession", ".xsessionrc", ".pam_environment",- ".gitconfig", ".ssh", ".gnupg", NULL };+ static const char *const startup[] = { ".bashrc", ".bash_profile", ".bash_login", ".bash_logout", ".bash_aliases",+ ".profile", ".zshrc", ".zprofile", ".zshenv", ".zlogin", ".zlogout",+ ".xprofile", ".xsession", ".xsessionrc", ".xinitrc", ".Xresources",+ ".pam_environment", ".gitconfig", ".ssh", ".gnupg", NULL };for (int i = 0; startup[i]; i++) if (!strcmp(base, startup[i])) return 0;+ struct stat st;+ if (!lstat(path, &st) && S_ISREG(st.st_mode) && st.st_nlink > 1) return 0; /* maybe another name of one of those */return 1;}static int is_dir(const char *p) { struct stat st; return !lstat(p, &st) && S_ISDIR(st.st_mode); }/* What a restricted app may touch (see sandbox.h). file: the realpath it was opened with, or NULL. */-static FilesPlan *files_plan(const DesktopApp *a, const char *file) {+static FilesPlan *files_plan(const DesktopApp *a, const char *file, const char *cwd) {const char *h = getenv("HOME");FilesPlan *p = calloc(1, sizeof *p);if (!p) return NULL;@@ -467,7 +503,13 @@ static FilesPlan *files_plan(const DesktopApp *a, const char *file) {const char *home = p->home;p->cfg.home = home;const char *rt = getenv("XDG_RUNTIME_DIR");- if (rt && rt[0] == '/' && realpath(rt, p->runtime)) p->cfg.runtime_dir = p->runtime;+ char rtdef[64];+ snprintf(rtdef, sizeof rtdef, "/run/user/%u", (unsigned)getuid());+ if (!(rt && rt[0] == '/' && realpath(rt, p->runtime)) && !realpath(rtdef, p->runtime)) {+ free(p); /* no runtime dir to hide: its sockets (the bus) would stay reachable */+ return NULL;+ }+ p->cfg.runtime_dir = p->runtime;/* the only sockets of the session it keeps: the display and the sound server's normal ones* (never pipewire-0-manager, the bus, systemd's, agents' or LordOS's own) */const char *wd = getenv("WAYLAND_DISPLAY");@@ -505,7 +547,9 @@ static FilesPlan *files_plan(const DesktopApp *a, const char *file) {* thumbnails are pictures of the user's documents) */static const char *const caches[] = { "fontconfig", "mesa_shader_cache", "mesa_shader_cache_db", "radv_builtin_shaders","gstreamer-1.0", NULL };- for (int k = 0; caches[k]; k++) plan_add(p, 1, "%s/.cache/%s", home, caches[k]);+ /* read only: they are shared with unrestricted apps, which load them as trusted (a crafted+ * font or shader cache would run in them) */+ for (int k = 0; caches[k]; k++) plan_add(p, 0, "%s/.cache/%s", home, caches[k]);/* the desktop's look and settings, read only */static const char *const look[] = { ".config/gtk-3.0", ".config/gtk-4.0", ".config/fontconfig", ".config/dconf",".config/mimeapps.list", ".config/user-dirs.dirs", ".config/user-dirs.locale",@@ -514,7 +558,16 @@ static FilesPlan *files_plan(const DesktopApp *a, const char *file) {".local/share/mime", ".local/share/applications", ".fonts", ".icons", ".themes", NULL };for (int k = 0; look[k]; k++) plan_add(p, 0, "%s/%s", home, look[k]);/* "Open with": that file or folder only (read only if it is one of the protected ones) */- if (file) plan_add(p, grant_ok(file), "%s%s", file, "");+ if (file) {+ struct stat st;+ if (stat(file, &st)) { free(p); return NULL; }+ plan_add(p, grant_ok(file), "%s%s", file, "");+ snprintf(p->opened, sizeof p->opened, "%s", file);+ p->cfg.opened = p->opened;+ p->cfg.opened_dev = (unsigned long long)st.st_dev;+ p->cfg.opened_ino = (unsigned long long)st.st_ino;+ }+ if (cwd && cwd[0] == '/') { snprintf(p->cwd, sizeof p->cwd, "%s", cwd); p->cfg.cwd = p->cwd; }return p;}@@ -561,7 +614,7 @@ static int launch(const char *id, const char *file) {char fwid[FW_APP_MAX];snprintf(fwid, sizeof fwid, "desktop:%s", id);if (restrict_blocks(fwid, FW_R_NO_FILES)) {- if (!sandbox_landlock_abi() || !(plan = files_plan(a, file))) {+ if (!sandbox_landlock_abi() || !(plan = files_plan(a, file, cwd))) {fprintf(stderr, "apps: %s is restricted to no files, but Landlock is not available: not launched\n", id);free(buf);return -1;@@ -583,7 +636,14 @@ static int launch(const char *id, const char *file) {syscall(SYS_close_range, 3, ~0u, 0);const char *home = getenv("HOME");if (!cwd[0] || chdir(cwd)) { if (home && chdir(home)) {} }- app_scope_enter(id); /* its own app-lordos-<id>.scope cgroup (the monitor attributes it) */+ /* its own app-lordos-<id>.scope cgroup: the firewall, the Monitor, the PipeWire guard and+ * the notification server know the app only by it. In a LordOS session a launch that can't+ * be placed there never runs (it would run as lord-server itself, with none of its rules). */+ if (app_scope_enter(id) && getenv("LORDOS_SESSIOND")) {+ static const char msg[] = "apps: could not place the app in its own scope: not launched\n";+ if (write(2, msg, sizeof msg - 1) < 0) {}+ _exit(126);+ }/* its own view (namespaces: no session sockets, only its folders), then Landlock */if (plan && (sandbox_files_isolate(&plan->cfg) || sandbox_apply_files(&plan->cfg))) {static const char msg[] = "apps: could not apply the no-files restriction: not launched\n";diff --git a/server/src/sec/cgroup.c b/server/src/sec/cgroup.cindex 2829a7b..cad2176 100644--- a/server/src/sec/cgroup.c+++ b/server/src/sec/cgroup.c@@ -250,11 +250,14 @@ int cgroup_delegate_session(unsigned uid, unsigned gid) {return 0;}-void app_scope_enter(const char *id) {- char name[80];- if (snprintf(name, sizeof name, "app-lordos-%s.scope", id) >= (int)sizeof name) return;+int app_scope_enter(const char *id) {+ char name[96];+ if (snprintf(name, sizeof name, "app-lordos-%s.scope", id) >= (int)sizeof name || !cgroup_scope_name_ok(name)) {+ fprintf(stderr, "cgroup: %s can't be an app scope\n", id);+ return -1;+ }CgroupLimits lim = { .mem_high_mb = 0, .mem_max_mb = 0, .cpu_percent = 0 }; /* Linux apps: no limit, attribution only */- cgroup_enter(name, &lim);+ return cgroup_enter(name, &lim);}/* ---- lord-sessiond side: placing a session process into its app scope ---- */diff --git a/server/src/sec/cgroup.h b/server/src/sec/cgroup.hindex b4943bd..a275a93 100644--- a/server/src/sec/cgroup.h+++ b/server/src/sec/cgroup.h@@ -23,9 +23,9 @@ typedef struct {* applies the limits. 0 if it ended up in the scope; -1 if it couldn't (already warned, the caller goes on). */int cgroup_enter(const char *name, const CgroupLimits *lim);-/* Shortcut for the child before execve: enters app-lordos-<id>.scope with loose limits. Only- * logs a warning if it fails. */-void app_scope_enter(const char *id);+/* Shortcut for the child before execve: enters app-lordos-<id>.scope with loose limits. The+ * launcher refuses to exec when it fails inside a LordOS session. */+int app_scope_enter(const char *id); /* 0 placed; -1 not (invalid scope name, refused or no answer) *//* The cgroup v2 path of the current process, relative to /sys/fs/cgroup (e.g. ".../app.slice/..."),* so the monitor knows which scope it's in. "" if it couldn't be read. */diff --git a/server/src/sec/sandbox.c b/server/src/sec/sandbox.cindex ec4f19e..33f19e7 100644--- a/server/src/sec/sandbox.c+++ b/server/src/sec/sandbox.c@@ -33,6 +33,10 @@#include <sys/socket.h>#ifdef __has_include+# if __has_include(<linux/openat2.h>)+# include <linux/openat2.h>+# define HAVE_OPENAT2 1+# endif# if __has_include(<linux/landlock.h>)# include <linux/landlock.h># define HAVE_LANDLOCK 1@@ -157,6 +161,29 @@ static int apply_landlock(const SandboxConfig *cfg, const int *ro_fds, const int/* ---- "no files" for Linux apps (sandbox.h) ---- */+/* The "Open with" grant, opened again without following any symlink, and only if it is still the+ * inode the launcher checked: a running instance of the app may have swapped a component of the+ * path for a symlink to somewhere else since. -1: the grant is dropped (fail closed). */+static int open_opened(const SandboxFilesCfg *cfg) {+#if defined(HAVE_OPENAT2) && defined(SYS_openat2)+ struct open_how how;+ memset(&how, 0, sizeof how);+ how.flags = O_PATH | O_CLOEXEC;+ how.resolve = RESOLVE_NO_SYMLINKS | RESOLVE_NO_MAGICLINKS;+ int fd = (int)syscall(SYS_openat2, AT_FDCWD, cfg->opened, &how, sizeof how);+ if (fd < 0) return -1;+ struct stat st;+ if (fstat(fd, &st) || (unsigned long long)st.st_dev != cfg->opened_dev || (unsigned long long)st.st_ino != cfg->opened_ino ||+ !(S_ISDIR(st.st_mode) || S_ISREG(st.st_mode))) { close(fd); return -1; }+ return fd;+#else+ (void)cfg;+ return -1;+#endif+}++static int is_opened(const SandboxFilesCfg *cfg, const char *path) { return cfg->opened && !strcmp(cfg->opened, path); }+int sandbox_landlock_abi(void) {#ifdef HAVE_LANDLOCKint abi = ll_abi();@@ -201,15 +228,21 @@ int sandbox_apply_files(const SandboxFilesCfg *cfg) {for (int i = 0; sys_ro[i]; i++) ll_path(rs, sys_ro[i], ro);for (int i = 0; sys_rw[i]; i++) ll_path(rs, sys_rw[i], rw);if (cfg->runtime_dir) ll_path(rs, cfg->runtime_dir, rw);- for (int i = 0; i < SANDBOX_FILES_MAX && cfg->ro[i]; i++) {- struct stat st;- if (stat(cfg->ro[i], &st)) continue;- ll_path(rs, cfg->ro[i], S_ISDIR(st.st_mode) ? ro : (LANDLOCK_ACCESS_FS_READ_FILE & handled));- }- for (int i = 0; i < SANDBOX_FILES_MAX && cfg->rw[i]; i++) {- struct stat st;- if (stat(cfg->rw[i], &st)) continue;- ll_path(rs, cfg->rw[i], S_ISDIR(st.st_mode) ? rw : file_rw);+ for (int pass = 0; pass < 2; pass++) {+ const char *const *list = pass ? cfg->rw : cfg->ro;+ for (int i = 0; i < SANDBOX_FILES_MAX && list[i]; i++) {+ struct stat st;+ if (is_opened(cfg, list[i])) {+ int fd = open_opened(cfg);+ if (fd < 0) continue;+ if (!fstat(fd, &st))+ ll_fd(rs, fd, S_ISDIR(st.st_mode) ? (pass ? rw : ro) : (pass ? file_rw : (LANDLOCK_ACCESS_FS_READ_FILE & handled)));+ close(fd);+ continue;+ }+ if (stat(list[i], &st)) continue;+ ll_path(rs, list[i], S_ISDIR(st.st_mode) ? (pass ? rw : ro) : (pass ? file_rw : (LANDLOCK_ACCESS_FS_READ_FILE & handled)));+ }}if (apply_nopriv()) { close(rs); return -1; }int r = ll_enforce(rs);@@ -268,7 +301,7 @@ int sandbox_files_isolate(const SandboxFilesCfg *cfg) {if (!cfg->home || cfg->home[0] != '/' || !strcmp(cfg->home, "/")) return -1;char map[64];unsigned uid = (unsigned)getuid(), gid = (unsigned)getgid();- if (unshare(CLONE_NEWUSER | CLONE_NEWNS | CLONE_NEWPID)) return -1;+ if (unshare(CLONE_NEWUSER | CLONE_NEWNS | CLONE_NEWPID | CLONE_NEWIPC)) return -1;if (write_file("/proc/self/setgroups", "deny")) return -1;snprintf(map, sizeof map, "%u %u 1", uid, uid);if (write_file("/proc/self/uid_map", map)) return -1;@@ -300,8 +333,16 @@ int sandbox_files_isolate(const SandboxFilesCfg *cfg) {for (int i = 0; i < SANDBOX_FILES_MAX && list[i]; i++) {if (!is_under(list[i], cfg->home) || !strcmp(list[i], cfg->home)) continue; /* outside home: Landlock alone */struct stat st;- if (lstat(list[i], &st) || !(S_ISDIR(st.st_mode) || S_ISREG(st.st_mode))) continue;- int t = (int)syscall(SYS_open_tree, AT_FDCWD, list[i], OPEN_TREE_CLONE | O_CLOEXEC);+ int t;+ if (is_opened(cfg, list[i])) {+ int fd = open_opened(cfg);+ if (fd < 0 || fstat(fd, &st)) { if (fd >= 0) close(fd); continue; }+ t = (int)syscall(SYS_open_tree, fd, "", OPEN_TREE_CLONE | O_CLOEXEC | AT_EMPTY_PATH);+ close(fd);+ } else {+ if (lstat(list[i], &st) || !(S_ISDIR(st.st_mode) || S_ISREG(st.st_mode))) continue;+ t = (int)syscall(SYS_open_tree, AT_FDCWD, list[i], OPEN_TREE_CLONE | O_CLOEXEC);+ }if (t < 0) continue;keep[nk].fd = t; keep[nk].dir = S_ISDIR(st.st_mode); keep[nk].path = list[i]; keep[nk].ro = pass; nk++;}@@ -325,11 +366,19 @@ int sandbox_files_isolate(const SandboxFilesCfg *cfg) {struct stat vt;if (!stat("/var/tmp", &vt)) bad |= mount("tmpfs", "/var/tmp", "tmpfs", MS_NOSUID | MS_NODEV, "mode=1777");bad |= mount("proc", "/proc", "proc", MS_NOSUID | MS_NODEV | MS_NOEXEC, NULL);+ /* /dev stays (GPU, sound, camera: lord-netperm decides those), but not the session's shared+ * memory nor its terminals (keystrokes of a sudo password, TIOCSTI) */+ if (!stat("/dev/shm", &vt)) bad |= mount("tmpfs", "/dev/shm", "tmpfs", MS_NOSUID | MS_NODEV, "mode=1777");+ bad |= mount("devpts", "/dev/pts", "devpts", MS_NOSUID | MS_NOEXEC, "newinstance,ptmxmode=0666,mode=0620");+ if (!bad) bad |= mount("/dev/pts/ptmx", "/dev/ptmx", NULL, MS_BIND, NULL);for (int i = 0; i < nk && !bad; i++) {if (bind_clone(keep[i].fd, keep[i].path, keep[i].dir)) { bad = 1; break; }if (keep[i].ro) mount(NULL, keep[i].path, NULL, MS_REMOUNT | MS_BIND | MS_RDONLY | MS_NOSUID | MS_NODEV, NULL);}for (int i = 0; i < nk; i++) close(keep[i].fd);+ /* the working directory again, inside the view: the one inherited still points into the real+ * folders under the tmpfs (relative connect() to the session bus, sockets in the home) */+ if (!bad && (!cfg->cwd || chdir(cfg->cwd)) && chdir(cfg->home)) bad = 1;char ok = !bad;if (write(sync[1], &ok, 1) < 0) {}close(sync[1]);diff --git a/server/src/sec/sandbox.h b/server/src/sec/sandbox.hindex c37ffd3..0a6eb2d 100644--- a/server/src/sec/sandbox.h+++ b/server/src/sec/sandbox.h@@ -89,6 +89,11 @@ typedef struct {const char *rw[SANDBOX_FILES_MAX + 1]; /* NULL-terminated */const char *ro[SANDBOX_FILES_MAX + 1];const char *sockets[8]; /* names inside runtime_dir kept visible (wayland-0...), NULL-terminated */+ const char *cwd; /* the .desktop's Path= (or NULL: the home folder), entered inside the view */+ /* the file or folder the app was opened with ("Open with"; also in rw[] or ro[]): opened+ * again without following any symlink and only if it is still the same inode the launcher checked */+ const char *opened;+ unsigned long long opened_dev, opened_ino;} SandboxFilesCfg;/* Before sandbox_apply_files: the app's own view of the system, so no unix socket of the session@@ -98,7 +103,10 @@ typedef struct {* - the home folder is an empty tmpfs with only rw[] and ro[] bound into it (ro[] read-only);* - the runtime dir is an empty tmpfs with only sockets[] bound into it: no session bus, no* systemd user manager, no agents, no LordOS sockets;- * - /tmp and /var/tmp are private tmpfs (no other program's sockets);+ * - /tmp, /var/tmp and /dev/shm are private tmpfs (no other program's sockets or shared memory),+ * with its own IPC namespace, and /dev/pts is a new devpts instance (not the session's terminals);+ * - the working directory is entered again inside the view (cwd, else the home folder): a+ * directory opened before the tmpfs went on would still reach what they hide;* - /proc is a new procfs of the new PID namespace (no /proc/<pid>/root of the session's* processes back into the real one).* The calling process forks: the parent _exits (the caller already is an orphan), the child isdiff --git a/server/tests/fwlinux/files.sh b/server/tests/fwlinux/files.shindex 38f13f4..7623b06 100755--- a/server/tests/fwlinux/files.sh+++ b/server/tests/fwlinux/files.sh@@ -19,7 +19,8 @@ mkdir -p "$APPS" ~/Documents ~/fwlinux-openecho secret > ~/Documents/fwlinux-secret.txtecho "opened with" > ~/fwlinux-open/note.txtecho sibling > ~/fwlinux-open/fwlinux-sibling.txt-mkdir -p ~/.config/fwprobe ~/.cache/fwprobe+mkdir -p ~/.config/fwprobe ~/.cache/fwprobe ~/.cache/fontconfig+echo shm > /dev/shm/fwlinux-shm-$U # the session's shared memory: not visible to the appPROBE=~/.config/fwprobe/probe.py # its own config dir: visible to the restricted appcp "$D/files_probe.py" "$PROBE"SPID=$(pgrep -u "$U" -o -x lord-server || echo 1) # a session process: its /proc/<pid>/root must not be reachable@@ -32,6 +33,7 @@ cat > "$APPS/fwprobe.desktop" <<DESKType=ApplicationName=Files restriction probeExec=python3 $PROBE --outside-pid=$SPID --tmp-socket=$TSOCK %f+Path=/run/user/$UMimeType=text/plain;NoDisplay=falseDESK@@ -77,6 +79,10 @@ expect connect_pipewire_manager "No such file"expect outside_proc_visible "No such file"expect outside_proc_root "No such file"expect connect_tmp_socket "No such file"+expect cwd_relative_bus "No such file"+expect session_pts_hidden ok+expect read_session_shm "No such file"+expect write_shared_cache "@(Read-only|Permission denied)*"expect systemd_run_user "exit"expect gdbus_start_transient_unit "exit"[ -e ~/.cache/fwprobe/escaped ] && bad "a process escaped through the user manager" || ok "nothing started through the user manager"@@ -87,6 +93,10 @@ expect read_opened_file okexpect write_opened_file okexpect read_next_to_opened "@(Permission denied|No such file)*"expect read_documents "@(Permission denied|No such file)*"+echo "3b. opened with a folder that holds protected ones (~/.config): never writable"+probe ~/.config+expect write_autostart "@(Permission denied|No such file|Read-only)*"+[ -e ~/.config/autostart/fwlinux.desktop ] && bad "an autostart entry was written through ~/.config" || ok "~/.config was not granted writable"echo "4. malicious .desktop files: names chosen to reach other programs' folders"EVIL=/usr/local/lib/lordos-tests/files_probe.py # a system path: these ids get no folders of their own@@ -148,6 +158,6 @@ DESKrm -f "$APPS/fwgtkdoc.desktop" "$APPS/fwgtkopen.desktop"rm -rf ~/.cache/fwgtkdoc ~/.cache/fwgtkopen ~/.config/fwgtkdoc ~/.config/fwgtkopen ~/.local/share/fwgtkdoc ~/.local/share/fwgtkopen ~/.local/state/fwgtkdoc ~/.local/state/fwgtkopenfi-rm -f "$APPS/fwprobe.desktop" "$APPS/fwgtk.desktop" ~/Documents/fwlinux-secret.txt "$OUT"+rm -f "$APPS/fwprobe.desktop" "$APPS/fwgtk.desktop" ~/Documents/fwlinux-secret.txt "$OUT" /dev/shm/fwlinux-shm-$U ~/.cache/fontconfig/fwlinux-proberm -rf ~/fwlinux-open ~/.config/fwprobe ~/.cache/fwprobe ~/.local/share/fwprobe ~/.local/state/fwprobefwlinux_donediff --git a/server/tests/fwlinux/files_probe.py b/server/tests/fwlinux/files_probe.pyindex 4b36114..785a7c6 100755--- a/server/tests/fwlinux/files_probe.py+++ b/server/tests/fwlinux/files_probe.py@@ -41,6 +41,14 @@ t("connect_systemd_private", lambda: conn(rt + "/systemd/private"))t("connect_pipewire_manager", lambda: conn(rt + "/pipewire-0-manager"))t("connect_wayland", lambda: conn(rt + "/" + os.environ.get("WAYLAND_DISPLAY", "wayland-0")))t("connect_pipewire", lambda: conn(rt + "/pipewire-0"))+# the working directory it was started in (the .desktop's Path=): a relative connect must not reach+# the real folder hidden under the tmpfs+t("cwd_relative_bus", lambda: conn("bus"))+def no_session_pts():+ if [n for n in os.listdir("/dev/pts") if n.isdigit()]: raise OSError(0, "session terminals visible")+t("session_pts_hidden", no_session_pts)+t("read_session_shm", lambda: rd("/dev/shm/fwlinux-shm-%d" % os.getuid()))+t("write_shared_cache", lambda: wr(home + "/.cache/fontconfig/fwlinux-probe"))if outside:t("outside_proc_root", lambda: conn("/proc/%s/root%s/bus" % (outside[0], rt)))t("outside_proc_visible", lambda: os.stat("/proc/%s" % outside[0]))