Skip to content

Commit 391b52f

Browse files
Michael Halcrowtorvalds
authored andcommitted
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>
1 parent 72b55ff commit 391b52f

4 files changed

Lines changed: 23 additions & 26 deletions

File tree

‎fs/ecryptfs/ecryptfs_kernel.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ struct ecryptfs_crypt_stat {
235235
#define ECRYPTFS_METADATA_IN_XATTR 0x00000100
236236
#define ECRYPTFS_VIEW_AS_ENCRYPTED 0x00000200
237237
#define ECRYPTFS_KEY_SET 0x00000400
238-
#define ECRYPTFS_DELAY_PERSISTENT 0x00000800
239238
u32 flags;
240239
unsigned int file_version;
241240
size_t iv_bytes;
@@ -576,7 +575,6 @@ struct ecryptfs_open_req {
576575
};
577576

578577
#define ECRYPTFS_INTERPOSE_FLAG_D_ADD 0x00000001
579-
#define ECRYPTFS_INTERPOSE_FLAG_DELAY_PERSISTENT_FILE 0x00000002
580578
int ecryptfs_interpose(struct dentry *hidden_dentry,
581579
struct dentry *this_dentry, struct super_block *sb,
582580
u32 flags);

‎fs/ecryptfs/file.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,6 @@ static int ecryptfs_open(struct inode *inode, struct file *file)
200200
goto out;
201201
}
202202
if (!ecryptfs_inode_to_private(inode)->lower_file) {
203-
BUG_ON(!(crypt_stat->flags & ECRYPTFS_DELAY_PERSISTENT));
204-
mutex_lock(&crypt_stat->cs_mutex);
205-
crypt_stat->flags &= ~(ECRYPTFS_ENCRYPTED);
206-
mutex_unlock(&crypt_stat->cs_mutex);
207203
rc = ecryptfs_init_persistent_file(ecryptfs_dentry);
208204
if (rc) {
209205
printk(KERN_ERR "%s: Error attempting to initialize "

‎fs/ecryptfs/inode.c‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ static int ecryptfs_initialize_file(struct dentry *ecryptfs_dentry)
189189
"context; rc = [%d]\n", rc);
190190
goto out;
191191
}
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+
}
192202
rc = ecryptfs_write_metadata(ecryptfs_dentry);
193203
if (rc) {
194204
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,
312322
ECRYPTFS_INTERPOSE_FLAG_D_ADD);
313323
if (rc) {
314324
ecryptfs_printk(KERN_ERR, "Error interposing\n");
315-
goto out_dput;
325+
goto out;
316326
}
317327
if (S_ISDIR(lower_inode->i_mode)) {
318328
ecryptfs_printk(KERN_DEBUG, "Is a directory; returning\n");
@@ -338,11 +348,21 @@ static struct dentry *ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
338348
rc = -ENOMEM;
339349
ecryptfs_printk(KERN_ERR,
340350
"Cannot ecryptfs_kmalloc a page\n");
341-
goto out_dput;
351+
goto out;
342352
}
343353
crypt_stat = &ecryptfs_inode_to_private(dentry->d_inode)->crypt_stat;
344354
if (!(crypt_stat->flags & ECRYPTFS_POLICY_APPLIED))
345355
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+
}
346366
rc = ecryptfs_read_and_validate_header_region(page_virt,
347367
dentry->d_inode);
348368
if (rc) {
@@ -538,8 +558,7 @@ ecryptfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
538558
rc = vfs_mknod(lower_dir_dentry->d_inode, lower_dentry, mode, dev);
539559
if (rc || !lower_dentry->d_inode)
540560
goto out;
541-
rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb,
542-
ECRYPTFS_INTERPOSE_FLAG_DELAY_PERSISTENT_FILE);
561+
rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb, 0);
543562
if (rc)
544563
goto out;
545564
fsstack_copy_attr_times(dir, lower_dir_dentry->d_inode);

‎fs/ecryptfs/main.c‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,6 @@ int ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
201201
/* This size will be overwritten for real files w/ headers and
202202
* other metadata */
203203
fsstack_copy_inode_size(inode, lower_inode);
204-
if (!(flags & ECRYPTFS_INTERPOSE_FLAG_DELAY_PERSISTENT_FILE)) {
205-
rc = ecryptfs_init_persistent_file(dentry);
206-
if (rc) {
207-
printk(KERN_ERR "%s: Error attempting to initialize "
208-
"the persistent file for the dentry with name "
209-
"[%s]; rc = [%d]\n", __func__,
210-
dentry->d_name.name, rc);
211-
goto out;
212-
}
213-
} else {
214-
struct ecryptfs_inode_info *inode_info =
215-
ecryptfs_inode_to_private(dentry->d_inode);
216-
217-
inode_info->lower_file = NULL;
218-
inode_info->crypt_stat.flags |= ECRYPTFS_DELAY_PERSISTENT;
219-
}
220204
out:
221205
return rc;
222206
}

0 commit comments

Comments
 (0)