Repository navigation
Confirm a resumed drive password change's new slot before removing a key - #14874
Conversation
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
left a comment
There was a problem hiding this comment.
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.
| 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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| # 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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…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>
|
maralcbr
left a comment
There was a problem hiding this comment.
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.
|
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 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. |
Resuming an interrupted
omarchy-drive-passwordchange 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
luksChangeKeyran and the owner then enrolled a recovery key withcryptsetup 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.shnot ok - a rerun with both keys refuses unconfirmed passwords: case 1. Run on its own against the old script, the enrolled-key case fails withnot ok - a rerun with old-password leaves a key enrolled after the change stopped to the owner.Test plan
Repo and temp images (no root; LUKS volumes are image files in a temp directory):
bash test/shell.d/drive-password-test.shpasses, including the luks1 and luks2 file-backed runs./test/shellfails only what unchangedquattrofails on the same machineReal machine (a LUKS2 system disk in a VM or spare machine, never a daily machine):
omarchy-drive-passwordduringluksChangeKey(or power the VM off), rerun it with the new password, confirm the old one when asked: the disk ends on the new password aloneluksChangeKeyafter 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 slotluksChangeKey, enroll a recovery key withcryptsetup luksAddKey, rerun with the old password and then with the recovery key: no key slot is removed, and it says how to settle by handMerge 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