Return-Path: Received: from mail-pf0-f196.google.com ([209.85.192.196]:35330 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751472AbdEDW1E (ORCPT ); Thu, 4 May 2017 18:27:04 -0400 Received: by mail-pf0-f196.google.com with SMTP id u26so2941231pfd.2 for ; Thu, 04 May 2017 15:27:04 -0700 (PDT) From: Eric Biggers To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , Theodore Ts'o , Eric Biggers Subject: [PATCH 2/3] ext4 crypto: use dget_parent() in ext4_d_revalidate() Date: Thu, 4 May 2017 15:26:19 -0700 Message-Id: <20170504222620.118347-2-ebiggers3@gmail.com> In-Reply-To: <20170504222620.118347-1-ebiggers3@gmail.com> References: <20170504222620.118347-1-ebiggers3@gmail.com> Sender: stable-owner@vger.kernel.org List-ID: From: Theodore Ts'o commit 3d43bcfef5f0548845a425365011c499875491b0 upstream. Please apply to 4.4-stable. 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 Signed-off-by: Theodore Ts'o Cc: stable@vger.kernel.org Signed-off-by: Eric Biggers --- fs/ext4/crypto.c | 11 ++++++++--- 1 file 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 -- 2.13.0.rc1.294.g07d810a77f-goog