Allow LUKS resume for device with cipher_null.

This commit is contained in:
Ondrej Kozina
2021-02-19 19:00:59 +01:00
parent 3367b78958
commit 6a8bade7e6
2 changed files with 16 additions and 4 deletions

View File

@@ -2927,7 +2927,9 @@ int dm_resume_and_reinstate_key(struct crypt_device *cd, const char *name,
if (!(dmt_flags & DM_KEY_WIPE_SUPPORTED))
goto out;
if (vk->key_description)
if (!vk->keylength)
msg_size = 11; // key set -
else if (vk->key_description)
msg_size = strlen(vk->key_description) + int_log10(vk->keylength) + 18;
else
msg_size = vk->keylength * 2 + 10; // key set <key>
@@ -2939,7 +2941,9 @@ int dm_resume_and_reinstate_key(struct crypt_device *cd, const char *name,
}
strcpy(msg, "key set ");
if (vk->key_description)
if (!vk->keylength)
snprintf(msg + 8, msg_size - 8, "-");
else if (vk->key_description)
snprintf(msg + 8, msg_size - 8, ":%zu:logon:%s", vk->keylength, vk->key_description);
else
hex_key(&msg[8], vk->keylength, vk->key);

View File

@@ -3115,9 +3115,15 @@ static int resume_by_volume_key(struct crypt_device *cd,
const char *name)
{
int digest, r;
struct volume_key *zerokey = NULL;
/* LUKS2 path only */
if (crypt_use_keyring_for_vk(cd) && !crypt_is_cipher_null(crypt_get_cipher_spec(cd))) {
if (crypt_is_cipher_null(crypt_get_cipher_spec(cd))) {
zerokey = crypt_alloc_volume_key(0, NULL);
if (!zerokey)
return -ENOMEM;
vk = zerokey;
} else if (crypt_use_keyring_for_vk(cd)) {
/* LUKS2 path only */
digest = LUKS2_digest_by_segment(&cd->u.luks2.hdr, CRYPT_DEFAULT_SEGMENT);
if (digest < 0)
return -EINVAL;
@@ -3137,6 +3143,8 @@ static int resume_by_volume_key(struct crypt_device *cd,
if (r < 0)
crypt_drop_keyring_key(cd, vk);
crypt_free_volume_key(zerokey);
return r;
}