Skip to content

Commit 53c87e8

Browse files
Petr TesarikChristoph Hellwig
authored andcommitted
swiotlb: fix out-of-bounds TLB allocations with CONFIG_SWIOTLB_DYNAMIC
Limit the free list length to the size of the IO TLB. Transient pool can be smaller than IO_TLB_SEGSIZE, but the free list is initialized with the assumption that the total number of slots is a multiple of IO_TLB_SEGSIZE. As a result, swiotlb_area_find_slots() may allocate slots past the end of a transient IO TLB buffer. Reported-by: Niklas Schnelle <[email protected]> Closes: https://lore.kernel.org/linux-iommu/[email protected]/ Fixes: 79636ca ("swiotlb: if swiotlb is full, fall back to a transient memory pool") Cc: [email protected] Signed-off-by: Petr Tesarik <[email protected]> Reviewed-by: Halil Pasic <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent a409d96 commit 53c87e8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/dma/swiotlb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,8 @@ static void swiotlb_init_io_tlb_pool(struct io_tlb_pool *mem, phys_addr_t start,
283283
}
284284

285285
for (i = 0; i < mem->nslabs; i++) {
286-
mem->slots[i].list = IO_TLB_SEGSIZE - io_tlb_offset(i);
286+
mem->slots[i].list = min(IO_TLB_SEGSIZE - io_tlb_offset(i),
287+
mem->nslabs - i);
287288
mem->slots[i].orig_addr = INVALID_PHYS_ADDR;
288289
mem->slots[i].alloc_size = 0;
289290
}

0 commit comments

Comments
 (0)