Skip to content

Commit cdcda0d

Browse files
kishonChristoph Hellwig
authored andcommitted
dma-direct: fix data truncation in dma_direct_get_required_mask()
The upper 32-bit physical address gets truncated inadvertently when dma_direct_get_required_mask() invokes phys_to_dma_direct(). This results in dma_addressing_limited() return incorrect value when used in platforms with LPAE enabled. Fix it here by explicitly type casting 'max_pfn' to phys_addr_t in order to prevent overflow of intermediate value while evaluating '(max_pfn - 1) << PAGE_SHIFT'. Signed-off-by: Kishon Vijay Abraham I <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent f5e94d1 commit cdcda0d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/dma/direct.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ static inline struct page *dma_direct_to_page(struct device *dev,
3939

4040
u64 dma_direct_get_required_mask(struct device *dev)
4141
{
42-
u64 max_dma = phys_to_dma_direct(dev, (max_pfn - 1) << PAGE_SHIFT);
42+
phys_addr_t phys = (phys_addr_t)(max_pfn - 1) << PAGE_SHIFT;
43+
u64 max_dma = phys_to_dma_direct(dev, phys);
4344

4445
return (1ULL << (fls64(max_dma) - 1)) * 2 - 1;
4546
}

0 commit comments

Comments
 (0)