Skip to content

fix(matching): don't read the SELinux label as a snap id - #154

Merged
PapyElGringo merged 1 commit into
mainfrom
fix/snap-app-id
Oct 16, 2026
Merged

PapyElGringo merged 1 commit into
mainfrom
fix/snap-app-id

Conversation

@PapyElGringo

Copy link
Copy Markdown
Contributor

Problem

On Fedora (SELinux), window matching is broken for ordinary applications: a tracked launch of an app lands in a fresh, empty "unknown" tile instead of its placeholder. Captured with a debug build on Fedora Kinoite 44 via ⋮ → "Launch and record", the dump shows the window's app id is the SELinux context:

{"method":"meta_window_created","message":{"appId":"unconfined_u:unconfined_r:unconfined_t:s0-s0:c0_c1023\u0000", ...}}
{"method":"meta_window_patch","message":{"value":"unconfined_u:unconfined_r:unconfined_t:s0-s0:c0_c1023\u0000","type":"UpdateAppId"}}
{"method":"_matching","message":{"kind":"fallback","outcome":"newWindow","trackedWindowId":null,...}}
{"method":"_matching","message":{"kind":"display","windowId":"p:c115d3ef-…","displayedWindowId":"cef79471-…"}}

The target placeholder was org.kde.konsole; with no candidate for the garbage app id the matcher fell through to "create a new window".

Root cause

get_snap_app_id_from_pid (src/embedder/meta_window_state/mod.rs) was written for Ubuntu/AppArmor but ported with the snapd C macro name instead of its value:

let security_label_contents =
    security_label_contents.trim_start_matches("SNAP_SECURITY_LABEL_PREFIX"); // literal, never matches
...
(true, Some(security_label_contents.replace('.', "_")))   // "is snap" whenever the file exists

SNAP_SECURITY_LABEL_PREFIX is a snapd macro whose value is "snap.". Because the literal never matched, the function reported is_snap = true for every process whose /proc/<pid>/attr/current is readable — which, under SELinux, is every process. determine_desktop_file_app_id_from_pid() then returned the SELinux context, and MetaWindow::patch_meta_window (meta_window.rs:318) overwrote the real app id with it (.or() prefers the pid-derived id). The same context also leaked into ProcessInfo::snap_id.

Fix

  • SNAP_SECURITY_LABEL_PREFIX = "snap." (the real value).
  • New snap_app_id_from_security_label() requires the prefix to be present and otherwise returns None, so SELinux contexts, docker-default, unconfined, etc. are not snaps.
  • get_snap_app_id_from_pid uses it.

Tests

Two unit tests cover the parsing: snap.firefox.firefox (enforce) → firefox_firefox, and SELinux/AppArmor non-snap labels → None. cargo test passes (meta_window_state::tests::{snap_security_labels_resolve_to_the_desktop_app_id, non_snap_security_labels_are_never_treated_as_snaps}).

Verification note

End-to-end re-run on the Kinoite VM is in progress. The VM has no GPU (Mesa llvmpipe), where the Flutter debug engine segfaults intermittently in the software rasterizer, which also leaves the DRM device wedged for the next start — a pre-existing environment issue unrelated to this change. I'll confirm the tile now matches once a clean run completes; the unit-level behavior (the parsing that caused the wrong app id) is covered above.

get_snap_app_id_from_pid used the snapd C macro *name*
"SNAP_SECURITY_LABEL_PREFIX" as a string literal; the macro's value is
"snap.". The literal matched nothing, and the function unconditionally
returned is_snap = true whenever /proc/<pid>/attr/current could be read. On
SELinux distributions every process has that file, so
determine_desktop_file_app_id_from_pid() returned the SELinux context and
MetaWindow::patch_meta_window overwrote the real app id with it (Konsole's
org.kde.konsole became
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023). The matcher then
found no app-id candidate and dropped every launch into a new "unknown"
tile.

Parse the AppArmor label with the real prefix and require it, so SELinux
contexts, unconfined profiles and any other non-snap label return no snap.
This also stops the context from leaking into ProcessInfo::snap_id.

Seen in a "Launch and record" dump on Fedora Kinoite 44: a tracked Konsole
launch reported appId as the SELinux context and
"_matching fallback: outcome newWindow, trackedWindowId null".
@PapyElGringo

Copy link
Copy Markdown
Contributor Author

Verified end-to-end on the Fedora Kinoite 44 VM with a debug build of this branch: a tracked Konsole launch now matches its org.kde.konsole placeholder instead of creating a new "unknown" tile (the pre-fix behaviour captured in the dump above).

Note: the VM has no GPU, and the Flutter debug engine then segfaults in Mesa llvmpipe on a later draw (Dolphin launch) — a software-renderer crash unrelated to this change (the release engine is stable on the same VM).

@PapyElGringo
PapyElGringo merged commit 0da3f3a into main Oct 16, 2026
2 checks passed
@PapyElGringo
PapyElGringo deleted the fix/snap-app-id branch October 16, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant