Skip to content

Commit 762c696

Browse files
author
Al Viro
committed
ecryptfs_lookup_interpose(): lower_dentry->d_parent is not stable either
We need to get the underlying dentry of parent; sure, absent the races it is the parent of underlying dentry, but there's nothing to prevent losing a timeslice to preemtion in the middle of evaluation of lower_dentry->d_parent->d_inode, having another process move lower_dentry around and have its (ex)parent not pinned anymore and freed on memory pressure. Then we regain CPU and try to fetch ->d_inode from memory that is freed by that point. dentry->d_parent *is* stable here - it's an argument of ->lookup() and we are guaranteed that it won't be moved anywhere until we feed it to d_add/d_splice_alias. So we safely go that way to get to its underlying dentry. Cc: [email protected] # since 2009 or so Signed-off-by: Al Viro <[email protected]>
1 parent e72b9dd commit 762c696

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

fs/ecryptfs/inode.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
319319
static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
320320
struct dentry *lower_dentry)
321321
{
322+
struct path *path = ecryptfs_dentry_to_lower_path(dentry->d_parent);
322323
struct inode *inode, *lower_inode;
323324
struct ecryptfs_dentry_info *dentry_info;
324-
struct vfsmount *lower_mnt;
325325
int rc = 0;
326326

327327
dentry_info = kmem_cache_alloc(ecryptfs_dentry_info_cache, GFP_KERNEL);
@@ -330,13 +330,12 @@ static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
330330
return ERR_PTR(-ENOMEM);
331331
}
332332

333-
lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent));
334333
fsstack_copy_attr_atime(d_inode(dentry->d_parent),
335-
d_inode(lower_dentry->d_parent));
334+
d_inode(path->dentry));
336335
BUG_ON(!d_count(lower_dentry));
337336

338337
ecryptfs_set_dentry_private(dentry, dentry_info);
339-
dentry_info->lower_path.mnt = lower_mnt;
338+
dentry_info->lower_path.mnt = mntget(path->mnt);
340339
dentry_info->lower_path.dentry = lower_dentry;
341340

342341
/*

0 commit comments

Comments
 (0)