Skip to content

Commit 4650433

Browse files
committed
Check for unbound keyslot in convert.
The type cannot be converted to LUKS1 if there is an unbound keyslot. It is already covered by digest count check, but in some specific use cases the explicit check can catch a new problem.
1 parent 50b762a commit 4650433

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

lib/luks2/luks2_luks1_convert.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ int LUKS2_luks2_to_luks1(struct crypt_device *cd, struct luks2_hdr *hdr2, struct
767767
int i, r, last_active = 0;
768768
uint64_t offset, area_length;
769769
char *buf, luksMagic[] = LUKS_MAGIC;
770+
crypt_keyslot_info ki;
770771

771772
jobj_digest = LUKS2_get_digest_jobj(hdr2, 0);
772773
if (!jobj_digest)
@@ -824,14 +825,21 @@ int LUKS2_luks2_to_luks1(struct crypt_device *cd, struct luks2_hdr *hdr2, struct
824825
key_size = r;
825826

826827
for (i = 0; i < LUKS2_KEYSLOTS_MAX; i++) {
827-
if (LUKS2_keyslot_info(hdr2, i) == CRYPT_SLOT_INACTIVE)
828+
ki = LUKS2_keyslot_info(hdr2, i);
829+
830+
if (ki == CRYPT_SLOT_INACTIVE)
828831
continue;
829832

830-
if (LUKS2_keyslot_info(hdr2, i) == CRYPT_SLOT_INVALID) {
833+
if (ki == CRYPT_SLOT_INVALID) {
831834
log_err(cd, _("Cannot convert to LUKS1 format - keyslot %u is in invalid state."), i);
832835
return -EINVAL;
833836
}
834837

838+
if (ki == CRYPT_SLOT_UNBOUND) {
839+
log_err(cd, _("Cannot convert to LUKS1 format - keyslot %u is unbound."), i);
840+
return -EINVAL;
841+
}
842+
835843
if (i >= LUKS_NUMKEYS) {
836844
log_err(cd, _("Cannot convert to LUKS1 format - slot %u (over maximum slots) is still active."), i);
837845
return -EINVAL;

0 commit comments

Comments
 (0)