Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8787c7a3 authored by Tyler Hicks's avatar Tyler Hicks
Browse files

eCryptfs: Revert "dont call lookup_one_len to avoid NULL nameidata"



This reverts commit 21edad32 and commit
93c3fe40, which fixed a regression by
the former.

Al Viro pointed out bypassed dcache lookups in
ecryptfs_new_lower_dentry(), misuse of vfs_path_lookup() in
ecryptfs_lookup_one_lower() and a dislike of passing nameidata to the
lower filesystem.

Reported-by: default avatarAl Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: default avatarTyler Hicks <tyhicks@linux.vnet.ibm.com>
parent 85e2efbb
Loading
Loading
Loading
Loading
+12 −94
Original line number Diff line number Diff line
@@ -348,75 +348,6 @@ int ecryptfs_lookup_and_interpose_lower(struct dentry *ecryptfs_dentry,
	return rc;
}

/**
 * ecryptfs_new_lower_dentry
 * @name: The name of the new dentry.
 * @lower_dir_dentry: Parent directory of the new dentry.
 * @nd: nameidata from last lookup.
 *
 * Create a new dentry or get it from lower parent dir.
 */
static struct dentry *
ecryptfs_new_lower_dentry(struct qstr *name, struct dentry *lower_dir_dentry,
			  struct nameidata *nd)
{
	struct dentry *new_dentry;
	struct dentry *tmp;
	struct inode *lower_dir_inode;

	lower_dir_inode = lower_dir_dentry->d_inode;

	tmp = d_alloc(lower_dir_dentry, name);
	if (!tmp)
		return ERR_PTR(-ENOMEM);

	mutex_lock(&lower_dir_inode->i_mutex);
	new_dentry = lower_dir_inode->i_op->lookup(lower_dir_inode, tmp, nd);
	mutex_unlock(&lower_dir_inode->i_mutex);

	if (!new_dentry)
		new_dentry = tmp;
	else
		dput(tmp);

	return new_dentry;
}


/**
 * ecryptfs_lookup_one_lower
 * @ecryptfs_dentry: The eCryptfs dentry that we are looking up
 * @lower_dir_dentry: lower parent directory
 * @name: lower file name
 *
 * Get the lower dentry from vfs. If lower dentry does not exist yet,
 * create it.
 */
static struct dentry *
ecryptfs_lookup_one_lower(struct dentry *ecryptfs_dentry,
			  struct dentry *lower_dir_dentry, struct qstr *name)
{
	struct nameidata nd;
	struct vfsmount *lower_mnt;
	int err;

	lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(
				    ecryptfs_dentry->d_parent));
	err = vfs_path_lookup(lower_dir_dentry, lower_mnt, name->name , 0, &nd);
	mntput(lower_mnt);

	if (!err) {
		/* we dont need the mount */
		mntput(nd.path.mnt);
		return nd.path.dentry;
	}
	if (err != -ENOENT)
		return ERR_PTR(err);

	/* create a new lower dentry */
	return ecryptfs_new_lower_dentry(name, lower_dir_dentry, &nd);
}

/**
 * ecryptfs_lookup
 * @ecryptfs_dir_inode: The eCryptfs directory inode
@@ -434,7 +365,6 @@ 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 qstr lower_name;
	int rc = 0;

	if ((ecryptfs_dentry->d_name.len == 1
@@ -444,20 +374,14 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
		goto out_d_drop;
	}
	lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent);
	lower_name.name = ecryptfs_dentry->d_name.name;
	lower_name.len = ecryptfs_dentry->d_name.len;
	lower_name.hash = ecryptfs_dentry->d_name.hash;
	if (lower_dir_dentry->d_op && lower_dir_dentry->d_op->d_hash) {
		rc = lower_dir_dentry->d_op->d_hash(lower_dir_dentry,
				lower_dir_dentry->d_inode, &lower_name);
		if (rc < 0)
			goto out_d_drop;
	}
	lower_dentry = ecryptfs_lookup_one_lower(ecryptfs_dentry,
						 lower_dir_dentry, &lower_name);
	mutex_lock(&lower_dir_dentry->d_inode->i_mutex);
	lower_dentry = lookup_one_len(ecryptfs_dentry->d_name.name,
				      lower_dir_dentry,
				      ecryptfs_dentry->d_name.len);
	mutex_unlock(&lower_dir_dentry->d_inode->i_mutex);
	if (IS_ERR(lower_dentry)) {
		rc = PTR_ERR(lower_dentry);
		ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_lower() returned "
		ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
				"[%d] on lower_dentry = [%s]\n", __func__, rc,
				encrypted_and_encoded_name);
		goto out_d_drop;
@@ -479,20 +403,14 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
		       "filename; rc = [%d]\n", __func__, rc);
		goto out_d_drop;
	}
	lower_name.name = encrypted_and_encoded_name;
	lower_name.len = encrypted_and_encoded_name_size;
	lower_name.hash = full_name_hash(lower_name.name, lower_name.len);
	if (lower_dir_dentry->d_op && lower_dir_dentry->d_op->d_hash) {
		rc = lower_dir_dentry->d_op->d_hash(lower_dir_dentry,
				lower_dir_dentry->d_inode, &lower_name);
		if (rc < 0)
			goto out_d_drop;
	}
	lower_dentry = ecryptfs_lookup_one_lower(ecryptfs_dentry,
						 lower_dir_dentry, &lower_name);
	mutex_lock(&lower_dir_dentry->d_inode->i_mutex);
	lower_dentry = lookup_one_len(encrypted_and_encoded_name,
				      lower_dir_dentry,
				      encrypted_and_encoded_name_size);
	mutex_unlock(&lower_dir_dentry->d_inode->i_mutex);
	if (IS_ERR(lower_dentry)) {
		rc = PTR_ERR(lower_dentry);
		ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_lower() returned "
		ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
				"[%d] on lower_dentry = [%s]\n", __func__, rc,
				encrypted_and_encoded_name);
		goto out_d_drop;