From: Pierre Barre <pierre@barre.sh>
To: ericvh@kernel.org, lucho@ionkov.net, asmadeus@codewreck.org
Cc: linux_oss@crudebyte.com, v9fs@lists.linux.dev,
linux-kernel@vger.kernel.org, Pierre Barre <pierre@barre.sh>
Subject: [PATCH v2] 9p: fix i_size update race in getattr with writeback caching
Date: Sat, 27 Dec 2025 19:01:37 +0100 [thread overview]
Message-ID: <20251227180137.730385-1-pierre@barre.sh> (raw)
With writeback caching (cache=mmap), v9fs_stat2inode() and
v9fs_stat2inode_dotl() unconditionally overwrite i_size from the server
response, even when dirty pages may exist locally. This causes processes
using lseek(SEEK_END) to see incorrect file sizes, leading to data
corruption when extending files while concurrent stat() calls occur.
Fix by passing V9FS_STAT2INODE_KEEP_ISIZE when CACHE_WRITEBACK is
enabled to preserve the client's authoritative i_size.
Signed-off-by: Pierre Barre <pierre@barre.sh>
---
fs/9p/vfs_inode.c | 7 ++++++-
fs/9p/vfs_inode_dotl.c | 7 ++++++-
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 97abe65bf7c1..bfba21f5d8a9 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -993,7 +993,12 @@ v9fs_vfs_getattr(struct mnt_idmap *idmap, const struct path *path,
if (IS_ERR(st))
return PTR_ERR(st);
- v9fs_stat2inode(st, d_inode(dentry), dentry->d_sb, 0);
+ /*
+ * With writeback caching, the client is authoritative for i_size.
+ * Don't let the server overwrite it with a potentially stale value.
+ */
+ v9fs_stat2inode(st, d_inode(dentry), dentry->d_sb,
+ (v9ses->cache & CACHE_WRITEBACK) ? V9FS_STAT2INODE_KEEP_ISIZE : 0);
generic_fillattr(&nop_mnt_idmap, request_mask, d_inode(dentry), stat);
p9stat_free(st);
diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c
index 643e759eacb2..67a0ded2e223 100644
--- a/fs/9p/vfs_inode_dotl.c
+++ b/fs/9p/vfs_inode_dotl.c
@@ -453,7 +453,12 @@ v9fs_vfs_getattr_dotl(struct mnt_idmap *idmap,
if (IS_ERR(st))
return PTR_ERR(st);
- v9fs_stat2inode_dotl(st, d_inode(dentry), 0);
+ /*
+ * With writeback caching, the client is authoritative for i_size.
+ * Don't let the server overwrite it with a potentially stale value.
+ */
+ v9fs_stat2inode_dotl(st, d_inode(dentry),
+ (v9ses->cache & CACHE_WRITEBACK) ? V9FS_STAT2INODE_KEEP_ISIZE : 0);
generic_fillattr(&nop_mnt_idmap, request_mask, d_inode(dentry), stat);
/* Change block size to what the server returned */
stat->blksize = st->st_blksize;
--
2.43.0
next reply other threads:[~2025-12-27 18:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-27 18:01 Pierre Barre [this message]
2026-01-05 11:35 ` Christian Schoenebeck
2026-01-07 0:27 ` Pierre Barre
2026-02-04 11:48 ` Christian Schoenebeck
2026-02-15 9:21 ` Dominique Martinet
2026-02-17 14:48 ` David Howells
2026-02-17 15:05 ` David Howells
2026-02-17 16:54 ` David Howells
2026-02-18 13:38 ` David Howells
2026-02-18 13:41 ` David Howells
2026-02-18 14:11 ` Dominique Martinet
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=20251227180137.730385-1-pierre@barre.sh \
--to=pierre@barre.sh \
--cc=asmadeus@codewreck.org \
--cc=ericvh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux_oss@crudebyte.com \
--cc=lucho@ionkov.net \
--cc=v9fs@lists.linux.dev \
/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®