From: Al Viro <viro@zeniv.linux.org.uk>
To: Edward Adam Davis <eadavis@qq.com>
Cc: hirofumi@mail.parknet.co.jp, linkinjeon@kernel.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
sj1557.seo@samsung.com,
syzbot+d3c29ed63db6ddf8406e@syzkaller.appspotmail.com,
syzkaller-bugs@googlegroups.com
Subject: Re: [PATCH V2] fat: Prevent the race of read/write the FAT32 entry
Date: Tue, 29 Jul 2025 11:06:35 +0100 [thread overview]
Message-ID: <20250729100635.GH222315@ZenIV> (raw)
In-Reply-To: <20250729093558.GG222315@ZenIV>
On Tue, Jul 29, 2025 at 10:35:58AM +0100, Al Viro wrote:
> On Tue, Jul 29, 2025 at 02:17:10PM +0800, Edward Adam Davis wrote:
> > syzbot reports data-race in fat32_ent_get/fat32_ent_put.
> >
> > CPU0(Task A) CPU1(Task B)
> > ==== ====
> > vfs_write
> > new_sync_write
> > generic_file_write_iter
> > fat_write_begin
> > block_write_begin vfs_statfs
> > fat_get_block statfs_by_dentry
> > fat_add_cluster fat_statfs
Sorry, no - you've missed an intermediate fat_chain_add() in the call chain
here. And that makes your race a non-issue.
> > fat_ent_write fat_count_free_clusters
> > fat32_ent_put fat32_ent_get
fat_count_free_clusters() doesn't care about exact value of entry;
the only thing that matters is whether it's equal to FAT_ENT_FREE.
Actualy changes of that predicate (i.e. allocating and freeing of
clusters) still happens under fat_lock() - nothing has changed in
that area. *That* is not happening simultaneously with reads in
fat_count_free_clusters(). It's attaching the new element to the
end of chain that is outside of fat_lock().
And that operation does not affect that predicate at all; it changes
the value of the entry for last cluster of file (FAT_ENT_EOF) to the
number of cluster being added to the file. Neither is equal to
FAT_ENT_FREE, so there's no problem - value you get ->ent_get()
is affected by that store, the value of
ops->ent_get(&fatent) == FAT_ENT_FREE
isn't. Probably worth a comment in fat_chain_add() re "this store
is safe outside of fat_lock() because of <list of reasons>".
Changes to this chain (both extending and truncating it) are
excluded by <lock> and as far as allocator is concerned, we are
not changing the state of any cluster.
Basically, FAT encodes both the free block map (entry[block] == FAT_ENT_FREE
<=> block is not in use) and linked lists of blocks for individual files -
they store the number of file's first block within directory entry and
use FAT for forwards pointers in the list. FAT_ENT_EOF is used for "no
more blocks, it's the end of file". Allocator and fat_count_free_clusters
care only about the free block map part of that thing; access to file
contents - the linked list for that file.
next prev parent reply other threads:[~2025-07-29 10:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-28 8:17 [syzbot] [exfat?] KCSAN: data-race in fat32_ent_get / fat32_ent_put syzbot
2025-07-28 11:37 ` [PATCH] fat: Prevent the race of read/write the FAT16 and FAT32 entry Edward Adam Davis
2025-07-28 15:10 ` OGAWA Hirofumi
2025-07-29 3:57 ` Edward Adam Davis
2025-07-28 16:04 ` Al Viro
2025-07-28 16:35 ` Al Viro
2025-07-29 4:17 ` Edward Adam Davis
2025-07-29 4:53 ` Al Viro
2025-07-29 5:04 ` Al Viro
2025-07-29 5:32 ` Edward Adam Davis
2025-07-29 6:17 ` [PATCH V2] fat: Prevent the race of read/write the " Edward Adam Davis
2025-07-29 9:03 ` OGAWA Hirofumi
2025-07-29 9:35 ` Al Viro
2025-07-29 10:06 ` Al Viro [this message]
2025-08-18 13:58 ` Edward Adam Davis
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=20250729100635.GH222315@ZenIV \
--to=viro@zeniv.linux.org.uk \
--cc=eadavis@qq.com \
--cc=hirofumi@mail.parknet.co.jp \
--cc=linkinjeon@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sj1557.seo@samsung.com \
--cc=syzbot+d3c29ed63db6ddf8406e@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.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