fuse: clear the old EOF tail when copying past EOF
Subsystems (2)
PATCH 1/1 fuse: clear the old EOF tail when copying past EOF
__fuse_copy_file_range() invalidates the copied range before updating the destination size, but does not clear the tail of the old EOF page. If that tail was modified through a shared mapping and the copy starts in a later page, the newly exposed gap can contain stale data instead of zeros. A subsequent writeback can also send those stale bytes to the server.
Remember the destination size before sending the COPY request. After a positive copy result, clear the gap from the old EOF to the copy start before publishing the new size. Keep the existing invalidation of the copied range. Apply the page-cache cleanup to non-DAX inodes and cover both write-through and writeback-cache connections.
--- fs/fuse/file.c | 6 ++++++ 1 file changed, 6 insertions(+)
fs/fuse/file.c +6 -0
@@ -3000,6 +3000,7 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,struct fuse_copy_file_range_out outarg_64;u64 bytes_copied;ssize_t err; +loff_t oldsize;/* mark unstable when write-back is not used, and file_out gets * extended */ bool is_unstable = (!fc->writeback_cache) &&
@@ -3047,6 +3048,8 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in,if (err) goto out; + oldsize =i_size_read (inode_out); +if (is_unstable)set_bit (FUSE_I_SIZE_UNSTABLE , &fi_out->state);
@@ -3087,6 +3090,9 @@ static ssize_t __fuse_copy_file_range(struct file *file_in, loff_t pos_in, goto out; } +if (bytes_copied && !IS_DAX (inode_out) && pos_out > oldsize) +truncate_pagecache_range (inode_out, oldsize, pos_out -1 ); +if (bytes_copied) invalidate_inode_pages2_range(inode_out->i_mapping, pos_out >> PAGE_SHIFT,
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.43.0