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 10:35:58 +0100 [thread overview]
Message-ID: <20250729093558.GG222315@ZenIV> (raw)
In-Reply-To: <tencent_24D0464B099CEEC72EFD4C95A7FB86DB9206@qq.com>
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
> fat_ent_write fat_count_free_clusters
> fat32_ent_put fat32_ent_get
>
> Task A's write operation on CPU0 and Task B's read operation on CPU1 occur
> simultaneously, generating an race condition.
>
> Add READ/WRITE_ONCE to solve the race condition that occurs when accessing
> FAT32 entry.
Solve it in which sense? fat32_ent_get() and fat32_ent_put()
are already atomic wrt each other; neither this nor your previous
variant change anything whatsoever. And if you are talking about the
results of *multiple* fat32_ent_get(), with some assumptions made by
fat_count_free_clusters() that somehow get screwed by the modifications
from fat_add_cluster(), your patch does not prevent any of that (not
that you explained what kind of assumptions would those be).
Long story short - accesses to individual entries are already
atomic wrt each other; the fact that they happen simultaneously _might_
be a symptom of insufficient serialization, but neither version of your
patch resolves that in any way - it just prevents the tool from reporting
its suspicions.
It does not give fat_count_free_clusters() a stable state of
the entire table, assuming it needs one. It might, at that - I hadn't
looked into that code since way back. But unless I'm missing something,
the only thing your patch does is making your (rather blunt) tool STFU.
If there is a race, explain what sequence of events leads to
incorrect behaviour and explain why your proposed change prevents that
incorrect behaviour.
Note that if that behaviour is "amount of free space reported
by statfs(2) depends upon how far did the ongoing write(2) get", it
is *not* incorrect - that's exactly what the userland has asked for.
If it's "statfs(2) gets confused into reporting an amount of free space
that wouldn't have been accurate for any moment of time (or, worse yet,
crashes, etc.)" - yes, that would be a problem, but it could not be
solved by preventing simultaneous access to *single* entries, if it
happens at all.
next prev parent reply other threads:[~2025-07-29 9:36 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 [this message]
2025-07-29 10:06 ` Al Viro
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=20250729093558.GG222315@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.