提交 cb69f36b 编写于 作者: K Kees Cook 提交者: Tyler Hicks

ecryptfs: avoid ctx initialization race

It might be possible for two callers to race the mutex lock after the
NULL ctx check. Instead, move the lock above the check so there isn't
the possibility of leaking a crypto ctx. Additionally, report the full
algo name when failing.
Signed-off-by: NKees Cook <keescook@chromium.org>
[tyhicks: remove out label, which is no longer used]
Signed-off-by: NTyler Hicks <tyhicks@canonical.com>
上级 e6cbd6a4
...@@ -614,30 +614,30 @@ int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat) ...@@ -614,30 +614,30 @@ int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat)
"key_size_bits = [%zd]\n", "key_size_bits = [%zd]\n",
crypt_stat->cipher, (int)strlen(crypt_stat->cipher), crypt_stat->cipher, (int)strlen(crypt_stat->cipher),
crypt_stat->key_size << 3); crypt_stat->key_size << 3);
mutex_lock(&crypt_stat->cs_tfm_mutex);
if (crypt_stat->tfm) { if (crypt_stat->tfm) {
rc = 0; rc = 0;
goto out; goto out_unlock;
} }
mutex_lock(&crypt_stat->cs_tfm_mutex);
rc = ecryptfs_crypto_api_algify_cipher_name(&full_alg_name, rc = ecryptfs_crypto_api_algify_cipher_name(&full_alg_name,
crypt_stat->cipher, "cbc"); crypt_stat->cipher, "cbc");
if (rc) if (rc)
goto out_unlock; goto out_unlock;
crypt_stat->tfm = crypto_alloc_ablkcipher(full_alg_name, 0, 0); crypt_stat->tfm = crypto_alloc_ablkcipher(full_alg_name, 0, 0);
kfree(full_alg_name);
if (IS_ERR(crypt_stat->tfm)) { if (IS_ERR(crypt_stat->tfm)) {
rc = PTR_ERR(crypt_stat->tfm); rc = PTR_ERR(crypt_stat->tfm);
crypt_stat->tfm = NULL; crypt_stat->tfm = NULL;
ecryptfs_printk(KERN_ERR, "cryptfs: init_crypt_ctx(): " ecryptfs_printk(KERN_ERR, "cryptfs: init_crypt_ctx(): "
"Error initializing cipher [%s]\n", "Error initializing cipher [%s]\n",
crypt_stat->cipher); full_alg_name);
goto out_unlock; goto out_free;
} }
crypto_ablkcipher_set_flags(crypt_stat->tfm, CRYPTO_TFM_REQ_WEAK_KEY); crypto_ablkcipher_set_flags(crypt_stat->tfm, CRYPTO_TFM_REQ_WEAK_KEY);
rc = 0; rc = 0;
out_free:
kfree(full_alg_name);
out_unlock: out_unlock:
mutex_unlock(&crypt_stat->cs_tfm_mutex); mutex_unlock(&crypt_stat->cs_tfm_mutex);
out:
return rc; return rc;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册