Blame SOURCES/cryptsetup-2.3.4-fix-crypto-backend-to-properly-handle-ECB-mode.patch

c44dd4
From f3906957675e466bbe7fa97a725f56c7c494d4a5 Mon Sep 17 00:00:00 2001
c44dd4
From: Milan Broz <gmazyland@gmail.com>
c44dd4
Date: Tue, 21 Jul 2020 14:14:54 +0200
c44dd4
Subject: [PATCH] Fix crypto backend to properly handle ECB mode.
c44dd4
c44dd4
Despite it should be never used, it should still work :)
c44dd4
c44dd4
Bug introduced in version 2.3.2.
c44dd4
---
c44dd4
 lib/crypto_backend/crypto_storage.c | 2 +-
c44dd4
 tests/compat-test2                  | 9 +++++++++
c44dd4
 2 files changed, 10 insertions(+), 1 deletion(-)
c44dd4
c44dd4
diff --git a/lib/crypto_backend/crypto_storage.c b/lib/crypto_backend/crypto_storage.c
c44dd4
index 8b6c19c..92dbae7 100644
c44dd4
--- a/lib/crypto_backend/crypto_storage.c
c44dd4
+++ b/lib/crypto_backend/crypto_storage.c
c44dd4
@@ -64,7 +64,7 @@ static int crypt_sector_iv_init(struct crypt_sector_iv *ctx,
c44dd4
 	memset(ctx, 0, sizeof(*ctx));
c44dd4
 
c44dd4
 	ctx->iv_size = crypt_cipher_ivsize(cipher_name, mode_name);
c44dd4
-	if (ctx->iv_size < 8)
c44dd4
+	if (ctx->iv_size < 0 || (strcmp(mode_name, "ecb") && ctx->iv_size < 8))
c44dd4
 		return -ENOENT;
c44dd4
 
c44dd4
 	if (!strcmp(cipher_name, "cipher_null") ||
c44dd4
diff --git a/tests/compat-test2 b/tests/compat-test2
c44dd4
index 0fad999..c3852cd 100755
c44dd4
--- a/tests/compat-test2
c44dd4
+++ b/tests/compat-test2
c44dd4
@@ -1023,5 +1023,14 @@ echo $PWD3 | $CRYPTSETUP luksConvertKey --key-slot 22 $LOOPDEV --keyslot-cipher
c44dd4
 [ "$($CRYPTSETUP luksDump $IMG | grep -A8 -m1 "22: luks2" | grep "Cipher:"    | sed -e 's/[[:space:]]\+Cipher:\ \+//g')" = $KEYSLOT_CIPHER ] || fail
c44dd4
 [ "$($CRYPTSETUP luksDump $IMG | grep -A8 -m1 "22: luks2" | grep "Cipher key:"| sed -e 's/[[:space:]]\+Cipher\ key:\ \+//g')" = "128 bits" ] || fail
c44dd4
 
c44dd4
+prepare "[42] Some encryption compatibility mode tests" wipe
c44dd4
+CIPHERS="aes-ecb aes-cbc-null aes-cbc-plain64 aes-cbc-essiv:sha256 aes-xts-plain64"
c44dd4
+key_size=256
c44dd4
+for cipher in $CIPHERS ; do
c44dd4
+	echo -n "[$cipher/$key_size]"
c44dd4
+	$CRYPTSETUP -q luksFormat --type luks2 $LOOPDEV $KEY1 $FAST_PBKDF_OPT --cipher $cipher --key-size $key_size || fail
c44dd4
+done
c44dd4
+echo
c44dd4
+
c44dd4
 remove_mapping
c44dd4
 exit 0
c44dd4
-- 
c44dd4
1.8.3.1
c44dd4