diff options
Diffstat (limited to 'fs/ecryptfs/crypto.c')
| -rw-r--r-- | fs/ecryptfs/crypto.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index b91851f1cda3..fbb6e5eed697 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
| @@ -245,13 +245,11 @@ void ecryptfs_destroy_crypt_stat(struct ecryptfs_crypt_stat *crypt_stat) | |||
| 245 | crypto_free_blkcipher(crypt_stat->tfm); | 245 | crypto_free_blkcipher(crypt_stat->tfm); |
| 246 | if (crypt_stat->hash_tfm) | 246 | if (crypt_stat->hash_tfm) |
| 247 | crypto_free_hash(crypt_stat->hash_tfm); | 247 | crypto_free_hash(crypt_stat->hash_tfm); |
| 248 | mutex_lock(&crypt_stat->keysig_list_mutex); | ||
| 249 | list_for_each_entry_safe(key_sig, key_sig_tmp, | 248 | list_for_each_entry_safe(key_sig, key_sig_tmp, |
| 250 | &crypt_stat->keysig_list, crypt_stat_list) { | 249 | &crypt_stat->keysig_list, crypt_stat_list) { |
| 251 | list_del(&key_sig->crypt_stat_list); | 250 | list_del(&key_sig->crypt_stat_list); |
| 252 | kmem_cache_free(ecryptfs_key_sig_cache, key_sig); | 251 | kmem_cache_free(ecryptfs_key_sig_cache, key_sig); |
| 253 | } | 252 | } |
| 254 | mutex_unlock(&crypt_stat->keysig_list_mutex); | ||
| 255 | memset(crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat)); | 253 | memset(crypt_stat, 0, sizeof(struct ecryptfs_crypt_stat)); |
| 256 | } | 254 | } |
| 257 | 255 | ||
| @@ -511,13 +509,14 @@ int ecryptfs_encrypt_page(struct page *page) | |||
| 511 | + extent_offset), crypt_stat); | 509 | + extent_offset), crypt_stat); |
| 512 | rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt, | 510 | rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt, |
| 513 | offset, crypt_stat->extent_size); | 511 | offset, crypt_stat->extent_size); |
| 514 | if (rc) { | 512 | if (rc < 0) { |
| 515 | ecryptfs_printk(KERN_ERR, "Error attempting " | 513 | ecryptfs_printk(KERN_ERR, "Error attempting " |
| 516 | "to write lower page; rc = [%d]" | 514 | "to write lower page; rc = [%d]" |
| 517 | "\n", rc); | 515 | "\n", rc); |
| 518 | goto out; | 516 | goto out; |
| 519 | } | 517 | } |
| 520 | } | 518 | } |
| 519 | rc = 0; | ||
| 521 | out: | 520 | out: |
| 522 | if (enc_extent_page) { | 521 | if (enc_extent_page) { |
| 523 | kunmap(enc_extent_page); | 522 | kunmap(enc_extent_page); |
| @@ -633,7 +632,7 @@ int ecryptfs_decrypt_page(struct page *page) | |||
| 633 | rc = ecryptfs_read_lower(enc_extent_virt, offset, | 632 | rc = ecryptfs_read_lower(enc_extent_virt, offset, |
| 634 | crypt_stat->extent_size, | 633 | crypt_stat->extent_size, |
| 635 | ecryptfs_inode); | 634 | ecryptfs_inode); |
| 636 | if (rc) { | 635 | if (rc < 0) { |
| 637 | ecryptfs_printk(KERN_ERR, "Error attempting " | 636 | ecryptfs_printk(KERN_ERR, "Error attempting " |
| 638 | "to read lower page; rc = [%d]" | 637 | "to read lower page; rc = [%d]" |
| 639 | "\n", rc); | 638 | "\n", rc); |
| @@ -797,6 +796,7 @@ int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat) | |||
| 797 | kfree(full_alg_name); | 796 | kfree(full_alg_name); |
| 798 | if (IS_ERR(crypt_stat->tfm)) { | 797 | if (IS_ERR(crypt_stat->tfm)) { |
| 799 | rc = PTR_ERR(crypt_stat->tfm); | 798 | rc = PTR_ERR(crypt_stat->tfm); |
| 799 | crypt_stat->tfm = NULL; | ||
| 800 | ecryptfs_printk(KERN_ERR, "cryptfs: init_crypt_ctx(): " | 800 | ecryptfs_printk(KERN_ERR, "cryptfs: init_crypt_ctx(): " |
| 801 | "Error initializing cipher [%s]\n", | 801 | "Error initializing cipher [%s]\n", |
| 802 | crypt_stat->cipher); | 802 | crypt_stat->cipher); |
| @@ -925,7 +925,9 @@ static int ecryptfs_copy_mount_wide_sigs_to_inode_sigs( | |||
| 925 | struct ecryptfs_global_auth_tok *global_auth_tok; | 925 | struct ecryptfs_global_auth_tok *global_auth_tok; |
| 926 | int rc = 0; | 926 | int rc = 0; |
| 927 | 927 | ||
| 928 | mutex_lock(&crypt_stat->keysig_list_mutex); | ||
| 928 | mutex_lock(&mount_crypt_stat->global_auth_tok_list_mutex); | 929 | mutex_lock(&mount_crypt_stat->global_auth_tok_list_mutex); |
| 930 | |||
| 929 | list_for_each_entry(global_auth_tok, | 931 | list_for_each_entry(global_auth_tok, |
| 930 | &mount_crypt_stat->global_auth_tok_list, | 932 | &mount_crypt_stat->global_auth_tok_list, |
| 931 | mount_crypt_stat_list) { | 933 | mount_crypt_stat_list) { |
| @@ -934,13 +936,13 @@ static int ecryptfs_copy_mount_wide_sigs_to_inode_sigs( | |||
| 934 | rc = ecryptfs_add_keysig(crypt_stat, global_auth_tok->sig); | 936 | rc = ecryptfs_add_keysig(crypt_stat, global_auth_tok->sig); |
| 935 | if (rc) { | 937 | if (rc) { |
| 936 | printk(KERN_ERR "Error adding keysig; rc = [%d]\n", rc); | 938 | printk(KERN_ERR "Error adding keysig; rc = [%d]\n", rc); |
| 937 | mutex_unlock( | ||
| 938 | &mount_crypt_stat->global_auth_tok_list_mutex); | ||
| 939 | goto out; | 939 | goto out; |
| 940 | } | 940 | } |
| 941 | } | 941 | } |
| 942 | mutex_unlock(&mount_crypt_stat->global_auth_tok_list_mutex); | 942 | |
| 943 | out: | 943 | out: |
| 944 | mutex_unlock(&mount_crypt_stat->global_auth_tok_list_mutex); | ||
| 945 | mutex_unlock(&crypt_stat->keysig_list_mutex); | ||
| 944 | return rc; | 946 | return rc; |
| 945 | } | 947 | } |
| 946 | 948 | ||
| @@ -1212,14 +1214,15 @@ int ecryptfs_read_and_validate_header_region(char *data, | |||
| 1212 | crypt_stat->extent_size = ECRYPTFS_DEFAULT_EXTENT_SIZE; | 1214 | crypt_stat->extent_size = ECRYPTFS_DEFAULT_EXTENT_SIZE; |
| 1213 | rc = ecryptfs_read_lower(data, 0, crypt_stat->extent_size, | 1215 | rc = ecryptfs_read_lower(data, 0, crypt_stat->extent_size, |
| 1214 | ecryptfs_inode); | 1216 | ecryptfs_inode); |
| 1215 | if (rc) { | 1217 | if (rc < 0) { |
| 1216 | printk(KERN_ERR "%s: Error reading header region; rc = [%d]\n", | 1218 | printk(KERN_ERR "%s: Error reading header region; rc = [%d]\n", |
| 1217 | __func__, rc); | 1219 | __func__, rc); |
| 1218 | goto out; | 1220 | goto out; |
| 1219 | } | 1221 | } |
| 1220 | if (!contains_ecryptfs_marker(data + ECRYPTFS_FILE_SIZE_BYTES)) { | 1222 | if (!contains_ecryptfs_marker(data + ECRYPTFS_FILE_SIZE_BYTES)) { |
| 1221 | rc = -EINVAL; | 1223 | rc = -EINVAL; |
| 1222 | } | 1224 | } else |
| 1225 | rc = 0; | ||
| 1223 | out: | 1226 | out: |
| 1224 | return rc; | 1227 | return rc; |
| 1225 | } | 1228 | } |
| @@ -1314,10 +1317,11 @@ ecryptfs_write_metadata_to_contents(struct dentry *ecryptfs_dentry, | |||
| 1314 | 1317 | ||
| 1315 | rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, virt, | 1318 | rc = ecryptfs_write_lower(ecryptfs_dentry->d_inode, virt, |
| 1316 | 0, virt_len); | 1319 | 0, virt_len); |
| 1317 | if (rc) | 1320 | if (rc < 0) |
| 1318 | printk(KERN_ERR "%s: Error attempting to write header " | 1321 | printk(KERN_ERR "%s: Error attempting to write header " |
| 1319 | "information to lower file; rc = [%d]\n", __func__, | 1322 | "information to lower file; rc = [%d]\n", __func__, rc); |
| 1320 | rc); | 1323 | else |
| 1324 | rc = 0; | ||
| 1321 | return rc; | 1325 | return rc; |
| 1322 | } | 1326 | } |
| 1323 | 1327 | ||
| @@ -1597,7 +1601,7 @@ int ecryptfs_read_metadata(struct dentry *ecryptfs_dentry) | |||
| 1597 | } | 1601 | } |
| 1598 | rc = ecryptfs_read_lower(page_virt, 0, crypt_stat->extent_size, | 1602 | rc = ecryptfs_read_lower(page_virt, 0, crypt_stat->extent_size, |
| 1599 | ecryptfs_inode); | 1603 | ecryptfs_inode); |
| 1600 | if (!rc) | 1604 | if (rc >= 0) |
| 1601 | rc = ecryptfs_read_headers_virt(page_virt, crypt_stat, | 1605 | rc = ecryptfs_read_headers_virt(page_virt, crypt_stat, |
| 1602 | ecryptfs_dentry, | 1606 | ecryptfs_dentry, |
| 1603 | ECRYPTFS_VALIDATE_HEADER_SIZE); | 1607 | ECRYPTFS_VALIDATE_HEADER_SIZE); |
| @@ -1702,7 +1706,7 @@ ecryptfs_encrypt_filename(struct ecryptfs_filename *filename, | |||
| 1702 | } else { | 1706 | } else { |
| 1703 | printk(KERN_ERR "%s: No support for requested filename " | 1707 | printk(KERN_ERR "%s: No support for requested filename " |
| 1704 | "encryption method in this release\n", __func__); | 1708 | "encryption method in this release\n", __func__); |
| 1705 | rc = -ENOTSUPP; | 1709 | rc = -EOPNOTSUPP; |
| 1706 | goto out; | 1710 | goto out; |
| 1707 | } | 1711 | } |
| 1708 | out: | 1712 | out: |
| @@ -1763,7 +1767,7 @@ ecryptfs_process_key_cipher(struct crypto_blkcipher **key_tfm, | |||
| 1763 | if (IS_ERR(*key_tfm)) { | 1767 | if (IS_ERR(*key_tfm)) { |
| 1764 | rc = PTR_ERR(*key_tfm); | 1768 | rc = PTR_ERR(*key_tfm); |
| 1765 | printk(KERN_ERR "Unable to allocate crypto cipher with name " | 1769 | printk(KERN_ERR "Unable to allocate crypto cipher with name " |
| 1766 | "[%s]; rc = [%d]\n", cipher_name, rc); | 1770 | "[%s]; rc = [%d]\n", full_alg_name, rc); |
| 1767 | goto out; | 1771 | goto out; |
| 1768 | } | 1772 | } |
| 1769 | crypto_blkcipher_set_flags(*key_tfm, CRYPTO_TFM_REQ_WEAK_KEY); | 1773 | crypto_blkcipher_set_flags(*key_tfm, CRYPTO_TFM_REQ_WEAK_KEY); |
| @@ -1776,7 +1780,8 @@ ecryptfs_process_key_cipher(struct crypto_blkcipher **key_tfm, | |||
| 1776 | rc = crypto_blkcipher_setkey(*key_tfm, dummy_key, *key_size); | 1780 | rc = crypto_blkcipher_setkey(*key_tfm, dummy_key, *key_size); |
| 1777 | if (rc) { | 1781 | if (rc) { |
| 1778 | printk(KERN_ERR "Error attempting to set key of size [%zd] for " | 1782 | printk(KERN_ERR "Error attempting to set key of size [%zd] for " |
| 1779 | "cipher [%s]; rc = [%d]\n", *key_size, cipher_name, rc); | 1783 | "cipher [%s]; rc = [%d]\n", *key_size, full_alg_name, |
| 1784 | rc); | ||
| 1780 | rc = -EINVAL; | 1785 | rc = -EINVAL; |
| 1781 | goto out; | 1786 | goto out; |
| 1782 | } | 1787 | } |
| @@ -2166,7 +2171,7 @@ int ecryptfs_encrypt_and_encode_filename( | |||
| 2166 | (*encoded_name)[(*encoded_name_size)] = '\0'; | 2171 | (*encoded_name)[(*encoded_name_size)] = '\0'; |
| 2167 | (*encoded_name_size)++; | 2172 | (*encoded_name_size)++; |
| 2168 | } else { | 2173 | } else { |
| 2169 | rc = -ENOTSUPP; | 2174 | rc = -EOPNOTSUPP; |
| 2170 | } | 2175 | } |
| 2171 | if (rc) { | 2176 | if (rc) { |
| 2172 | printk(KERN_ERR "%s: Error attempting to encode " | 2177 | printk(KERN_ERR "%s: Error attempting to encode " |
