From: Wahid Khan <wahidzk0091@gmail.com>
To: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Cc: ntfs3@lists.linux.dev, linux-kernel@vger.kernel.org,
Wahid Khan <wahidzk0091@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] fs/ntfs3: fix endless readdir loop on a directory without a $BITMAP
Date: Fri, 6 Nov 2026 11:40:04 +0530 [thread overview]
Message-ID: <20261106061004.2338569-1-wahidzk0091@gmail.com> (raw)
ntfs_readdir() saves ctx->pos in "pos" before it emits "." and "..".
If indx_used_bit() returns -ENOENT, the exit path puts that stale value
back into ctx->pos and returns 0, although the dot entries were already
copied to user space. The next getdents64() call starts at the same
position and emits them again, so a reader of the directory never sees
the end of it. ls, find and rm -r spin forever.
indx_used_bit() returns -ENOENT when the directory has no $BITMAP
attribute named $I30. That is a damaged directory, but it simply means
that no index block is in use, and indx_find_sort() already treats it
that way. Do the same in ntfs_readdir() and end the enumeration.
Reproduced under KASAN with a crafted image: changing the first
character of the $I30 name of the $BITMAP attribute in the root
directory's MFT record is enough.
Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
Cc: stable@vger.kernel.org
Signed-off-by: Wahid Khan <wahidzk0091@gmail.com>
---
fs/ntfs3/dir.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c
index 7ee1a5d4189e..dafd309e136d 100644
--- a/fs/ntfs3/dir.c
+++ b/fs/ntfs3/dir.c
@@ -584,6 +584,11 @@ static int ntfs_readdir(struct file *file, struct dir_context *ctx)
for (; bit < max_bit; bit += 1) {
/* Get the next used index. */
err = indx_used_bit(&ni->dir, ni, &bit);
+ if (err == -ENOENT) {
+ /* No $BITMAP, so no used indexes. End of dir. */
+ err = 0;
+ break;
+ }
if (err)
goto out;
--
2.56.0
reply other threads:[~2026-11-06 6:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261106061004.2338569-1-wahidzk0091@gmail.com \
--to=wahidzk0091@gmail.com \
--cc=almaz.alexandrovich@paragon-software.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ntfs3@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®