[PATCH v3 01/10] ecryptfs: write from the right offset in ecryptfs_write_lower_page_segment()
From: Tal Zussman
Date: Mon Nov 16 2026 - 17:08:31 EST
ecryptfs_write_lower_page_segment() writes part of a folio to the lower
file at offset_in_page, but takes the bytes from the start of the folio
instead of from offset_in_page.
ecryptfs_write() calls it with a non-zero offset for a file that is not
encrypted, which is possible with the ecryptfs_passthrough mount option.
For such a file, ecryptfs_write() is only called when a truncate extends
the file, to write a zero byte at the new last position. The lower file
gets the first byte of that page instead. If the page already holds
data, the last byte of the file reads back as that data once the page
has left the page cache, although it should be zero.
To fix it, map the folio at offset_in_page.
Fixes: 13a791b4e63e ("eCryptfs: Fix data corruption when using ecryptfs_passthrough")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/ecryptfs/read_write.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
index b3b451c2b941..e7319216a2f1 100644
--- a/fs/ecryptfs/read_write.c
+++ b/fs/ecryptfs/read_write.c
@@ -63,7 +63,7 @@ int ecryptfs_write_lower_page_segment(struct inode *ecryptfs_inode,
int rc;
offset = (loff_t)folio_for_lower->index * PAGE_SIZE + offset_in_page;
- virt = kmap_local_folio(folio_for_lower, 0);
+ virt = kmap_local_folio(folio_for_lower, offset_in_page);
rc = ecryptfs_write_lower(ecryptfs_inode, virt, offset, size);
if (rc > 0)
rc = 0;
--
2.39.5