ntfs3: fix out-of-bounds read in ntfs_read_mft()
PATCH 1/1 ntfs3: fix out-of-bounds read in ntfs_read_mft()
ntfs_read_mft() walks the attributes of an MFT record and, for each FILE_NAME attribute, compares the resident on-disk name with the name being looked up. The only size check before the compare is rsize >= SIZEOF_ATTRIBUTE_FILENAME, which covers the fixed header up to and including name_len, but not the variable-length name that follows it.
name_len comes straight from disk and is not validated against the resident data_size. A crafted image can set name_len large while keeping data_size at the header size, so ntfs_cmp_names_cpu() reads name_len le16 characters past the end of the MFT record buffer:
BUG: KASAN: slab-out-of-bounds in ntfs_cmp_names_cpu (fs/ntfs3/upcase.c:84) Read of size 2 at addr ffff888031879c00 by task a.out ntfs_cmp_names_cpu (fs/ntfs3/upcase.c:84) ntfs_iget5 (fs/ntfs3/inode.c:209) dir_search_u (fs/ntfs3/dir.c:265) ntfs_lookup (fs/ntfs3/namei.c:85) __lookup_slow (fs/namei.c:1915) lookup_slow (fs/namei.c:1932) path_lookupat (fs/namei.c:2278) vfs_statx (fs/stat.c) vfs_fstatat (fs/stat.c) __do_sys_newfstatat (fs/stat.c)
Allocated by task:
mi_init (fs/ntfs3/record.c)
ntfs_iget5 (fs/ntfs3/inode.c)
dir_search_u (fs/ntfs3/dir.c)
ntfs_lookup (fs/ntfs3/namei.c)
Check that the name fits in the resident data before using it.
--- fs/ntfs3/inode.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/ntfs3/inode.c +5 -0
@@ -201,6 +201,11 @@ static struct inode *ntfs_read_mft(struct inode *inode, names +=1 ; fname =Add2Ptr (attr, roff); + +/* Make sure the full name fits in the resident data. */ +if (rsize <fname_full_size (fname)) + goto out; +if (fname->type ==FILE_NAME_DOS ) goto next_attr;
Signature · 1 line
2.43.0
Konstantin Komarov
maintainerQuoted 46 lines · Weiming Shi
ntfs_read_mft()walks the attributes of an MFT record and, for eachFILE_NAMEattribute, compares the resident on-disk name with the name being looked up. The only size check before the compare is rsize >=SIZEOF_ATTRIBUTE_FILENAME, which covers the fixed header up to and includingname_len, but not the variable-length name that follows it.
name_lencomes straight from disk and is not validated against the residentdata_size. A crafted image can setname_lenlarge while keepingdata_sizeat the header size, sontfs_cmp_names_cpu()readsname_lenle16 characters past the end of the MFT record buffer:BUG: KASAN: slab-out-of-bounds in ntfs_cmp_names_cpu (fs/ntfs3/upcase.c:84) Read of size 2 at addr ffff888031879c00 by task a.out ntfs_cmp_names_cpu (fs/ntfs3/upcase.c:84) ntfs_iget5 (fs/ntfs3/inode.c:209) dir_search_u (fs/ntfs3/dir.c:265) ntfs_lookup (fs/ntfs3/namei.c:85) __lookup_slow (fs/namei.c:1915) lookup_slow (fs/namei.c:1932) path_lookupat (fs/namei.c:2278) vfs_statx (fs/stat.c) vfs_fstatat (fs/stat.c) __do_sys_newfstatat (fs/stat.c)Allocated by task: mi_init (fs/ntfs3/record.c) ntfs_iget5 (fs/ntfs3/inode.c) dir_search_u (fs/ntfs3/dir.c) ntfs_lookup (fs/ntfs3/namei.c)Check that the name fits in the resident data before using it.
Fixes 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")Reported-by Xiang Mei <[email protected]>Assisted-by Claude:claude-opus-4-8Signed-off-by Weiming Shi <[email protected]>--- fs/ntfs3/inode.c | 5 +++++ 1 file changed, 5 insertions(+)fs/ntfs3/inode.c +0
-0@@ -201,6 +201,11 @@ static struct inode *ntfs_read_mft(struct inode *inode,
fs/ntfs3/inode.c static struct inode *ntfs_read_mft(struct inode *inode, · line 211
Quoted 10 lines
fs/ntfs3/inode.c +5
-0names +=1 ; fname =Add2Ptr (attr, roff); + +/* Make sure the full name fits in the resident data. */ +if (rsize <fname_full_size (fname)) + goto out; +if (fname->type ==FILE_NAME_DOS ) goto next_attr;
Hello,
Sorry for the delay.
Your patch was applied, thank you.
Regards,
Konstantin