Repository navigation
Conversation
struct ane_bo keeps its page count in a u32, and ane_iommu_map_pages(), ane_iommu_map_each() and the unmap paths computed sizes and offsets as `npages << ane->shift` and `i << ane->shift`. Both sides are 32-bit, so with 16 KiB pages a page count of 2^18 or more wraps. A buffer of 2^18 + 1 pages reserved a 16 KiB drm_mm node, while the default batch path (ane_iommu_map_batch(), which already used size_t) mapped all 4 GiB + 16 KiB from that node's start, over IOVA the allocator could hand to other buffers; the per-page path mapped page i at the IOVA of a much lower page. DRM_IOCTL_ANE_BO_INIT accepted any non-zero u64 size from any client that can open the accel node, and round_up() of a size near U64_MAX wrapped to 0. Record the size of the range ane->mm hands out (below 4 GiB) at domain init and return -E2BIG from BO_INIT for a larger buffer, before anything is allocated. A buffer that cannot be mapped whole is never created, and its page count always fits the u32. Also do every page-to-IOVA shift in u64, as ane_iommu_map_batch() already did, so the arithmetic stays right if the limit ever changes. Verified with a host harness under ASan and UBSan: the old expressions give 0 for a 4 GiB buffer and wrap page offsets past 2^18 pages; with the new check sizes up to the aperture are accepted with exact page counts and no truncation, and aperture+1, 4 GiB, U64_MAX and sizes that wrap round_up() return -E2BIG, for four aperture shapes. The harness models the patched expressions; the kernel object was not built here, and no ANE hardware was used. Signed-off-by: Alyx-ML <256263590+Alyx-ML@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of the #2755 split. Draft until it has a run on a Mac (the last Evidence line says which).
Summary
Evidence
from its start, over IOVA that belongs to other buffers. A host harness (ASan, UBSan) shows the
old expressions give 0 for 4 GiB.
aperture + 1, 4 GiB, U64_MAX and sizes that wrap
round_up(). Build and KUnit (ane-boot,ane-transport,ane-pm): passed, Apple build and KUnit.buffers are still accepted.
Merge Danger
Door: two-way
Blast Radius: ANE allocation
Only a buffer larger than the engine can map is refused.
Assisted-by: LLM (Claude:Opus 5.5)