From: DaeMyung Kang <charsyam@gmail.com>
To: Namjae Jeon <linkinjeon@kernel.org>, Hyunchul Lee <hyc.lee@gmail.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
DaeMyung Kang <charsyam@gmail.com>
Subject: [PATCH v2 1/3] ntfs: free volume-wide resources on fill_super failure
Date: Thu, 21 May 2026 19:17:49 +0900 [thread overview]
Message-ID: <20260521101751.591345-2-charsyam@gmail.com> (raw)
In-Reply-To: <20260521101751.591345-1-charsyam@gmail.com>
ntfs_fill_super()'s err_out_now path frees only the volume struct via
kfree(vol), leaving several vol-owned allocations behind on every mount
failure:
- vol->nls_map, loaded by ntfs_init_fs_context() via
load_nls_default() (or replaced by an explicit nls= option in
ntfs_parse_param()), is never unload_nls()'d.
- vol->volume_label, allocated by load_system_files() through
ntfs_ucstonls() once the $Volume name attribute has been parsed, is
not released by load_system_files()'s own error labels nor by the
fill_super() inline cleanup that only runs on d_make_root()
failure. Any later failure inside load_system_files() leaks it.
- vol->lcn_empty_bits_per_page was kvfree()'d in
unl_upcase_iput_tmp_ino_err_out_now without clearing the pointer,
so it could not be folded into a single common cleanup.
Because the failure paths never call ntfs_volume_free() and never reach
the d_make_root() inline cleanup block (it sits above the label and is
jumped over by the load_system_files() / kvmalloc failure gotos), these
resources accumulate per failed mount attempt with no chance of
recovery short of unloading the module. This is a silent leak: the
inodes loaded prior to failure remain hashed but generic_shutdown_super()
skips evict_inodes() when sb->s_root is unset, so no CHECK_DATA_CORRUPTION
warning is emitted either.
Move the per-volume frees down to err_out_now and drop the
lcn_empty_bits_per_page kvfree() from the upper label so the cleanup is
performed exactly once on every failure path. Using unconditional
kvfree() / kfree() / unload_nls() is safe because they all accept NULL
and the upper labels that previously freed nls_map (the d_make_root()
inline cleanup) already clear the pointer.
Signed-off-by: DaeMyung Kang <charsyam@gmail.com>
---
fs/ntfs/super.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
index 9e321cc2febe..7e3561265b47 100644
--- a/fs/ntfs/super.c
+++ b/fs/ntfs/super.c
@@ -2530,8 +2530,6 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
}
/* Error exit code path. */
unl_upcase_iput_tmp_ino_err_out_now:
- if (vol->lcn_empty_bits_per_page)
- kvfree(vol->lcn_empty_bits_per_page);
/*
* Decrease the number of upcase users and destroy the global default
* upcase table if necessary.
@@ -2551,6 +2549,9 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
/* Errors at this stage are irrelevant. */
err_out_now:
sb->s_fs_info = NULL;
+ kvfree(vol->lcn_empty_bits_per_page);
+ kfree(vol->volume_label);
+ unload_nls(vol->nls_map);
kfree(vol);
ntfs_debug("Failed, returning -EINVAL.");
lockdep_on();
--
2.43.0
next prev parent reply other threads:[~2026-05-21 10:18 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 17:01 [PATCH 0/3] ntfs: fix mount failure cleanup and free-count setup DaeMyung Kang
2026-05-20 17:01 ` [PATCH 1/3] ntfs: free volume-wide resources on fill_super failure DaeMyung Kang
2026-05-21 1:03 ` Hyunchul Lee
2026-05-20 17:01 ` [PATCH 2/3] ntfs: wake free-cluster waiters when precalc allocation fails DaeMyung Kang
2026-05-21 1:03 ` Hyunchul Lee
2026-05-20 17:01 ` [PATCH 3/3] ntfs: only alias volume $UpCase to default on exact match DaeMyung Kang
2026-05-21 1:04 ` Hyunchul Lee
2026-05-21 1:02 ` [PATCH 0/3] ntfs: fix mount failure cleanup and free-count setup Hyunchul Lee
2026-05-21 10:17 ` [PATCH v2 " DaeMyung Kang
2026-05-21 10:17 ` DaeMyung Kang [this message]
2026-05-21 10:17 ` [PATCH v2 2/3] ntfs: avoid heap allocation for free-cluster readahead state DaeMyung Kang
2026-05-21 12:19 ` Namjae Jeon
2026-05-21 12:48 ` CharSyam
2026-05-22 0:00 ` Hyunchul Lee
2026-05-22 0:28 ` Namjae Jeon
2026-05-22 1:22 ` CharSyam
2026-05-22 4:31 ` Namjae Jeon
2026-05-21 10:17 ` [PATCH v2 3/3] ntfs: only alias volume $UpCase to default on exact match DaeMyung Kang
2026-05-21 13:00 ` [PATCH v3 0/3] ntfs: fix mount failure cleanup and free-count setup DaeMyung Kang
2026-05-21 13:00 ` [PATCH v3 1/3] ntfs: free volume-wide resources on fill_super failure DaeMyung Kang
2026-05-21 13:00 ` [PATCH v3 2/3] ntfs: avoid heap allocation for free-cluster readahead state DaeMyung Kang
2026-05-21 13:00 ` [PATCH v3 3/3] ntfs: only alias volume $UpCase to default on exact match DaeMyung Kang
2026-05-23 14:11 ` [PATCH v3 0/3] ntfs: fix mount failure cleanup and free-count setup Namjae Jeon
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=20260521101751.591345-2-charsyam@gmail.com \
--to=charsyam@gmail.com \
--cc=hyc.lee@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome