[PATCH] fuse: clear stale page-cache data before direct-I/O extension

From: Shawn Shao

Date: Tue Dec 01 2026 - 09:18:58 EST


Hello,

A FUSE file opened with FOPEN_DIRECT_IO can expose stale page-cache data when
an extending write starts after the old end of file. The direct-I/O path
invalidates pages covering the write itself, but it does not clear the range
between the old i_size and the write offset before fuse_write_update_attr()
publishes the larger size.

A process that previously dirtied bytes past EOF through a MAP_SHARED mapping
can therefore read those bytes after the direct-I/O write makes the gap part
of the file. The included FUSE server/client reproducer observes the stale
bytes in the page cache and also observes them being written back to the
server when the direct-I/O file is closed.

The buffered write path already clears this gap with
truncate_pagecache_range() before writing. This adds the same operation to
the common FOPEN_DIRECT_IO write entry point, covering both synchronous and
asynchronous requests before they are submitted.

This is related to, but distinct from, my earlier report about a larger size
returned by FUSE_GETATTR: that report concerns fuse_change_attributes_i();
this trigger uses FOPEN_DIRECT_IO and does not require GETATTR.

The trigger requires a FUSE server that returns FOPEN_KEEP_CACHE and
FOPEN_DIRECT_IO for separate opens of the same file. It demonstrates stale
file contents and writeback within that FUSE filesystem. It does not
establish a cross-user disclosure or privilege escalation.

HEAD commit: 7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046
git tree: 194227446ae61b4971eea1b7bed06856fe3cc477
source version: v7.3-23903-g7cd8495c0f162 (Linux 7.4.0-rc4)
compiler: gcc 11.4.0, GNU ld 2.38

The Gist contains the standalone PoC, exact kernel configuration, full
baseline and fixed-kernel console output, patch, and reproducible build/run
instructions:

https://gist.githubusercontent.com/shaos26/94f67aa7af346dcdfeb8b80658c28647/raw/04ea360ce23413142bea04cbfc2c328f97aebe0a/poc.c
https://gist.githubusercontent.com/shaos26/94f67aa7af346dcdfeb8b80658c28647/raw/04ea360ce23413142bea04cbfc2c328f97aebe0a/kernel-config.txt
https://gist.githubusercontent.com/shaos26/94f67aa7af346dcdfeb8b80658c28647/raw/04ea360ce23413142bea04cbfc2c328f97aebe0a/console-output.txt
https://gist.githubusercontent.com/shaos26/94f67aa7af346dcdfeb8b80658c28647/raw/04ea360ce23413142bea04cbfc2c328f97aebe0a/fix.patch
https://gist.githubusercontent.com/shaos26/94f67aa7af346dcdfeb8b80658c28647/raw/04ea360ce23413142bea04cbfc2c328f97aebe0a/repro.md

The reproduction builds the kernel from the commit above, runs the PoC on the
unmodified kernel, applies the patch, and repeats the same cases. The
positive baseline returns 100 stale marker bytes from a 100-byte read over
the newly exposed gap; the patched run returns 100 zero bytes. Buffered,
same-page, truncate, and clean-tail controls return zeroes on both kernels.

Signed-off-by: Shawn Shao <shawnq1@xxxxxxx>

Thanks,
Shawn Shao

---
fs/fuse/file.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 993a1d2b31511..5bebe1abb5e60 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -1853,6 +1853,10 @@ static ssize_t fuse_direct_write_iter(struct kiocb *iocb, struct iov_iter *from)
res = generic_write_checks(iocb, from);
if (res > 0) {
loff_t pos = iocb->ki_pos;
+ loff_t oldsize = i_size_read(inode);
+
+ if (pos > oldsize)
+ truncate_pagecache_range(inode, oldsize, pos - 1);

task_io_account_write(res);
if (!is_sync_kiocb(iocb)) {
--
2.43.0