From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Vegard Nossum <vegard.nossum@oracle.com>,
LKML <linux-kernel@vger.kernel.org>,
Richard Weinberger <richard@nod.at>
Subject: Re: Endless getdents() in vfat filesystem
Date: Sun, 15 Nov 2015 21:59:15 +0900 [thread overview]
Message-ID: <87a8qf2zbw.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <56486B59.9010400@nod.at> (Richard Weinberger's message of "Sun, 15 Nov 2015 12:24:09 +0100")
Richard Weinberger <richard@nod.at> writes:
>> It would be nice to have a proper patch description too. How about this?
>>
>> """
>> For the root directory, . and .. are faked (using dir_emit_dots()) and
>> ctx->pos is reset from 2 to 0.
>>
>> A corrupted root directory could cause fat_get_entry() to fail, but
>> ->iterate() (fat_readdir()) reports progress to the VFS (with ctx->pos
>> rewound to 0), so any following calls to ->iterate() continue to return
>> the same entries again and again.
>>
>> The result is that userspace will never see the end of the directory,
>> causing e.g. 'ls' to hang in a getdents() loop.
>> """
>
> Agreed. And you deserve also a Reported-and-tested-by. :-)
Sounds good, updated patch here.
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
[PATCH v3] fat: Fix fake_offset handling on error path
For the root directory, . and .. are faked (using dir_emit_dots()) and
ctx->pos is reset from 2 to 0.
A corrupted root directory could cause fat_get_entry() to fail, but
->iterate() (fat_readdir()) reports progress to the VFS (with ctx->pos
rewound to 0), so any following calls to ->iterate() continue to return
the same entries again and again.
The result is that userspace will never see the end of the directory,
causing e.g. 'ls' to hang in a getdents() loop.
[hirofumi@mail.parknet.co.jp: cleanup and make sure to correct fake_offset]
Cc: stable@vger.kernel.org
Reported-and-tested-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Richard Weinberger <richard.weinberger@gmail.com>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
---
fs/fat/dir.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff -puN fs/fat/dir.c~fat-fake_offset-fix fs/fat/dir.c
--- linux/fs/fat/dir.c~fat-fake_offset-fix 2015-11-14 23:31:45.904700155 +0900
+++ linux-hirofumi/fs/fat/dir.c 2015-11-15 02:45:13.861256766 +0900
@@ -610,9 +610,9 @@ parse_record:
int status = fat_parse_long(inode, &cpos, &bh, &de,
&unicode, &nr_slots);
if (status < 0) {
- ctx->pos = cpos;
+ bh = NULL;
ret = status;
- goto out;
+ goto end_of_dir;
} else if (status == PARSE_INVALID)
goto record_end;
else if (status == PARSE_NOT_LONGNAME)
@@ -654,8 +654,9 @@ parse_record:
fill_len = short_len;
start_filldir:
- if (!fake_offset)
- ctx->pos = cpos - (nr_slots + 1) * sizeof(struct msdos_dir_entry);
+ ctx->pos = cpos - (nr_slots + 1) * sizeof(struct msdos_dir_entry);
+ if (fake_offset && ctx->pos < 2)
+ ctx->pos = 2;
if (!memcmp(de->name, MSDOS_DOT, MSDOS_NAME)) {
if (!dir_emit_dot(file, ctx))
@@ -681,14 +682,19 @@ record_end:
fake_offset = 0;
ctx->pos = cpos;
goto get_new;
+
end_of_dir:
- ctx->pos = cpos;
+ if (fake_offset && cpos < 2)
+ ctx->pos = 2;
+ else
+ ctx->pos = cpos;
fill_failed:
brelse(bh);
if (unicode)
__putname(unicode);
out:
mutex_unlock(&sbi->s_lock);
+
return ret;
}
_
prev parent reply other threads:[~2015-11-15 12:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-14 1:19 Endless getdents() in vfat filesystem Vegard Nossum
2015-11-14 10:32 ` Richard Weinberger
2015-11-14 12:42 ` Vegard Nossum
2015-11-14 14:28 ` OGAWA Hirofumi
2015-11-14 15:06 ` Richard Weinberger
2015-11-14 18:19 ` OGAWA Hirofumi
2015-11-15 11:05 ` Vegard Nossum
2015-11-15 11:24 ` Richard Weinberger
2015-11-15 12:59 ` OGAWA Hirofumi [this message]
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=87a8qf2zbw.fsf@mail.parknet.co.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=richard@nod.at \
--cc=vegard.nossum@oracle.com \
/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