[PATCH] ntfs: fix error handling in ntfs_readdir()
From: Hongling Zeng
Date: Fri Aug 07 2026 - 05:11:00 EST
ntfs_readdir() converts all non-zero errors to success before returning.
This hides real errors such as -ENOMEM or -EIO from userspace and makes
them look like end-of-directory.
Only positive return values from ntfs_filldir(), which indicate that the
user buffer is full, should be converted to 0. Negative errors should be
propagated.
Additionally, when the user buffer is full (err > 0), the iterator should
not be marked as completed since directory traversal has not ended.
This allows subsequent readdir() calls to continue from the saved position.
Fixes: 956ce2083c93 ("[readdir] convert ntfs")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hongling Zeng <zenghongling@xxxxxxxxxx>
---
fs/ntfs/dir.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
index 2d594cbb4ebe..ba17d9805326 100644
--- a/fs/ntfs/dir.c
+++ b/fs/ntfs/dir.c
@@ -982,8 +982,10 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
if (!err)
private->end_in_iterate = true;
- else
+ else if (err > 0)
err = 0;
+ else
+ goto out;
private->curr_pos = actor->pos = ie_pos;
out:
@@ -1000,12 +1002,13 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor)
kfree(cnir);
}
- if (err) {
+ if (err > 0) {
if (private) {
private->curr_pos = actor->pos;
- private->end_in_iterate = true;
}
err = 0;
+ } else if (err < 0 && private) {
+ private->curr_pos = actor->pos;
}
ntfs_index_ctx_put(ictx);
kfree(name);
--
2.25.1