Skip to contentSkip to conversation

fscrypt: verify that the crypto_skcipher has the correct ivsize

PATCH Applied Eric Biggers 1 participant 2 messages Dec 9, 2019 – Jan 3, 2020 fscrypt: file system level encryption support

lore
Share & tools
lore

Eric Biggers

author maintainer
#0 lore raw

PATCH 1/1 fscrypt: verify that the crypto_skcipher has the correct ivsize

From: Eric Biggers <[email protected]>

As a sanity check, verify that the allocated crypto_skcipher actually has the ivsize that fscrypt is assuming it has. This will always be the case unless there's a bug. But if there ever is such a bug (e.g. like there was in earlier versions of the ESSIV conversion patch [1]) it's preferable for it to be immediately obvious, and not rely on the ciphertext verification tests failing due to uninitialized IV bytes.

[1] https://lkml.kernel.org/linux-crypto/[email protected]/

---
 fs/crypto/keysetup.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/crypto/keysetup.c +4 -0
index c9f4fe955971f..39fdea79e912f 100644
@@ -91,6 +91,10 @@ struct crypto_skcipher *fscrypt_allocate_skcipher(struct fscrypt_mode *mode,
 		pr_info("fscrypt: %s using implementation \"%s\"\n",
 			mode->friendly_name, crypto_skcipher_driver_name(tfm));
 	}
+	if (WARN_ON(crypto_skcipher_ivsize(tfm) != mode->ivsize)) {
+		err = -EINVAL;
+		goto err_free_tfm;
+	}
 	crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
 	err = crypto_skcipher_setkey(tfm, raw_key, mode->keysize);
 	if (err)
Signature · 1 line
2.24.0.393.g34dc348eaf-goog
author maintainer Applied
#1 lore raw
Quoted 34 lines · Eric Biggers

From: Eric Biggers <[email protected]>

As a sanity check, verify that the allocated crypto_skcipher actually has the ivsize that fscrypt is assuming it has. This will always be the case unless there's a bug. But if there ever is such a bug (e.g. like there was in earlier versions of the ESSIV conversion patch [1]) it's preferable for it to be immediately obvious, and not rely on the ciphertext verification tests failing due to uninitialized IV bytes.

[1] https://lkml.kernel.org/linux-crypto/[email protected]/

---
 fs/crypto/keysetup.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/crypto/keysetup.c +4 -0
index c9f4fe955971f..39fdea79e912f 100644
@@ -91,6 +91,10 @@ struct crypto_skcipher *fscrypt_allocate_skcipher(struct fscrypt_mode *mode,
 		pr_info("fscrypt: %s using implementation \"%s\"\n",
 			mode->friendly_name, crypto_skcipher_driver_name(tfm));
 	}
+	if (WARN_ON(crypto_skcipher_ivsize(tfm) != mode->ivsize)) {
+		err = -EINVAL;
+		goto err_free_tfm;
+	}
 	crypto_skcipher_set_flags(tfm, CRYPTO_TFM_REQ_FORBID_WEAK_KEYS);
 	err = crypto_skcipher_setkey(tfm, raw_key, mode->keysize);
 	if (err)
Signature · 1 line
2.24.0.393.g34dc348eaf-goog

Applied to fscrypt.git#master for 5.6.

- Eric