diff --git a/lib/utils_crypt.c b/lib/utils_crypt.c index f5bc566f..8021d054 100644 --- a/lib/utils_crypt.c +++ b/lib/utils_crypt.c @@ -302,6 +302,7 @@ int crypt_keyfile_read(struct crypt_device *cd, const char *keyfile, char_read = read(fd, &pass[i], 1); if (char_read < 0) { log_err(cd, _("Error reading passphrase.\n")); + r = -EPIPE; goto out_err; } diff --git a/src/cryptsetup.c b/src/cryptsetup.c index 8920c1e8..0dcb601d 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -933,6 +933,12 @@ static int action_luksKillSlot(void) _("This is the last keyslot. Device will become unusable after purging this key."), _("Enter any remaining passphrase: "), opt_key_file, opt_keyfile_offset, opt_keyfile_size); + + if (r == -EPIPE && (!opt_key_file || tools_is_stdin(opt_key_file))) { + log_dbg("Failed read from input, ignoring passphrase."); + r = 0; + } + if (r < 0) goto out; } diff --git a/tests/compat-test b/tests/compat-test index 32b63a0f..4ffe3546 100755 --- a/tests/compat-test +++ b/tests/compat-test @@ -354,6 +354,8 @@ prepare "[18] RemoveKey passphrase and keyfile" reuse $CRYPTSETUP luksRemoveKey $LOOPDEV $KEY1 || fail $CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 3: DISABLED" || fail $CRYPTSETUP luksRemoveKey $LOOPDEV $KEY1 2>/dev/null && fail +$CRYPTSETUP luksAddKey $LOOPDEV -i1 -d $KEY2 $KEY1 --key-slot 3 2>/dev/null || fail +$CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 3: ENABLED" || fail $CRYPTSETUP luksRemoveKey $LOOPDEV $KEY2 --keyfile-size 1 2>/dev/null && fail $CRYPTSETUP luksRemoveKey $LOOPDEV $KEY2 || fail $CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 4: DISABLED" || fail @@ -366,6 +368,9 @@ $CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 2: ENABLED" || fail # kill slot using passphrase from 1 echo $PWD2 | $CRYPTSETUP luksKillSlot $LOOPDEV 2 || fail $CRYPTSETUP luksDump $LOOPDEV | grep -q "Key Slot 2: DISABLED" || fail +# kill slot with redirected stdin +$CRYPTSETUP luksKillSlot $LOOPDEV 3