diff options
author | Eric Biggers <ebiggers@google.com> | 2017-02-01 21:07:11 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-03-12 00:41:46 -0500 |
commit | 68ca0fdac41fa801e1e6c2f99e27a9c24e494532 (patch) | |
tree | 622940a502b9e8819e95582327f1db4488e24e6c /fs | |
parent | a5a9cf387de6dde4c79b6e7fb6311dbd7ec86f02 (diff) |
ext4: fix use-after-iput when fscrypt contexts are inconsistent
commit dd01b690f8f4b1e414f89e5a9a5326bf720d6652 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: d9cdc9033181 ("ext4 crypto: enforce context consistency")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ext4/namei.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 104f8bfba718..c4a389a6027b 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
@@ -1616,13 +1616,15 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi | |||
1616 | !fscrypt_has_permitted_context(dir, inode)) { | 1616 | !fscrypt_has_permitted_context(dir, inode)) { |
1617 | int nokey = ext4_encrypted_inode(inode) && | 1617 | int nokey = ext4_encrypted_inode(inode) && |
1618 | !fscrypt_has_encryption_key(inode); | 1618 | !fscrypt_has_encryption_key(inode); |
1619 | iput(inode); | 1619 | if (nokey) { |
1620 | if (nokey) | 1620 | iput(inode); |
1621 | return ERR_PTR(-ENOKEY); | 1621 | return ERR_PTR(-ENOKEY); |
1622 | } | ||
1622 | ext4_warning(inode->i_sb, | 1623 | ext4_warning(inode->i_sb, |
1623 | "Inconsistent encryption contexts: %lu/%lu", | 1624 | "Inconsistent encryption contexts: %lu/%lu", |
1624 | (unsigned long) dir->i_ino, | 1625 | (unsigned long) dir->i_ino, |
1625 | (unsigned long) inode->i_ino); | 1626 | (unsigned long) inode->i_ino); |
1627 | iput(inode); | ||
1626 | return ERR_PTR(-EPERM); | 1628 | return ERR_PTR(-EPERM); |
1627 | } | 1629 | } |
1628 | } | 1630 | } |