All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Cc: Lukas Czerner <lczerner@redhat.com>,
	Jeff Layton <jlayton@kernel.org>, Theodore Ts'o <tytso@mit.edu>,
	stable@vger.kernel.org, Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [f2fs-dev] [PATCH v3 1/5] ext4: fix memory leak in parse_apply_sb_mount_options()
Date: Fri, 13 May 2022 16:16:01 -0700	[thread overview]
Message-ID: <20220513231605.175121-2-ebiggers@kernel.org> (raw)
In-Reply-To: <20220513231605.175121-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

If processing the on-disk mount options fails after any memory was
allocated in the ext4_fs_context, e.g. s_qf_names, then this memory is
leaked.  Fix this by calling ext4_fc_free() instead of kfree() directly.

Reproducer:

    mkfs.ext4 -F /dev/vdc
    tune2fs /dev/vdc -E mount_opts=usrjquota=file
    echo clear > /sys/kernel/debug/kmemleak
    mount /dev/vdc /vdc
    echo scan > /sys/kernel/debug/kmemleak
    sleep 5
    echo scan > /sys/kernel/debug/kmemleak
    cat /sys/kernel/debug/kmemleak

Fixes: 7edfd85b1ffd ("ext4: Completely separate options parsing and sb setup")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/ext4/super.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 1466fbdbc8e34..60fa2f2623e07 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2625,8 +2625,10 @@ static int parse_apply_sb_mount_options(struct super_block *sb,
 	ret = ext4_apply_options(fc, sb);
 
 out_free:
-	kfree(s_ctx);
-	kfree(fc);
+	if (fc) {
+		ext4_fc_free(fc);
+		kfree(fc);
+	}
 	kfree(s_mount_opts);
 	return ret;
 }
-- 
2.36.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

WARNING: multiple messages have this Message-ID (diff)
From: Eric Biggers <ebiggers@kernel.org>
To: linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org,
	linux-f2fs-devel@lists.sourceforge.net
Cc: Jeff Layton <jlayton@kernel.org>,
	Lukas Czerner <lczerner@redhat.com>,
	Theodore Ts'o <tytso@mit.edu>, Jaegeuk Kim <jaegeuk@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH v3 1/5] ext4: fix memory leak in parse_apply_sb_mount_options()
Date: Fri, 13 May 2022 16:16:01 -0700	[thread overview]
Message-ID: <20220513231605.175121-2-ebiggers@kernel.org> (raw)
In-Reply-To: <20220513231605.175121-1-ebiggers@kernel.org>

From: Eric Biggers <ebiggers@google.com>

If processing the on-disk mount options fails after any memory was
allocated in the ext4_fs_context, e.g. s_qf_names, then this memory is
leaked.  Fix this by calling ext4_fc_free() instead of kfree() directly.

Reproducer:

    mkfs.ext4 -F /dev/vdc
    tune2fs /dev/vdc -E mount_opts=usrjquota=file
    echo clear > /sys/kernel/debug/kmemleak
    mount /dev/vdc /vdc
    echo scan > /sys/kernel/debug/kmemleak
    sleep 5
    echo scan > /sys/kernel/debug/kmemleak
    cat /sys/kernel/debug/kmemleak

Fixes: 7edfd85b1ffd ("ext4: Completely separate options parsing and sb setup")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 fs/ext4/super.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 1466fbdbc8e34..60fa2f2623e07 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -2625,8 +2625,10 @@ static int parse_apply_sb_mount_options(struct super_block *sb,
 	ret = ext4_apply_options(fc, sb);
 
 out_free:
-	kfree(s_ctx);
-	kfree(fc);
+	if (fc) {
+		ext4_fc_free(fc);
+		kfree(fc);
+	}
 	kfree(s_mount_opts);
 	return ret;
 }
-- 
2.36.1


  reply	other threads:[~2022-05-13 23:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-13 23:16 [f2fs-dev] [PATCH v3 0/5] test_dummy_encryption fixes and cleanups Eric Biggers
2022-05-13 23:16 ` Eric Biggers
2022-05-13 23:16 ` Eric Biggers [this message]
2022-05-13 23:16   ` [PATCH v3 1/5] ext4: fix memory leak in parse_apply_sb_mount_options() Eric Biggers
2022-05-14 12:09   ` [f2fs-dev] " Ritesh Harjani
2022-05-14 12:09     ` Ritesh Harjani
2022-05-19  2:10   ` Theodore Ts'o
2022-05-19  2:10     ` [f2fs-dev] " Theodore Ts'o
2022-05-13 23:16 ` [f2fs-dev] [PATCH v3 2/5] ext4: only allow test_dummy_encryption when supported Eric Biggers
2022-05-13 23:16   ` Eric Biggers
2022-05-19  2:11   ` Theodore Ts'o
2022-05-19  2:11     ` [f2fs-dev] " Theodore Ts'o
2022-05-13 23:16 ` [f2fs-dev] [PATCH v3 3/5] ext4: fix up test_dummy_encryption handling for new mount API Eric Biggers
2022-05-13 23:16   ` Eric Biggers
2022-05-13 23:16 ` [f2fs-dev] [PATCH v3 4/5] f2fs: use the updated test_dummy_encryption helper functions Eric Biggers
2022-05-13 23:16   ` Eric Biggers
2022-05-19 11:21   ` [f2fs-dev] " Chao Yu
2022-05-19 11:21     ` Chao Yu
2022-05-13 23:16 ` [f2fs-dev] [PATCH v3 5/5] fscrypt: remove fscrypt_set_test_dummy_encryption() Eric Biggers
2022-05-13 23:16   ` Eric Biggers
2022-08-15 18:48   ` [f2fs-dev] " Eric Biggers
2022-08-15 18:48     ` Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220513231605.175121-2-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=lczerner@redhat.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.