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
lord-sessiond: remove the leaving session's framebuffers on a switch, and keep the boot splash only for the first lend
Federico Pereira4989ef85a71c
diff --git a/server/src/remote/monitor.c b/server/src/remote/monitor.cindex 21ee8e1..3f108a7 100644--- a/server/src/remote/monitor.c+++ b/server/src/remote/monitor.c@@ -92,6 +92,32 @@ static int send_msg(int type, const void *d, size_t n, const int *fds, int nfds)return r == (ssize_t)(5 + n) ? 0 : -1;}+/* Removes every framebuffer of the leaving session. They belong to the open file we lent (ours+ * is the same one), and the next DRM master could otherwise read them back (GETFB2 + map): the+ * last frame of an unlocked desktop. The session itself frees them when it handles RP_UNDISPLAY,+ * but that is asynchronous and a stuck or hostile session never does. Removing the one on the+ * screen turns that output off, which is what a switch shows anyway. */+static void drop_framebuffers(int fd) {+ for (int pass = 0; pass < 16; pass++) {+ uint32_t ids[64];+ struct drm_mode_card_res r = {0};+ if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &r) || !r.count_fbs) return;+ uint32_t n = r.count_fbs < 64 ? r.count_fbs : 64;+ r = (struct drm_mode_card_res){ .fb_id_ptr = (uint64_t)(uintptr_t)ids, .count_fbs = n };+ if (ioctl(fd, DRM_IOCTL_MODE_GETRESOURCES, &r)) return;+ if (r.count_fbs < n) n = r.count_fbs;+ int removed = 0;+ for (uint32_t i = 0; i < n; i++) {+ uint32_t id = ids[i];+ if (!ioctl(fd, DRM_IOCTL_MODE_RMFB, &id)) removed++;+ }+ if (!removed) {+ sd_log("warning: %u framebuffer(s) of the leaving session could not be removed", n);+ return;+ }+ }+}+/* Takes the monitor away from the session that has it. */static void take_back(void) {if (conn >= 0) send_msg(RP_UNDISPLAY, NULL, 0, NULL, 0);@@ -101,6 +127,7 @@ static void take_back(void) {}nin = 0;if (drm >= 0) {+ drop_framebuffers(drm);ioctl(drm, DRM_IOCTL_DROP_MASTER, NULL);close(drm);}diff --git a/server/src/remote/sessiond.c b/server/src/remote/sessiond.cindex d939ec6..3c663f6 100644--- a/server/src/remote/sessiond.c+++ b/server/src/remote/sessiond.c@@ -553,10 +553,22 @@ static int splash_up(void) {static void first_frame(void) {if (!splash_up()) return;int f = open(SD_FIRST_FRAME, O_WRONLY | O_CREAT | O_CLOEXEC | O_NOFOLLOW, 0644);- if (f >= 0) close(f);+ if (f < 0) { sd_log("warning: %s: %s", SD_FIRST_FRAME, strerror(errno)); return; }+ close(f);sd_log("first frame on the monitor: the boot splash can go");}+/* RP_DISPLAY_KEEP only for the first lend of this process: whatever happens to RP_SHOWN (lost on a+ * switch, the file could not be created), a later lend (lock, user switch) must start black, never+ * on the picture left by the previous session. */+static int keep_lend(void) {+ static int lent;+ int keep = !lent && splash_up();+ if (lent) first_frame();+ lent = 1;+ return keep;+}+/* What the workers send: which session to show and messages for the login screen. */static void from_worker(void) {char buf[4200];@@ -566,13 +578,13 @@ static void from_worker(void) {char user[40];if (!strcmp(buf, "show g") && fd >= 0) {set_shown('g', NULL);- if (sd_mon_show(fd, "-", splash_up())) { sd_mon_lost(); set_shown('-', NULL); }+ if (sd_mon_show(fd, "-", keep_lend())) { sd_mon_lost(); set_shown('-', NULL); }return;}if (sscanf(buf, "show u %32s", user) == 1 && fd >= 0 && sd_valid_username(user)) {sd_log("monitor: %s's session", user);set_shown('u', user);- if (sd_mon_show(fd, user, splash_up())) { sd_mon_lost(); set_shown('-', NULL); show_greeter("login", NULL); }+ if (sd_mon_show(fd, user, keep_lend())) { sd_mon_lost(); set_shown('-', NULL); show_greeter("login", NULL); }else save_last_user(user);return;}