OSDN Git Service

fs/ntfs3: Check reserved size for maximum allowed
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Thu, 12 May 2022 16:18:11 +0000 (19:18 +0300)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Wed, 3 Aug 2022 15:25:04 +0000 (18:25 +0300)
Also don't mask EFBIG
Fixes xfstest generic/485
Fixes: 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/attrib.c
fs/ntfs3/file.c

index 3e9aefc..c9b7181 100644 (file)
@@ -2114,9 +2114,11 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
 
        if (!attr_b->non_res) {
                data_size = le32_to_cpu(attr_b->res.data_size);
+               alloc_size = data_size;
                mask = sbi->cluster_mask; /* cluster_size - 1 */
        } else {
                data_size = le64_to_cpu(attr_b->nres.data_size);
+               alloc_size = le64_to_cpu(attr_b->nres.alloc_size);
                mask = (sbi->cluster_size << attr_b->nres.c_unit) - 1;
        }
 
@@ -2130,6 +2132,13 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
                return -EINVAL;
        }
 
+       /*
+        * valid_size <= data_size <= alloc_size
+        * Check alloc_size for maximum possible.
+        */
+       if (bytes > sbi->maxbytes_sparse - alloc_size)
+               return -EFBIG;
+
        vcn = vbo >> sbi->cluster_bits;
        len = bytes >> sbi->cluster_bits;
 
index bdffe4b..cf16bde 100644 (file)
@@ -733,9 +733,6 @@ out:
        if (map_locked)
                filemap_invalidate_unlock(mapping);
 
-       if (err == -EFBIG)
-               err = -ENOSPC;
-
        if (!err) {
                inode->i_ctime = inode->i_mtime = current_time(inode);
                mark_inode_dirty(inode);