diff options
| author | Eric Biggers <ebiggers@google.com> | 2022-11-04 16:12:45 -0700 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2022-11-10 18:15:37 +0100 |
| commit | cff805b1518f38d57866065343db2285f2dcd5ab (patch) | |
| tree | 670df71500f42138dd8c79f810fb24428cb0b84a /fs/super.c | |
| parent | e6f4fd85ef1ee6ab356bfbd64df28c1cb73aee7e (diff) | |
| download | linux-cff805b1518f38d57866065343db2285f2dcd5ab.tar.gz linux-cff805b1518f38d57866065343db2285f2dcd5ab.tar.bz2 linux-cff805b1518f38d57866065343db2285f2dcd5ab.zip | |
fscrypt: fix keyring memory leak on mount failure
commit ccd30a476f8e864732de220bd50e6f372f5ebcab upstream.
Commit d7e7b9af104c ("fscrypt: stop using keyrings subsystem for
fscrypt_master_key") moved the keyring destruction from __put_super() to
generic_shutdown_super() so that the filesystem's block device(s) are
still available. Unfortunately, this causes a memory leak in the case
where a mount is attempted with the test_dummy_encryption mount option,
but the mount fails after the option has already been processed.
To fix this, attempt the keyring destruction in both places.
Reported-by: syzbot+104c2a89561289cec13e@syzkaller.appspotmail.com
Fixes: d7e7b9af104c ("fscrypt: stop using keyrings subsystem for fscrypt_master_key")
Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Link: https://lore.kernel.org/r/20221011213838.209879-1-ebiggers@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/super.c')
| -rw-r--r-- | fs/super.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/fs/super.c b/fs/super.c index 479c6bfc5033..7fa3ee79ec89 100644 --- a/fs/super.c +++ b/fs/super.c @@ -293,6 +293,7 @@ static void __put_super(struct super_block *s) WARN_ON(s->s_inode_lru.node); WARN_ON(!list_empty(&s->s_mounts)); security_sb_free(s); + fscrypt_destroy_keyring(s); put_user_ns(s->s_user_ns); kfree(s->s_subtype); call_rcu(&s->rcu, destroy_super_rcu); @@ -453,7 +454,7 @@ void generic_shutdown_super(struct super_block *sb) evict_inodes(sb); /* only nonzero refcount inodes can have marks */ fsnotify_sb_delete(sb); - fscrypt_sb_delete(sb); + fscrypt_destroy_keyring(sb); security_sb_delete(sb); if (sb->s_dio_done_wq) { |
