Skip to content

Commit d8073dc

Browse files
Alexander GordeevVasily Gorbik
authored andcommitted
s390/mm: Allow large pages only for aligned physical addresses
Do not allow creation of large pages against physical addresses, which itself are not aligned on the correct boundary. Failure to do so might lead to referencing wrong memory as result of the way DAT works. Fixes: c98d2ec ("s390/mm: Uncouple physical vs virtual address spaces") Reviewed-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent b01b815 commit d8073dc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/s390/boot/vmem.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,21 @@ static bool large_allowed(enum populate_mode mode)
267267
static bool can_large_pud(pud_t *pu_dir, unsigned long addr, unsigned long end,
268268
enum populate_mode mode)
269269
{
270+
unsigned long size = end - addr;
271+
270272
return machine.has_edat2 && large_allowed(mode) &&
271-
IS_ALIGNED(addr, PUD_SIZE) && (end - addr) >= PUD_SIZE;
273+
IS_ALIGNED(addr, PUD_SIZE) && (size >= PUD_SIZE) &&
274+
IS_ALIGNED(_pa(addr, size, mode), PUD_SIZE);
272275
}
273276

274277
static bool can_large_pmd(pmd_t *pm_dir, unsigned long addr, unsigned long end,
275278
enum populate_mode mode)
276279
{
280+
unsigned long size = end - addr;
281+
277282
return machine.has_edat1 && large_allowed(mode) &&
278-
IS_ALIGNED(addr, PMD_SIZE) && (end - addr) >= PMD_SIZE;
283+
IS_ALIGNED(addr, PMD_SIZE) && (size >= PMD_SIZE) &&
284+
IS_ALIGNED(_pa(addr, size, mode), PMD_SIZE);
279285
}
280286

281287
static void pgtable_pte_populate(pmd_t *pmd, unsigned long addr, unsigned long end,

0 commit comments

Comments
 (0)