Skip to content

Confirm a resumed drive password change's new slot before removing a key - #14874

Merged
ryanrhughes merged 2 commits into
omacom:quattrofrom
scottjones:fix/drive-password-resume-slot
Oct 21, 2026
Merged

ryanrhughes merged 2 commits into
omacom:quattrofrom
scottjones:fix/drive-password-resume-slot

Conversation

@scottjones

@scottjones scottjones commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Resuming an interrupted omarchy-drive-password change now confirms which key slot is the change's before it removes one. Greptile flagged this on #14675.

@maralcbr, this is your journal and recovery design: could you confirm the two-password check fits how you meant an interrupted change to resume?

The rerun treated any single slot added since the change began as the change's new key. Suppose the change stopped before luksChangeKey ran and the owner then enrolled a recovery key with cryptsetup luksAddKey. Entering the old password at the rerun removed the recovery key, and entering the recovery key removed the old password's slot. The journal can't tell these apart. This both-keys state is also what a change killed mid-way leaves on any LUKS2 disk.

When the disk holds the old password's slot plus one added slot, the rerun now asks for the new password you chose, and for the old one too if you entered the new one first. It only removes a slot once the new password opens the added slot and the old password opens the old slot. It then finishes or rolls back as before, depending on which password you entered first. Otherwise it removes nothing and says how to settle the disk by hand.

If the change was killed after rewriting the old slot, the new password works but the old one opens nothing, which looks the same as a typo. So it refuses, asks you to check the old password, and says how to remove the old slot once you're sure.

What it can't catch: the journal holds no check value for the new password, so whatever you type at the "new password" prompt is taken as the new one. The password you entered first is taken as the one to keep, and the other password's slot is removed, even if it held a recovery key. It's not a lockout, because you keep the password you entered first.

Evidence

test/shell.d/drive-password-test.sh

  • Before, with the full file against quattro's script, the first failure is the new both-keys case: not ok - a rerun with both keys refuses unconfirmed passwords: case 1. Run on its own against the old script, the enrolled-key case fails with not ok - a rerun with old-password leaves a key enrolled after the change stopped to the owner.
  • After: all 64 pass, including the file-backed LUKS1 and LUKS2 runs, the kill-after-every-step loop, and the new enrolled-key, wrong-password and rewritten-old-slot cases.

Test plan

Repo and temp images (no root; LUKS volumes are image files in a temp directory):

  • bash test/shell.d/drive-password-test.sh passes, including the luks1 and luks2 file-backed runs
  • ./test/shell fails only what unchanged quattro fails on the same machine

Real machine (a LUKS2 system disk in a VM or spare machine, never a daily machine):

  • Kill omarchy-drive-password during luksChangeKey (or power the VM off), rerun it with the new password, confirm the old one when asked: the disk ends on the new password alone
  • Same, rerunning with the old password and confirming the new one: the disk ends on the old password alone
  • Optional, needs gdb: kill luksChangeKey after it rewrites the old slot but before its second header write, then rerun with the new password: nothing is removed, and the message asks to check the old password before removing the old slot
  • Kill it before luksChangeKey, enroll a recovery key with cryptsetup luksAddKey, rerun with the old password and then with the recovery key: no key slot is removed, and it says how to settle by hand

Merge Danger

Door: two-way.

Blast Radius: small. It only affects resuming an interrupted system-disk password change that left two keys on the disk. That rerun asks for one or two more passwords, and never removes a slot it couldn't confirm.

🤖 Generated with Claude Code

The rerun after an interrupted change treated any one slot added since as
the change's new key. If the change stopped before luksChangeKey and a
recovery key was enrolled before the rerun, entering the old password
removed the recovery key, and entering the recovery key removed the old
password's slot. luksChangeKey picks the new slot itself, so the journal
can't name it, and LUKS2 leaves both keys between its two header updates.

With both slots on the disk the rerun now asks for the new password, and
the old one when it has only the new, and removes a slot only once the new
password opens the added slot and the old password the old one. Otherwise
it removes nothing and says how to settle the disk by hand.

Found by Greptile on omacom#14675.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@maralcbr maralcbr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two-password confirmation is how I meant an interrupted change to resume. Refusing to remove a slot it can't confirm is the right call.

I ran it on an Apple Silicon test machine (Arch Linux ARM, cryptsetup 2.8.8): all 64 tests pass, including the luks1 and luks2 file-backed runs. A wrong passphrase with --key-slot exits 2 on both formats, and LUKS2's luksChangeKey does commit the new key to a free slot before a second header update, so the rewritten-old-slot state is real.

One fix before merge, in the new both-keys test (inline). Once that's pushed I'll approve.

Comment thread test/shell.d/drive-password-test.sh Outdated
attempt 0 "$old_password" "$new_password" "$new_password" || true
unset TEST_CHANGE_PARTIAL TEST_KILL_FAIL
for answers in "$old_password not-the-new-one" "$new_password not-the-new-one $old_password" "$new_password $new_password not-the-old-one"; do
read -r -a answer_list <<<"$answers"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_password is 'new pass:word', so read -a splits it at the space. In the second and third cases the first answer becomes new, which opens nothing, and the run stops at "That password does not finish the change" before it reaches confirm_added_slot. said "so no key is removed" still passes because attempt appends to $tmp/output and the first case's text is still there.

