Skip to content

Commit c83ed4c

Browse files
ubifs: Abort readdir upon error
If UBIFS is facing an error while walking a directory, it reports this error and ubifs_readdir() returns the error code. But the VFS readdir logic does not make the getdents system call fail in all cases. When the readdir cursor indicates that more entries are present, the system call will just return and the libc wrapper will try again since it also knows that more entries are present. This causes the libc wrapper to busy loop for ever when a directory is corrupted on UBIFS. A common approach do deal with corrupted directory entries is skipping them by setting the cursor to the next entry. On UBIFS this approach is not possible since we cannot compute the next directory entry cursor position without reading the current entry. So all we can do is setting the cursor to the "no more entries" position and make getdents exit. Cc: stable@vger.kernel.org Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 884a3b6 commit c83ed4c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

fs/ubifs/dir.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ static unsigned int vfs_dent_type(uint8_t type)
439439
*/
440440
static int ubifs_readdir(struct file *file, struct dir_context *ctx)
441441
{
442-
int err;
442+
int err = 0;
443443
struct qstr nm;
444444
union ubifs_key key;
445445
struct ubifs_dent_node *dent;
@@ -541,14 +541,12 @@ static int ubifs_readdir(struct file *file, struct dir_context *ctx)
541541
kfree(file->private_data);
542542
file->private_data = NULL;
543543

544-
if (err != -ENOENT) {
544+
if (err != -ENOENT)
545545
ubifs_err(c, "cannot find next direntry, error %d", err);
546-
return err;
547-
}
548546

549547
/* 2 is a special value indicating that there are no more direntries */
550548
ctx->pos = 2;
551-
return 0;
549+
return err;
552550
}
553551

554552
/* Free saved readdir() state when the directory is closed */

0 commit comments

Comments
 (0)