]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ntfs: bound the attribute-list entry in ntfs_read_inode_mount()
authorBryam Vargas <hexlabsecurity@proton.me>
Sun, 7 Jun 2026 20:30:00 +0000 (20:30 +0000)
committerNamjae Jeon <linkinjeon@kernel.org>
Mon, 8 Jun 2026 13:58:05 +0000 (22:58 +0900)
The $MFT attribute-list walk in ntfs_read_inode_mount() validates each
entry only with "(u8 *)al_entry + 6 > al_end" and
"(u8 *)al_entry + le16_to_cpu(al_entry->length) > al_end", but then reads
al_entry->lowest_vcn (an __le64 at offset 8) and al_entry->mft_reference
(offset 16) -- fields beyond the 6 bytes proven in range. al_entry->length
is attacker-controlled and only required non-zero, so a short entry (e.g.
length 8) placed at the tail passes both checks while the lowest_vcn /
mft_reference reads fall past al_end.

al_end is ni->attr_list + attr_list_size (the on-disk size); the buffer is
kvzalloc(round_up(attr_list_size, SECTOR_SIZE)), so the sector rounding
usually absorbs the over-read -- but when attr_list_size is a multiple of
SECTOR_SIZE there is no slack and a crafted $MFT attribute list produces an
out-of-bounds read at mount time.

Validate the entry with ntfs_attr_list_entry_is_valid() (added in patch
1/3) before dereferencing it, matching the bound the other attribute-list
walks now use. The validator already requires the length to cover the fixed
header, which makes the separate "!al_entry->length" check redundant, so
drop it too.

Fixes: 1e9ea7e04472 ("Revert "fs: Remove NTFS classic"")
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/ntfs/inode.c

index 8a7798d7f5fc0ce730b4c317d15992d6c988ce9b..2f2634baa285583bfee5eaec47b1baeab3125c16 100644 (file)
@@ -1997,10 +1997,7 @@ int ntfs_read_inode_mount(struct inode *vi)
                        /* Catch the end of the attribute list. */
                        if ((u8 *)al_entry == al_end)
                                goto em_put_err_out;
-                       if (!al_entry->length)
-                               goto em_put_err_out;
-                       if ((u8 *)al_entry + 6 > al_end ||
-                           (u8 *)al_entry + le16_to_cpu(al_entry->length) > al_end)
+                       if (!ntfs_attr_list_entry_is_valid(al_entry, al_end))
                                goto em_put_err_out;
                        next_al_entry = (struct attr_list_entry *)((u8 *)al_entry +
                                        le16_to_cpu(al_entry->length));