Skip to content

Commit

Permalink
dma-buf: heaps: Fix off-by-one in CMA heap fault handler
Browse files Browse the repository at this point in the history
commit ea5ff5d upstream.

Until VM_DONTEXPAND was added in commit 1c1914d ("dma-buf: heaps:
Don't track CMA dma-buf pages under RssFile") it was possible to obtain
a mapping larger than the buffer size via mremap and bypass the overflow
check in dma_buf_mmap_internal. When using such a mapping to attempt to
fault past the end of the buffer, the CMA heap fault handler also checks
the fault offset against the buffer size, but gets the boundary wrong by
1. Fix the boundary check so that we don't read off the end of the pages
array and insert an arbitrary page in the mapping.

Reported-by: Xingyu Jin <[email protected]>
Fixes: a5d2d29 ("dma-buf: heaps: Move heap-helper logic into the cma_heap implementation")
Cc: [email protected] # Applicable >= 5.10. Needs adjustments only for 5.10.
Signed-off-by: T.J. Mercier <[email protected]>
Acked-by: John Stultz <[email protected]>
Signed-off-by: Sumit Semwal <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
T.J. Mercier authored and gregkh committed Sep 18, 2024
1 parent 7333381 commit e790508
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/dma-buf/heaps/cma_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static vm_fault_t cma_heap_vm_fault(struct vm_fault *vmf)
struct vm_area_struct *vma = vmf->vma;
struct cma_heap_buffer *buffer = vma->vm_private_data;

if (vmf->pgoff > buffer->pagecount)
if (vmf->pgoff >= buffer->pagecount)
return VM_FAULT_SIGBUS;

return vmf_insert_pfn(vma, vmf->address, page_to_pfn(buffer->pages[vmf->pgoff]));
Expand Down

0 comments on commit e790508

Please sign in to comment.