Skip to content

Commit cc5d2b3

Browse files
mrutland-armwildea01
authored andcommitted
arm64: mm: detect bad __create_mapping uses
If a caller of __create_mapping provides a PA and VA which have different sub-page offsets, it is not clear which offset they expect to apply to the mapping, and is indicative of a bad caller. In some cases, the region we wish to map may validly have a sub-page offset in the physical and virtual addresses. For example, EFI runtime regions have 4K granularity, yet may be mapped by a 64K page kernel. So long as the physical and virtual offsets are the same, the region will be mapped at the expected VAs. Disallow calls with differing sub-page offsets, and WARN when they are encountered, so that we can detect and fix such cases. Cc: Laura Abbott <[email protected]> Acked-by: Ard Biesheuvel <[email protected]> Acked-by: Catalin Marinas <[email protected]> Reviewed-by: Steve Capper <[email protected]> Signed-off-by: Mark Rutland <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent 31ade3b commit cc5d2b3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/arm64/mm/mmu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,13 @@ static void __create_mapping(struct mm_struct *mm, pgd_t *pgd,
251251
{
252252
unsigned long addr, length, end, next;
253253

254+
/*
255+
* If the virtual and physical address don't have the same offset
256+
* within a page, we cannot map the region as the caller expects.
257+
*/
258+
if (WARN_ON((phys ^ virt) & ~PAGE_MASK))
259+
return;
260+
254261
addr = virt & PAGE_MASK;
255262
length = PAGE_ALIGN(size + (virt & ~PAGE_MASK));
256263

0 commit comments

Comments
 (0)