[PATCH v2 2/9] ecryptfs: keep the folio locked while ecryptfs_write() writes it out
From: Tal Zussman
Date: Fri Oct 30 2026 - 06:27:17 EST
ecryptfs_write() unlocks the folio before writing it to the lower file.
If that write fails, the folio stays uptodate with data that never made
it to disk, and reads return it until the folio is evicted. Keep the
folio locked until it has been written out, as ecryptfs_writepages()
and ecryptfs_write_end() do, and clear uptodate if the write fails.
Fixes: 16a72c455a67 ("ecryptfs: clean up page flag handling")
Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/ecryptfs/read_write.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
index b3b451c2b941..a31f1e90c40e 100644
--- a/fs/ecryptfs/read_write.c
+++ b/fs/ecryptfs/read_write.c
@@ -166,7 +166,6 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset,
kunmap_local(ecryptfs_page_virt);
flush_dcache_folio(ecryptfs_folio);
folio_mark_uptodate(ecryptfs_folio);
- folio_unlock(ecryptfs_folio);
if (crypt_stat->flags & ECRYPTFS_ENCRYPTED)
rc = ecryptfs_encrypt_page(ecryptfs_folio);
else
@@ -174,6 +173,9 @@ int ecryptfs_write(struct inode *ecryptfs_inode, char *data, loff_t offset,
ecryptfs_folio,
start_offset_in_page,
data_offset);
+ if (rc)
+ folio_clear_uptodate(ecryptfs_folio);
+ folio_unlock(ecryptfs_folio);
folio_put(ecryptfs_folio);
if (rc) {
printk(KERN_ERR "%s: Error encrypting "
--
2.39.5