[PATCH 4/4] ext4: use file_dentry()

From: Miklos Szeredi
Date: Thu Mar 17 2016 - 05:01:31 EST

From: Miklos Szeredi <mszeredi@xxxxxxxxxx>

EXT4 may be used as lower layer of overlayfs and accessing f_path.dentry
can lead to a crash.

Fix by replacing direct access of file->f_path.dentry with the
file_dentry() accessor, which will always return a native object.

Reported-by: Daniel Axtens <dja@xxxxxxxxxx>
Fixes: 4bacc9c9234c ("overlayfs: Make f_path always point to the overlay and f_inode to the underlay")
Fixes: ff978b09f973 ("ext4 crypto: move context consistency check to ext4_file_open()")
Signed-off-by: Miklos Szeredi <mszeredi@xxxxxxxxxx>
Cc: Theodore Ts'o <tytso@xxxxxxx>
Cc: David Howells <dhowells@xxxxxxxxxx>
Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
Cc: <stable@xxxxxxxxxxxxxxx> # v4.5
fs/ext4/file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index feb9ffc6f20d..38847f38b34a 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -380,7 +380,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
return -ENOKEY;

- dir = dget_parent(filp->f_path.dentry);
+ dir = dget_parent(file_dentry(filp));
if (ext4_encrypted_inode(d_inode(dir)) &&
!ext4_is_child_context_consistent_with_parent(d_inode(dir), inode)) {