ext4: fix use-after-iput when fscrypt contexts are inconsistent
PATCH 1/1 ext4: fix use-after-iput when fscrypt contexts are inconsistent
From: Eric Biggers <[email protected]>
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 d9cdc9033181 ("ext4 crypto: enforce context consistency")
Signed-off-by Eric Biggers <[email protected]>
--- fs/ext4/namei.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
fs/ext4/namei.c +4 -2
@@ -1618,13 +1618,15 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi !fscrypt_has_permitted_context(dir, inode)) {int nokey =ext4_encrypted_inode (inode) && !fscrypt_has_encryption_key (inode); -iput (inode); -if (nokey) +if (nokey) { +iput (inode);return ERR_PTR (-ENOKEY ); + }ext4_warning (inode->i_sb,"Inconsistent encryption contexts: %lu/%lu" , (unsigned long ) dir->i_ino, (unsigned long ) inode->i_ino); +iput (inode);return ERR_PTR (-EPERM ); } }
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Quoted 7 lines · Eric Biggers
From: Eric Biggers <[email protected]>
In the case where the child's encryption context was inconsistent with its parent directory, we were using
inode->i_sbandinode->i_inoafter the inode had already beeniput(). Fix this by doing theiput()in the correct places.
Quoted 5 lines
Note: only ext4 had this bug, not f2fs and ubifs.
Fixes d9cdc9033181 ("ext4 crypto: enforce context consistency")Signed-off-by Eric Biggers <[email protected]>
Thanks, applied.
- Ted