[PATCH] arm: dma-mapping: don't call folio_next() beyond the requested region

Marek Szyprowski m.szyprowski at samsung.com
Thu Aug 10 02:19:55 PDT 2023


Add a check for the non-zero offset case to avoid calling folio_next()
beyond the requested region and relying on its parameters.

Fixes: cc24e9c0895c ("arm: implement the new page table range API")
Signed-off-by: Marek Szyprowski <m.szyprowski at samsung.com>
Suggested-by: Matthew Wilcox <willy at infradead.org>
---
 arch/arm/mm/dma-mapping.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index 0474840224d9..6c952d6899f2 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -715,6 +715,8 @@ static void __dma_page_dev_to_cpu(struct page *page, unsigned long off,
 
 		if (offset) {
 			left -= folio_size(folio) - offset;
+			if (left <= 0)
+				return;
 			folio = folio_next(folio);
 		}
 
-- 
2.34.1




More information about the linux-arm-kernel mailing list