summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2016-03-26 16:15:42 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-05-08 07:46:02 +0200
commit41948f88a521b95e8abc793602015a6d45f52a06 (patch)
treeefd46586d7ece6f4e98d0f8fe4a47d7372c28d78
parent2faff9d1dfc560da3bfba6a8ab0c30246fd6c1cb (diff)
ext4 crypto: use dget_parent() in ext4_d_revalidate()
commit 3d43bcfef5f0548845a425365011c499875491b0 upstream. This avoids potential problems caused by a race where the inode gets renamed out from its parent directory and the parent directory is deleted while ext4_d_revalidate() is running. Fixes: 28b4c263961c Reported-by: Al Viro <viro@ZenIV.linux.org.uk> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--fs/ext4/crypto.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
index 13a69e0fb90d..1259ade2f10a 100644
--- a/fs/ext4/crypto.c
+++ b/fs/ext4/crypto.c
@@ -477,16 +477,21 @@ uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size)
*/
static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags)
{
- struct inode *dir = d_inode(dentry->d_parent);
- struct ext4_crypt_info *ci = EXT4_I(dir)->i_crypt_info;
+ struct dentry *dir;
+ struct ext4_crypt_info *ci;
int dir_has_key, cached_with_key;
- if (!ext4_encrypted_inode(dir))
+ dir = dget_parent(dentry);
+ if (!ext4_encrypted_inode(d_inode(dir))) {
+ dput(dir);
return 0;
+ }
+ ci = EXT4_I(d_inode(dir))->i_crypt_info;
/* this should eventually be an flag in d_flags */
cached_with_key = dentry->d_fsdata != NULL;
dir_has_key = (ci != NULL);
+ dput(dir);
/*
* If the dentry was cached without the key, and it is a