Skip to contentSkip to conversation

ntfs: move check for valid resident attribute offset and length

PATCH In review Rustam Kovhaev 2 participants 3 messages Feb 14, 2021 – Feb 16, 2021 NTFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ntfs: move check for valid resident attribute offset and length

we should check for valid resident atribute offset and length before loading STANDARD_INFORMATION attribute in ntfs_read_locked_inode() let's make that check a bit earlier in the same function to avoid use-after-free bug

---
 fs/ntfs/inode.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
fs/ntfs/inode.c +7 -8
index f7e4cbc26eaf..70745aea5106 100644
@@ -629,6 +629,13 @@ static int ntfs_read_locked_inode(struct inode *vi)
 	}
 	a = ctx->attr;
 	/* Get the standard information attribute value. */
+	if ((u8 *)a + le16_to_cpu(a->data.resident.value_offset)
+			+ le32_to_cpu(
+			a->data.resident.value_length) >
+			(u8 *)ctx->mrec + vol->mft_record_size) {
+		ntfs_error(vi->i_sb, "Corrupt attribute list in inode.");
+		goto unm_err_out;
+	}
 	si = (STANDARD_INFORMATION*)((u8*)a +
 			le16_to_cpu(a->data.resident.value_offset));
 
@@ -731,14 +738,6 @@ static int ntfs_read_locked_inode(struct inode *vi)
 				goto unm_err_out;
 			}
 		} else /* if (!a->non_resident) */ {
-			if ((u8*)a + le16_to_cpu(a->data.resident.value_offset)
-					+ le32_to_cpu(
-					a->data.resident.value_length) >
-					(u8*)ctx->mrec + vol->mft_record_size) {
-				ntfs_error(vi->i_sb, "Corrupt attribute list "
-						"in inode.");
-				goto unm_err_out;
-			}
 			/* Now copy the attribute list. */
 			memcpy(ni->attr_list, (u8*)a + le16_to_cpu(
 					a->data.resident.value_offset),
Signature · 1 line
2.30.0
#1 lore raw

Hi Rustam,

Thank you for the patch but it is not quite correct:

1) The first delta: yes that is a good idea to add this check but the error message is incorrect. It should say "Corrupt standard information attribute in inode." instead.

2) The second delta: The check of the attribute list attribute needs to remain, i.e. your second delta needs to be deleted.

Please could you address both of the above comments and then resend? Please then also add: "Acked-by: Anton Altaparmakov <[email protected]>" to the patch.

Thanks a lot in advance!

Best regards,

Anton

Quoted 50 lines · Rustam Kovhaev

we should check for valid resident atribute offset and length before loading STANDARD_INFORMATION attribute in ntfs_read_locked_inode() let's make that check a bit earlier in the same function to avoid use-after-free bug

---
fs/ntfs/inode.c | 15 +++++++--------

1 file changed, 7 insertions(+), 8 deletions(-)
fs/ntfs/inode.c +7 -8
index f7e4cbc26eaf..70745aea5106 100644
@@ -629,6 +629,13 @@ static int ntfs_read_locked_inode(struct inode *vi)
 	}
 	a = ctx->attr;
 	/* Get the standard information attribute value. */
+	if ((u8 *)a + le16_to_cpu(a->data.resident.value_offset)
+			+ le32_to_cpu(
+			a->data.resident.value_length) >
+			(u8 *)ctx->mrec + vol->mft_record_size) {
+		ntfs_error(vi->i_sb, "Corrupt attribute list in inode.");
+		goto unm_err_out;
+	}
 	si = (STANDARD_INFORMATION*)((u8*)a +
 			le16_to_cpu(a->data.resident.value_offset));
 
@@ -731,14 +738,6 @@ static int ntfs_read_locked_inode(struct inode *vi)
 				goto unm_err_out;
 			}
 		} else /* if (!a->non_resident) */ {
-			if ((u8*)a + le16_to_cpu(a->data.resident.value_offset)
-					+ le32_to_cpu(
-					a->data.resident.value_length) >
-					(u8*)ctx->mrec + vol->mft_record_size) {
-				ntfs_error(vi->i_sb, "Corrupt attribute list "
-						"in inode.");
-				goto unm_err_out;
-			}
 			/* Now copy the attribute list. */
 			memcpy(ni->attr_list, (u8*)a + le16_to_cpu(
 					a->data.resident.value_offset),
Signature · 1 line
2.30.0
Signature · 3 lines
Anton Altaparmakov <anton at tuxera.com> (replace at with @)
Lead in File System Development, Tuxera Inc., http://www.tuxera.com/
Linux NTFS maintainer
#2 lore raw
Quoted 8 lines · Anton Altaparmakov

Hi Rustam,

Thank you for the patch but it is not quite correct:

1) The first delta: yes that is a good idea to add this check but the error message is incorrect. It should say "Corrupt standard information attribute in inode." instead.

2) The second delta: The check of the attribute list attribute needs to remain, i.e. your second delta needs to be deleted.

Quoted 8 lines

Please could you address both of the above comments and then resend? Please then also add: "Acked-by: Anton Altaparmakov <[email protected]>" to the patch.

Thanks a lot in advance!

Best regards,

Anton

hi Anton, thank you for the review! I'll resend the patch!