Commit 9dd78d8c authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Theodore Ts'o

ext4: use dget_parent() in ext4_file_open()

In f_op->open() lock on parent is not held, so there's no guarantee that
parent dentry won't go away at any time.

Even after this patch there's no guarantee that 'dir' will stay the parent
of 'inode', but at least it won't be freed while being used.

Fixes: ff978b09 ("ext4 crypto: move context consistency check to ext4_file_open()")
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Cc: <stable@vger.kernel.org> # v4.5
parent be62a1a8
...@@ -329,7 +329,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp) ...@@ -329,7 +329,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
struct vfsmount *mnt = filp->f_path.mnt; struct vfsmount *mnt = filp->f_path.mnt;
struct inode *dir = filp->f_path.dentry->d_parent->d_inode; struct dentry *dir;
struct path path; struct path path;
char buf[64], *cp; char buf[64], *cp;
int ret; int ret;
...@@ -373,14 +373,18 @@ static int ext4_file_open(struct inode * inode, struct file * filp) ...@@ -373,14 +373,18 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
if (ext4_encryption_info(inode) == NULL) if (ext4_encryption_info(inode) == NULL)
return -ENOKEY; return -ENOKEY;
} }
if (ext4_encrypted_inode(dir) &&
!ext4_is_child_context_consistent_with_parent(dir, inode)) { dir = dget_parent(filp->f_path.dentry);
if (ext4_encrypted_inode(d_inode(dir)) &&
!ext4_is_child_context_consistent_with_parent(d_inode(dir), inode)) {
ext4_warning(inode->i_sb, ext4_warning(inode->i_sb,
"Inconsistent encryption contexts: %lu/%lu\n", "Inconsistent encryption contexts: %lu/%lu\n",
(unsigned long) dir->i_ino, (unsigned long) d_inode(dir)->i_ino,
(unsigned long) inode->i_ino); (unsigned long) inode->i_ino);
dput(dir);
return -EPERM; return -EPERM;
} }
dput(dir);
/* /*
* Set up the jbd2_inode if we are opening the inode for * Set up the jbd2_inode if we are opening the inode for
* writing and the journal is present * writing and the journal is present
......
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