From: Konstantin Komarov Date: Thu, 30 May 2024 07:44:17 +0000 (+0300) Subject: fs/ntfs3: Fix attr_insert_range at end of file X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=519f38de57cd0c5e0043795b5fb0686c97311f6d;p=linux.git fs/ntfs3: Fix attr_insert_range at end of file If the offset is equal to or greater than the end of file, an error is returned. For such operations (i.e., inserting a hole at the end of file), ftruncate(2) should be used. Signed-off-by: Konstantin Komarov --- diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index 0d13da5523b1..68d1c61fe3b5 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -2373,8 +2373,13 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes) mask = (sbi->cluster_size << attr_b->nres.c_unit) - 1; } - if (vbo > data_size) { - /* Insert range after the file size is not allowed. */ + if (vbo >= data_size) { + /* + * Insert range after the file size is not allowed. + * If the offset is equal to or greater than the end of + * file, an error is returned. For such operations (i.e., inserting + * a hole at the end of file), ftruncate(2) should be used. + */ return -EINVAL; }