Repository navigation
Confirm a resumed drive password change's new slot before removing a key #14874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -467,9 +467,12 @@ for run_spec in "${matrix[@]}"; do | |
| [[ -e $journal ]] || fail "$backend: after '$point' a refused rerun keeps the journal" | ||
| answer=$new_password | ||
| fi | ||
| # A rerun that finds both keys (killed between luksChangeKey's two header | ||
| # updates) asks for the new password, and the old one when it was given | ||
| # the new, before it removes either slot. | ||
| for (( again = 1; ; again++ )); do | ||
| status=0 | ||
| attempt "$again" "$answer" || status=$? | ||
| attempt "$again" "$answer" "$new_password" "$old_password" || status=$? | ||
| (( status == 0 )) && break | ||
| (( status == 137 )) || fail "$backend: the rerun after '$point' finishes" "$(cat "$tmp/output")" | ||
| recoverable "rerun after '$point' killed at step $again" | ||
|
|
@@ -521,18 +524,34 @@ unset TEST_CHANGE_PARTIAL TEST_KILL_FAIL | |
| if attempt 0 "$recovery_key"; then fail "an unconfirmed change refuses the recovery key"; fi | ||
| said "That password does not finish the change" | ||
| [[ -e $journal && -n $(opens "$system" "$recovery_key") ]] || fail "refusing the recovery key changes nothing" | ||
| attempt 0 "$new_password" || fail "the rerun retires the old key and finishes" "$(cat "$tmp/output")" | ||
| attempt 0 "$new_password" "$new_password" "$old_password" || fail "the rerun retires the old key and finishes" "$(cat "$tmp/output")" | ||
| consistent "rerun after a failed retirement" "$new_password" | ||
| pass "before the change is confirmed a rerun refuses the recovery key and retires the old key" | ||
|
|
||
| fixture | ||
| export TEST_CHANGE_PARTIAL=1 TEST_KILL_FAIL=1 | ||
| attempt 0 "$old_password" "$new_password" "$new_password" || true | ||
| unset TEST_CHANGE_PARTIAL TEST_KILL_FAIL | ||
| attempt 0 "$old_password" || fail "the rerun with the old password rolls back" "$(cat "$tmp/output")" | ||
| attempt 0 "$old_password" "$new_password" || fail "the rerun with the old password rolls back" "$(cat "$tmp/output")" | ||
| consistent "rollback with the old password" "$old_password" | ||
| pass "a rerun with the old password removes the half-added new key" | ||
|
|
||
| # With both keys on the disk, the added slot is only removed or kept once the | ||
| # new password opens it and the old password the old slot: a wrong new password | ||
| # removes nothing. | ||
| fixture | ||
| export TEST_CHANGE_PARTIAL=1 TEST_KILL_FAIL=1 | ||
| 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" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| if attempt 0 "${answer_list[@]}"; then fail "a rerun with both keys refuses unconfirmed passwords: $answers"; fi | ||
| said "so no key is removed" | ||
| [[ -e $journal && -n $(opens "$system" "$old_password") && -n $(opens "$system" "$new_password") ]] || | ||
| fail "a rerun with unconfirmed passwords removes neither key: $answers" "$(cat "$tmp/output")" | ||
| done | ||
| pass "with both keys on the disk, a rerun removes neither until both passwords confirm the added slot" | ||
|
|
||
| # On Apple the slot record follows the confirmed change: a crash there leaves | ||
| # the confirmed phase. | ||
| use fake apple | ||
|
|
@@ -595,6 +614,42 @@ attempt 0 "$new_password" || fail "the rerun finishes after the orphaned change" | |
| consistent "orphaned luksChangeKey" "$new_password" | ||
| pass "a luksChangeKey that outlives its run finishes before the rerun reads the disk" | ||
|
|
||
| # A change that stopped before luksChangeKey added nothing, so a key enrolled | ||
| # before the rerun (a recovery key, with cryptsetup luksAddKey) is not the | ||
| # change's, though it sits where the change's key would. Whichever password | ||
| # the rerun gets, the new password doesn't open that slot, so it removes | ||
| # neither that key nor the old password's slot. | ||
| for answer in "$old_password" later-key; do | ||
| fixture | ||
| attempt "$change_step" "$old_password" "$new_password" "$new_password" || true | ||
| [[ -e $journal && -z $(opens "$system" "$new_password") ]] || fail "the change stops before its key is added" "$(cat "$tmp/trace")" | ||
| printf '2\tlater-key\n' >>"$system.slots" | ||
| if attempt 0 "$answer" "$new_password" "$old_password"; then fail "a rerun with $answer leaves a key enrolled after the change stopped to the owner"; fi | ||
| said "Settle it by hand" | ||
| [[ -e $journal && $(opens "$system" later-key) == "2" && $(opens "$system" "$old_password") == "0" && -n $(opens "$system" "$recovery_key") ]] || | ||
| fail "a rerun with $answer removes no key" "$(cat "$tmp/sudo-calls" "$tmp/output")" | ||
| ! grep -q 'luksKillSlot' "$tmp/sudo-calls" || fail "a rerun with $answer kills no slot" "$(cat "$tmp/sudo-calls")" | ||
| done | ||
| pass "a rerun never removes a key enrolled after a change that stopped before adding its own" | ||
|
|
||
| # luksChangeKey killed after rewriting the old slot's key and before its last | ||
| # header update leaves the old slot listed but opened by nothing, and the new | ||
| # key in the added slot. The rerun removes nothing and says the old slot is | ||
| # safe to remove; once the owner removes it, the rerun finishes on the new key. | ||
| fixture | ||
| attempt "$change_step" "$old_password" "$new_password" "$new_password" || true | ||
| awk -F'\t' -v OFS='\t' '$1 == 0 { $2 = "overwritten" } 1' "$system.slots" >"$system.slots.next" && mv -f "$system.slots.next" "$system.slots" | ||
| printf '2\t%s\n' "$new_password" >>"$system.slots" | ||
| if attempt 0 "$new_password" "$new_password" "$old_password"; then fail "a rerun with the old slot rewritten removes nothing"; fi | ||
| said "The new password opens key slot 2, but the old password doesn't open slot 0" | ||
| said "removing it is safe: sudo cryptsetup luksKillSlot $system 0" | ||
| ! grep -q 'luksKillSlot' "$tmp/sudo-calls" && grep -q '^0'$'\t' "$system.slots" && [[ -e $journal ]] || | ||
| fail "a rerun with the old slot rewritten kills no slot and keeps the journal" "$(cat "$tmp/sudo-calls")" | ||
| awk -F'\t' '$1 != 0' "$system.slots" >"$system.slots.next" && mv -f "$system.slots.next" "$system.slots" | ||
| attempt 0 "$new_password" || fail "the rerun finishes once the rewritten slot is removed" "$(cat "$tmp/output")" | ||
| consistent "rewritten old slot removed by hand" "$new_password" | ||
| pass "a rerun with the old slot rewritten says it is safe to remove, then finishes once it is gone" | ||
|
|
||
| fixture | ||
| printf '/dev/mapper/root crypt btrfs\n%s part \n/dev/fake-disk disk \n' "$system" >"$tmp/root-ancestry" | ||
| if attempt 0 "$old_password" "$new_password" "$new_password"; then fail "a crypt layer without a named LUKS partition fails"; fi | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.