Skip to content

Commit cb3161d

Browse files
mjbommargregkh
authored andcommitted
ntfs3: bound to_move in indx_insert_into_root before hdr_insert_head
commit 9b6926a upstream. indx_insert_into_root() promotes a full resident $INDEX_ROOT into $INDEX_ALLOCATION and copies all non-last resident root entries into a newly allocated INDEX_BUFFER via hdr_insert_head(). The source byte count 'to_move' is summed from the on-disk resident entry sizes and is independent of the destination buffer size, which comes from root->index_block_size (via indx->index_bits). A crafted NTFS image that keeps a valid, full resident root but shrinks root->index_block_size down to 512 after the root has been populated makes hdr_insert_head() memcpy attacker-controlled resident entry bytes past the end of the kmalloc(1u << indx->index_bits) allocation returned by indx_new(). For a 512-byte destination and a resident root whose non-last entries total 560 bytes, the memcpy overruns by 120 bytes and a following memmove extends the highest written offset to 136 bytes past the allocation. The overflow bytes are a direct copy of on-disk entries (via kmemdup), so they are fully attacker-controlled. The write is reachable from unprivileged open(O_CREAT) on a mounted crafted NTFS image: a single sufficiently long create in a directory whose resident root is already full forces root promotion and triggers the copy. This is a controlled out-of-bounds write of 120-136 bytes past a kmalloc(index_block_size) allocation, with attacker-controlled content. It is a bounded adjacent-heap corruption primitive; it is not an arbitrary-address write. Successful exploitation into a named victim object depends on the surrounding slab layout. Reject the copy at the sink. The destination's INDEX_HDR already reports hdr_total (the payload capacity of the new buffer) and hdr_used (the bytes already consumed by the terminal END entry installed by indx_new()); require that to_move fits in the remaining payload before calling hdr_insert_head(). On mismatch, fail with -EINVAL and mark the filesystem as having a detected on-disk inconsistency, which is the same behaviour as the surrounding validation in this function. Fixes: 82cae26 ("fs/ntfs3: Add initialization of super block") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7972df4 commit cb3161d

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

fs/ntfs3/index.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,22 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,
17301730
hdr_used = le32_to_cpu(hdr->used);
17311731
hdr_total = le32_to_cpu(hdr->total);
17321732

1733+
/*
1734+
* The destination INDEX_BUFFER has 'hdr_total' bytes of payload
1735+
* available after the header, of which 'hdr_used' are already
1736+
* consumed by the single terminal END entry installed by
1737+
* indx_new(). A crafted image can present a resident root whose
1738+
* non-last entries (summing to 'to_move') exceed what fits in
1739+
* this buffer; copying them unchecked would overrun the
1740+
* kmalloc(1u << indx->index_bits) allocation backing the new
1741+
* buffer. Reject the copy in that case.
1742+
*/
1743+
if (to_move > hdr_total - hdr_used) {
1744+
err = -EINVAL;
1745+
ntfs_set_state(sbi, NTFS_DIRTY_ERROR);
1746+
goto out_put_n;
1747+
}
1748+
17331749
/* Copy root entries into new buffer. */
17341750
hdr_insert_head(hdr, re, to_move);
17351751

0 commit comments

Comments
 (0)