All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ntfs: Fix validity check for file name attribute
@ 2021-06-14  5:05 ` Desmond Cheong Zhi Xi
  0 siblings, 0 replies; 12+ messages in thread
From: Desmond Cheong Zhi Xi @ 2021-06-14  5:05 UTC (permalink / raw)
  To: anton
  Cc: Desmond Cheong Zhi Xi, linux-ntfs-dev, linux-kernel, skhan,
	gregkh, linux-kernel-mentees, syzbot+213ac8bb98f7f4420840

When checking the file name attribute, we want to ensure that it fits
within the bounds of ATTR_RECORD. To do this, we should check
that (attr record + file name offset + file name length) < (attr
record + attr record length).

However, the original check did not include the file name offset in
the calculation. This means that corrupted on-disk metadata might not
caught by the incorrect file name check, and lead to an invalid memory
access.

An example can be seen in the crash report of a memory corruption
error found by Syzbot:
https://syzkaller.appspot.com/bug?id=a1a1e379b225812688566745c3e2f7242bffc246

Adding the file name offset to the validity check fixes this error and
passes the Syzbot reproducer test.

Reported-by: syzbot+213ac8bb98f7f4420840@syzkaller.appspotmail.com
Tested-by: syzbot+213ac8bb98f7f4420840@syzkaller.appspotmail.com
Signed-off-by: Desmond Cheong Zhi Xi <desmondcheongzx@gmail.com>
---
 fs/ntfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c
index f5c058b3192c..4474adb393ca 100644
--- a/fs/ntfs/inode.c
+++ b/fs/ntfs/inode.c
@@ -477,7 +477,7 @@ static int ntfs_is_extended_system_file(ntfs_attr_search_ctx *ctx)
 		}
 		file_name_attr = (FILE_NAME_ATTR*)((u8*)attr +
 				le16_to_cpu(attr->data.resident.value_offset));
-		p2 = (u8*)attr + le32_to_cpu(attr->data.resident.value_length);
+		p2 = (u8 *)file_name_attr + le32_to_cpu(attr->data.resident.value_length);
 		if (p2 < (u8*)attr || p2 > p)
 			goto err_corrupt_attr;
 		/* This attribute is ok, but is it in the $Extend directory? */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-07-29 11:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-14  5:05 [PATCH] ntfs: Fix validity check for file name attribute Desmond Cheong Zhi Xi
2021-06-14  5:05 ` Desmond Cheong Zhi Xi
2021-06-28  2:45 ` Desmond Cheong Zhi Xi
2021-06-28  2:45   ` Desmond Cheong Zhi Xi
2021-06-28  9:22   ` Anton Altaparmakov
2021-06-28  9:22     ` Anton Altaparmakov
2021-06-28  9:22 ` Anton Altaparmakov
2021-06-28  9:22   ` Anton Altaparmakov
2021-07-29  8:31 ` Rolf Eike Beer
2021-07-29  8:31   ` Rolf Eike Beer
2021-07-29 11:56   ` Desmond Cheong Zhi Xi
2021-07-29 11:56     ` Desmond Cheong Zhi Xi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.