Skip to content

Commit 382a03e

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64: Move fixmap and kasan page tables to end of kernel image
Move the fixmap and kasan page tables out of the BSS section, and place them at the end of the image, right before the init_pg_dir section where some of the other statically allocated page tables live. These page tables are currently the only data objects in vmlinux that are meant to be accessed via the kernel image's linear alias, and so placing them together allows the remainder of the data/bss section to be remapped read-only or unmapped entirely. Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Will Deacon <will@kernel.org>
1 parent 28becb2 commit 382a03e

4 files changed

Lines changed: 13 additions & 5 deletions

File tree

arch/arm64/include/asm/mmu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#ifndef __ASSEMBLER__
1515

16+
#define __pgtbl_bss __section(".pgdir.bss") __aligned(PAGE_SIZE)
17+
1618
#include <linux/refcount.h>
1719
#include <asm/cpufeature.h>
1820

arch/arm64/kernel/vmlinux.lds.S

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,15 @@ SECTIONS
349349
_edata = .;
350350

351351
/* start of zero-init region */
352-
BSS_SECTION(SBSS_ALIGN, 0, 0)
352+
BSS_SECTION(SBSS_ALIGN, 0, PAGE_SIZE)
353353
__pi___bss_start = __bss_start;
354354

355+
/* fixmap BSS starts here - preceding data/BSS is omitted from the linear map */
356+
.pgdir.bss (NOLOAD) : ALIGN(PAGE_SIZE) {
357+
*(.pgdir.bss)
358+
}
359+
ASSERT(ADDR(.pgdir.bss) == __bss_stop, ".pgdir.bss must follow BSS")
360+
355361
. = ALIGN(PAGE_SIZE);
356362
__pi_init_pg_dir = .;
357363
. += INIT_DIR_SIZE;

arch/arm64/mm/fixmap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ static_assert(NR_BM_PMD_TABLES == 1);
3131

3232
#define BM_PTE_TABLE_IDX(addr) __BM_TABLE_IDX(addr, PMD_SHIFT)
3333

34-
static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __page_aligned_bss;
35-
static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss __maybe_unused;
36-
static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss __maybe_unused;
34+
static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __pgtbl_bss;
35+
static pmd_t bm_pmd[PTRS_PER_PMD] __pgtbl_bss __maybe_unused;
36+
static pud_t bm_pud[PTRS_PER_PUD] __pgtbl_bss __maybe_unused;
3737

3838
static inline pte_t *fixmap_pte(unsigned long addr)
3939
{

arch/arm64/mm/kasan_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ asmlinkage void __init kasan_early_init(void)
214214
* shadow pud_t[]/p4d_t[], which could end up getting corrupted
215215
* when the linear region is mapped.
216216
*/
217-
static pte_t tbl[PTRS_PER_PTE] __page_aligned_bss;
217+
static pte_t tbl[PTRS_PER_PTE] __pgtbl_bss;
218218
pgd_t *pgdp = pgd_offset_k(KASAN_SHADOW_START);
219219

220220
set_pgd(pgdp, __pgd(__pa_symbol(tbl) | PGD_TYPE_TABLE));

0 commit comments

Comments
 (0)