1 ext4: use dget_parent() in ext4_file_open()
3 From: Miklos Szeredi <mszeredi@redhat.com>
5 In f_op->open() lock on parent is not held, so there's no guarantee that
6 parent dentry won't go away at any time.
8 Even after this patch there's no guarantee that 'dir' will stay the parent
9 of 'inode', but at least it won't be freed while being used.
11 Fixes: ff978b09f973 ("ext4 crypto: move context consistency check to ext4_file_open()")
12 Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
14 Cc: <stable@vger.kernel.org> # v4.5
16 fs/ext4/file.c | 12 ++++++++----
17 1 file changed, 8 insertions(+), 4 deletions(-)
19 diff --git a/fs/ext4/file.c b/fs/ext4/file.c
20 index 4cd318f31cbe..feb9ffc6f20d 100644
23 @@ -335,7 +335,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
24 struct super_block *sb = inode->i_sb;
25 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
26 struct vfsmount *mnt = filp->f_path.mnt;
27 - struct inode *dir = filp->f_path.dentry->d_parent->d_inode;
32 @@ -379,14 +379,18 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
33 if (ext4_encryption_info(inode) == NULL)
36 - if (ext4_encrypted_inode(dir) &&
37 - !ext4_is_child_context_consistent_with_parent(dir, inode)) {
39 + dir = dget_parent(filp->f_path.dentry);
40 + if (ext4_encrypted_inode(d_inode(dir)) &&
41 + !ext4_is_child_context_consistent_with_parent(d_inode(dir), inode)) {
42 ext4_warning(inode->i_sb,
43 "Inconsistent encryption contexts: %lu/%lu\n",
44 - (unsigned long) dir->i_ino,
45 + (unsigned long) d_inode(dir)->i_ino,
46 (unsigned long) inode->i_ino);
52 * Set up the jbd2_inode if we are opening the inode for
53 * writing and the journal is present