Skip to contentSkip to conversation

ntfs: check for valid standard information attribute

PATCH Applied Rustam Kovhaev 3 participants 5 messages Feb 17, 2021 – Feb 22, 2021 NTFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ntfs: check for valid standard information attribute

we should check for valid STANDARD_INFORMATION attribute offset and length before trying to access it

---
 fs/ntfs/inode.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/ntfs/inode.c +6 -0
index f7e4cbc26eaf..be4ff9386ec0 100644
@@ -629,6 +629,12 @@ 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 standard information attribute in inode.");
+		goto unm_err_out;
+	}
 	si = (STANDARD_INFORMATION*)((u8*)a +
 			le16_to_cpu(a->data.resident.value_offset));
 
Signature · 1 line
2.30.0
#1 lore raw

Hi Andrew,

Can you please push this one upstream? Thanks a lot in advance!

Best regards,

Anton

Quoted 33 lines · Rustam Kovhaev

we should check for valid STANDARD_INFORMATION attribute offset and length before trying to access it

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

1 file changed, 6 insertions(+)
fs/ntfs/inode.c +6 -0
index f7e4cbc26eaf..be4ff9386ec0 100644
@@ -629,6 +629,12 @@ 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 standard information attribute in inode.");
+		goto unm_err_out;
+	}
 	si = (STANDARD_INFORMATION*)((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 3 lines · On Fri, 19 Feb 2021 01:54:30 +0000 Anton Altaparmakov <[email protected]> wrote:

Hi Andrew,

Can you please push this one upstream? Thanks a lot in advance!

The changelog is a bit brief...

Quoted 5 lines
Quoted 5 lines · Rustam Kovhaev

we should check for valid STANDARD_INFORMATION attribute offset and length before trying to access it

It's a kernel a crash and I assume it results from mounting a corrupted filesystem?

I think it's worth a cc:stable, yes?

#3 lore raw

Hi Andrew,

Sorry for the delay in replying.

Quoted 9 lines · Andrew Morton
Quoted 3 lines · On Fri, 19 Feb 2021 01:54:30 +0000 Anton Altaparmakov <[email protected]> wrote:

Hi Andrew,

Can you please push this one upstream? Thanks a lot in advance!

The changelog is a bit brief...

Yes you are right it is a bit brief. I guess I thought the syzkaller link was sufficient... Rustam would you like to resubmit with an improved/extended description?

Quoted 9 lines
Quoted 4 lines
Quoted 4 lines · Rustam Kovhaev

we should check for valid STANDARD_INFORMATION attribute offset and length before trying to access it

It's a kernel a crash and I assume it results from mounting a corrupted filesystem?

I think it's worth a cc:stable, yes?

The problem is an invalid memory access due to corrupt on-disk metadata.

The issue with NTFS is that it is effectively a relational database so it is full of "struct X, field A" contains offset to "struct Y" so you get: "&struct Y = &struct X + X->A" and if the value of A is corrupt on-disk then your Y pointer is now pointing to random memory.

The patch fixes one such place by validating that Y pointer is within bounds of the structure/buffer it is in.

So I guess this could be worth a cc:stable? I guess we can add it and Greg / others can decide whether to put it into stable or not... Rustam when resubmitting with better description, please also add the "Cc: [email protected]" line together with the "Signed-off-by", etc lines (note no need to actually put this in CC: field of the email iteslf).

Best regards,

Anton

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
#4 lore raw
Quoted 1 line · Anton Altaparmakov

Rustam would you like to resubmit with an improved/extended description?

sure thing, no problem!

Quoted 4 lines

when resubmitting with better description, please also add the "Cc: [email protected]" line together with the "Signed-off-by", etc lines (note no need to actually put this in CC: field of the email iteslf).

i will do that, thanks Andrew and Anton