From: Karl Mehltretter <kmehltretter@gmail.com>
To: Namjae Jeon <linkinjeon@kernel.org>
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
Hyunchul Lee <hyc.lee@gmail.com>,
ntfs@lists.linux.dev, stable@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] ntfs: map each LogFile page once in ntfs_check_logfile()
Date: Tue, 6 Oct 2026 06:38:10 +0200 [thread overview]
Message-ID: <20261006043810.5393-4-kmehltretter@gmail.com> (raw)
In-Reply-To: <20261006043810.5393-1-kmehltretter@gmail.com>
ntfs_check_logfile() calls kmap_local_folio() on every iteration of its
search loop but calls kunmap_local() only when it moves on to the next
folio. With 4 KiB pages the positions 0, 512, 1024 and 2048 are all in
the first page, so every mount leaves three entries on the kmap_local
stack of the mounting task.
64-bit kernels do not notice, kmap_local_folio() does not touch the
stack there. 32-bit kernels with HIGHMEM return from mount(2) with the
mappings in place. With the generic entry code that is a warning:
DEBUG_LOCKS_WARN_ON(current->kmap_ctrl.idx)
WARNING: include/linux/highmem-internal.h:17 at __do_fast_syscall_32+0x21e/0x550
The stack has 16 slots, so a process that mounts ntfs volumes five
times hits the BUG_ON() in kmap_local_idx_push() during the fifth
mount:
kernel BUG at mm/highmem.c:480!
Map each page once, when it is read, and unmap that address.
Fixes: 5218cd102aec ("ntfs: update misc operations")
Cc: stable@vger.kernel.org
Assisted-by: LLM
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
Tested on top of patch 1 in QEMU with a fresh mkntfs volume and a small
program that calls mount(2) and umount(2) eight times in one process:
- 32-bit ARM (multi_v7_defconfig plus KCOV, virt, 1 GiB RAM, 256 MiB
highmem) and x86-32 (i386_defconfig plus HIGHMEM4G, 2 GiB RAM): without
this patch mounts one to four succeed and the fifth hits the BUG_ON()
in kmap_local_idx_push() on both. With it all eight complete.
- x86-32 no longer warns when mount(2) returns. Three mounts in a row
with mount(8) are clean on both.
The other kmap_local_folio() loops in fs/ntfs (lcnalloc.c, mft.c,
bitmap.c, compress.c) unmap on every path before they map again.
fs/ntfs/logfile.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/fs/ntfs/logfile.c b/fs/ntfs/logfile.c
index 1404664dacc0..ce38ce87f8fc 100644
--- a/fs/ntfs/logfile.c
+++ b/fs/ntfs/logfile.c
@@ -457,7 +457,7 @@ bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
struct ntfs_volume *vol = NTFS_SB(log_vi->i_sb);
struct address_space *mapping = log_vi->i_mapping;
struct folio *folio = NULL;
- u8 *kaddr = NULL;
+ u8 *kaddr = NULL, *kbase = NULL;
struct restart_page_header *rstr1_ph = NULL;
struct restart_page_header *rstr2_ph = NULL;
int log_page_size, err;
@@ -511,7 +511,7 @@ bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
if (!folio || folio->index != idx) {
if (folio) {
- kunmap_local(kaddr);
+ kunmap_local(kbase);
folio_put(folio);
}
folio = read_mapping_folio(mapping, idx, NULL);
@@ -520,8 +520,9 @@ bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
idx);
goto err_out;
}
+ kbase = kmap_local_folio(folio, 0);
}
- kaddr = (u8 *)kmap_local_folio(folio, 0) + (pos & ~PAGE_MASK);
+ kaddr = kbase + (pos & ~PAGE_MASK);
/*
* A non-empty block means the logfile is not empty while an
* empty block after a non-empty block has been encountered
@@ -574,7 +575,7 @@ bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
* find a valid one further in the file.
*/
if (err != -EINVAL) {
- kunmap_local(kaddr);
+ kunmap_local(kbase);
folio_put(folio);
goto err_out;
}
@@ -583,7 +584,7 @@ bool ntfs_check_logfile(struct inode *log_vi, struct restart_page_header **rp)
pos = NTFS_BLOCK_SIZE >> 1;
}
if (folio) {
- kunmap_local(kaddr);
+ kunmap_local(kbase);
folio_put(folio);
}
if (logfile_is_empty) {
--
2.53.0
next prev parent reply other threads:[~2026-10-06 4:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-06 4:38 [PATCH 0/2] ntfs: fix two kmap_local bugs on 32-bit kernels Karl Mehltretter
2026-10-06 4:38 ` [PATCH 1/2] ntfs: fix kunmap_local() of advanced pointers in check_mft_mirror() Karl Mehltretter
2026-10-06 4:38 ` [PATCH 2/2] ntfs: fix kmap_local leak in ntfs_check_logfile() Karl Mehltretter
2026-10-06 4:38 ` Karl Mehltretter [this message]
2026-10-06 4:50 ` [PATCH 0/2] ntfs: fix two kmap_local bugs on 32-bit kernels Karl Mehltretter
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=20261006043810.5393-4-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=hyc.lee@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs@lists.linux.dev \
--cc=stable@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
all inboxes | Powered by JetHome®