Skip to contentSkip to conversation

fs/ntfs3: Validate attribute data and valid sizes

PATCH In review Abdun Nihaal 2 participants 2 messages Nov 14, 2022 – Dec 26, 2022 NTFS3 filesystem

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fs/ntfs3: Validate attribute data and valid sizes

The data_size and valid_size fields of non resident attributes should be less than the its alloc_size field, but this is not checked in ntfs_read_mft function.

Syzbot reports a allocation order warning due to a large unchecked value of data_size getting assigned to inode->i_size which is then passed to kcalloc.

Add sanity check for ensuring that the data_size and valid_size fields are not larger than alloc_size field.

Reported-and-tested-by [email protected]
Fixes 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")

---

Please apply this instead of my previous patch.

Changes in v2:
Correct the format used for the Fixes tag.

 fs/ntfs3/inode.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/ntfs3/inode.c +7 -0
index 970bb7c357c7..763dd982a43a 100644
@@ -132,6 +132,13 @@ static struct inode *ntfs_read_mft(struct inode *inode,
 	if (le16_to_cpu(attr->name_off) + attr->name_len > asize)
 		goto out;
 
+	if (attr->non_res) {
+		t64 = le64_to_cpu(attr->nres.alloc_size);
+		if (le64_to_cpu(attr->nres.data_size) > t64 ||
+		    le64_to_cpu(attr->nres.valid_size) > t64)
+			goto out;
+	}
+
 	switch (attr->type) {
 	case ATTR_STD:
 		if (attr->non_res ||
Signature · 1 line
2.37.3
#1 lore raw
Quoted 33 lines · Abdun Nihaal

The data_size and valid_size fields of non resident attributes should be less than the its alloc_size field, but this is not checked in ntfs_read_mft function.

Syzbot reports a allocation order warning due to a large unchecked value of data_size getting assigned to inode->i_size which is then passed to kcalloc.

Add sanity check for ensuring that the data_size and valid_size fields are not larger than alloc_size field.

Reported-and-tested-by [email protected]
Fixes 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")

---

Please apply this instead of my previous patch.

Changes in v2:
Correct the format used for the Fixes tag.

  fs/ntfs3/inode.c | 7 +++++++
  1 file changed, 7 insertions(+)
fs/ntfs3/inode.c +0 -0
index 970bb7c357c7..763dd982a43a 100644
@@ -132,6 +132,13 @@ static struct inode *ntfs_read_mft(struct inode *inode,
  	if (le16_to_cpu(attr->name_off) + attr->name_len > asize)
  		goto out;
 

fs/ntfs3/inode.c static struct inode *ntfs_read_mft(struct inode *inode, · line 144

Quoted 10 lines
fs/ntfs3/inode.c +7 -0
+	if (attr->non_res) {
+		t64 = le64_to_cpu(attr->nres.alloc_size);
+		if (le64_to_cpu(attr->nres.data_size) > t64 ||
+		    le64_to_cpu(attr->nres.valid_size) > t64)
+			goto out;
+	}
+
  	switch (attr->type) {
  	case ATTR_STD:
  		if (attr->non_res ||

Hello. Your patch has been already applied.