[PATCH] omfs: reject unsupported nonzero size changes
From: Hungyu Lin
Date: Wed Nov 04 2026 - 06:47:45 EST
omfs_shrink_inode() only implements truncation to zero and returns -EIO
for a nonzero i_size. However, omfs_setattr() updates i_size and the page
cache before calling omfs_truncate(), which discards that error.
As a result, ftruncate() on an empty file to 16384 bytes succeeds, but
reading the extended file fails with EIO. Shrinking to a nonzero size
also leaves the old extents in place, so a later extension can expose
data that should have been discarded.
Reject size changes with a nonzero target before changing i_size or the
page cache. Keep truncation to zero and requests that leave the size
unchanged working.
Fixes: 8f09e98768c1 ("omfs: add file routines")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>
---
fs/omfs/file.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/omfs/file.c b/fs/omfs/file.c
index 79a413f1dc0..a4bf45d73bc 100644
--- a/fs/omfs/file.c
+++ b/fs/omfs/file.c
@@ -353,6 +353,9 @@ static int omfs_setattr(const struct mnt_idmap *idmap,
error = inode_newsize_ok(inode, attr->ia_size);
if (error)
return error;
+ /* Only truncation to zero is implemented. */
+ if (attr->ia_size)
+ return -EOPNOTSUPP;
truncate_setsize(inode, attr->ia_size);
omfs_truncate(inode);
}
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
--
2.50.1 (Apple Git-155)