From 1e68d73bc32a63091218f2b9dcd65a98d5e99fdb Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Thu, 11 Feb 2021 11:43:10 +0100 Subject: [PATCH] Fix device comparison for dm-crypt with cipher_null. Do not compare volume keys if segment uses cipher_null. The key is ignored by lower layer (internal libdevmapper) anyway. --- lib/setup.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/setup.c b/lib/setup.c index 488ecc9b..d0b8b7cf 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -2388,11 +2388,6 @@ static int _compare_crypt_devices(struct crypt_device *cd, if (!src->u.crypt.vk || !tgt->u.crypt.vk) return -EINVAL; - if (_compare_volume_keys(src->u.crypt.vk, 0, tgt->u.crypt.vk, tgt->u.crypt.vk->key_description != NULL)) { - log_dbg(cd, "Keys in context and target device do not match."); - return -EINVAL; - } - /* CIPHER checks */ if (!src->u.crypt.cipher || !tgt->u.crypt.cipher) return -EINVAL; @@ -2400,6 +2395,14 @@ static int _compare_crypt_devices(struct crypt_device *cd, log_dbg(cd, "Cipher specs do not match."); return -EINVAL; } + + if (tgt->u.crypt.vk->keylength == 0 && crypt_is_cipher_null(tgt->u.crypt.cipher)) + log_dbg(cd, "Existing device uses cipher null. Skipping key comparison."); + else if (_compare_volume_keys(src->u.crypt.vk, 0, tgt->u.crypt.vk, tgt->u.crypt.vk->key_description != NULL)) { + log_dbg(cd, "Keys in context and target device do not match."); + return -EINVAL; + } + if (crypt_strcmp(src->u.crypt.integrity, tgt->u.crypt.integrity)) { log_dbg(cd, "Integrity parameters do not match."); return -EINVAL;