Skip to content

Commit a4ab7de

Browse files
jpemartinsjgunthorpe
authored andcommitted
iommufd/iova_bitmap: Bounds check mapped::pages access
Dirty IOMMU hugepages reported on a base page page-size granularity can lead to an attempt to set dirty pages in the bitmap beyond the limits that are pinned. Bounds check the page index of the array we are trying to access is within the limits before we kmap() and return otherwise. While it is also a defensive check, this is also in preparation to defer setting bits (outside the mapped range) to the next iteration(s) when the pages become available. Fixes: b058ea3 ("vfio/iova_bitmap: refactor iova_bitmap_set() to better handle page boundaries") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joao Martins <[email protected]> Tested-by: Avihai Horon <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 54be6c6 commit a4ab7de

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/iommu/iommufd/iova_bitmap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ void iova_bitmap_set(struct iova_bitmap *bitmap,
409409
mapped->pgshift) + mapped->pgoff * BITS_PER_BYTE;
410410
unsigned long last_bit = (((iova + length - 1) - mapped->iova) >>
411411
mapped->pgshift) + mapped->pgoff * BITS_PER_BYTE;
412+
unsigned long last_page_idx = mapped->npages - 1;
412413

413414
do {
414415
unsigned int page_idx = cur_bit / BITS_PER_PAGE;
@@ -417,6 +418,9 @@ void iova_bitmap_set(struct iova_bitmap *bitmap,
417418
last_bit - cur_bit + 1);
418419
void *kaddr;
419420

421+
if (unlikely(page_idx > last_page_idx))
422+
break;
423+
420424
kaddr = kmap_local_page(mapped->pages[page_idx]);
421425
bitmap_set(kaddr, offset, nbits);
422426
kunmap_local(kaddr);

0 commit comments

Comments
 (0)