Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d16c842e authored by Theodore Ts'o's avatar Theodore Ts'o Committed by Eric Biggers
Browse files

UPSTREAM: 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: default avatarAl Viro <viro@ZenIV.linux.org.uk>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 41948f88a521b95e8abc793602015a6d45f52a06)
Change-Id: Icea8f440a708274ecfa12d0c2a392b6aa3cc22c4
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
parent fa9d8ddc
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -478,16 +478,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