aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2011-03-19 02:38:50 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2011-03-19 02:38:50 -0400
commit97eb3f24352ec6632c2127b35d8087d2a809a9b9 (patch)
tree722948059bbd325bbca232269490124231df80d4 /fs/ecryptfs
parent439581ec07fa9cf3f519dd461a2cf41cfd3adcb4 (diff)
parentdef179c271ac9b5020deca798470521f14d11edd (diff)
Merge branch 'next' into for-linus
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r--fs/ecryptfs/crypto.c30
-rw-r--r--fs/ecryptfs/dentry.c9
-rw-r--r--fs/ecryptfs/ecryptfs_kernel.h2
-rw-r--r--fs/ecryptfs/file.c28
-rw-r--r--fs/ecryptfs/inode.c43
-rw-r--r--fs/ecryptfs/keystore.c26
-rw-r--r--fs/ecryptfs/main.c165
-rw-r--r--fs/ecryptfs/mmap.c35
-rw-r--r--fs/ecryptfs/super.c13
9 files changed, 174 insertions, 177 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index cbadc1bee6e7..bfd8b680e648 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -348,7 +348,7 @@ static int encrypt_scatterlist(struct ecryptfs_crypt_stat *crypt_stat,
348 BUG_ON(!crypt_stat || !crypt_stat->tfm 348 BUG_ON(!crypt_stat || !crypt_stat->tfm
349 || !(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED)); 349 || !(crypt_stat->flags & ECRYPTFS_STRUCT_INITIALIZED));
350 if (unlikely(ecryptfs_verbosity > 0)) { 350 if (unlikely(ecryptfs_verbosity > 0)) {
351 ecryptfs_printk(KERN_DEBUG, "Key size [%d]; key:\n", 351 ecryptfs_printk(KERN_DEBUG, "Key size [%zd]; key:\n",
352 crypt_stat->key_size); 352 crypt_stat->key_size);
353 ecryptfs_dump_hex(crypt_stat->key, 353 ecryptfs_dump_hex(crypt_stat->key,
354 crypt_stat->key_size); 354 crypt_stat->key_size);
@@ -413,10 +413,9 @@ static int ecryptfs_encrypt_extent(struct page *enc_extent_page,
413 rc = ecryptfs_derive_iv(extent_iv, crypt_stat, 413 rc = ecryptfs_derive_iv(extent_iv, crypt_stat,
414 (extent_base + extent_offset)); 414 (extent_base + extent_offset));
415 if (rc) { 415 if (rc) {
416 ecryptfs_printk(KERN_ERR, "Error attempting to " 416 ecryptfs_printk(KERN_ERR, "Error attempting to derive IV for "
417 "derive IV for extent [0x%.16x]; " 417 "extent [0x%.16llx]; rc = [%d]\n",
418 "rc = [%d]\n", (extent_base + extent_offset), 418 (unsigned long long)(extent_base + extent_offset), rc);
419 rc);
420 goto out; 419 goto out;
421 } 420 }
422 if (unlikely(ecryptfs_verbosity > 0)) { 421 if (unlikely(ecryptfs_verbosity > 0)) {
@@ -443,9 +442,9 @@ static int ecryptfs_encrypt_extent(struct page *enc_extent_page,
443 } 442 }
444 rc = 0; 443 rc = 0;
445 if (unlikely(ecryptfs_verbosity > 0)) { 444 if (unlikely(ecryptfs_verbosity > 0)) {
446 ecryptfs_printk(KERN_DEBUG, "Encrypt extent [0x%.16x]; " 445 ecryptfs_printk(KERN_DEBUG, "Encrypt extent [0x%.16llx]; "
447 "rc = [%d]\n", (extent_base + extent_offset), 446 "rc = [%d]\n",
448 rc); 447 (unsigned long long)(extent_base + extent_offset), rc);
449 ecryptfs_printk(KERN_DEBUG, "First 8 bytes after " 448 ecryptfs_printk(KERN_DEBUG, "First 8 bytes after "
450 "encryption:\n"); 449 "encryption:\n");
451 ecryptfs_dump_hex((char *)(page_address(enc_extent_page)), 8); 450 ecryptfs_dump_hex((char *)(page_address(enc_extent_page)), 8);
@@ -540,10 +539,9 @@ static int ecryptfs_decrypt_extent(struct page *page,
540 rc = ecryptfs_derive_iv(extent_iv, crypt_stat, 539 rc = ecryptfs_derive_iv(extent_iv, crypt_stat,
541 (extent_base + extent_offset)); 540 (extent_base + extent_offset));
542 if (rc) { 541 if (rc) {
543 ecryptfs_printk(KERN_ERR, "Error attempting to " 542 ecryptfs_printk(KERN_ERR, "Error attempting to derive IV for "
544 "derive IV for extent [0x%.16x]; " 543 "extent [0x%.16llx]; rc = [%d]\n",
545 "rc = [%d]\n", (extent_base + extent_offset), 544 (unsigned long long)(extent_base + extent_offset), rc);
546 rc);
547 goto out; 545 goto out;
548 } 546 }
549 if (unlikely(ecryptfs_verbosity > 0)) { 547 if (unlikely(ecryptfs_verbosity > 0)) {
@@ -571,9 +569,9 @@ static int ecryptfs_decrypt_extent(struct page *page,
571 } 569 }
572 rc = 0; 570 rc = 0;
573 if (unlikely(ecryptfs_verbosity > 0)) { 571 if (unlikely(ecryptfs_verbosity > 0)) {
574 ecryptfs_printk(KERN_DEBUG, "Decrypt extent [0x%.16x]; " 572 ecryptfs_printk(KERN_DEBUG, "Decrypt extent [0x%.16llx]; "
575 "rc = [%d]\n", (extent_base + extent_offset), 573 "rc = [%d]\n",
576 rc); 574 (unsigned long long)(extent_base + extent_offset), rc);
577 ecryptfs_printk(KERN_DEBUG, "First 8 bytes after " 575 ecryptfs_printk(KERN_DEBUG, "First 8 bytes after "
578 "decryption:\n"); 576 "decryption:\n");
579 ecryptfs_dump_hex((char *)(page_address(page) 577 ecryptfs_dump_hex((char *)(page_address(page)
@@ -780,7 +778,7 @@ int ecryptfs_init_crypt_ctx(struct ecryptfs_crypt_stat *crypt_stat)
780 } 778 }
781 ecryptfs_printk(KERN_DEBUG, 779 ecryptfs_printk(KERN_DEBUG,
782 "Initializing cipher [%s]; strlen = [%d]; " 780 "Initializing cipher [%s]; strlen = [%d]; "
783 "key_size_bits = [%d]\n", 781 "key_size_bits = [%zd]\n",
784 crypt_stat->cipher, (int)strlen(crypt_stat->cipher), 782 crypt_stat->cipher, (int)strlen(crypt_stat->cipher),
785 crypt_stat->key_size << 3); 783 crypt_stat->key_size << 3);
786 if (crypt_stat->tfm) { 784 if (crypt_stat->tfm) {
diff --git a/fs/ecryptfs/dentry.c b/fs/ecryptfs/dentry.c
index 906e803f7f79..6fc4f319b550 100644
--- a/fs/ecryptfs/dentry.c
+++ b/fs/ecryptfs/dentry.c
@@ -44,12 +44,17 @@
44 */ 44 */
45static int ecryptfs_d_revalidate(struct dentry *dentry, struct nameidata *nd) 45static int ecryptfs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
46{ 46{
47 struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); 47 struct dentry *lower_dentry;
48 struct vfsmount *lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry); 48 struct vfsmount *lower_mnt;
49 struct dentry *dentry_save; 49 struct dentry *dentry_save;
50 struct vfsmount *vfsmount_save; 50 struct vfsmount *vfsmount_save;
51 int rc = 1; 51 int rc = 1;
52 52
53 if (nd->flags & LOOKUP_RCU)
54 return -ECHILD;
55
56 lower_dentry = ecryptfs_dentry_to_lower(dentry);
57 lower_mnt = ecryptfs_dentry_to_lower_mnt(dentry);
53 if (!lower_dentry->d_op || !lower_dentry->d_op->d_revalidate) 58 if (!lower_dentry->d_op || !lower_dentry->d_op->d_revalidate)
54 goto out; 59 goto out;
55 dentry_save = nd->path.dentry; 60 dentry_save = nd->path.dentry;
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index 413a3c48f0bb..dbc84ed96336 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -192,7 +192,6 @@ ecryptfs_get_key_payload_data(struct key *key)
192 (((struct user_key_payload*)key->payload.data)->data); 192 (((struct user_key_payload*)key->payload.data)->data);
193} 193}
194 194
195#define ECRYPTFS_SUPER_MAGIC 0xf15f
196#define ECRYPTFS_MAX_KEYSET_SIZE 1024 195#define ECRYPTFS_MAX_KEYSET_SIZE 1024
197#define ECRYPTFS_MAX_CIPHER_NAME_SIZE 32 196#define ECRYPTFS_MAX_CIPHER_NAME_SIZE 32
198#define ECRYPTFS_MAX_NUM_ENC_KEYS 64 197#define ECRYPTFS_MAX_NUM_ENC_KEYS 64
@@ -584,6 +583,7 @@ ecryptfs_set_dentry_lower_mnt(struct dentry *dentry, struct vfsmount *lower_mnt)
584 583
585#define ecryptfs_printk(type, fmt, arg...) \ 584#define ecryptfs_printk(type, fmt, arg...) \
586 __ecryptfs_printk(type "%s: " fmt, __func__, ## arg); 585 __ecryptfs_printk(type "%s: " fmt, __func__, ## arg);
586__attribute__ ((format(printf, 1, 2)))
587void __ecryptfs_printk(const char *fmt, ...); 587void __ecryptfs_printk(const char *fmt, ...);
588 588
589extern const struct file_operations ecryptfs_main_fops; 589extern const struct file_operations ecryptfs_main_fops;
diff --git a/fs/ecryptfs/file.c b/fs/ecryptfs/file.c
index 91da02987bff..81e10e6a9443 100644
--- a/fs/ecryptfs/file.c
+++ b/fs/ecryptfs/file.c
@@ -47,7 +47,7 @@ static ssize_t ecryptfs_read_update_atime(struct kiocb *iocb,
47 const struct iovec *iov, 47 const struct iovec *iov,
48 unsigned long nr_segs, loff_t pos) 48 unsigned long nr_segs, loff_t pos)
49{ 49{
50 int rc; 50 ssize_t rc;
51 struct dentry *lower_dentry; 51 struct dentry *lower_dentry;
52 struct vfsmount *lower_vfsmount; 52 struct vfsmount *lower_vfsmount;
53 struct file *file = iocb->ki_filp; 53 struct file *file = iocb->ki_filp;
@@ -191,18 +191,16 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
191 | ECRYPTFS_ENCRYPTED); 191 | ECRYPTFS_ENCRYPTED);
192 } 192 }
193 mutex_unlock(&crypt_stat->cs_mutex); 193 mutex_unlock(&crypt_stat->cs_mutex);
194 if (!ecryptfs_inode_to_private(inode)->lower_file) { 194 rc = ecryptfs_init_persistent_file(ecryptfs_dentry);
195 rc = ecryptfs_init_persistent_file(ecryptfs_dentry); 195 if (rc) {
196 if (rc) { 196 printk(KERN_ERR "%s: Error attempting to initialize "
197 printk(KERN_ERR "%s: Error attempting to initialize " 197 "the persistent file for the dentry with name "
198 "the persistent file for the dentry with name " 198 "[%s]; rc = [%d]\n", __func__,
199 "[%s]; rc = [%d]\n", __func__, 199 ecryptfs_dentry->d_name.name, rc);
200 ecryptfs_dentry->d_name.name, rc); 200 goto out_free;
201 goto out_free;
202 }
203 } 201 }
204 if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_RDONLY) 202 if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_ACCMODE)
205 && !(file->f_flags & O_RDONLY)) { 203 == O_RDONLY && (file->f_flags & O_ACCMODE) != O_RDONLY) {
206 rc = -EPERM; 204 rc = -EPERM;
207 printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs " 205 printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs "
208 "file must hence be opened RO\n", __func__); 206 "file must hence be opened RO\n", __func__);
@@ -243,9 +241,9 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
243 } 241 }
244 } 242 }
245 mutex_unlock(&crypt_stat->cs_mutex); 243 mutex_unlock(&crypt_stat->cs_mutex);
246 ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = [0x%.16x] " 244 ecryptfs_printk(KERN_DEBUG, "inode w/ addr = [0x%p], i_ino = "
247 "size: [0x%.16x]\n", inode, inode->i_ino, 245 "[0x%.16lx] size: [0x%.16llx]\n", inode, inode->i_ino,
248 i_size_read(inode)); 246 (unsigned long long)i_size_read(inode));
249 goto out; 247 goto out;
250out_free: 248out_free:
251 kmem_cache_free(ecryptfs_file_info_cache, 249 kmem_cache_free(ecryptfs_file_info_cache,
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
index 9d1a22d62765..bd33f87a1907 100644
--- a/fs/ecryptfs/inode.c
+++ b/fs/ecryptfs/inode.c
@@ -185,15 +185,13 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry)
185 "context; rc = [%d]\n", rc); 185 "context; rc = [%d]\n", rc);
186 goto out; 186 goto out;
187 } 187 }
188 if (!ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->lower_file) { 188 rc = ecryptfs_init_persistent_file(ecryptfs_dentry);
189 rc = ecryptfs_init_persistent_file(ecryptfs_dentry); 189 if (rc) {
190 if (rc) { 190 printk(KERN_ERR "%s: Error attempting to initialize "
191 printk(KERN_ERR "%s: Error attempting to initialize " 191 "the persistent file for the dentry with name "
192 "the persistent file for the dentry with name " 192 "[%s]; rc = [%d]\n", __func__,
193 "[%s]; rc = [%d]\n", __func__, 193 ecryptfs_dentry->d_name.name, rc);
194 ecryptfs_dentry->d_name.name, rc); 194 goto out;
195 goto out;
196 }
197 } 195 }
198 rc = ecryptfs_write_metadata(ecryptfs_dentry); 196 rc = ecryptfs_write_metadata(ecryptfs_dentry);
199 if (rc) { 197 if (rc) {
@@ -260,7 +258,7 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry,
260 ecryptfs_dentry->d_parent)); 258 ecryptfs_dentry->d_parent));
261 lower_inode = lower_dentry->d_inode; 259 lower_inode = lower_dentry->d_inode;
262 fsstack_copy_attr_atime(ecryptfs_dir_inode, lower_dir_dentry->d_inode); 260 fsstack_copy_attr_atime(ecryptfs_dir_inode, lower_dir_dentry->d_inode);
263 BUG_ON(!atomic_read(&lower_dentry->d_count)); 261 BUG_ON(!lower_dentry->d_count);
264 ecryptfs_set_dentry_private(ecryptfs_dentry, 262 ecryptfs_set_dentry_private(ecryptfs_dentry,
265 kmem_cache_alloc(ecryptfs_dentry_info_cache, 263 kmem_cache_alloc(ecryptfs_dentry_info_cache,
266 GFP_KERNEL)); 264 GFP_KERNEL));
@@ -302,15 +300,13 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry,
302 rc = -ENOMEM; 300 rc = -ENOMEM;
303 goto out; 301 goto out;
304 } 302 }
305 if (!ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->lower_file) { 303 rc = ecryptfs_init_persistent_file(ecryptfs_dentry);
306 rc = ecryptfs_init_persistent_file(ecryptfs_dentry); 304 if (rc) {
307 if (rc) { 305 printk(KERN_ERR "%s: Error attempting to initialize "
308 printk(KERN_ERR "%s: Error attempting to initialize " 306 "the persistent file for the dentry with name "
309 "the persistent file for the dentry with name " 307 "[%s]; rc = [%d]\n", __func__,
310 "[%s]; rc = [%d]\n", __func__, 308 ecryptfs_dentry->d_name.name, rc);
311 ecryptfs_dentry->d_name.name, rc); 309 goto out_free_kmem;
312 goto out_free_kmem;
313 }
314 } 310 }
315 crypt_stat = &ecryptfs_inode_to_private( 311 crypt_stat = &ecryptfs_inode_to_private(
316 ecryptfs_dentry->d_inode)->crypt_stat; 312 ecryptfs_dentry->d_inode)->crypt_stat;
@@ -441,7 +437,6 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
441 struct qstr lower_name; 437 struct qstr lower_name;
442 int rc = 0; 438 int rc = 0;
443 439
444 ecryptfs_dentry->d_op = &ecryptfs_dops;
445 if ((ecryptfs_dentry->d_name.len == 1 440 if ((ecryptfs_dentry->d_name.len == 1
446 && !strcmp(ecryptfs_dentry->d_name.name, ".")) 441 && !strcmp(ecryptfs_dentry->d_name.name, "."))
447 || (ecryptfs_dentry->d_name.len == 2 442 || (ecryptfs_dentry->d_name.len == 2
@@ -454,7 +449,7 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
454 lower_name.hash = ecryptfs_dentry->d_name.hash; 449 lower_name.hash = ecryptfs_dentry->d_name.hash;
455 if (lower_dir_dentry->d_op && lower_dir_dentry->d_op->d_hash) { 450 if (lower_dir_dentry->d_op && lower_dir_dentry->d_op->d_hash) {
456 rc = lower_dir_dentry->d_op->d_hash(lower_dir_dentry, 451 rc = lower_dir_dentry->d_op->d_hash(lower_dir_dentry,
457 &lower_name); 452 lower_dir_dentry->d_inode, &lower_name);
458 if (rc < 0) 453 if (rc < 0)
459 goto out_d_drop; 454 goto out_d_drop;
460 } 455 }
@@ -489,7 +484,7 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
489 lower_name.hash = full_name_hash(lower_name.name, lower_name.len); 484 lower_name.hash = full_name_hash(lower_name.name, lower_name.len);
490 if (lower_dir_dentry->d_op && lower_dir_dentry->d_op->d_hash) { 485 if (lower_dir_dentry->d_op && lower_dir_dentry->d_op->d_hash) {
491 rc = lower_dir_dentry->d_op->d_hash(lower_dir_dentry, 486 rc = lower_dir_dentry->d_op->d_hash(lower_dir_dentry,
492 &lower_name); 487 lower_dir_dentry->d_inode, &lower_name);
493 if (rc < 0) 488 if (rc < 0)
494 goto out_d_drop; 489 goto out_d_drop;
495 } 490 }
@@ -980,8 +975,10 @@ int ecryptfs_truncate(struct dentry *dentry, loff_t new_length)
980} 975}
981 976
982static int 977static int
983ecryptfs_permission(struct inode *inode, int mask) 978ecryptfs_permission(struct inode *inode, int mask, unsigned int flags)
984{ 979{
980 if (flags & IPERM_FLAG_RCU)
981 return -ECHILD;
985 return inode_permission(ecryptfs_inode_to_lower(inode), mask); 982 return inode_permission(ecryptfs_inode_to_lower(inode), mask);
986} 983}
987 984
diff --git a/fs/ecryptfs/keystore.c b/fs/ecryptfs/keystore.c
index b1f6858a5223..c1436cff6f2d 100644
--- a/fs/ecryptfs/keystore.c
+++ b/fs/ecryptfs/keystore.c
@@ -59,7 +59,7 @@ static int process_request_key_err(long err_code)
59 break; 59 break;
60 default: 60 default:
61 ecryptfs_printk(KERN_WARNING, "Unknown error code: " 61 ecryptfs_printk(KERN_WARNING, "Unknown error code: "
62 "[0x%.16x]\n", err_code); 62 "[0x%.16lx]\n", err_code);
63 rc = -EINVAL; 63 rc = -EINVAL;
64 } 64 }
65 return rc; 65 return rc;
@@ -130,7 +130,7 @@ int ecryptfs_write_packet_length(char *dest, size_t size,
130 } else { 130 } else {
131 rc = -EINVAL; 131 rc = -EINVAL;
132 ecryptfs_printk(KERN_WARNING, 132 ecryptfs_printk(KERN_WARNING,
133 "Unsupported packet size: [%d]\n", size); 133 "Unsupported packet size: [%zd]\n", size);
134 } 134 }
135 return rc; 135 return rc;
136} 136}
@@ -1672,7 +1672,7 @@ decrypt_passphrase_encrypted_session_key(struct ecryptfs_auth_tok *auth_tok,
1672 auth_tok->session_key.decrypted_key_size); 1672 auth_tok->session_key.decrypted_key_size);
1673 crypt_stat->flags |= ECRYPTFS_KEY_VALID; 1673 crypt_stat->flags |= ECRYPTFS_KEY_VALID;
1674 if (unlikely(ecryptfs_verbosity > 0)) { 1674 if (unlikely(ecryptfs_verbosity > 0)) {
1675 ecryptfs_printk(KERN_DEBUG, "FEK of size [%d]:\n", 1675 ecryptfs_printk(KERN_DEBUG, "FEK of size [%zd]:\n",
1676 crypt_stat->key_size); 1676 crypt_stat->key_size);
1677 ecryptfs_dump_hex(crypt_stat->key, 1677 ecryptfs_dump_hex(crypt_stat->key,
1678 crypt_stat->key_size); 1678 crypt_stat->key_size);
@@ -1754,7 +1754,7 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
1754 if (ECRYPTFS_SIG_SIZE != tag_11_contents_size) { 1754 if (ECRYPTFS_SIG_SIZE != tag_11_contents_size) {
1755 ecryptfs_printk(KERN_ERR, "Expected " 1755 ecryptfs_printk(KERN_ERR, "Expected "
1756 "signature of size [%d]; " 1756 "signature of size [%d]; "
1757 "read size [%d]\n", 1757 "read size [%zd]\n",
1758 ECRYPTFS_SIG_SIZE, 1758 ECRYPTFS_SIG_SIZE,
1759 tag_11_contents_size); 1759 tag_11_contents_size);
1760 rc = -EIO; 1760 rc = -EIO;
@@ -1787,8 +1787,8 @@ int ecryptfs_parse_packet_set(struct ecryptfs_crypt_stat *crypt_stat,
1787 goto out_wipe_list; 1787 goto out_wipe_list;
1788 break; 1788 break;
1789 default: 1789 default:
1790 ecryptfs_printk(KERN_DEBUG, "No packet at offset " 1790 ecryptfs_printk(KERN_DEBUG, "No packet at offset [%zd] "
1791 "[%d] of the file header; hex value of " 1791 "of the file header; hex value of "
1792 "character is [0x%.2x]\n", i, src[i]); 1792 "character is [0x%.2x]\n", i, src[i]);
1793 next_packet_is_auth_tok_packet = 0; 1793 next_packet_is_auth_tok_packet = 0;
1794 } 1794 }
@@ -1864,8 +1864,8 @@ found_matching_auth_tok:
1864 "session key for authentication token with sig " 1864 "session key for authentication token with sig "
1865 "[%.*s]; rc = [%d]. Removing auth tok " 1865 "[%.*s]; rc = [%d]. Removing auth tok "
1866 "candidate from the list and searching for " 1866 "candidate from the list and searching for "
1867 "the next match.\n", candidate_auth_tok_sig, 1867 "the next match.\n", ECRYPTFS_SIG_SIZE_HEX,
1868 ECRYPTFS_SIG_SIZE_HEX, rc); 1868 candidate_auth_tok_sig, rc);
1869 list_for_each_entry_safe(auth_tok_list_item, 1869 list_for_each_entry_safe(auth_tok_list_item,
1870 auth_tok_list_item_tmp, 1870 auth_tok_list_item_tmp,
1871 &auth_tok_list, list) { 1871 &auth_tok_list, list) {
@@ -2168,7 +2168,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes,
2168 if (encrypted_session_key_valid) { 2168 if (encrypted_session_key_valid) {
2169 ecryptfs_printk(KERN_DEBUG, "encrypted_session_key_valid != 0; " 2169 ecryptfs_printk(KERN_DEBUG, "encrypted_session_key_valid != 0; "
2170 "using auth_tok->session_key.encrypted_key, " 2170 "using auth_tok->session_key.encrypted_key, "
2171 "where key_rec->enc_key_size = [%d]\n", 2171 "where key_rec->enc_key_size = [%zd]\n",
2172 key_rec->enc_key_size); 2172 key_rec->enc_key_size);
2173 memcpy(key_rec->enc_key, 2173 memcpy(key_rec->enc_key,
2174 auth_tok->session_key.encrypted_key, 2174 auth_tok->session_key.encrypted_key,
@@ -2198,7 +2198,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes,
2198 if (rc < 1 || rc > 2) { 2198 if (rc < 1 || rc > 2) {
2199 ecryptfs_printk(KERN_ERR, "Error generating scatterlist " 2199 ecryptfs_printk(KERN_ERR, "Error generating scatterlist "
2200 "for crypt_stat session key; expected rc = 1; " 2200 "for crypt_stat session key; expected rc = 1; "
2201 "got rc = [%d]. key_rec->enc_key_size = [%d]\n", 2201 "got rc = [%d]. key_rec->enc_key_size = [%zd]\n",
2202 rc, key_rec->enc_key_size); 2202 rc, key_rec->enc_key_size);
2203 rc = -ENOMEM; 2203 rc = -ENOMEM;
2204 goto out; 2204 goto out;
@@ -2209,7 +2209,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes,
2209 ecryptfs_printk(KERN_ERR, "Error generating scatterlist " 2209 ecryptfs_printk(KERN_ERR, "Error generating scatterlist "
2210 "for crypt_stat encrypted session key; " 2210 "for crypt_stat encrypted session key; "
2211 "expected rc = 1; got rc = [%d]. " 2211 "expected rc = 1; got rc = [%d]. "
2212 "key_rec->enc_key_size = [%d]\n", rc, 2212 "key_rec->enc_key_size = [%zd]\n", rc,
2213 key_rec->enc_key_size); 2213 key_rec->enc_key_size);
2214 rc = -ENOMEM; 2214 rc = -ENOMEM;
2215 goto out; 2215 goto out;
@@ -2224,7 +2224,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes,
2224 goto out; 2224 goto out;
2225 } 2225 }
2226 rc = 0; 2226 rc = 0;
2227 ecryptfs_printk(KERN_DEBUG, "Encrypting [%d] bytes of the key\n", 2227 ecryptfs_printk(KERN_DEBUG, "Encrypting [%zd] bytes of the key\n",
2228 crypt_stat->key_size); 2228 crypt_stat->key_size);
2229 rc = crypto_blkcipher_encrypt(&desc, dst_sg, src_sg, 2229 rc = crypto_blkcipher_encrypt(&desc, dst_sg, src_sg,
2230 (*key_rec).enc_key_size); 2230 (*key_rec).enc_key_size);
@@ -2235,7 +2235,7 @@ write_tag_3_packet(char *dest, size_t *remaining_bytes,
2235 } 2235 }
2236 ecryptfs_printk(KERN_DEBUG, "This should be the encrypted key:\n"); 2236 ecryptfs_printk(KERN_DEBUG, "This should be the encrypted key:\n");
2237 if (ecryptfs_verbosity > 0) { 2237 if (ecryptfs_verbosity > 0) {
2238 ecryptfs_printk(KERN_DEBUG, "EFEK of size [%d]:\n", 2238 ecryptfs_printk(KERN_DEBUG, "EFEK of size [%zd]:\n",
2239 key_rec->enc_key_size); 2239 key_rec->enc_key_size);
2240 ecryptfs_dump_hex(key_rec->enc_key, 2240 ecryptfs_dump_hex(key_rec->enc_key,
2241 key_rec->enc_key_size); 2241 key_rec->enc_key_size);
diff --git a/fs/ecryptfs/main.c b/fs/ecryptfs/main.c
index a9dbd62518e6..758323a0f09a 100644
--- a/fs/ecryptfs/main.c
+++ b/fs/ecryptfs/main.c
@@ -36,6 +36,7 @@
36#include <linux/parser.h> 36#include <linux/parser.h>
37#include <linux/fs_stack.h> 37#include <linux/fs_stack.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/magic.h>
39#include "ecryptfs_kernel.h" 40#include "ecryptfs_kernel.h"
40 41
41/** 42/**
@@ -141,25 +142,12 @@ int ecryptfs_init_persistent_file(struct dentry *ecryptfs_dentry)
141 return rc; 142 return rc;
142} 143}
143 144
144/** 145static struct inode *ecryptfs_get_inode(struct inode *lower_inode,
145 * ecryptfs_interpose 146 struct super_block *sb)
146 * @lower_dentry: Existing dentry in the lower filesystem
147 * @dentry: ecryptfs' dentry
148 * @sb: ecryptfs's super_block
149 * @flags: flags to govern behavior of interpose procedure
150 *
151 * Interposes upper and lower dentries.
152 *
153 * Returns zero on success; non-zero otherwise
154 */
155int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
156 struct super_block *sb, u32 flags)
157{ 147{
158 struct inode *lower_inode;
159 struct inode *inode; 148 struct inode *inode;
160 int rc = 0; 149 int rc = 0;
161 150
162 lower_inode = lower_dentry->d_inode;
163 if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) { 151 if (lower_inode->i_sb != ecryptfs_superblock_to_lower(sb)) {
164 rc = -EXDEV; 152 rc = -EXDEV;
165 goto out; 153 goto out;
@@ -189,17 +177,38 @@ int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
189 if (special_file(lower_inode->i_mode)) 177 if (special_file(lower_inode->i_mode))
190 init_special_inode(inode, lower_inode->i_mode, 178 init_special_inode(inode, lower_inode->i_mode,
191 lower_inode->i_rdev); 179 lower_inode->i_rdev);
192 dentry->d_op = &ecryptfs_dops;
193 fsstack_copy_attr_all(inode, lower_inode); 180 fsstack_copy_attr_all(inode, lower_inode);
194 /* This size will be overwritten for real files w/ headers and 181 /* This size will be overwritten for real files w/ headers and
195 * other metadata */ 182 * other metadata */
196 fsstack_copy_inode_size(inode, lower_inode); 183 fsstack_copy_inode_size(inode, lower_inode);
184 return inode;
185out:
186 return ERR_PTR(rc);
187}
188
189/**
190 * ecryptfs_interpose
191 * @lower_dentry: Existing dentry in the lower filesystem
192 * @dentry: ecryptfs' dentry
193 * @sb: ecryptfs's super_block
194 * @flags: flags to govern behavior of interpose procedure
195 *
196 * Interposes upper and lower dentries.
197 *
198 * Returns zero on success; non-zero otherwise
199 */
200int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
201 struct super_block *sb, u32 flags)
202{
203 struct inode *lower_inode = lower_dentry->d_inode;
204 struct inode *inode = ecryptfs_get_inode(lower_inode, sb);
205 if (IS_ERR(inode))
206 return PTR_ERR(inode);
197 if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD) 207 if (flags & ECRYPTFS_INTERPOSE_FLAG_D_ADD)
198 d_add(dentry, inode); 208 d_add(dentry, inode);
199 else 209 else
200 d_instantiate(dentry, inode); 210 d_instantiate(dentry, inode);
201out: 211 return 0;
202 return rc;
203} 212}
204 213
205enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig, 214enum { ecryptfs_opt_sig, ecryptfs_opt_ecryptfs_sig,
@@ -492,59 +501,11 @@ struct kmem_cache *ecryptfs_sb_info_cache;
492static struct file_system_type ecryptfs_fs_type; 501static struct file_system_type ecryptfs_fs_type;
493 502
494/** 503/**
495 * ecryptfs_read_super
496 * @sb: The ecryptfs super block
497 * @dev_name: The path to mount over
498 *
499 * Read the super block of the lower filesystem, and use
500 * ecryptfs_interpose to create our initial inode and super block
501 * struct.
502 */
503static int ecryptfs_read_super(struct super_block *sb, const char *dev_name)
504{
505 struct path path;
506 int rc;
507
508 rc = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
509 if (rc) {
510 ecryptfs_printk(KERN_WARNING, "path_lookup() failed\n");
511 goto out;
512 }
513 if (path.dentry->d_sb->s_type == &ecryptfs_fs_type) {
514 rc = -EINVAL;
515 printk(KERN_ERR "Mount on filesystem of type "
516 "eCryptfs explicitly disallowed due to "
517 "known incompatibilities\n");
518 goto out_free;
519 }
520 ecryptfs_set_superblock_lower(sb, path.dentry->d_sb);
521 sb->s_maxbytes = path.dentry->d_sb->s_maxbytes;
522 sb->s_blocksize = path.dentry->d_sb->s_blocksize;
523 ecryptfs_set_dentry_lower(sb->s_root, path.dentry);
524 ecryptfs_set_dentry_lower_mnt(sb->s_root, path.mnt);
525 rc = ecryptfs_interpose(path.dentry, sb->s_root, sb, 0);
526 if (rc)
527 goto out_free;
528 rc = 0;
529 goto out;
530out_free:
531 path_put(&path);
532out:
533 return rc;
534}
535
536/**
537 * ecryptfs_get_sb 504 * ecryptfs_get_sb
538 * @fs_type 505 * @fs_type
539 * @flags 506 * @flags
540 * @dev_name: The path to mount over 507 * @dev_name: The path to mount over
541 * @raw_data: The options passed into the kernel 508 * @raw_data: The options passed into the kernel
542 *
543 * The whole ecryptfs_get_sb process is broken into 3 functions:
544 * ecryptfs_parse_options(): handle options passed to ecryptfs, if any
545 * ecryptfs_read_super(): this accesses the lower filesystem and uses
546 * ecryptfs_interpose to perform most of the linking
547 * ecryptfs_interpose(): links the lower filesystem into ecryptfs (inode.c)
548 */ 509 */
549static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags, 510static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags,
550 const char *dev_name, void *raw_data) 511 const char *dev_name, void *raw_data)
@@ -553,6 +514,8 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
553 struct ecryptfs_sb_info *sbi; 514 struct ecryptfs_sb_info *sbi;
554 struct ecryptfs_dentry_info *root_info; 515 struct ecryptfs_dentry_info *root_info;
555 const char *err = "Getting sb failed"; 516 const char *err = "Getting sb failed";
517 struct inode *inode;
518 struct path path;
556 int rc; 519 int rc;
557 520
558 sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache, GFP_KERNEL); 521 sbi = kmem_cache_zalloc(ecryptfs_sb_info_cache, GFP_KERNEL);
@@ -575,10 +538,8 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
575 538
576 s->s_flags = flags; 539 s->s_flags = flags;
577 rc = bdi_setup_and_register(&sbi->bdi, "ecryptfs", BDI_CAP_MAP_COPY); 540 rc = bdi_setup_and_register(&sbi->bdi, "ecryptfs", BDI_CAP_MAP_COPY);
578 if (rc) { 541 if (rc)
579 deactivate_locked_super(s); 542 goto out1;
580 goto out;
581 }
582 543
583 ecryptfs_set_superblock_private(s, sbi); 544 ecryptfs_set_superblock_private(s, sbi);
584 s->s_bdi = &sbi->bdi; 545 s->s_bdi = &sbi->bdi;
@@ -586,34 +547,55 @@ static struct dentry *ecryptfs_mount(struct file_system_type *fs_type, int flags
586 /* ->kill_sb() will take care of sbi after that point */ 547 /* ->kill_sb() will take care of sbi after that point */
587 sbi = NULL; 548 sbi = NULL;
588 s->s_op = &ecryptfs_sops; 549 s->s_op = &ecryptfs_sops;
550 s->s_d_op = &ecryptfs_dops;
589 551
590 rc = -ENOMEM; 552 err = "Reading sb failed";
591 s->s_root = d_alloc(NULL, &(const struct qstr) { 553 rc = kern_path(dev_name, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
592 .hash = 0,.name = "/",.len = 1}); 554 if (rc) {
555 ecryptfs_printk(KERN_WARNING, "kern_path() failed\n");
556 goto out1;
557 }
558 if (path.dentry->d_sb->s_type == &ecryptfs_fs_type) {
559 rc = -EINVAL;
560 printk(KERN_ERR "Mount on filesystem of type "
561 "eCryptfs explicitly disallowed due to "
562 "known incompatibilities\n");
563 goto out_free;
564 }
565 ecryptfs_set_superblock_lower(s, path.dentry->d_sb);
566 s->s_maxbytes = path.dentry->d_sb->s_maxbytes;
567 s->s_blocksize = path.dentry->d_sb->s_blocksize;
568 s->s_magic = ECRYPTFS_SUPER_MAGIC;
569
570 inode = ecryptfs_get_inode(path.dentry->d_inode, s);
571 rc = PTR_ERR(inode);
572 if (IS_ERR(inode))
573 goto out_free;
574
575 s->s_root = d_alloc_root(inode);
593 if (!s->s_root) { 576 if (!s->s_root) {
594 deactivate_locked_super(s); 577 iput(inode);
595 goto out; 578 rc = -ENOMEM;
579 goto out_free;
596 } 580 }
597 s->s_root->d_op = &ecryptfs_dops;
598 s->s_root->d_sb = s;
599 s->s_root->d_parent = s->s_root;
600 581
582 rc = -ENOMEM;
601 root_info = kmem_cache_zalloc(ecryptfs_dentry_info_cache, GFP_KERNEL); 583 root_info = kmem_cache_zalloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
602 if (!root_info) { 584 if (!root_info)
603 deactivate_locked_super(s); 585 goto out_free;
604 goto out; 586
605 }
606 /* ->kill_sb() will take care of root_info */ 587 /* ->kill_sb() will take care of root_info */
607 ecryptfs_set_dentry_private(s->s_root, root_info); 588 ecryptfs_set_dentry_private(s->s_root, root_info);
589 ecryptfs_set_dentry_lower(s->s_root, path.dentry);
590 ecryptfs_set_dentry_lower_mnt(s->s_root, path.mnt);
591
608 s->s_flags |= MS_ACTIVE; 592 s->s_flags |= MS_ACTIVE;
609 rc = ecryptfs_read_super(s, dev_name);
610 if (rc) {
611 deactivate_locked_super(s);
612 err = "Reading sb failed";
613 goto out;
614 }
615 return dget(s->s_root); 593 return dget(s->s_root);
616 594
595out_free:
596 path_put(&path);
597out1:
598 deactivate_locked_super(s);
617out: 599out:
618 if (sbi) { 600 if (sbi) {
619 ecryptfs_destroy_mount_crypt_stat(&sbi->mount_crypt_stat); 601 ecryptfs_destroy_mount_crypt_stat(&sbi->mount_crypt_stat);
@@ -828,9 +810,10 @@ static int __init ecryptfs_init(void)
828 ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is " 810 ecryptfs_printk(KERN_ERR, "The eCryptfs extent size is "
829 "larger than the host's page size, and so " 811 "larger than the host's page size, and so "
830 "eCryptfs cannot run on this system. The " 812 "eCryptfs cannot run on this system. The "
831 "default eCryptfs extent size is [%d] bytes; " 813 "default eCryptfs extent size is [%u] bytes; "
832 "the page size is [%d] bytes.\n", 814 "the page size is [%lu] bytes.\n",
833 ECRYPTFS_DEFAULT_EXTENT_SIZE, PAGE_CACHE_SIZE); 815 ECRYPTFS_DEFAULT_EXTENT_SIZE,
816 (unsigned long)PAGE_CACHE_SIZE);
834 goto out; 817 goto out;
835 } 818 }
836 rc = ecryptfs_init_kmem_caches(); 819 rc = ecryptfs_init_kmem_caches();
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index b1d82756544b..cc64fca89f8d 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -65,7 +65,7 @@ static int ecryptfs_writepage(struct page *page, struct writeback_control *wbc)
65 rc = ecryptfs_encrypt_page(page); 65 rc = ecryptfs_encrypt_page(page);
66 if (rc) { 66 if (rc) {
67 ecryptfs_printk(KERN_WARNING, "Error encrypting " 67 ecryptfs_printk(KERN_WARNING, "Error encrypting "
68 "page (upper index [0x%.16x])\n", page->index); 68 "page (upper index [0x%.16lx])\n", page->index);
69 ClearPageUptodate(page); 69 ClearPageUptodate(page);
70 goto out; 70 goto out;
71 } 71 }
@@ -237,7 +237,7 @@ out:
237 ClearPageUptodate(page); 237 ClearPageUptodate(page);
238 else 238 else
239 SetPageUptodate(page); 239 SetPageUptodate(page);
240 ecryptfs_printk(KERN_DEBUG, "Unlocking page with index = [0x%.16x]\n", 240 ecryptfs_printk(KERN_DEBUG, "Unlocking page with index = [0x%.16lx]\n",
241 page->index); 241 page->index);
242 unlock_page(page); 242 unlock_page(page);
243 return rc; 243 return rc;
@@ -290,6 +290,7 @@ static int ecryptfs_write_begin(struct file *file,
290 return -ENOMEM; 290 return -ENOMEM;
291 *pagep = page; 291 *pagep = page;
292 292
293 prev_page_end_size = ((loff_t)index << PAGE_CACHE_SHIFT);
293 if (!PageUptodate(page)) { 294 if (!PageUptodate(page)) {
294 struct ecryptfs_crypt_stat *crypt_stat = 295 struct ecryptfs_crypt_stat *crypt_stat =
295 &ecryptfs_inode_to_private(mapping->host)->crypt_stat; 296 &ecryptfs_inode_to_private(mapping->host)->crypt_stat;
@@ -335,18 +336,23 @@ static int ecryptfs_write_begin(struct file *file,
335 SetPageUptodate(page); 336 SetPageUptodate(page);
336 } 337 }
337 } else { 338 } else {
338 rc = ecryptfs_decrypt_page(page); 339 if (prev_page_end_size
339 if (rc) { 340 >= i_size_read(page->mapping->host)) {
340 printk(KERN_ERR "%s: Error decrypting page " 341 zero_user(page, 0, PAGE_CACHE_SIZE);
341 "at index [%ld]; rc = [%d]\n", 342 } else {
342 __func__, page->index, rc); 343 rc = ecryptfs_decrypt_page(page);
343 ClearPageUptodate(page); 344 if (rc) {
344 goto out; 345 printk(KERN_ERR "%s: Error decrypting "
346 "page at index [%ld]; "
347 "rc = [%d]\n",
348 __func__, page->index, rc);
349 ClearPageUptodate(page);
350 goto out;
351 }
345 } 352 }
346 SetPageUptodate(page); 353 SetPageUptodate(page);
347 } 354 }
348 } 355 }
349 prev_page_end_size = ((loff_t)index << PAGE_CACHE_SHIFT);
350 /* If creating a page or more of holes, zero them out via truncate. 356 /* If creating a page or more of holes, zero them out via truncate.
351 * Note, this will increase i_size. */ 357 * Note, this will increase i_size. */
352 if (index != 0) { 358 if (index != 0) {
@@ -488,7 +494,7 @@ static int ecryptfs_write_end(struct file *file,
488 } else 494 } else
489 ecryptfs_printk(KERN_DEBUG, "Not a new file\n"); 495 ecryptfs_printk(KERN_DEBUG, "Not a new file\n");
490 ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page" 496 ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page"
491 "(page w/ index = [0x%.16x], to = [%d])\n", index, to); 497 "(page w/ index = [0x%.16lx], to = [%d])\n", index, to);
492 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) { 498 if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
493 rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, page, 0, 499 rc = ecryptfs_write_lower_page_segment(ecryptfs_inode, page, 0,
494 to); 500 to);
@@ -503,19 +509,20 @@ static int ecryptfs_write_end(struct file *file,
503 rc = fill_zeros_to_end_of_page(page, to); 509 rc = fill_zeros_to_end_of_page(page, to);
504 if (rc) { 510 if (rc) {
505 ecryptfs_printk(KERN_WARNING, "Error attempting to fill " 511 ecryptfs_printk(KERN_WARNING, "Error attempting to fill "
506 "zeros in page with index = [0x%.16x]\n", index); 512 "zeros in page with index = [0x%.16lx]\n", index);
507 goto out; 513 goto out;
508 } 514 }
509 rc = ecryptfs_encrypt_page(page); 515 rc = ecryptfs_encrypt_page(page);
510 if (rc) { 516 if (rc) {
511 ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper " 517 ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper "
512 "index [0x%.16x])\n", index); 518 "index [0x%.16lx])\n", index);
513 goto out; 519 goto out;
514 } 520 }
515 if (pos + copied > i_size_read(ecryptfs_inode)) { 521 if (pos + copied > i_size_read(ecryptfs_inode)) {
516 i_size_write(ecryptfs_inode, pos + copied); 522 i_size_write(ecryptfs_inode, pos + copied);
517 ecryptfs_printk(KERN_DEBUG, "Expanded file size to " 523 ecryptfs_printk(KERN_DEBUG, "Expanded file size to "
518 "[0x%.16x]\n", i_size_read(ecryptfs_inode)); 524 "[0x%.16llx]\n",
525 (unsigned long long)i_size_read(ecryptfs_inode));
519 } 526 }
520 rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode); 527 rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode);
521 if (rc) 528 if (rc)
diff --git a/fs/ecryptfs/super.c b/fs/ecryptfs/super.c
index 253732382d37..3042fe123a34 100644
--- a/fs/ecryptfs/super.c
+++ b/fs/ecryptfs/super.c
@@ -28,7 +28,6 @@
28#include <linux/key.h> 28#include <linux/key.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/seq_file.h> 30#include <linux/seq_file.h>
31#include <linux/smp_lock.h>
32#include <linux/file.h> 31#include <linux/file.h>
33#include <linux/crypto.h> 32#include <linux/crypto.h>
34#include "ecryptfs_kernel.h" 33#include "ecryptfs_kernel.h"
@@ -63,6 +62,16 @@ out:
63 return inode; 62 return inode;
64} 63}
65 64
65static void ecryptfs_i_callback(struct rcu_head *head)
66{
67 struct inode *inode = container_of(head, struct inode, i_rcu);
68 struct ecryptfs_inode_info *inode_info;
69 inode_info = ecryptfs_inode_to_private(inode);
70
71 INIT_LIST_HEAD(&inode->i_dentry);
72 kmem_cache_free(ecryptfs_inode_info_cache, inode_info);
73}
74
66/** 75/**
67 * ecryptfs_destroy_inode 76 * ecryptfs_destroy_inode
68 * @inode: The ecryptfs inode 77 * @inode: The ecryptfs inode
@@ -89,7 +98,7 @@ static void ecryptfs_destroy_inode(struct inode *inode)
89 } 98 }
90 } 99 }
91 ecryptfs_destroy_crypt_stat(&inode_info->crypt_stat); 100 ecryptfs_destroy_crypt_stat(&inode_info->crypt_stat);
92 kmem_cache_free(ecryptfs_inode_info_cache, inode_info); 101 call_rcu(&inode->i_rcu, ecryptfs_i_callback);
93} 102}
94 103
95/** 104/**