Commit c9bcbdfe authored by Eric Biggers's avatar Eric Biggers Committed by Greg Kroah-Hartman

ext4: fix use-after-iput when fscrypt contexts are inconsistent

commit dd01b690 upstream.

In the case where the child's encryption context was inconsistent with
its parent directory, we were using inode->i_sb and inode->i_ino after
the inode had already been iput().  Fix this by doing the iput() in the
correct places.

Note: only ext4 had this bug, not f2fs and ubifs.

Fixes: d9cdc903 ("ext4 crypto: enforce context consistency")
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c8f246b4
...@@ -1616,13 +1616,15 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi ...@@ -1616,13 +1616,15 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi
!fscrypt_has_permitted_context(dir, inode)) { !fscrypt_has_permitted_context(dir, inode)) {
int nokey = ext4_encrypted_inode(inode) && int nokey = ext4_encrypted_inode(inode) &&
!fscrypt_has_encryption_key(inode); !fscrypt_has_encryption_key(inode);
if (nokey) {
iput(inode); iput(inode);
if (nokey)
return ERR_PTR(-ENOKEY); return ERR_PTR(-ENOKEY);
}
ext4_warning(inode->i_sb, ext4_warning(inode->i_sb,
"Inconsistent encryption contexts: %lu/%lu", "Inconsistent encryption contexts: %lu/%lu",
(unsigned long) dir->i_ino, (unsigned long) dir->i_ino,
(unsigned long) inode->i_ino); (unsigned long) inode->i_ino);
iput(inode);
return ERR_PTR(-EPERM); return ERR_PTR(-EPERM);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment