aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2016-03-26 16:15:42 -0400
committerTheodore Ts'o <tytso@mit.edu>2016-03-26 16:15:42 -0400
commit3d43bcfef5f0548845a425365011c499875491b0 (patch)
treed2d0be7090b3e17401a70788e93a2668866c831b
parentc0a37d48788475d0a2cf4fbfaa28559a9de612fc (diff)
ext4 crypto: use dget_parent() in ext4_d_revalidate()
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> Cc: stable@vger.kernel.org
-rw-r--r--fs/ext4/crypto.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c
index 012fd3285147..ea69ce4f6d8f 100644
--- a/fs/ext4/crypto.c
+++ b/fs/ext4/crypto.c
@@ -478,13 +478,16 @@ uint32_t ext4_validate_encryption_key_size(uint32_t mode, uint32_t size)
478 */ 478 */
479static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags) 479static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags)
480{ 480{
481 struct inode *dir = d_inode(dentry->d_parent); 481 struct dentry *dir;
482 struct ext4_crypt_info *ci = EXT4_I(dir)->i_crypt_info; 482 struct ext4_crypt_info *ci;
483 int dir_has_key, cached_with_key; 483 int dir_has_key, cached_with_key;
484 484
485 if (!ext4_encrypted_inode(dir)) 485 dir = dget_parent(dentry);
486 if (!ext4_encrypted_inode(d_inode(dir))) {
487 dput(dir);
486 return 0; 488 return 0;
487 489 }
490 ci = EXT4_I(d_inode(dir))->i_crypt_info;
488 if (ci && ci->ci_keyring_key && 491 if (ci && ci->ci_keyring_key &&
489 (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) | 492 (ci->ci_keyring_key->flags & ((1 << KEY_FLAG_INVALIDATED) |
490 (1 << KEY_FLAG_REVOKED) | 493 (1 << KEY_FLAG_REVOKED) |
@@ -494,6 +497,7 @@ static int ext4_d_revalidate(struct dentry *dentry, unsigned int flags)
494 /* this should eventually be an flag in d_flags */ 497 /* this should eventually be an flag in d_flags */
495 cached_with_key = dentry->d_fsdata != NULL; 498 cached_with_key = dentry->d_fsdata != NULL;
496 dir_has_key = (ci != NULL); 499 dir_has_key = (ci != NULL);
500 dput(dir);
497 501
498 /* 502 /*
499 * If the dentry was cached without the key, and it is a 503 * If the dentry was cached without the key, and it is a