Skip to content

Commit 825d0b7

Browse files
liu-song-6KAGA-KOKO
authored andcommitted
x86/mm/pti: Handle unaligned address gracefully in pti_clone_pagetable()
pti_clone_pmds() assumes that the supplied address is either: - properly PUD/PMD aligned or - the address is actually mapped which means that independently of the mapping level (PUD/PMD/PTE) the next higher mapping exists. If that's not the case the unaligned address can be incremented by PUD or PMD size incorrectly. All callers supply mapped and/or aligned addresses, but for the sake of robustness it's better to handle that case properly and to emit a warning. [ tglx: Rewrote changelog and added WARN_ON_ONCE() ] Signed-off-by: Song Liu <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent a55aa89 commit 825d0b7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

arch/x86/mm/pti.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,13 +330,15 @@ pti_clone_pgtable(unsigned long start, unsigned long end,
330330

331331
pud = pud_offset(p4d, addr);
332332
if (pud_none(*pud)) {
333-
addr += PUD_SIZE;
333+
WARN_ON_ONCE(addr & ~PUD_MASK);
334+
addr = round_up(addr + 1, PUD_SIZE);
334335
continue;
335336
}
336337

337338
pmd = pmd_offset(pud, addr);
338339
if (pmd_none(*pmd)) {
339-
addr += PMD_SIZE;
340+
WARN_ON_ONCE(addr & ~PMD_MASK);
341+
addr = round_up(addr + 1, PMD_SIZE);
340342
continue;
341343
}
342344

0 commit comments

Comments
 (0)