Skip to content

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.

lord-netperm: keep no-mic out of the user@ union (it took the microphone away from the whole desktop); test an unknown ALSA node in the scope and from user@

Federico Pereira8eeb8e2edd3f
diff --git a/docs/FIREWALL.md b/docs/FIREWALL.md
index 3fcbe82..d2b4acf 100644
--- a/docs/FIREWALL.md
+++ b/docs/FIREWALL.md
@@ -190,8 +190,10 @@ on `open()` and `mknod()` of a device node, and returns 0 only for the device cl
restricted from (`np_dev_restriction()` in `np_shared.h`, plus, for "no microphone", the ALSA
capture PCMs in `np_snd`). In the app's own scope "no microphone" fails closed: an ALSA node the
last scan of `/sys/class/sound` hasn't classified yet (a USB microphone plugged in, at most 5 s)
-is denied too. In the `user@` union only the known capture nodes are, so the user's own PipeWire
-can still open a headset plugged in meanwhile. Everything else returns 1. Programs systemd attaches higher up (`DeviceAllow=`) still
+is denied too. "No microphone" is never part of the `user@` union: there it would deny the ALSA
+capture nodes to the user's own PipeWire, which drops the microphone for every app and doesn't
+get it back. A process that escaped to `user@` is held by the PipeWire guard instead; opening the
+card directly from there is a residual risk. Everything else returns 1. Programs systemd attaches higher up (`DeviceAllow=`) still
apply: the kernel allows only what all of them allow. A denial is logged by `lord-netperm` once per
5 s, not counted with the connections. `lord-server`'s own scope (`lordos`) never gets device
restrictions in the kernel: it opens the camera, the FIDO key and the sound for the apps after
diff --git a/server/src/netperm/netperm.c b/server/src/netperm/netperm.c
index b13ced9..aec7363 100644
--- a/server/src/netperm/netperm.c
+++ b/server/src/netperm/netperm.c
@@ -313,7 +313,12 @@ static void sync_union(Session *s) {
if (!G.bpf_ok || !s->user_cg) return;
NpApp u;
memset(&u, 0, sizeof u);
- for (int k = 0; k < s->nsc; k++) u.flags |= s->sc[k].app_v.flags;
+ /* "no microphone" stays out of the union: under user@ it would deny the ALSA capture nodes
+ * to the user's own PipeWire, which then drops the microphone for every app (and doesn't get
+ * it back). A process escaped there is held by the PipeWire guard instead (its clients count
+ * as restricted while restricted apps run); reading the card directly from there is the
+ * residual risk (docs/FIREWALL.md). */
+ for (int k = 0; k < s->nsc; k++) u.flags |= s->sc[k].app_v.flags & ~NP_R_NO_MIC;
if (u.flags) {
u.trusted = 1; /* whatever the union doesn't restrict is allowed without notice */
u.mode = NP_M_SILENT;
diff --git a/server/src/netperm/np.bpf.c b/server/src/netperm/np.bpf.c
index 18a2afd..0e63582 100644
--- a/server/src/netperm/np.bpf.c
+++ b/server/src/netperm/np.bpf.c
@@ -296,9 +296,9 @@ SEC("cgroup/dev") int np_dev(struct bpf_cgroup_dev_ctx *ctx) {
if (!app) return 1;
if (snd) {
/* Recording straight from the card. In the app's own scope this fails closed: an ALSA node
- * the last scan didn't classify (a USB microphone plugged in since) counts as capture. In
- * the user@ union (the user's own PipeWire and WirePlumber too) only the known capture
- * nodes are denied, so plugging in a headset still works for the desktop. */
+ * the last scan didn't classify (a USB microphone plugged in since) counts as capture.
+ * Outside it only the known capture nodes count (lord-netperm keeps no-mic out of the
+ * user@ union today, so this is for a union that ever carries it). */
np_u32 minor = ctx->minor;
np_u32 *kind = bpf_map_lookup_elem(&np_snd, &minor);
np_u64 sid = bpf_get_current_ancestor_cgroup_id((int)cfg->level);
diff --git a/server/tests/fwlinux/mic.sh b/server/tests/fwlinux/mic.sh
index 1a236d1..a068903 100755
--- a/server/tests/fwlinux/mic.sh
+++ b/server/tests/fwlinux/mic.sh
@@ -88,6 +88,21 @@ except OSError as e: print(errno.errorcode.get(e.errno))' "$CAP" 2>&1 | tail -1)
try: os.close(os.open(sys.argv[1], os.O_RDONLY | os.O_NONBLOCK)); print("ok")
except OSError as e: print(errno.errorcode.get(e.errno))' "$PB" 2>&1 | tail -1)
[ "$got" != EPERM ] && ok "the playback node $PB is not refused ($got)" || bad "playback node refused"
+ # an ALSA node the last scan hasn't seen (a microphone plugged in a moment ago): refused to the
+ # app (fail closed), but not to the user's own services in user@ (the restriction union)
+ NODE=$HOME/fwlinux-snd-new
+ sudo rm -f "$NODE"; sudo mknod -m 666 "$NODE" c 116 250
+ got=$(in_scope "$SC" python3 -c 'import os,sys,errno
+try: os.close(os.open(sys.argv[1], os.O_RDONLY | os.O_NONBLOCK)); print("ok")
+except OSError as e: print(errno.errorcode.get(e.errno))' "$NODE" 2>&1 | tail -1)
+ [ "$got" = EPERM ] && ok "an unknown ALSA node → EPERM in the app's scope" || bad "unknown ALSA node in the scope → $got"
+ if command -v systemd-run >/dev/null; then
+ got=$(timeout 10 systemd-run --user --pipe --quiet python3 -c 'import os,sys,errno
+try: os.close(os.open(sys.argv[1], os.O_RDONLY | os.O_NONBLOCK)); print("ok")
+except OSError as e: print(errno.errorcode.get(e.errno))' "$NODE" 2>&1 | tail -1)
+ [ "$got" != EPERM ] && ok "the same node from user@ is not refused ($got)" || bad "unknown ALSA node refused in user@"
+ fi
+ sudo rm -f "$NODE"
fi
echo "7. lying about who it is: still nothing recorded"