Skip to content

fix(devices): close the LUKS mapping when locking internal volumes - #1952

Merged
l0gicgate merged 5 commits into
lgse:mainfrom
wmfeht:fix/1923-lock-internal-luks
Oct 31, 2026
Merged

l0gicgate merged 5 commits into
lgse:mainfrom
wmfeht:fix/1923-lock-internal-luks

Conversation

@wmfeht

@wmfeht wmfeht commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Description

Locking an encrypted volume on an internal (non-removable) disk left its dm-crypt mapping open. Lock only closed the container by stopping a removable password drive through GIO; internal SATA/NVMe disks have no stoppable drive, so Lock unmounted the filesystem and stopped there, and once the filesystem was unmounted it refused with "This volume has no supported lock operation while unmounted".

  • When there is no stoppable drive, Lock now unmounts (if mounted) and closes the container with UDisks2 Encrypted.Lock. The container is resolved from the volume's device path (the container itself or its open cleartext mapping) and falls back to the LUKS UUID. Only a block carrying the Encrypted interface is ever locked, and an already closed container is left alone.
  • The call allows interactive polkit authorization, for mappings opened by another user or through fstab; dismissing the prompt is quiet.
  • Removable encrypted drives keep the existing Drive::stop path.
  • The sidebar treats an open dm-crypt mapping whose filesystem is unmounted as unlocked when GVfs shows no padlock emblem, so the row offers Lock rather than Unlock.

Visual evidence

N/A. The change is in how Lock closes the volume; the dialogs and sidebar controls are unchanged.

How to test

  1. On an internal disk, unlock and mount a LUKS volume from the sidebar under Devices, then choose Lock.
  2. Run lsblk: the partition has no crypt (luks-<uuid>) child.
  3. Unlock the volume again, unmount only the filesystem (for example umount or udisksctl unmount -b /dev/mapper/luks-<uuid>), then choose Lock in Strata.
  4. Run lsblk again.
  5. Optional: with a shell cd'd into the mounted volume, choose Lock.
  6. Optional: lock a removable LUKS USB stick.

Expected result: Steps 2 and 4 show no crypt child and no error dialog appears. In step 5 the busy error is shown and the mapping stays open. The removable stick locks as before.

Related issue

Closes #1923

Lock only stopped removable password drives through GIO, so on an
internal disk it unmounted the filesystem and left the dm-crypt mapping
open, and refused outright once the filesystem was unmounted. When no
stoppable drive exists, Lock now closes the container with UDisks2
Encrypted.Lock, resolving it from the device path (container or open
mapping) or the LUKS UUID, and never locks a block without the
Encrypted interface. The sidebar also treats an open mapping with an
unmounted filesystem as unlocked when GVfs shows no padlock emblem.

Fixes lgse#1923
@wmfeht

wmfeht commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator Author

Looks good — two optional nits, nothing blocking.

The change fixes the cause described in #1923. When there is no stoppable password drive, Lock now resolves the container through UDisks and calls Encrypted.Lock, both after unmounting and when the filesystem was already unmounted. Removable drives still use Drive::stop. Things I checked:

  • Container resolution (src/ui/window/drive_ops.rs:412-470):
    • It only locks a block that has the Encrypted interface.
    • It follows CryptoBackingDevice from the cleartext mapping to its container.
    • It falls back to the LUKS UUID when the device path finds no container.
    • If a lookup returns more than one block (for example cloned disks with the same LUKS UUID), it locks nothing.
    • A container that is already closed is a successful no-op, so a stale sidebar state is harmless.
  • Cancelling the password prompt: lock_error maps NotAuthorizedDismissed to Cancelled, which becomes FailedHandled. release_error_is_quiet in device_release.rs treats that as quiet, so no dialog appears. Other UDisks errors, such as "busy", show their message without the D-Bus prefix.
  • Mounts without a GIO volume (the fstab case): lock_encrypted_mount finds the device from the mount table before unmounting. A /dev/mapper/luks-… path is one of the block's UDisks symlinks, so ResolveDevice with path still finds it.
  • Sidebar state: cleartext_open goes through the existing asynchronous, cached block_crypto_hint. It is rechecked on volume-monitor events, and the sidebar refreshes when the hint changes, so nothing new blocks the UI thread. The padlock emblem still decides the state when GVfs shows one. Without an emblem, an open mapping now shows Lock. The same flag also controls whether crypto_password_uuid_for_volume falls back to volume.uuid(). For the open container that is fine, because the udev hint already gives the LUKS UUID.
  • Translations and tests: the new string is in all 13 catalogs. Tests are in the adjacent tests.rs files and check behaviour (which object gets locked, the fallback order, never locking a non-encrypted block, already closed, a cancelled prompt versus a real failure). No QA scenario covers Lock, and the container cannot provide UDisks, so not adding one is reasonable.

