Skip to content

Commit

Permalink
ecryptfs: avoid multiple aliases for directories
Browse files Browse the repository at this point in the history
ecryptfs_lookup_interpose should use d_splice_alias(), not d_add()
(and return struct dentry * rather than int).  Get rid of
redundant dir_inode argument, while we are touching it...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Mar 31, 2016
1 parent 0c93b7d commit b1168a9
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions fs/ecryptfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,8 @@ static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
/**
* ecryptfs_lookup_interpose - Dentry interposition for a lookup
*/
static int ecryptfs_lookup_interpose(struct dentry *dentry,
struct dentry *lower_dentry,
struct inode *dir_inode)
static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
struct dentry *lower_dentry)
{
struct inode *inode, *lower_inode = d_inode(lower_dentry);
struct ecryptfs_dentry_info *dentry_info;
Expand All @@ -339,11 +338,12 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
"to allocate ecryptfs_dentry_info struct\n",
__func__);
dput(lower_dentry);
return -ENOMEM;
return ERR_PTR(-ENOMEM);
}

lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent));
fsstack_copy_attr_atime(dir_inode, d_inode(lower_dentry->d_parent));
fsstack_copy_attr_atime(d_inode(dentry->d_parent),
d_inode(lower_dentry->d_parent));
BUG_ON(!d_count(lower_dentry));

ecryptfs_set_dentry_private(dentry, dentry_info);
Expand All @@ -353,27 +353,25 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
if (d_really_is_negative(lower_dentry)) {
/* We want to add because we couldn't find in lower */
d_add(dentry, NULL);
return 0;
return NULL;
}
inode = __ecryptfs_get_inode(lower_inode, dir_inode->i_sb);
inode = __ecryptfs_get_inode(lower_inode, dentry->d_sb);
if (IS_ERR(inode)) {
printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n",
__func__, PTR_ERR(inode));
return PTR_ERR(inode);
return ERR_CAST(inode);
}
if (S_ISREG(inode->i_mode)) {
rc = ecryptfs_i_size_read(dentry, inode);
if (rc) {
make_bad_inode(inode);
return rc;
return ERR_PTR(rc);
}
}

if (inode->i_state & I_NEW)
unlock_new_inode(inode);
d_add(dentry, inode);

return rc;
return d_splice_alias(inode, dentry);
}

/**
Expand All @@ -393,17 +391,18 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
size_t encrypted_and_encoded_name_size;
struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
struct dentry *lower_dir_dentry, *lower_dentry;
struct dentry *res;
int rc = 0;

lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent);
lower_dentry = lookup_one_len_unlocked(ecryptfs_dentry->d_name.name,
lower_dir_dentry,
ecryptfs_dentry->d_name.len);
if (IS_ERR(lower_dentry)) {
rc = PTR_ERR(lower_dentry);
ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
"[%d] on lower_dentry = [%pd]\n", __func__, rc,
ecryptfs_dentry);
"[%ld] on lower_dentry = [%pd]\n", __func__,
PTR_ERR(lower_dentry), ecryptfs_dentry);
res = ERR_CAST(lower_dentry);
goto out;
}
if (d_really_is_positive(lower_dentry))
Expand All @@ -421,24 +420,25 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
if (rc) {
printk(KERN_ERR "%s: Error attempting to encrypt and encode "
"filename; rc = [%d]\n", __func__, rc);
res = ERR_PTR(rc);
goto out;
}
lower_dentry = lookup_one_len_unlocked(encrypted_and_encoded_name,
lower_dir_dentry,
encrypted_and_encoded_name_size);
if (IS_ERR(lower_dentry)) {
rc = PTR_ERR(lower_dentry);
ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
"[%d] on lower_dentry = [%s]\n", __func__, rc,
"[%ld] on lower_dentry = [%s]\n", __func__,
PTR_ERR(lower_dentry),
encrypted_and_encoded_name);
res = ERR_CAST(lower_dentry);
goto out;
}
interpose:
rc = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry,
ecryptfs_dir_inode);
res = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry);
out:
kfree(encrypted_and_encoded_name);
return ERR_PTR(rc);
return res;
}

static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
Expand Down

0 comments on commit b1168a9

Please sign in to comment.