From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Matteo Croce <technoboy85@gmail.com>
Cc: Timothy Redaelli <tredaelli@redhat.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Matteo Croce <teknoraver@meta.com>
Subject: Re: [PATCH v2] fat: stop reading directory entries past the end-of-directory marker
Date: Wed, 10 Jun 2026 15:32:04 +0900 [thread overview]
Message-ID: <87qzmehpnf.fsf@mail.parknet.co.jp> (raw)
In-Reply-To: <20260606105420.26641-1-technoboy85@gmail.com>
Matteo Croce <technoboy85@gmail.com> writes:
> @@ -1310,12 +1333,15 @@ int fat_add_entries(struct inode *dir, void *slots, int nr_slots,
> bh = prev = NULL;
> pos = 0;
> err = -ENOSPC;
> + saw_eod = false;
> while (fat_get_entry(dir, &pos, &bh, &de) > -1) {
> /* check the maximum size of directory */
> if (pos >= FAT_MAX_DIR_SIZE)
> goto error;
>
> if (IS_FREE(de->name)) {
> + if (de->name[0] == 0)
> + saw_eod = true;
> if (prev != bh) {
> get_bh(bh);
> bhs[nr_bhs] = prev = bh;
> @@ -1325,6 +1351,12 @@ int fat_add_entries(struct inode *dir, void *slots, int nr_slots,
> if (free_slots == nr_slots)
> goto found;
> } else {
> + if (saw_eod) {
> + fat_msg_ratelimit(sb, KERN_WARNING,
> + "allocated dir entry found after end-of-directory marker (i_pos %lld); please run fsck",
> + MSDOS_I(dir)->i_pos);
> + saw_eod = false;
Although this doesn't catch all cases, if it found the corruption, maybe
we should make FS read-only (fat_fs_error()), and return -EIO error? Is
there the reason to allow continue to write?
Thanks.
> + }
> for (i = 0; i < nr_bhs; i++)
> brelse(bhs[i]);
> prev = NULL;
--
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
next prev parent reply other threads:[~2026-06-10 6:32 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-06 10:54 Matteo Croce
2026-06-10 6:32 ` OGAWA Hirofumi [this message]
2026-06-10 10:55 ` Matteo Croce
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=87qzmehpnf.fsf@mail.parknet.co.jp \
--to=hirofumi@mail.parknet.co.jp \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=technoboy85@gmail.com \
--cc=teknoraver@meta.com \
--cc=tredaelli@redhat.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
all inboxes | Powered by JetHome®