diff options
author | Michael Halcrow <mhalcrow@us.ibm.com> | 2008-07-24 00:30:08 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-24 13:47:31 -0400 |
commit | 391b52f98cf2e9bff227dad8bf9ea206fec43fa4 (patch) | |
tree | 40eb4e0d6d399d9b98b791db497097a1ff44894e /fs/ecryptfs/inode.c | |
parent | 72b55fffd631a89e5be6fe1b4f2565bc4cd90deb (diff) |
eCryptfs: Make all persistent file opens delayed
There is no good reason to immediately open the lower file, and that can
cause problems with files that the user does not intend to immediately
open, such as device nodes.
This patch removes the persistent file open from the interpose step and
pushes that to the locations where eCryptfs really does need the lower
persistent file, such as just before reading or writing the metadata
stored in the lower file header.
Two functions are jumping to out_dput when they should just be jumping to
out on error paths. This patch also fixes these.
Signed-off-by: Michael Halcrow <mhalcrow@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ecryptfs/inode.c')
-rw-r--r-- | fs/ecryptfs/inode.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c index 26090878c930..d755455e3bff 100644 --- a/fs/ecryptfs/inode.c +++ b/fs/ecryptfs/inode.c | |||
@@ -189,6 +189,16 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry) | |||
189 | "context; rc = [%d]\n", rc); | 189 | "context; rc = [%d]\n", rc); |
190 | goto out; | 190 | goto out; |
191 | } | 191 | } |
192 | if (!ecryptfs_inode_to_private(ecryptfs_dentry->d_inode)->lower_file) { | ||
193 | rc = ecryptfs_init_persistent_file(ecryptfs_dentry); | ||
194 | if (rc) { | ||
195 | printk(KERN_ERR "%s: Error attempting to initialize " | ||
196 | "the persistent file for the dentry with name " | ||
197 | "[%s]; rc = [%d]\n", __func__, | ||
198 | ecryptfs_dentry->d_name.name, rc); | ||
199 | goto out; | ||
200 | } | ||
201 | } | ||
192 | rc = ecryptfs_write_metadata(ecryptfs_dentry); | 202 | rc = ecryptfs_write_metadata(ecryptfs_dentry); |
193 | if (rc) { | 203 | if (rc) { |
194 | printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc); | 204 | printk(KERN_ERR "Error writing headers; rc = [%d]\n", rc); |
@@ -312,7 +322,7 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry, | |||
312 | ECRYPTFS_INTERPOSE_FLAG_D_ADD); | 322 | ECRYPTFS_INTERPOSE_FLAG_D_ADD); |
313 | if (rc) { | 323 | if (rc) { |
314 | ecryptfs_printk(KERN_ERR, "Error interposing\n"); | 324 | ecryptfs_printk(KERN_ERR, "Error interposing\n"); |
315 | goto out_dput; | 325 | goto out; |
316 | } | 326 | } |
317 | if (S_ISDIR(lower_inode->i_mode)) { | 327 | if (S_ISDIR(lower_inode->i_mode)) { |
318 | ecryptfs_printk(KERN_DEBUG, "Is a directory; returning\n"); | 328 | ecryptfs_printk(KERN_DEBUG, "Is a directory; returning\n"); |
@@ -338,11 +348,21 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry, | |||
338 | rc = -ENOMEM; | 348 | rc = -ENOMEM; |
339 | ecryptfs_printk(KERN_ERR, | 349 | ecryptfs_printk(KERN_ERR, |
340 | "Cannot ecryptfs_kmalloc a page\n"); | 350 | "Cannot ecryptfs_kmalloc a page\n"); |
341 | goto out_dput; | 351 | goto out; |
342 | } | 352 | } |
343 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; | 353 | crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat; |
344 | if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) | 354 | if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED)) |
345 | ecryptfs_set_default_sizes(crypt_stat); | 355 | ecryptfs_set_default_sizes(crypt_stat); |
356 | if (!ecryptfs_inode_to_private(dentry->d_inode)->lower_file) { | ||
357 | rc = ecryptfs_init_persistent_file(dentry); | ||
358 | if (rc) { | ||
359 | printk(KERN_ERR "%s: Error attempting to initialize " | ||
360 | "the persistent file for the dentry with name " | ||
361 | "[%s]; rc = [%d]\n", __func__, | ||
362 | dentry->d_name.name, rc); | ||
363 | goto out; | ||
364 | } | ||
365 | } | ||
346 | rc = ecryptfs_read_and_validate_header_region(page_virt, | 366 | rc = ecryptfs_read_and_validate_header_region(page_virt, |
347 | dentry->d_inode); | 367 | dentry->d_inode); |
348 | if (rc) { | 368 | if (rc) { |
@@ -538,8 +558,7 @@ ecryptfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev) | |||
538 | rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev); | 558 | rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev); |
539 | if (rc || !lower_dentry->d_inode) | 559 | if (rc || !lower_dentry->d_inode) |
540 | goto out; | 560 | goto out; |
541 | rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, | 561 | rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0); |
542 | ECRYPTFS_INTERPOSE_FLAG_DELAY_PERSISTENT_FILE); | ||
543 | if (rc) | 562 | if (rc) |
544 | goto out; | 563 | goto out; |
545 | fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); | 564 | fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode); |