mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] udf: Fix endless loop in udf_readdir() on iterator error
@ 2026-12-03 14:22 Timofei Novikov
  0 siblings, 0 replies; only message in thread
From: Timofei Novikov @ 2026-12-03 14:22 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-kernel, linux-fsdevel

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03 14:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 14:22 [PATCH] udf: Fix endless loop in udf_readdir() on iterator error Timofei Novikov

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®