From: Timofei Novikov <tictacnumt@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH] udf: Fix endless loop in udf_readdir() on iterator error
Date: Thu, 3 Dec 2026 17:22:01 +0300 [thread overview]
Message-ID: <20261203142201.321453-1-tictacnumt@gmail.com> (raw)
udf_fiiter_advance() advances iter.pos to the next entry before loading
it. If loading or verification then fails, udf_readdir() returns the
error but leaves ctx->pos at the last successfully processed entry,
because the post-loop position update only runs when ret == 0.
This would be harmless if the error reached userspace, but getdents64()
treats an already produced partial result as success: when
buf.prev_reclen is non-zero, it overwrites the error with the number of
bytes copied and stores ctx->pos as the next f_pos. Userspace therefore
calls getdents64() again from the same position, reads the same entries,
and hits the same error forever.
Update ctx->pos on error as well, but only if iteration has already
reached emit_pos. During a rescan after lseek or a directory change, an
error before the requested position must not move f_pos backwards.
Fixes: 7cd7a36ab44d ("udf: Convert udf_readdir() to new directory iteration")
Signed-off-by: Timofei Novikov <tictacnumt@gmail.com>
---
fs/udf/dir.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/udf/dir.c b/fs/udf/dir.c
index 425e3c162935..2cbdc0f03953 100644
--- a/fs/udf/dir.c
+++ b/fs/udf/dir.c
@@ -115,7 +115,7 @@ static int udf_readdir(struct file *file, struct dir_context *ctx)
goto out_iter;
}
- if (!ret) {
+ if (!ret || iter.pos >= emit_pos) {
ctx->pos = (iter.pos >> 2) + 1;
pos_valid = true;
}
--
2.43.0
reply other threads:[~2026-12-03 14:24 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=20261203142201.321453-1-tictacnumt@gmail.com \
--to=tictacnumt@gmail.com \
--cc=jack@suse.cz \
--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
all inboxes | Powered by JetHome®