1 ext4 crypto: use dget_parent() in ext4_d_revalidate()
3 This avoids potential problems caused by a race where the inode gets
4 renamed out from its parent directory and the parent directory is
5 deleted while ext4_d_revalidate() is running.
8 Reported-by: Al Viro <viro@ZenIV.linux.org.uk>
9 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 Cc: stable@vger.kernel.org
13 fs/ext4/crypto.c | 12 ++++++++----
14 1 file changed, 8 insertions(+), 4 deletions(-)
16 diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
17 index 38f7562..ecb5439 100644
18 --- a/fs/ext4/crypto.c
19 +++ b/fs/ext4/crypto.c
20 @@ -475,13 +475,16 @@ uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size)
22 static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags)
24 - struct inode *dir = d_inode(dentry->d_parent);
25 - struct ext4_crypt_info *ci = EXT4_I(dir)->i_crypt_info;
27 + struct ext4_crypt_info *ci;
28 int dir_has_key, cached_with_key;
30 - if (!ext4_encrypted_inode(dir))
31 + dir = dget_parent(dentry);
32 + if (!ext4_encrypted_inode(d_inode(dir))) {
37 + ci = EXT4_I(d_inode(dir))->i_crypt_info;
38 if (ci && ci->ci_keyring_key &&
39 (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) |
40 (1 << KEY_FLAG_REVOKED) |
41 @@ -491,6 +494,7 @@ static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags)
42 /* this should eventually be an flag in d_flags */
43 cached_with_key = dentry->d_fsdata != NULL;
44 dir_has_key = (ci != NULL);
48 * If the dentry was cached without the key, and it is a