Commit b28866f4 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'work.ecryptfs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull exryptfs updates from Al Viro:
 "The interesting part here is (ecryptfs) lock_parent() fixes - its
  treatment of ->d_parent had been very wrong.

  The rest is trivial cleanups"

* 'work.ecryptfs' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  ecryptfs: ecryptfs_dentry_info->crypt_stat is never used
  ecryptfs: get rid of unused accessors
  ecryptfs: saner API for lock_parent()
  ecryptfs: get rid of pointless dget/dput in ->symlink() and ->link()
parents 17ae69ab 9d786beb
...@@ -262,10 +262,7 @@ struct ecryptfs_inode_info { ...@@ -262,10 +262,7 @@ struct ecryptfs_inode_info {
* vfsmount too. */ * vfsmount too. */
struct ecryptfs_dentry_info { struct ecryptfs_dentry_info {
struct path lower_path; struct path lower_path;
union { struct rcu_head rcu;
struct ecryptfs_crypt_stat *crypt_stat;
struct rcu_head rcu;
};
}; };
/** /**
...@@ -496,12 +493,6 @@ ecryptfs_set_superblock_lower(struct super_block *sb, ...@@ -496,12 +493,6 @@ ecryptfs_set_superblock_lower(struct super_block *sb,
((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb = lower_sb; ((struct ecryptfs_sb_info *)sb->s_fs_info)->wsi_sb = lower_sb;
} }
static inline struct ecryptfs_dentry_info *
ecryptfs_dentry_to_private(struct dentry *dentry)
{
return (struct ecryptfs_dentry_info *)dentry->d_fsdata;
}
static inline void static inline void
ecryptfs_set_dentry_private(struct dentry *dentry, ecryptfs_set_dentry_private(struct dentry *dentry,
struct ecryptfs_dentry_info *dentry_info) struct ecryptfs_dentry_info *dentry_info)
...@@ -515,12 +506,6 @@ ecryptfs_dentry_to_lower(struct dentry *dentry) ...@@ -515,12 +506,6 @@ ecryptfs_dentry_to_lower(struct dentry *dentry)
return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry; return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.dentry;
} }
static inline struct vfsmount *
ecryptfs_dentry_to_lower_mnt(struct dentry *dentry)
{
return ((struct ecryptfs_dentry_info *)dentry->d_fsdata)->lower_path.mnt;
}
static inline struct path * static inline struct path *
ecryptfs_dentry_to_lower_path(struct dentry *dentry) ecryptfs_dentry_to_lower_path(struct dentry *dentry)
{ {
......
...@@ -22,19 +22,18 @@ ...@@ -22,19 +22,18 @@
#include <asm/unaligned.h> #include <asm/unaligned.h>
#include "ecryptfs_kernel.h" #include "ecryptfs_kernel.h"
static struct dentry *lock_parent(struct dentry *dentry) static int lock_parent(struct dentry *dentry,
struct dentry **lower_dentry,
struct inode **lower_dir)
{ {
struct dentry *dir; struct dentry *lower_dir_dentry;
dir = dget_parent(dentry); lower_dir_dentry = ecryptfs_dentry_to_lower(dentry->d_parent);
inode_lock_nested(d_inode(dir), I_MUTEX_PARENT); *lower_dir = d_inode(lower_dir_dentry);
return dir; *lower_dentry = ecryptfs_dentry_to_lower(dentry);
}
static void unlock_dir(struct dentry *dir) inode_lock_nested(*lower_dir, I_MUTEX_PARENT);
{ return (*lower_dentry)->d_parent == lower_dir_dentry ? 0 : -EINVAL;
inode_unlock(d_inode(dir));
dput(dir);
} }
static int ecryptfs_inode_test(struct inode *inode, void *lower_inode) static int ecryptfs_inode_test(struct inode *inode, void *lower_inode)
...@@ -128,32 +127,29 @@ static int ecryptfs_interpose(struct dentry *lower_dentry, ...@@ -128,32 +127,29 @@ static int ecryptfs_interpose(struct dentry *lower_dentry,
static int ecryptfs_do_unlink(struct inode *dir, struct dentry *dentry, static int ecryptfs_do_unlink(struct inode *dir, struct dentry *dentry,
struct inode *inode) struct inode *inode)
{ {
struct dentry *lower_dentry = ecryptfs_dentry_to_lower(dentry); struct dentry *lower_dentry;
struct dentry *lower_dir_dentry; struct inode *lower_dir;
struct inode *lower_dir_inode;
int rc; int rc;
lower_dir_dentry = ecryptfs_dentry_to_lower(dentry->d_parent); rc = lock_parent(dentry, &lower_dentry, &lower_dir);
lower_dir_inode = d_inode(lower_dir_dentry);
inode_lock_nested(lower_dir_inode, I_MUTEX_PARENT);
dget(lower_dentry); // don't even try to make the lower negative dget(lower_dentry); // don't even try to make the lower negative
if (lower_dentry->d_parent != lower_dir_dentry) if (!rc) {
rc = -EINVAL; if (d_unhashed(lower_dentry))
else if (d_unhashed(lower_dentry)) rc = -EINVAL;
rc = -EINVAL; else
else rc = vfs_unlink(&init_user_ns, lower_dir, lower_dentry,
rc = vfs_unlink(&init_user_ns, lower_dir_inode, lower_dentry, NULL);
NULL); }
if (rc) { if (rc) {
printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc); printk(KERN_ERR "Error in vfs_unlink; rc = [%d]\n", rc);
goto out_unlock; goto out_unlock;
} }
fsstack_copy_attr_times(dir, lower_dir_inode); fsstack_copy_attr_times(dir, lower_dir);
set_nlink(inode, ecryptfs_inode_to_lower(inode)->i_nlink); set_nlink(inode, ecryptfs_inode_to_lower(inode)->i_nlink);
inode->i_ctime = dir->i_ctime; inode->i_ctime = dir->i_ctime;
out_unlock: out_unlock:
dput(lower_dentry); dput(lower_dentry);
inode_unlock(lower_dir_inode); inode_unlock(lower_dir);
if (!rc) if (!rc)
d_drop(dentry); d_drop(dentry);
return rc; return rc;
...@@ -177,13 +173,13 @@ ecryptfs_do_create(struct inode *directory_inode, ...@@ -177,13 +173,13 @@ ecryptfs_do_create(struct inode *directory_inode,
{ {
int rc; int rc;
struct dentry *lower_dentry; struct dentry *lower_dentry;
struct dentry *lower_dir_dentry; struct inode *lower_dir;
struct inode *inode; struct inode *inode;
lower_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry); rc = lock_parent(ecryptfs_dentry, &lower_dentry, &lower_dir);
lower_dir_dentry = lock_parent(lower_dentry); if (!rc)
rc = vfs_create(&init_user_ns, d_inode(lower_dir_dentry), lower_dentry, rc = vfs_create(&init_user_ns, lower_dir,
mode, true); lower_dentry, mode, true);
if (rc) { if (rc) {
printk(KERN_ERR "%s: Failure to create dentry in lower fs; " printk(KERN_ERR "%s: Failure to create dentry in lower fs; "
"rc = [%d]\n", __func__, rc); "rc = [%d]\n", __func__, rc);
...@@ -193,14 +189,13 @@ ecryptfs_do_create(struct inode *directory_inode, ...@@ -193,14 +189,13 @@ ecryptfs_do_create(struct inode *directory_inode,
inode = __ecryptfs_get_inode(d_inode(lower_dentry), inode = __ecryptfs_get_inode(d_inode(lower_dentry),
directory_inode->i_sb); directory_inode->i_sb);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
vfs_unlink(&init_user_ns, d_inode(lower_dir_dentry), vfs_unlink(&init_user_ns, lower_dir, lower_dentry, NULL);
lower_dentry, NULL);
goto out_lock; goto out_lock;
} }
fsstack_copy_attr_times(directory_inode, d_inode(lower_dir_dentry)); fsstack_copy_attr_times(directory_inode, lower_dir);
fsstack_copy_inode_size(directory_inode, d_inode(lower_dir_dentry)); fsstack_copy_inode_size(directory_inode, lower_dir);
out_lock: out_lock:
unlock_dir(lower_dir_dentry); inode_unlock(lower_dir);
return inode; return inode;
} }
...@@ -431,32 +426,28 @@ static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir, ...@@ -431,32 +426,28 @@ static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
{ {
struct dentry *lower_old_dentry; struct dentry *lower_old_dentry;
struct dentry *lower_new_dentry; struct dentry *lower_new_dentry;
struct dentry *lower_dir_dentry; struct inode *lower_dir;
u64 file_size_save; u64 file_size_save;
int rc; int rc;
file_size_save = i_size_read(d_inode(old_dentry)); file_size_save = i_size_read(d_inode(old_dentry));
lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry); lower_old_dentry = ecryptfs_dentry_to_lower(old_dentry);
lower_new_dentry = ecryptfs_dentry_to_lower(new_dentry); rc = lock_parent(new_dentry, &lower_new_dentry, &lower_dir);
dget(lower_old_dentry); if (!rc)
dget(lower_new_dentry); rc = vfs_link(lower_old_dentry, &init_user_ns, lower_dir,
lower_dir_dentry = lock_parent(lower_new_dentry); lower_new_dentry, NULL);
rc = vfs_link(lower_old_dentry, &init_user_ns,
d_inode(lower_dir_dentry), lower_new_dentry, NULL);
if (rc || d_really_is_negative(lower_new_dentry)) if (rc || d_really_is_negative(lower_new_dentry))
goto out_lock; goto out_lock;
rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb); rc = ecryptfs_interpose(lower_new_dentry, new_dentry, dir->i_sb);
if (rc) if (rc)
goto out_lock; goto out_lock;
fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry)); fsstack_copy_attr_times(dir, lower_dir);
fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry)); fsstack_copy_inode_size(dir, lower_dir);
set_nlink(d_inode(old_dentry), set_nlink(d_inode(old_dentry),
ecryptfs_inode_to_lower(d_inode(old_dentry))->i_nlink); ecryptfs_inode_to_lower(d_inode(old_dentry))->i_nlink);
i_size_write(d_inode(new_dentry), file_size_save); i_size_write(d_inode(new_dentry), file_size_save);
out_lock: out_lock:
unlock_dir(lower_dir_dentry); inode_unlock(lower_dir);
dput(lower_new_dentry);
dput(lower_old_dentry);
return rc; return rc;
} }
...@@ -471,14 +462,14 @@ static int ecryptfs_symlink(struct user_namespace *mnt_userns, ...@@ -471,14 +462,14 @@ static int ecryptfs_symlink(struct user_namespace *mnt_userns,
{ {
int rc; int rc;
struct dentry *lower_dentry; struct dentry *lower_dentry;
struct dentry *lower_dir_dentry; struct inode *lower_dir;
char *encoded_symname; char *encoded_symname;
size_t encoded_symlen; size_t encoded_symlen;
struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL; struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
lower_dentry = ecryptfs_dentry_to_lower(dentry); rc = lock_parent(dentry, &lower_dentry, &lower_dir);
dget(lower_dentry); if (rc)
lower_dir_dentry = lock_parent(lower_dentry); goto out_lock;
mount_crypt_stat = &ecryptfs_superblock_to_private( mount_crypt_stat = &ecryptfs_superblock_to_private(
dir->i_sb)->mount_crypt_stat; dir->i_sb)->mount_crypt_stat;
rc = ecryptfs_encrypt_and_encode_filename(&encoded_symname, rc = ecryptfs_encrypt_and_encode_filename(&encoded_symname,
...@@ -487,7 +478,7 @@ static int ecryptfs_symlink(struct user_namespace *mnt_userns, ...@@ -487,7 +478,7 @@ static int ecryptfs_symlink(struct user_namespace *mnt_userns,
strlen(symname)); strlen(symname));
if (rc) if (rc)
goto out_lock; goto out_lock;
rc = vfs_symlink(&init_user_ns, d_inode(lower_dir_dentry), lower_dentry, rc = vfs_symlink(&init_user_ns, lower_dir, lower_dentry,
encoded_symname); encoded_symname);
kfree(encoded_symname); kfree(encoded_symname);
if (rc || d_really_is_negative(lower_dentry)) if (rc || d_really_is_negative(lower_dentry))
...@@ -495,11 +486,10 @@ static int ecryptfs_symlink(struct user_namespace *mnt_userns, ...@@ -495,11 +486,10 @@ static int ecryptfs_symlink(struct user_namespace *mnt_userns,
rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb); rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
if (rc) if (rc)
goto out_lock; goto out_lock;
fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry)); fsstack_copy_attr_times(dir, lower_dir);
fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry)); fsstack_copy_inode_size(dir, lower_dir);
out_lock: out_lock:
unlock_dir(lower_dir_dentry); inode_unlock(lower_dir);
dput(lower_dentry);
if (d_really_is_negative(dentry)) if (d_really_is_negative(dentry))
d_drop(dentry); d_drop(dentry);
return rc; return rc;
...@@ -510,22 +500,22 @@ static int ecryptfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, ...@@ -510,22 +500,22 @@ static int ecryptfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
{ {
int rc; int rc;
struct dentry *lower_dentry; struct dentry *lower_dentry;
struct dentry *lower_dir_dentry; struct inode *lower_dir;
lower_dentry = ecryptfs_dentry_to_lower(dentry); rc = lock_parent(dentry, &lower_dentry, &lower_dir);
lower_dir_dentry = lock_parent(lower_dentry); if (!rc)
rc = vfs_mkdir(&init_user_ns, d_inode(lower_dir_dentry), lower_dentry, rc = vfs_mkdir(&init_user_ns, lower_dir,
mode); lower_dentry, mode);
if (rc || d_really_is_negative(lower_dentry)) if (rc || d_really_is_negative(lower_dentry))
goto out; goto out;
rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb); rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
if (rc) if (rc)
goto out; goto out;
fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry)); fsstack_copy_attr_times(dir, lower_dir);
fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry)); fsstack_copy_inode_size(dir, lower_dir);
set_nlink(dir, d_inode(lower_dir_dentry)->i_nlink); set_nlink(dir, lower_dir->i_nlink);
out: out:
unlock_dir(lower_dir_dentry); inode_unlock(lower_dir);
if (d_really_is_negative(dentry)) if (d_really_is_negative(dentry))
d_drop(dentry); d_drop(dentry);
return rc; return rc;
...@@ -534,29 +524,24 @@ static int ecryptfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir, ...@@ -534,29 +524,24 @@ static int ecryptfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry) static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
{ {
struct dentry *lower_dentry; struct dentry *lower_dentry;
struct dentry *lower_dir_dentry; struct inode *lower_dir;
struct inode *lower_dir_inode;
int rc; int rc;
lower_dentry = ecryptfs_dentry_to_lower(dentry); rc = lock_parent(dentry, &lower_dentry, &lower_dir);
lower_dir_dentry = ecryptfs_dentry_to_lower(dentry->d_parent);
lower_dir_inode = d_inode(lower_dir_dentry);
inode_lock_nested(lower_dir_inode, I_MUTEX_PARENT);
dget(lower_dentry); // don't even try to make the lower negative dget(lower_dentry); // don't even try to make the lower negative
if (lower_dentry->d_parent != lower_dir_dentry) if (!rc) {
rc = -EINVAL; if (d_unhashed(lower_dentry))
else if (d_unhashed(lower_dentry)) rc = -EINVAL;
rc = -EINVAL; else
else rc = vfs_rmdir(&init_user_ns, lower_dir, lower_dentry);
rc = vfs_rmdir(&init_user_ns, lower_dir_inode, lower_dentry); }
if (!rc) { if (!rc) {
clear_nlink(d_inode(dentry)); clear_nlink(d_inode(dentry));
fsstack_copy_attr_times(dir, lower_dir_inode); fsstack_copy_attr_times(dir, lower_dir);
set_nlink(dir, lower_dir_inode->i_nlink); set_nlink(dir, lower_dir->i_nlink);
} }
dput(lower_dentry); dput(lower_dentry);
inode_unlock(lower_dir_inode); inode_unlock(lower_dir);
if (!rc) if (!rc)
d_drop(dentry); d_drop(dentry);
return rc; return rc;
...@@ -568,21 +553,21 @@ ecryptfs_mknod(struct user_namespace *mnt_userns, struct inode *dir, ...@@ -568,21 +553,21 @@ ecryptfs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
{ {
int rc; int rc;
struct dentry *lower_dentry; struct dentry *lower_dentry;
struct dentry *lower_dir_dentry; struct inode *lower_dir;
lower_dentry = ecryptfs_dentry_to_lower(dentry); rc = lock_parent(dentry, &lower_dentry, &lower_dir);
lower_dir_dentry = lock_parent(lower_dentry); if (!rc)
rc = vfs_mknod(&init_user_ns, d_inode(lower_dir_dentry), lower_dentry, rc = vfs_mknod(&init_user_ns, lower_dir,
mode, dev); lower_dentry, mode, dev);
if (rc || d_really_is_negative(lower_dentry)) if (rc || d_really_is_negative(lower_dentry))
goto out; goto out;
rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb); rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb);
if (rc) if (rc)
goto out; goto out;
fsstack_copy_attr_times(dir, d_inode(lower_dir_dentry)); fsstack_copy_attr_times(dir, lower_dir);
fsstack_copy_inode_size(dir, d_inode(lower_dir_dentry)); fsstack_copy_inode_size(dir, lower_dir);
out: out:
unlock_dir(lower_dir_dentry); inode_unlock(lower_dir);
if (d_really_is_negative(dentry)) if (d_really_is_negative(dentry))
d_drop(dentry); d_drop(dentry);
return rc; return rc;
......
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