Skip to content

Commit 92bbd16

Browse files
committed
arm64: mmu: Place guard page after mapping of kernel image
The vast majority of virtual allocations in the vmalloc region are followed by a guard page, which can help to avoid overruning on vma into another, which may map a read-sensitive device. This patch adds a guard page to the end of the kernel image mapping (i.e. following the data/bss segments). Cc: Mark Rutland <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Signed-off-by: Will Deacon <[email protected]>
1 parent a3287c4 commit 92bbd16

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

arch/arm64/mm/mmu.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ void mark_rodata_ro(void)
496496

497497
static void __init map_kernel_segment(pgd_t *pgd, void *va_start, void *va_end,
498498
pgprot_t prot, struct vm_struct *vma,
499-
int flags)
499+
int flags, unsigned long vm_flags)
500500
{
501501
phys_addr_t pa_start = __pa_symbol(va_start);
502502
unsigned long size = va_end - va_start;
@@ -507,10 +507,13 @@ static void __init map_kernel_segment(pgd_t *pgd, void *va_start, void *va_end,
507507
__create_pgd_mapping(pgd, pa_start, (unsigned long)va_start, size, prot,
508508
early_pgtable_alloc, flags);
509509

510+
if (!(vm_flags & VM_NO_GUARD))
511+
size += PAGE_SIZE;
512+
510513
vma->addr = va_start;
511514
vma->phys_addr = pa_start;
512515
vma->size = size;
513-
vma->flags = VM_MAP;
516+
vma->flags = VM_MAP | vm_flags;
514517
vma->caller = __builtin_return_address(0);
515518

516519
vm_area_add_early(vma);
@@ -541,14 +544,15 @@ static void __init map_kernel(pgd_t *pgd)
541544
* Only rodata will be remapped with different permissions later on,
542545
* all other segments are allowed to use contiguous mappings.
543546
*/
544-
map_kernel_segment(pgd, _text, _etext, text_prot, &vmlinux_text, 0);
547+
map_kernel_segment(pgd, _text, _etext, text_prot, &vmlinux_text, 0,
548+
VM_NO_GUARD);
545549
map_kernel_segment(pgd, __start_rodata, __inittext_begin, PAGE_KERNEL,
546-
&vmlinux_rodata, NO_CONT_MAPPINGS);
550+
&vmlinux_rodata, NO_CONT_MAPPINGS, VM_NO_GUARD);
547551
map_kernel_segment(pgd, __inittext_begin, __inittext_end, text_prot,
548-
&vmlinux_inittext, 0);
552+
&vmlinux_inittext, 0, VM_NO_GUARD);
549553
map_kernel_segment(pgd, __initdata_begin, __initdata_end, PAGE_KERNEL,
550-
&vmlinux_initdata, 0);
551-
map_kernel_segment(pgd, _data, _end, PAGE_KERNEL, &vmlinux_data, 0);
554+
&vmlinux_initdata, 0, VM_NO_GUARD);
555+
map_kernel_segment(pgd, _data, _end, PAGE_KERNEL, &vmlinux_data, 0, 0);
552556

553557
if (!pgd_val(*pgd_offset_raw(pgd, FIXADDR_START))) {
554558
/*

0 commit comments

Comments
 (0)