omfs: reject unsupported nonzero size changes
Subsystems (3)
PATCH 1/1 omfs: reject unsupported nonzero size changes
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")
Signed-off-by Hungyu Lin <[email protected]>
--- fs/omfs/file.c | 3 +++ 1 file changed, 3 insertions(+)
fs/omfs/file.c +3 -0
@@ -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
Signature · 1 line
2.50.1 (Apple Git-155)