fs/ntfs3: Check new size for limits
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Mon, 25 Oct 2021 15:34:06 +0000 (18:34 +0300)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Wed, 24 Nov 2021 12:13:27 +0000 (15:13 +0300)
We must check size before trying to allocate.
Size can be set for example by "ulimit -f".
Fixes xfstest generic/228
Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/file.c

index 6242708980d0a6f14d4142b688891e2c334c9bd8..f8360f9bfaf0278b32c321cd51fdbb826c2f5408 100644 (file)
@@ -661,7 +661,13 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)
                /*
                 * Normal file: Allocate clusters, do not change 'valid' size.
                 */
-               err = ntfs_set_size(inode, max(end, i_size));
+               loff_t new_size = max(end, i_size);
+
+               err = inode_newsize_ok(inode, new_size);
+               if (err)
+                       goto out;
+
+               err = ntfs_set_size(inode, new_size);
                if (err)
                        goto out;