Skip to content

Commit b81c84b

Browse files
committed
Do not allow null cipher for LUKS2 keyslot even in conversion.
1 parent 8d7ee84 commit b81c84b

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

lib/luks2/luks2_keyslot.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ int LUKS2_keyslot_cipher_incompatible(struct crypt_device *cd, const char *ciphe
175175
if (!strncmp(cipher_spec, "capi:", 5))
176176
return 1;
177177

178+
if (crypt_is_cipher_null(cipher_spec))
179+
return 1;
180+
178181
if (crypt_parse_name_and_mode(cipher_spec, cipher, NULL, cipher_mode) < 0)
179182
return 1;
180183

lib/luks2/luks2_luks1_convert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ int LUKS2_luks1_to_luks2(struct crypt_device *cd, struct luks_phdr *hdr1, struct
596596
if (r < 0 || (size_t)r >= sizeof(cipher_spec))
597597
return -EINVAL;
598598
if (LUKS2_keyslot_cipher_incompatible(cd, cipher_spec)) {
599-
log_err(cd, _("Unable to use cipher specification %s-%s for LUKS2."),
599+
log_err(cd, _("Unable to use cipher specification %s-%s for LUKS2 keyslot."),
600600
hdr1->cipherName, hdr1->cipherMode);
601601
return -EINVAL;
602602
}

src/cryptsetup.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static bool isLUKS(const char *type)
7878
static int _set_keyslot_encryption_params(struct crypt_device *cd)
7979
{
8080
const char *type = crypt_get_type(cd);
81+
int r;
8182

8283
if (!ARG_SET(OPT_KEYSLOT_KEY_SIZE_ID) && !ARG_SET(OPT_KEYSLOT_CIPHER_ID))
8384
return 0;
@@ -87,7 +88,11 @@ static int _set_keyslot_encryption_params(struct crypt_device *cd)
8788
return -EINVAL;
8889
}
8990

90-
return crypt_keyslot_set_encryption(cd, ARG_STR(OPT_KEYSLOT_CIPHER_ID), ARG_UINT32(OPT_KEYSLOT_KEY_SIZE_ID) / 8);
91+
r = crypt_keyslot_set_encryption(cd, ARG_STR(OPT_KEYSLOT_CIPHER_ID), ARG_UINT32(OPT_KEYSLOT_KEY_SIZE_ID) / 8);
92+
if (r < 0)
93+
log_err(_("Keyslot encryption parameters are not compatible with LUKS2 keyslot encryption."));
94+
95+
return r;
9196
}
9297

9398
static int init_new_keyslot_context(struct crypt_device *cd,

tests/luks2-reencryption-test

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,14 +1855,16 @@ if [ $HAVE_KEYRING -gt 0 ]; then
18551855
fi
18561856
$CRYPTSETUP close $DEV_NAME
18571857

1858-
# simulate LUKS2 device with cipher_null in both keyslot and segment (it can be created only by up conversion from LUKS1)
1859-
echo $PWD1 | $CRYPTSETUP -q luksFormat --type luks1 -s 128 -c cipher_null-ecb --offset 8192 $FAST_PBKDF2 $DEV || fail
1860-
$CRYPTSETUP convert -q --type luks2 $DEV || fail
1861-
wipe $PWD1
1862-
echo $PWD1 | $CRYPTSETUP reencrypt $DEV -q $FAST_PBKDF_ARGON >/dev/null || fail
1863-
check_hash $PWD1 $HASH1
1864-
# both keyslot and segment cipher must not be null after reencryption with default params
1865-
$CRYPTSETUP luksDump $DEV | grep -q "cipher_null" && fail
1858+
# FIXME: Add test luks2 image with both keyslot and data using cipher_null and verify LUKS2 reencryption fixes this.
1859+
1860+
## simulate LUKS2 device with cipher_null in both keyslot and segment (it can be created only by up conversion from LUKS1)
1861+
#echo $PWD1 | $CRYPTSETUP -q luksFormat --type luks1 -s 128 -c cipher_null-ecb --offset 8192 $FAST_PBKDF2 $DEV || fail
1862+
#$CRYPTSETUP convert -q --type luks2 $DEV || fail
1863+
#wipe $PWD1
1864+
#echo $PWD1 | $CRYPTSETUP reencrypt $DEV -q $FAST_PBKDF_ARGON >/dev/null || fail
1865+
#check_hash $PWD1 $HASH1
1866+
## both keyslot and segment cipher must not be null after reencryption with default params
1867+
#$CRYPTSETUP luksDump $DEV | grep -q "cipher_null" && fail
18661868

18671869
# multistep reencryption with initial cipher_null
18681870
preparebig 64

0 commit comments

Comments
 (0)