[PATCH] powerpc/iommu: avoid derefence before pointer check

Subsystems: linux for powerpc (32-bit and 64-bit), the rest

STALE2875d

2 messages, 2 authors, 2018-09-20 · open the first message on its own page

[PATCH] powerpc/iommu: avoid derefence before pointer check

From: Breno Leitao <leitao@debian.org>
Date: 2018-08-21 18:44:57

The tbl pointer is being derefenced by IOMMU_PAGE_SIZE prior the check if
it is not NULL.

Just moving the dereference code to after the check, where there will be
guarantee that 'tbl' will not be NULL.

CC: Alistair Popple <redacted>
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 arch/powerpc/kernel/iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/powerpc/kernel/iommu.c b/arch/powerpc/kernel/iommu.c
index af7a20dc6e09..80b6caaa9b92 100644
--- a/arch/powerpc/kernel/iommu.c
+++ b/arch/powerpc/kernel/iommu.c
@@ -785,9 +785,9 @@ dma_addr_t iommu_map_page(struct device *dev, struct iommu_table *tbl,
 
 	vaddr = page_address(page) + offset;
 	uaddr = (unsigned long)vaddr;
-	npages = iommu_num_pages(uaddr, size, IOMMU_PAGE_SIZE(tbl));
 
 	if (tbl) {
+		npages = iommu_num_pages(uaddr, size, IOMMU_PAGE_SIZE(tbl));
 		align = 0;
 		if (tbl->it_page_shift < PAGE_SHIFT && size >= PAGE_SIZE &&
 		    ((unsigned long)vaddr & ~PAGE_MASK) == 0)
-- 
2.16.3

Re: powerpc/iommu: avoid derefence before pointer check

From: Michael Ellerman <hidden>
Date: 2018-09-20 04:21:00

On Tue, 2018-08-21 at 18:44:48 UTC, Breno Leitao wrote:
The tbl pointer is being derefenced by IOMMU_PAGE_SIZE prior the check if
it is not NULL.

Just moving the dereference code to after the check, where there will be
guarantee that 'tbl' will not be NULL.

CC: Alistair Popple <redacted>
Signed-off-by: Breno Leitao <leitao@debian.org>
Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/984ecdd68de0fa1f63ce205d6c19ef

cheers
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help