summaryrefslogtreecommitdiff
path: root/fs/ntfs3/attrib.c
diff options
context:
space:
mode:
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>2022-05-12 19:18:11 +0300
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>2022-08-03 18:25:04 +0300
commit13747aac8984e069427e5de5d68bb6cefa98551e (patch)
tree9a2994550d067c240fbc61e3bb9171c8db9745a4 /fs/ntfs3/attrib.c
parent460bbf2990b3fdc597601c2cf669a3371c069242 (diff)
downloadlinux-13747aac8984e069427e5de5d68bb6cefa98551e.tar.xz
fs/ntfs3: Check reserved size for maximum allowed
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>
Diffstat (limited to 'fs/ntfs3/attrib.c')
-rw-r--r--fs/ntfs3/attrib.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c
index 3e9aefcb3e6c..c9b718143603 100644
--- a/fs/ntfs3/attrib.c
+++ b/fs/ntfs3/attrib.c
@@ -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;