1 ext4: fix use-after-iput when fscrypt contexts are inconsistent
3 From: Eric Biggers <ebiggers@google.com>
5 In the case where the child's encryption context was inconsistent with
6 its parent directory, we were using inode->i_sb and inode->i_ino after
7 the inode had already been iput(). Fix this by doing the iput() in the
10 Note: only ext4 had this bug, not f2fs and ubifs.
12 Fixes: d9cdc9033181 ("ext4 crypto: enforce context consistency")
13 Cc: stable@vger.kernel.org
14 Signed-off-by: Eric Biggers <ebiggers@google.com>
15 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
17 fs/ext4/namei.c | 6 ++++--
18 1 file changed, 4 insertions(+), 2 deletions(-)
20 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
21 index bb880c326191..931da9d5d915 100644
24 @@ -1618,13 +1618,15 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
25 !fscrypt_has_permitted_context(dir, inode)) {
26 int nokey = ext4_encrypted_inode(inode) &&
27 !fscrypt_has_encryption_key(inode);
32 return ERR_PTR(-ENOKEY);
34 ext4_warning(inode->i_sb,
35 "Inconsistent encryption contexts: %lu/%lu",
36 (unsigned long) dir->i_ino,
37 (unsigned long) inode->i_ino);
39 return ERR_PTR(-EPERM);
43 2.11.0.483.g087da7b7c-goog