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-netperm watches a recreated session folder (a new scope is seen at once), new scopes settle a moment before connecting, the panel's graph redraws once per bar; protocol notes for COUNTS ports and system entries
Federico Pereirae637d8f18775
diff --git a/sdk/netstatus.jsx b/sdk/netstatus.jsxindex 7d9cdec..e4b84aa 100644--- a/sdk/netstatus.jsx+++ b/sdk/netstatus.jsx@@ -10,7 +10,7 @@//// startNetStatus() (startShell) also asks lord-server, once an hour, to download the enabled// blocklists that are a day old (lord.fw.updateLists; lord-server does nothing when they are fresh).-import { useEffect, useRef, useState } from 'react';+import { memo, useEffect, useRef, useState } from 'react';import { View, Text, addListener } from '@lordos/runtime';import { createStore, useStore } from './store.js';import { settings } from './settings.js';@@ -30,7 +30,7 @@ const SAMPLES = 300; // one per second: the last five minutes// idle network redraws nothing. The rates and the five minutes behind them stay out of any store;// the panel, while open, reads them once per second.export const netStatus = createStore({ rx: '0', tx: '0' });-const live = { rx: 0, tx: 0, hist: [] }; // hist: [[rxRate, txRate], …]+const live = { rx: 0, tx: 0, hist: [], n: 0 }; // hist: [[rxRate, txRate], …]; n: samples so farlet timer = null, prev = null, panelOpen = false, ticks = 0;const shown = () => settings.get()?.monitor?.menuItem === true;@@ -43,6 +43,7 @@ function tick() {live.rx = Math.max(0, (s.rx - prev.rx) / dt);live.tx = Math.max(0, (s.tx - prev.tx) / dt);live.hist.push([live.rx, live.tx]);+ live.n++;if (live.hist.length > SAMPLES) live.hist.shift();// the bar's text every other second (the panel's numbers every second)if (++ticks % 2 === 0) {@@ -75,7 +76,8 @@ function short(n) {// ---- the panel -----function Graph({ hist }) {+// redrawn when a new 5-second bar is complete, not every second (60 bars are 180 nodes)+const Graph = memo(function Graph({ hist }) {const th = useTheme();// 60 bars of 5 s each (the newest on the right), sent above the line and received belowconst bars = Array.from({ length: 60 }, (_, i) => {@@ -100,7 +102,7 @@ function Graph({ hist }) {))}</View>);-}+}, (a, b) => a.bucket === b.bucket);function appLabel(id, launcher) {if (id === 'lordos') return t('monitor.lordos');@@ -148,7 +150,7 @@ function Panel({ onClose }) {<Text style={{ fontSize: 11, color: '#22c55e' }}>{`↓ ${rate(st.rx)}`}</Text><Text style={{ fontSize: 11, color: '#f97316' }}>{`↑ ${rate(st.tx)}`}</Text></View>- <Graph hist={st.hist} />+ <Graph hist={st.hist} bucket={Math.floor(st.n / 5)} /><Text style={{ fontSize: 10, color: th.textDim, textAlign: 'start' }}>{t('monitor.status.lastMinutes', { down: formatBytes(sum[0]), up: formatBytes(sum[1]) })}</Text>diff --git a/server/src/netperm/netperm.c b/server/src/netperm/netperm.cindex 3848d01..b82c9ae 100644--- a/server/src/netperm/netperm.c+++ b/server/src/netperm/netperm.c@@ -679,6 +679,15 @@ static void scan_all(void) {sync_blk(s);}s->seen = 1;+ /* a session that ended and started again has a new folder under the same name: watch the+ * one there now (for the same folder this returns the same watch), or a new scope would only+ * be found by the 5-second rescan (0.8.4: a component's scope connects right away) */+ {+ char path[160];+ snprintf(path, sizeof path, CG_ROOT "/" CG_SERVICE "/%s", s->dir);+ int wd = inotify_add_watch(G.ifd, path, IN_CREATE | IN_DELETE | IN_ONLYDIR);+ if (wd >= 0) s->wd = wd;+ }scan_session(s);}if (d) closedir(d);diff --git a/server/src/netperm/npproto.h b/server/src/netperm/npproto.hindex 95acf72..27c249d 100644--- a/server/src/netperm/npproto.h+++ b/server/src/netperm/npproto.h@@ -7,7 +7,8 @@* u32 length (little endian, counts the type and the data) · u8 type · data** From lord-server to lord-netperm there is ONE single message, with no data:- * NP_MSG_RELOAD "reread my user's ~/.config/lordos/firewall.json"+ * NP_MSG_RELOAD "reread my user's ~/.config/lordos/firewall.json" (and, 0.8.4, fwlists.txt, the+ * compiled blocklists, through the same reader)* Rules never travel over the socket: lord-netperm reads the user's file itself, from a fixed,* validated path (no links, owned by the user, regular file, up to 4 MB) with the strict reader* of fw/rules.c. Any other message, or one longer than NP_IN_MAX bytes, closes the connection.@@ -16,12 +17,18 @@* NP_MSG_STATUS {"bpf":true,"devices":true,"bluetooth":true,"bytes":true,"dns":"resolved","error":""}* on connect and when it changes* NP_MSG_EVENT {"app":"desktop:x","v":"deny","dir":"out","proto":"tcp","addr":"1.2.3.4",- * "port":443,"by":"rule","rule":7,"flag":"","record":0,+ * "port":443,"by":"rule"|"restricted"|"trusted"|"mode"|"list","rule":7,"flag":"","record":0,* "hosts":["example.com"]} a new connection; hosts:* up to 4 names the resolver* gave for addr* NP_MSG_COUNTS {"desktop:x":[allowed,denied,rx,tx,rxRate,txRate,- * [["1.2.3.4",rx,tx,rxRate,txRate,blocked],...],blocked],...}+ * [["1.2.3.4",rx,tx,rxRate,txRate,blocked,+ * [[port,"tcp"|"udp"|"other","out"|"in",rx,tx,rxRate,txRate],...]],...],blocked],+ * "system:dns":[0,0,rx,tx,rxRate,txRate,[],0],...}+ * (0.8.4: each address's 8 busiest+ * ports; the essential system+ * services' bytes, the same for+ * every user)* every second, if it changed:* connections, bytes (the* cgroup_skb accounting), thediff --git a/server/src/sec/cgroup.c b/server/src/sec/cgroup.cindex f977416..3af8a56 100644--- a/server/src/sec/cgroup.c+++ b/server/src/sec/cgroup.c@@ -240,14 +240,21 @@ int cgroup_enter_root(const char *name) {if (!sess || sscanf(sess + 1, "lordos-session-%u%c", &uid, &tail) != 1) return -1;int fd = open(dir, O_PATH | O_DIRECTORY | O_CLOEXEC);if (fd < 0) return -1;- if (mkdirat(fd, name, 0755) && errno != EEXIST) { close(fd); return -1; }+ int fresh = !mkdirat(fd, name, 0755);+ if (!fresh && errno != EEXIST) { close(fd); return -1; }int lfd = openat(fd, name, O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC);int r = lfd >= 0 ? write_at(lfd, "cgroup.procs", "0") : -1;if (lfd >= 0) close(lfd);close(fd);+ if (!r && fresh) cgroup_settle();return r;}+void cgroup_settle(void) {+ struct timespec ts = { 0, 250 * 1000 * 1000 };+ nanosleep(&ts, NULL);+}+int cgroup_service_leaf(const char *name) {if (!name || strcmp(name, "netd")) return -1; /* the only one (docs/MONITOR.md, "Essential system traffic") */char svc[PATH_MAX];diff --git a/server/src/sec/cgroup.h b/server/src/sec/cgroup.hindex 33c5c8a..d42a28b 100644--- a/server/src/sec/cgroup.h+++ b/server/src/sec/cgroup.h@@ -54,6 +54,12 @@ int cgroup_service_leaf(const char *name);* from the session's «server» leaf, only itself. 0 placed. */int cgroup_enter_root(const char *name);+/* (0.8.4) A quarter of a second for lord-netperm to see a scope that was just created (it watches+ * the session folder with inotify) before the process in it opens a connection: otherwise the first+ * connections would meet no policy. Called after placing a process in a new scope that connects at+ * once (the Store's download child, the components' connectors). */+void cgroup_settle(void);+/* ---- Root-owned app scopes (lord-sessiond) ----* With lord-sessiond, a session's subtree stays root-owned: the scopes are created by root, with a* root-owned cgroup.procs, so an app cannot move itself to another cgroup (it would escape itsdiff --git a/server/src/sec/netconn.c b/server/src/sec/netconn.cindex f7c414e..fa7c816 100644--- a/server/src/sec/netconn.c+++ b/server/src/sec/netconn.c@@ -209,6 +209,7 @@ int netconn_main(int argc, char **argv) {fprintf(stderr, "netconn: could not place the %s connector in %s: its connections are refused\n", argv[2], scope);return 3; /* fail closed: lord-server's requests get EPIPE */}+ if (getenv("LORDOS_SESSIOND")) cgroup_settle(); /* lord-netperm sees the scope before the first connect */for (;;) {NcReq r;ssize_t n = recv(3, &r, sizeof r, 0);