[PATCH] x86/mm/pti: in pti_clone_pgtable(), increase addr properly

From: Song Liu
Date: Tue Aug 20 2019 - 02:59:47 EST


Before 32-bit support, pti_clone_pmds() always adds PMD_SIZE to addr.
This behavior changes after the 32-bit support: pti_clone_pgtable()
increases addr by PUD_SIZE for pud_none(*pud) case, and increases addr by
PMD_SIZE for pmd_none(*pmd) case. However, this is not accurate because
addr may not be PUD_SIZE/PMD_SIZE aligned.

Fix this issue by properly rounding up addr to next PUD_SIZE/PMD_SIZE
in these two cases.

Cc: stable@xxxxxxxxxxxxxxx # v4.19+
Fixes: 16a3fe634f6a ("x86/mm/pti: Clone kernel-image on PTE level for 32 bi=
t")
Signed-off-by: Song Liu <songliubraving@xxxxxx>
Cc: Joerg Roedel <jroedel@xxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Cc: Andy Lutomirski <luto@xxxxxxxxxx>
Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
---
arch/x86/mm/pti.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index b196524759ec..1337494e22ef 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -330,13 +330,13 @@ pti_clone_pgtable(unsigned long start, unsigned long =
end,

pud =3D pud_offset(p4d, addr);
if (pud_none(*pud)) {
- addr +=3D PUD_SIZE;
+ addr =3D round_up(addr + 1, PUD_SIZE);
continue;
}

pmd =3D pmd_offset(pud, addr);
if (pmd_none(*pmd)) {
- addr +=3D PMD_SIZE;
+ addr =3D round_up(addr + 1, PMD_SIZE);
continue;
}

--
2.17.1