Re: [PATCH v2] ntfs: validate usa_ofs before preserving the update sequence number

Hyunchul Lee <[email protected]>
Newsgroups org.kernel.vger.linux-fsdevel,org.kernel.vger.linux-kernel
Message-ID <CANFS6bZBHLNZCONECcnns8KgiBsBmJpAmHe5wQRFHfDsgWb_kg@mail.gmail.com>
2026년 8월 20일 (목) 오후 3:42, Dennis Tighe <[email protected]>님이 작성:
>
> When ntfs_mft_record_alloc() reuses a free mft record it reads the old
> update sequence number straight from the on-disk record:
>
>     usn = *(__le16 *)((u8 *)m + le16_to_cpu(m->usa_ofs));
>
> Here m points into the raw $MFT page-cache folio, which still holds
> unvalidated, MST-protected bytes: the folio is read by a plain
> iomap_read_folio() and neither post_read_mst_fixup() nor
> ntfs_mft_record_check() has run on it (both work on private copies).
> m->usa_ofs is therefore an untrusted u16, and a corrupted record can put
> it past the end of the record so the two-byte read lands outside the
> folio.  Reading such a record while creating a file gives, under KASAN:
>
>   BUG: KASAN: use-after-free in ntfs_mft_record_alloc+...
>   Read of size 2 at addr ...
>    ntfs_mft_record_alloc -> __ntfs_create -> ntfs_create -> path_openat
>
> Only preserve the old update sequence number when usa_ofs is even and in
> range, mirroring the check ntfs_mft_record_check() already applies;
> otherwise leave usn zero, which the existing restore below skips.
>
> Fixes: 495e90fa3348 ("ntfs: update attrib operations")
> Assisted-by: Claude:claude-opus-4-8
> Signed-off-by: Dennis Tighe <[email protected]>

Looks good to me.

Reviewed-by: Hyunchul Lee <[email protected]>

-- 
Thanks,
Hyunchul
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.