Skip to content

Commit ddd63c8

Browse files
Alexander Gordeevhcahca
authored andcommitted
s390/kasan: fix large PMD pages address alignment check
It is currently possible to initialize a large PMD page when the address is not aligned on page boundary. Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com> Reviewed-by: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
1 parent c42257d commit ddd63c8

1 file changed

Lines changed: 20 additions & 21 deletions

File tree

‎arch/s390/mm/kasan_init.c‎

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ static void __init kasan_early_pgtable_populate(unsigned long address,
107107
sgt_prot &= ~_SEGMENT_ENTRY_NOEXEC;
108108
}
109109

110+
/*
111+
* The first 1MB of 1:1 mapping is mapped with 4KB pages
112+
*/
110113
while (address < end) {
111114
pg_dir = pgd_offset_k(address);
112115
if (pgd_none(*pg_dir)) {
@@ -157,30 +160,26 @@ static void __init kasan_early_pgtable_populate(unsigned long address,
157160

158161
pm_dir = pmd_offset(pu_dir, address);
159162
if (pmd_none(*pm_dir)) {
160-
if (mode == POPULATE_ZERO_SHADOW &&
161-
IS_ALIGNED(address, PMD_SIZE) &&
163+
if (IS_ALIGNED(address, PMD_SIZE) &&
162164
end - address >= PMD_SIZE) {
163-
pmd_populate(&init_mm, pm_dir,
164-
kasan_early_shadow_pte);
165-
address = (address + PMD_SIZE) & PMD_MASK;
166-
continue;
167-
}
168-
/* the first megabyte of 1:1 is mapped with 4k pages */
169-
if (has_edat && address && end - address >= PMD_SIZE &&
170-
mode != POPULATE_ZERO_SHADOW) {
171-
void *page;
172-
173-
if (mode == POPULATE_ONE2ONE) {
174-
page = (void *)address;
175-
} else {
176-
page = kasan_early_alloc_segment();
177-
memset(page, 0, _SEGMENT_SIZE);
165+
if (mode == POPULATE_ZERO_SHADOW) {
166+
pmd_populate(&init_mm, pm_dir, kasan_early_shadow_pte);
167+
address = (address + PMD_SIZE) & PMD_MASK;
168+
continue;
169+
} else if (has_edat && address) {
170+
void *page;
171+
172+
if (mode == POPULATE_ONE2ONE) {
173+
page = (void *)address;
174+
} else {
175+
page = kasan_early_alloc_segment();
176+
memset(page, 0, _SEGMENT_SIZE);
177+
}
178+
pmd_val(*pm_dir) = __pa(page) | sgt_prot;
179+
address = (address + PMD_SIZE) & PMD_MASK;
180+
continue;
178181
}
179-
pmd_val(*pm_dir) = __pa(page) | sgt_prot;
180-
address = (address + PMD_SIZE) & PMD_MASK;
181-
continue;
182182
}
183-
184183
pt_dir = kasan_early_pte_alloc();
185184
pmd_populate(&init_mm, pm_dir, pt_dir);
186185
} else if (pmd_large(*pm_dir)) {

0 commit comments

Comments
 (0)