Re: [PATCH] fs: stat: Mark accesses in generic_fillattr
From: Mateusz Guzik
Date: Fri Jul 10 2026 - 10:09:30 EST
On Fri, Jul 10, 2026 at 03:14:43PM +0800, Can Peng wrote:
> KCSAN reports a data race between generic_fillattr() reading
> inode->i_nlink while filling st_nlink and inc_nlink() updating
> the link count during ramfs_mkdir().
>
> getattr does not take the inode's i_rwsem, so st_nlink
> is a snapshot and may observe either the old or new link count
> when it races with directory updates. This is expected and
> does not require serializing the stat path with link count updates.
>
The link count is merely one example, several other fields are also
susceptible (notably i_mode and uid/gid). So I don't believe the patch
as proposed makes sense.
Taking the lock around getattr is out of the question, so data races are
unavoidable.
I would argue correctness requires a sequence counter around this, but
afair the vfs folk are opposed to the idea.
So if one wants to do anything here, all relevant fields need to be
annotated. But I don't know if this is worth the effort.