Commit c83ed4c9 authored by Richard Weinberger's avatar Richard Weinberger

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: default avatarRichard Weinberger <richard@nod.at>
parent 884a3b64
...@@ -439,7 +439,7 @@ static unsigned int vfs_dent_type(uint8_t type) ...@@ -439,7 +439,7 @@ static unsigned int vfs_dent_type(uint8_t type)
*/ */
static int ubifs_readdir(struct file *file, struct dir_context *ctx) static int ubifs_readdir(struct file *file, struct dir_context *ctx)
{ {
int err; int err = 0;
struct qstr nm; struct qstr nm;
union ubifs_key key; union ubifs_key key;
struct ubifs_dent_node *dent; struct ubifs_dent_node *dent;
...@@ -541,14 +541,12 @@ static int ubifs_readdir(struct file *file, struct dir_context *ctx) ...@@ -541,14 +541,12 @@ static int ubifs_readdir(struct file *file, struct dir_context *ctx)
kfree(file->private_data); kfree(file->private_data);
file->private_data = NULL; file->private_data = NULL;
if (err != -ENOENT) { if (err != -ENOENT)
ubifs_err(c, "cannot find next direntry, error %d", err); ubifs_err(c, "cannot find next direntry, error %d", err);
return err;
}
/* 2 is a special value indicating that there are no more direntries */ /* 2 is a special value indicating that there are no more direntries */
ctx->pos = 2; ctx->pos = 2;
return 0; return err;
} }
/* Free saved readdir() state when the directory is closed */ /* Free saved readdir() state when the directory is closed */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment