diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-09-11 22:17:04 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-09-11 22:17:04 -0400 |
commit | 1ae276a9113305fb74c54f8df72da3ba2d559e60 (patch) | |
tree | 1a71302c1f856a5b2c3e2d195b9c3719500dd251 | |
parent | 3b38f56c9dc262c31391b5ae095178960108049b (diff) | |
parent | cb69f36ba1f8d5e73c46538e84a88178fb17f23d (diff) |
Merge tag 'ecryptfs-3.12-rc1-crypt-ctx' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs
Pull eCryptfs fixes from Tyler Hicks:
"Two small fixes to the code that initializes the per-file crypto
contexts"
* tag 'ecryptfs-3.12-rc1-crypt-ctx' of git://git.kernel.org/pub/scm/linux/kernel/git/tyhicks/ecryptfs:
ecryptfs: avoid ctx initialization race
ecryptfs: remove check for if an array is NULL
-rw-r--r-- | fs/ecryptfs/crypto.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index d10757635b9c..c88e355f7635 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -609,39 +609,35 @@ int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat) | |||
609 | char *full_alg_name; | 609 | char *full_alg_name; |
610 | int rc = -EINVAL; | 610 | int rc = -EINVAL; |
611 | 611 | ||
612 | if (!crypt_stat->cipher) { | ||
613 | ecryptfs_printk(KERN_ERR, "No cipher specified\n"); | ||
614 | goto out; | ||
615 | } | ||
616 | ecryptfs_printk(KERN_DEBUG, | 612 | ecryptfs_printk(KERN_DEBUG, |
617 | "Initializing cipher [%s]; strlen = [%d]; " | 613 | "Initializing cipher [%s]; strlen = [%d]; " |
618 | "key_size_bits = [%zd]\n", | 614 | "key_size_bits = [%zd]\n", |
619 | crypt_stat->cipher, (int)strlen(crypt_stat->cipher), | 615 | crypt_stat->cipher, (int)strlen(crypt_stat->cipher), |
620 | crypt_stat->key_size << 3); | 616 | crypt_stat->key_size << 3); |
617 | mutex_lock(&crypt_stat->cs_tfm_mutex); | ||
621 | if (crypt_stat->tfm) { | 618 | if (crypt_stat->tfm) { |
622 | rc = 0; | 619 | rc = 0; |
623 | goto out; | 620 | goto out_unlock; |
624 | } | 621 | } |
625 | mutex_lock(&crypt_stat->cs_tfm_mutex); | ||
626 | rc = ecryptfs_crypto_api_algify_cipher_name(&full_alg_name, | 622 | rc = ecryptfs_crypto_api_algify_cipher_name(&full_alg_name, |
627 | crypt_stat->cipher, "cbc"); | 623 | crypt_stat->cipher, "cbc"); |
628 | if (rc) | 624 | if (rc) |
629 | goto out_unlock; | 625 | goto out_unlock; |
630 | crypt_stat->tfm = crypto_alloc_ablkcipher(full_alg_name, 0, 0); | 626 | crypt_stat->tfm = crypto_alloc_ablkcipher(full_alg_name, 0, 0); |
631 | kfree(full_alg_name); | ||
632 | if (IS_ERR(crypt_stat->tfm)) { | 627 | if (IS_ERR(crypt_stat->tfm)) { |
633 | rc = PTR_ERR(crypt_stat->tfm); | 628 | rc = PTR_ERR(crypt_stat->tfm); |
634 | crypt_stat->tfm = NULL; | 629 | crypt_stat->tfm = NULL; |
635 | ecryptfs_printk(KERN_ERR, "cryptfs: init_crypt_ctx(): " | 630 | ecryptfs_printk(KERN_ERR, "cryptfs: init_crypt_ctx(): " |
636 | "Error initializing cipher [%s]\n", | 631 | "Error initializing cipher [%s]\n", |
637 | crypt_stat->cipher); | 632 | full_alg_name); |
638 | goto out_unlock; | 633 | goto out_free; |
639 | } | 634 | } |
640 | crypto_ablkcipher_set_flags(crypt_stat->tfm, CRYPTO_TFM_REQ_WEAK_KEY); | 635 | crypto_ablkcipher_set_flags(crypt_stat->tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
641 | rc = 0; | 636 | rc = 0; |
637 | out_free: | ||
638 | kfree(full_alg_name); | ||
642 | out_unlock: | 639 | out_unlock: |
643 | mutex_unlock(&crypt_stat->cs_tfm_mutex); | 640 | mutex_unlock(&crypt_stat->cs_tfm_mutex); |
644 | out: | ||
645 | return rc; | 641 | return rc; |
646 | } | 642 | } |
647 | 643 | ||