Could you pass each case as an array and clear the output before each attempt? Something like:

for c in 1 2 3; do
  case $c in
    1) answers=("$old_password" not-the-new-one) ;;
    2) answers=("$new_password" not-the-new-one "$old_password") ;;
    3) answers=("$new_password" "$new_password" not-the-old-one) ;;
  esac
  : >"$tmp/output"
  if attempt 0 "${answers[@]}"; then fail "a rerun with both keys refuses unconfirmed passwords: case $c"; fi
  ...

I ran it that way: all three refuse and remove nothing (the first two say "Settle it by hand", the third gives the rewritten-slot message), so the script is fine. Only the test needs it.

@scottjones scottjones Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. Fixed in fa34321: each case now passes its answers as an array, clears the output and prompts before its attempt, checks it reached the "New encryption password you chose" prompt, and asserts its own message ("Settle it by hand" for 1 and 2, the old-slot message for 3). With confirm_added_slot bypassed, both the old block and the new one fail at case 1, since case 1's answers never had a space. Breaking only the case 2 check or only the case 3 check is where it shows: the old block still passed (only the later-key and old-slot-rewritten tests caught it), and the new one fails at case 2 or case 3.

Comment thread bin/omarchy-drive-password Outdated
# last header update: the slot is still listed, but no password opens it.
if (( status == 2 )); then
echo "The new password opens key slot $added, but the old password doesn't open slot $old_slot, so no key is removed."
echo "If you typed the old password correctly, slot $old_slot no longer holds it (the change stopped while rewriting that slot), and removing it is safe: sudo cryptsetup luksKillSlot $root_drive $old_slot"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, not blocking: a failed old-password check can't tell us why the slot stopped opening. It may be a typo, or a slot rekeyed by hand since. The new password was just confirmed, so following this can't lock anyone out, but I'd soften it. Say the new password opens slot $added, ask them to check they typed the old password, and only then remove slot $old_slot if it holds nothing they still need.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, softened in fa34321. It now says the new password opens slot $added but the old one didn't open slot $old_slot, asks to check the old password was typed right and run it again, and only then to remove slot $old_slot once they're sure it holds nothing they still need.

@maralcbr maralcbr left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of the review above, please ignore.

@maralcbr maralcbr left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate of the review above, please ignore.

…dvice

The test split its answers on spaces, and the new password has one, so two
of its three cases stopped before the confirm step and still passed on the
first case's output. Each case now keeps its answers whole, starts from empty
output and prompts, checks it reached the confirm step and says its own
message.

When the new password opens the added slot but the old one doesn't open the
old slot, that may be a typo or a slot rekeyed since, so the message now asks
to check the old password before removing the slot.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@scottjones
scottjones marked this pull request as ready for review October 12, 2026 02:20
@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Critical impact] The PR appears safe to merge; the added checks stop slot deletion unless both passwords open their expected slots.

Summary

Resuming an interrupted system-disk password change now checks both passwords against their expected slots before removing either key.

  • Resumed drive password changes confirm the new slot before removing a key.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Resume interrupted change] --> B{Old slot and one added slot remain?}
  B -->|No| C[Use existing resume checks]
  B -->|Yes| D[Ask for the chosen new password]
  D --> E[Get the old password if needed]
  E --> F{Both passwords open their expected slots?}
  F -->|No| G[Keep all slots and the journal]
  F -->|Yes| H[Keep the first password entered]
  H --> I[Remove the other slot]
  I --> J[Record the kept slot and clear the journal]
Loading

Reviews (1) · Last reviewed commit: "Check each both-keys rerun case on its o..." · Reviewed by Greptile

@maralcbr maralcbr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fa34321 covers both. All 64 tests pass (fake, luks2 and luks1 runs, cryptsetup 2.7.5 on arm64). The both-keys cases now hold up: they fail if the old-password prompt is skipped, if the old-slot check is skipped, or if the new-slot check is skipped. The softened message reads right. Ready to merge from my side.

@omarchybot

Copy link
Copy Markdown
Collaborator

This pull request was read but not yet reviewed, and nothing has run yet. Its classification isn't settled, so it has no label for now.

Before anything is verified, two models each classify an item on their own. Claude Opus 5.5 classified this as a bug fix. The second classification, from Codex Medium, was refused because the bot reached its daily review limit, so there is nothing to compare against. Without an agreed class the next steps don't start: no reproduction on a worker, no test suite run, and no second-opinion review of the diff. Reading bin/omarchy-drive-password and the new tests at fa34321 turned up no defect, but that is one model's reading and nothing has run, so it is not a verdict.

Nothing is needed from you. The item will be classified again on a later pass, and the review and the worker run come after that.

@ryanrhughes
ryanrhughes merged commit 087f73d into omacom:quattro Oct 21, 2026
1 check passed
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.

4 participants