Nits

  1. Real D-Bus failures are reported as "device not found"

    • Where: src/ui/window/drive_ops.rs:450-457
    • Problem: let Ok(Some(cleartext)) = … else { continue; } treats any error reading Encrypted.CleartextDevice as "this block isn't encrypted". A real failure, such as udisksd restarting or a call timing out, ends at line 469 as DeviceNotFound. That shows "Could not identify the drive's block device" right after the filesystem was unmounted, and the real cause is lost.
    • Suggested fix: skip only when the interface is missing (org.freedesktop.DBus.Error.InvalidArgs / UnknownInterface) and return other errors. This needs the D-Bus error name to reach this point, because lock_error currently reduces it to a string. If that is too much plumbing for the gain, leave it.
  2. Catalog key placement

    • Where: data/locales/messages/*.json:441
    • Problem: "Locking task did not complete" sits between "Formatting task did not complete" and "Formatting…", apparently copied next to its counterpart.
    • Suggested fix: move it to the other Lo… keys (next to "Loading directory", around line 501 in en.json) in all 13 catalogs. The catalogs are not strictly sorted, so this is cosmetic only.

wmfeht and others added 4 commits October 30, 2026 16:49
…tainer

Reading Encrypted.CleartextDevice treated every error as a block without
the Encrypted interface, so a udisksd restart or call timeout after the
unmount surfaced as "Could not identify the drive's block device". Only
InvalidArgs, UnknownInterface and UnknownProperty now skip the block;
other failures keep their D-Bus message.
…locking

Only the Encrypted.Lock call needs to wait indefinitely for the polkit
prompt. ResolveDevice and property reads now use the default timeout so
a hung udisksd reports an error instead of leaving Lock in flight. Also
drop two doc comments that only restated the type names.
@l0gicgate

Copy link
Copy Markdown
Contributor

Review

Merged main (e7f3d06) into the branch; no conflicts. Reviewed the full diff against the updated main for correctness, error handling, i18n, test value, and comment quality. No merge blockers.

What I checked

  • Container resolution only locks a block carrying Encrypted, follows CryptoBackingDevice from an open mapping, falls back to the LUKS UUID, locks nothing when a lookup is ambiguous, and treats an already closed container as a no-op.
  • A dismissed polkit prompt maps to Cancelled → FailedHandled, which release_error_is_quiet already treats as quiet; other UDisks errors keep their message.
  • The sidebar's cleartext_open flag goes through the existing cached, asynchronous block_crypto_hint, so no new blocking work on the UI thread, and the padlock emblem still wins when GVfs provides one.
  • Both self-review nits are addressed in the current head: real D-Bus failures while reading Encrypted.CleartextDevice now surface (only InvalidArgs/UnknownInterface/UnknownProperty skip the block), and the catalog key sits with the other Lo… keys. The new string is present in all 13 catalogs.
  • Tests: all six new/changed tests exercise distinct behaviour (resolution routes, non-encrypted blocks, closed container, failed read vs. missing device, error mapping, padlock/mount/mapping precedence). Nothing tautological to remove.

Change made in this review (253f1b6)

  • Only the Encrypted.Lock call now uses the indefinite timeout needed for the interactive polkit prompt. ResolveDevice and the property reads use the default D-Bus timeout, so a hung udisksd reports an error instead of leaving Lock in flight forever.
  • Dropped two doc comments that only restated their type names.

Local verification (review worktree, private Xvfb/D-Bus via scripts/test-headless.py)

  • ui::window:: + i18n::: 357 passed, 0 failed.
  • i18n:: drive_ops:: devices:: device_release::: 55 passed, 0 failed.
  • cargo fmt --all --check and cargo clippy --all-targets --all-features -- -D warnings: clean.
  • Scoped rather than full suite: the change is confined to the device lock flow, sidebar lock state, and one catalog string; CI ran the full suite and is green.
  • Not exercised: a real LUKS lock on hardware (no UDisks in the headless/container environment). The author's hardware steps in the PR description remain the manual evidence.

CI on the new head: all required checks green (QA scenarios job is dispatch-only and skipped as usual).

@yeggis

yeggis commented Oct 31, 2026

Copy link
Copy Markdown

Thanks for the quick turnaround and the fast fix. Both cases from the issue work as expected on my end.

I built fix/1923-lock-internal-luks (8bb8624) in a separate checkout, so my installed Strata and config were not touched, and tested it on CachyOS with Niri (Wayland). The disk is an internal SATA SSD with LUKS2 and btrfs, mounted through noauto,user,x-gvfs-show in fstab.

  • Mounted: Lock in the sidebar unmounted the volume and closed the LUKS mapping. Clicking the device again asked for the passphrase.
  • Unmounted but still open: I unmounted the filesystem from a terminal with udisksctl unmount. The sidebar kept the open padlock and offered "Lock". Clicking it closed the mapping without an error dialog, and lsblk shows no crypt device left.

I also ran the drive_ops and devices tests locally, and all 32 pass. Everything worked smoothly without any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lock does not close the dm-crypt mapping of internal LUKS volumes

3 participants