[PATCH] udf: Fix endless loop in udf_readdir() on iterator error
From: Timofei Novikov
Date: Thu Dec 03 2026 - 09:24:56 EST
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@xxxxxxxxx>
---
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