Commit b1168a92 authored by Al Viro's avatar Al Viro

ecryptfs: avoid multiple aliases for directories

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: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 0c93b7d8
...@@ -324,9 +324,8 @@ static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode) ...@@ -324,9 +324,8 @@ static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
/** /**
* ecryptfs_lookup_interpose - Dentry interposition for a lookup * ecryptfs_lookup_interpose - Dentry interposition for a lookup
*/ */
static int ecryptfs_lookup_interpose(struct dentry *dentry, static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
struct dentry *lower_dentry, struct dentry *lower_dentry)
struct inode *dir_inode)
{ {
struct inode *inode, *lower_inode = d_inode(lower_dentry); struct inode *inode, *lower_inode = d_inode(lower_dentry);
struct ecryptfs_dentry_info *dentry_info; struct ecryptfs_dentry_info *dentry_info;
...@@ -339,11 +338,12 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry, ...@@ -339,11 +338,12 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
"to allocate ecryptfs_dentry_info struct\n", "to allocate ecryptfs_dentry_info struct\n",
__func__); __func__);
dput(lower_dentry); dput(lower_dentry);
return -ENOMEM; return ERR_PTR(-ENOMEM);
} }
lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent)); 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)); BUG_ON(!d_count(lower_dentry));
ecryptfs_set_dentry_private(dentry, dentry_info); ecryptfs_set_dentry_private(dentry, dentry_info);
...@@ -353,27 +353,25 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry, ...@@ -353,27 +353,25 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
if (d_really_is_negative(lower_dentry)) { if (d_really_is_negative(lower_dentry)) {
/* We want to add because we couldn't find in lower */ /* We want to add because we couldn't find in lower */
d_add(dentry, NULL); 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)) { if (IS_ERR(inode)) {
printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n", printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n",
__func__, PTR_ERR(inode)); __func__, PTR_ERR(inode));
return PTR_ERR(inode); return ERR_CAST(inode);
} }
if (S_ISREG(inode->i_mode)) { if (S_ISREG(inode->i_mode)) {
rc = ecryptfs_i_size_read(dentry, inode); rc = ecryptfs_i_size_read(dentry, inode);
if (rc) { if (rc) {
make_bad_inode(inode); make_bad_inode(inode);
return rc; return ERR_PTR(rc);
} }
} }
if (inode->i_state & I_NEW) if (inode->i_state & I_NEW)
unlock_new_inode(inode); unlock_new_inode(inode);
d_add(dentry, inode); return d_splice_alias(inode, dentry);
return rc;
} }
/** /**
...@@ -393,6 +391,7 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, ...@@ -393,6 +391,7 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
size_t encrypted_and_encoded_name_size; size_t encrypted_and_encoded_name_size;
struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL; struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
struct dentry *lower_dir_dentry, *lower_dentry; struct dentry *lower_dir_dentry, *lower_dentry;
struct dentry *res;
int rc = 0; int rc = 0;
lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent); lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent);
...@@ -400,10 +399,10 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, ...@@ -400,10 +399,10 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
lower_dir_dentry, lower_dir_dentry,
ecryptfs_dentry->d_name.len); ecryptfs_dentry->d_name.len);
if (IS_ERR(lower_dentry)) { if (IS_ERR(lower_dentry)) {
rc = PTR_ERR(lower_dentry);
ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
"[%d] on lower_dentry = [%pd]\n", __func__, rc, "[%ld] on lower_dentry = [%pd]\n", __func__,
ecryptfs_dentry); PTR_ERR(lower_dentry), ecryptfs_dentry);
res = ERR_CAST(lower_dentry);
goto out; goto out;
} }
if (d_really_is_positive(lower_dentry)) if (d_really_is_positive(lower_dentry))
...@@ -421,24 +420,25 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, ...@@ -421,24 +420,25 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
if (rc) { if (rc) {
printk(KERN_ERR "%s: Error attempting to encrypt and encode " printk(KERN_ERR "%s: Error attempting to encrypt and encode "
"filename; rc = [%d]\n", __func__, rc); "filename; rc = [%d]\n", __func__, rc);
res = ERR_PTR(rc);
goto out; goto out;
} }
lower_dentry = lookup_one_len_unlocked(encrypted_and_encoded_name, lower_dentry = lookup_one_len_unlocked(encrypted_and_encoded_name,
lower_dir_dentry, lower_dir_dentry,
encrypted_and_encoded_name_size); encrypted_and_encoded_name_size);
if (IS_ERR(lower_dentry)) { if (IS_ERR(lower_dentry)) {
rc = PTR_ERR(lower_dentry);
ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " 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); encrypted_and_encoded_name);
res = ERR_CAST(lower_dentry);
goto out; goto out;
} }
interpose: interpose:
rc = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry, res = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry);
ecryptfs_dir_inode);
out: out:
kfree(encrypted_and_encoded_name); kfree(encrypted_and_encoded_name);
return ERR_PTR(rc); return res;
} }
static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir, static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment