arm64: Unmap linear alias of kernel data/bss
cover arm64: Unmap linear alias of kernel data/bss
From: Ard Biesheuvel <[email protected]>
One of the reasons the lack of randomization of the linear map on arm64 is considered problematic is the fact that bootloaders adhering to the original arm64 boot protocol may place the kernel at the base of DRAM, and therefore at the base of the non-randomized linear map. This puts a writable alias of the kernel's data and bss regions at a predictable location, removing the need for an attacker to guess where KASLR mapped the kernel.
Let's unmap this linear, writable alias entirely, so that knowing the location of the linear alias does not give write access to the kernel's data and bss regions.
Ard Biesheuvel (4):
arm64: Move fixmap page tables to end of kernel image
arm64: Map the kernel data/bss read-only in the linear map
arm64: Move the zero page to rodata
arm64: Unmap kernel data/bss entirely from the linear map
arch/arm64/include/asm/mmu.h | 2 +- arch/arm64/kernel/smp.c | 2 +- arch/arm64/kernel/vmlinux.lds.S | 5 +++ arch/arm64/mm/fixmap.c | 7 +-- arch/arm64/mm/mmu.c | 46 ++++++++++++++++++-- 5 files changed, 54 insertions(+), 8 deletions(-)
Signature · 1 line
2.52.0.457.g6b5491de43-goog
PATCH 1/4 arm64: Move fixmap page tables to end of kernel image
From: Ard Biesheuvel <[email protected]>
Move the fixmap 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.
--- arch/arm64/kernel/vmlinux.lds.S | 5 +++++ arch/arm64/mm/fixmap.c | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-)
arch/arm64/kernel/vmlinux.lds.S +5 -0
@@ -334,6 +334,11 @@ SECTIONS __pi___bss_start = __bss_start; . = ALIGN(PAGE_SIZE); + .pgdir : { + __pgdir_start = .; + *(.fixmap_bss) + } + __pi_init_pg_dir = .; . += INIT_DIR_SIZE; __pi_init_pg_end = .;
arch/arm64/mm/fixmap.c +4 -3
@@ -31,9 +31,10 @@ static_assert(NR_BM_PMD_TABLES == 1);#define BM_PTE_TABLE_IDX (addr) __BM_TABLE_IDX(addr, PMD_SHIFT) -static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __page_aligned_bss; -static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss __maybe_unused; -static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss __maybe_unused; +#define __fixmap_bss __section(".fixmap_bss") __aligned(PAGE_SIZE) +static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __fixmap_bss; +static pmd_t bm_pmd[PTRS_PER_PMD] __fixmap_bss __maybe_unused; +static pud_t bm_pud[PTRS_PER_PUD] __fixmap_bss __maybe_unused;static inline pte_t *fixmap_pte (unsigned long addr) {
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Re: [PATCH 1/4] arm64: Move fixmap page tables to end of kernel image
Quoted 22 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Move the fixmap page tables out of the BSS section, and place them at the end of the image, right before the
init_pg_dirsection 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.
Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm64/kernel/vmlinux.lds.S | 5 +++++ arch/arm64/mm/fixmap.c | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-)arch/arm64/kernel/vmlinux.lds.S +0
-0
arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 338
Quoted 5 lines
arch/arm64/kernel/vmlinux.lds.S +2
-0@@ -334,6 +334,11 @@ SECTIONS __pi___bss_start = __bss_start; . = ALIGN(PAGE_SIZE); + .pgdir : { + __pgdir_start = .;
Does __fixmap_pgdir_start with an end marker __fixmap_pgdir_end sound better ?
Quoted 24 lines
arch/arm64/kernel/vmlinux.lds.S +3
-0+ *(.fixmap_bss) + } + __pi_init_pg_dir = .; . += INIT_DIR_SIZE; __pi_init_pg_end = .;arch/arm64/mm/fixmap.c +4
-3@@ -31,9 +31,10 @@ static_assert(NR_BM_PMD_TABLES == 1);#define BM_PTE_TABLE_IDX (addr) __BM_TABLE_IDX(addr, PMD_SHIFT) -static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __page_aligned_bss; -static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss __maybe_unused; -static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss __maybe_unused; +#define __fixmap_bss __section(".fixmap_bss") __aligned(PAGE_SIZE) +static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __fixmap_bss; +static pmd_t bm_pmd[PTRS_PER_PMD] __fixmap_bss __maybe_unused; +static pud_t bm_pud[PTRS_PER_PUD] __fixmap_bss __maybe_unused;static inline pte_t *fixmap_pte (unsigned long addr) {
Re: [PATCH 1/4] arm64: Move fixmap page tables to end of kernel image
Hello Anshuman,
Quoted 28 lines · Anshuman Khandual
Quoted 24 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
Move the fixmap page tables out of the BSS section, and place them at the end of the image, right before the
init_pg_dirsection 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.
Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm64/kernel/vmlinux.lds.S | 5 +++++ arch/arm64/mm/fixmap.c | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-)arch/arm64/kernel/vmlinux.lds.S +0
-0@@ -334,6 +334,11 @@ SECTIONS __pi___bss_start = __bss_start;
Quoted 6 lines
arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 338
Quoted 3 lines
arch/arm64/kernel/vmlinux.lds.S +2
-0. = ALIGN(PAGE_SIZE); + .pgdir : { + __pgdir_start = .;Does
__fixmap_pgdir_startwith an end marker__fixmap_pgdir_endsound better ?
No. __pgdir_start covers the init_pg_dir as well. And I don't think we should be adding end markers that we do not intend to use.
Quoted 25 lines
Quoted 24 lines
arch/arm64/kernel/vmlinux.lds.S +3
-0+ *(.fixmap_bss) + } + __pi_init_pg_dir = .; . += INIT_DIR_SIZE; __pi_init_pg_end = .;arch/arm64/mm/fixmap.c +4
-3@@ -31,9 +31,10 @@ static_assert(NR_BM_PMD_TABLES == 1);#define BM_PTE_TABLE_IDX (addr) __BM_TABLE_IDX(addr, PMD_SHIFT) -static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __page_aligned_bss; -static pmd_t bm_pmd[PTRS_PER_PMD] __page_aligned_bss __maybe_unused; -static pud_t bm_pud[PTRS_PER_PUD] __page_aligned_bss __maybe_unused; +#define __fixmap_bss __section(".fixmap_bss") __aligned(PAGE_SIZE) +static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __fixmap_bss; +static pmd_t bm_pmd[PTRS_PER_PMD] __fixmap_bss __maybe_unused; +static pud_t bm_pud[PTRS_PER_PUD] __fixmap_bss __maybe_unused;static inline pte_t *fixmap_pte (unsigned long addr) {
PATCH 2/4 arm64: Map the kernel data/bss read-only in the linear map
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
On systems where the bootloader adheres to the original arm64 boot protocol, the placement of the kernel in the physical address space is highly predictable, and this makes the placement of its linear alias in the kernel virtual address space equally predictable, given the lack of randomization of the linear map.
The linear aliases of the kernel text and rodata regions are already mapped read-only, but the kernel data and bss are mapped read-write in this region in this region. This is not needed, so map them read-only as well.
Note that the statically allocated kernel page tables do need to be modifiable via the linear map, so leave these mapped read-write.
--- arch/arm64/include/asm/mmu.h | 2 +- arch/arm64/kernel/smp.c | 2 +- arch/arm64/mm/mmu.c | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-)
arch/arm64/include/asm/mmu.h +1 -1
@@ -77,7 +77,7 @@ extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, unsigned long virt, phys_addr_t size, pgprot_t prot, bool page_mappings_only);extern void *fixmap_remap_fdt (phys_addr_t dt_phys,int *size,pgprot_t prot); -extern void mark_linear_text_alias_ro (void ); +extern void remap_linear_kernel_alias (void );extern int split_kernel_leaf_mapping (unsigned long start,unsigned long end);extern void linear_map_maybe_split_to_ptes (void );
arch/arm64/kernel/smp.c +1 -1
@@ -441,7 +441,7 @@ void __init smp_cpus_done(unsigned int max_cpus)hyp_mode_check ();setup_system_features ();setup_user_features (); -mark_linear_text_alias_ro (); +remap_linear_kernel_alias (); }void __init smp_prepare_boot_cpu (void )
arch/arm64/mm/mmu.c +12 -2
@@ -1023,14 +1023,24 @@ static void __init __map_memblock(pgd_t *pgdp, phys_addr_t start, prot, early_pgtable_alloc, flags); } -void __init mark_linear_text_alias_ro (void ) +static void remap_linear_data_alias (void ) +{ +extern const u8 __pgdir_start[]; + +update_mapping_prot (__pa_symbol (__init_end), (unsigned long )lm_alias (__init_end), + (unsigned long )__pgdir_start - (unsigned long )__init_end, +PAGE_KERNEL_RO ); +} + +void __init remap_linear_kernel_alias (void ) {/* -* Remove the write permissions from the linear alias of .text/.rodata +* Remove the write permissions from the linear alias of the kernel */ update_mapping_prot (__pa_symbol (_text), (unsigned long )lm_alias (_text), (unsigned long )__init_begin - (unsigned long )_text,PAGE_KERNEL_RO ); +remap_linear_data_alias (); }#ifdef CONFIG_KFENCE
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Re: [PATCH 2/4] arm64: Map the kernel data/bss read-only in the linear map
Quoted 41 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
On systems where the bootloader adheres to the original arm64 boot protocol, the placement of the kernel in the physical address space is highly predictable, and this makes the placement of its linear alias in the kernel virtual address space equally predictable, given the lack of randomization of the linear map.
The linear aliases of the kernel text and rodata regions are already mapped read-only, but the kernel data and bss are mapped read-write in this region in this region. This is not needed, so map them read-only as well.
Note that the statically allocated kernel page tables do need to be modifiable via the linear map, so leave these mapped read-write.
Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm64/include/asm/mmu.h | 2 +- arch/arm64/kernel/smp.c | 2 +- arch/arm64/mm/mmu.c | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-)arch/arm64/include/asm/mmu.h +1
-1@@ -77,7 +77,7 @@ extern void create_pgd_mapping(struct mm_struct *mm, phys_addr_t phys, unsigned long virt, phys_addr_t size, pgprot_t prot, bool page_mappings_only);extern void *fixmap_remap_fdt (phys_addr_t dt_phys,int *size,pgprot_t prot); -extern void mark_linear_text_alias_ro (void ); +extern void remap_linear_kernel_alias (void );extern int split_kernel_leaf_mapping (unsigned long start,unsigned long end);extern void linear_map_maybe_split_to_ptes (void );arch/arm64/kernel/smp.c +0
-0
arch/arm64/kernel/smp.c void __init smp_cpus_done(unsigned int max_cpus) · line 444
Quoted 5 lines
arch/arm64/kernel/smp.c +1
-1@@ -441,7 +441,7 @@ void __init smp_cpus_done(unsigned int max_cpus)hyp_mode_check ();setup_system_features ();setup_user_features (); -mark_linear_text_alias_ro (); +remap_linear_kernel_alias ();
Both kernel text/rodat and now the bss segment are mapped via PAGE_KERNEL_RO. Hence the new name here should still have __ro at the end as well.
Quoted 10 lines
arch/arm64/kernel/smp.c +0
-0}void __init smp_prepare_boot_cpu (void )arch/arm64/mm/mmu.c +0
-0@@ -1023,14 +1023,24 @@ static void __init __map_memblock(pgd_t *pgdp, phys_addr_t start, prot, early_pgtable_alloc, flags); }
arch/arm64/mm/mmu.c static void __init __map_memblock(pgd_t *pgdp, phys_addr_t start, · line 1033
Quoted 10 lines
arch/arm64/mm/mmu.c +8
-1-void __init mark_linear_text_alias_ro (void ) +static void remap_linear_data_alias (void ) +{ +extern const u8 __pgdir_start[]; + +update_mapping_prot (__pa_symbol (__init_end), (unsigned long )lm_alias (__init_end), + (unsigned long )__pgdir_start - (unsigned long )__init_end, +PAGE_KERNEL_RO ); +}
BSS segment mapping update is split into its own helper here because it gets used later in the series. Probably would be helpful to just mention that in the commit message here.
Quoted 14 lines
arch/arm64/mm/mmu.c +4
-1+ +void __init remap_linear_kernel_alias (void ) {/* -* Remove the write permissions from the linear alias of .text/.rodata +* Remove the write permissions from the linear alias of the kernel */ update_mapping_prot (__pa_symbol (_text), (unsigned long )lm_alias (_text), (unsigned long )__init_begin - (unsigned long )_text,PAGE_KERNEL_RO ); +remap_linear_data_alias (); }#ifdef CONFIG_KFENCE
PATCH 3/4 arm64: Move the zero page to rodata
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
The zero page should contain only zero bytes, and so mapping it read-write is unnecessary. Move it to __ro_after_init instead.
--- arch/arm64/mm/mmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/mm/mmu.c +2 -1
@@ -68,7 +68,8 @@ long __section(".mmuoff.data.write") __early_cpu_boot_status;* Empty_zero_page is a special page that is used for zero-initialized data * and COW. */ -unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss; +unsigned long empty_zero_page[PAGE_SIZE /sizeof (unsigned long )] +__ro_after_init __aligned(PAGE_SIZE) ;EXPORT_SYMBOL (empty_zero_page);static DEFINE_SPINLOCK (swapper_pgdir_lock);
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Re: [PATCH 3/4] arm64: Move the zero page to rodata
Quoted 15 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
The zero page should contain only zero bytes, and so mapping it read-write is unnecessary. Move it to
__ro_after_initinstead.Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm64/mm/mmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/arm64/mm/mmu.c +0
-0
arch/arm64/mm/mmu.c long __section(".mmuoff.data.write") __early_cpu_boot_status; · line 75
Quoted 9 lines
arch/arm64/mm/mmu.c +2
-1@@ -68,7 +68,8 @@ long __section(".mmuoff.data.write") __early_cpu_boot_status;* Empty_zero_page is a special page that is used for zero-initialized data * and COW. */ -unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss; +unsigned long empty_zero_page[PAGE_SIZE /sizeof (unsigned long )] +__ro_after_init __aligned(PAGE_SIZE) ;EXPORT_SYMBOL (empty_zero_page);static DEFINE_SPINLOCK (swapper_pgdir_lock);
A small nit - could this be the first patch in the series here ? Becasue it is not related to other three patches.
Re: [PATCH 3/4] arm64: Move the zero page to rodata
Quoted 27 lines · Anshuman Khandual
Quoted 23 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
The zero page should contain only zero bytes, and so mapping it read-write is unnecessary. Move it to
__ro_after_initinstead.Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm64/mm/mmu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/arm64/mm/mmu.c +2
-1@@ -68,7 +68,8 @@ long __section(".mmuoff.data.write") __early_cpu_boot_status;* Empty_zero_page is a special page that is used for zero-initialized data * and COW. */ -unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)] __page_aligned_bss; +unsigned long empty_zero_page[PAGE_SIZE /sizeof (unsigned long )] +__ro_after_init __aligned(PAGE_SIZE) ;EXPORT_SYMBOL (empty_zero_page);
Quoted 5 lines
arch/arm64/mm/mmu.c long __section(".mmuoff.data.write") __early_cpu_boot_status; · line 75
Quoted 1 line
arch/arm64/mm/mmu.c +0
-0static DEFINE_SPINLOCK (swapper_pgdir_lock);A small nit - could this be the first patch in the series here ? Becasue it is not related to other three patches.
It is related to the other three patches: the 4th patch requires it.
Quoted 1 line
Reviewed-by Anshuman Khandual <[email protected]>
Thanks!
PATCH 4/4 arm64: Unmap kernel data/bss entirely from the linear map
In reply to Ard BiesheuvelFrom: Ard Biesheuvel <[email protected]>
The linear aliases of the kernel text and rodata are mapped read-only as well. Given that the contents of these regions are mostly identical to the version in the loadable image, mapping them read-only is a reasonable hardening measure.
Data and bss, however, are now also mapped read-only but the contents of these regions are more likely to contain data that we'd rather not leak. So let's unmap these entirely in the linear map when the kernel is running normally.
Only when going into hibernation or waking up from it do these regions need to be mapped, so take care of this using a PM notifier.
--- arch/arm64/mm/mmu.c | 35 ++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-)
arch/arm64/mm/mmu.c +32 -3
@@ -24,6 +24,7 @@#include <linux/mm.h> #include <linux/vmalloc.h> #include <linux/set_memory.h> +#include <linux/suspend.h> #include <linux/kfence.h> #include <linux/pkeys.h> #include <linux/mm_inline.h>
@@ -1024,13 +1025,13 @@ static void __init __map_memblock(pgd_t *pgdp, phys_addr_t start, prot, early_pgtable_alloc, flags); } -static void remap_linear_data_alias (void ) +static void remap_linear_data_alias (bool unmap) {extern const u8 __pgdir_start[];update_mapping_prot (__pa_symbol (__init_end), (unsigned long )lm_alias (__init_end), (unsigned long )__pgdir_start - (unsigned long )__init_end, -PAGE_KERNEL_RO ); + unmap ?__pgprot (0 ) :PAGE_KERNEL_RO ); }void __init remap_linear_kernel_alias (void )
@@ -1041,7 +1042,7 @@ void __init remap_linear_kernel_alias(void)update_mapping_prot (__pa_symbol (_text), (unsigned long )lm_alias (_text), (unsigned long )__init_begin - (unsigned long )_text,PAGE_KERNEL_RO ); -remap_linear_data_alias (); +remap_linear_data_alias (true); }#ifdef CONFIG_KFENCE
@@ -2257,3 +2258,31 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsigned long i return 0; }#endif + +#ifdef CONFIG_HIBERNATION +static int arm64_hibernate_pm_notify (struct notifier_block *nb, +unsigned long mode,void *unused) +{ +switch (mode) { +case PM_HIBERNATION_PREPARE : +case PM_RESTORE_PREPARE : +remap_linear_data_alias (false); +break ; +case PM_POST_HIBERNATION : +case PM_POST_RESTORE : +remap_linear_data_alias (true); +break ; + } +return 0 ; +} + +static struct notifier_block arm64_hibernate_pm_notifier = { + .notifier_call = arm64_hibernate_pm_notify, +}; + +static int arm64_hibernate_register_pm_notifier (void ) +{ +return register_pm_notifier (&arm64_hibernate_pm_notifier); +} +late_initcall (arm64_hibernate_register_pm_notifier); +#endif
Signature · 1 line
2.52.0.457.g6b5491de43-goog
Re: [PATCH 4/4] arm64: Unmap kernel data/bss entirely from the linear map
Quoted 7 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
The linear aliases of the kernel text and rodata are mapped read-only as well. Given that the contents of these regions are mostly identical to the version in the loadable image, mapping them read-only is a reasonable hardening measure.
Quoted 7 lines
Data and bss, however, are now also mapped read-only but the contents of these regions are more likely to contain data that we'd rather not leak. So let's unmap these entirely in the linear map when the kernel is running normally.
Only when going into hibernation or waking up from it do these regions need to be mapped, so take care of this using a PM notifier.
Just curious - why do we need them mapped while going into or coming back from the hibernation ?
Quoted 75 lines
Signed-off-by Ard Biesheuvel <[email protected]>--- arch/arm64/mm/mmu.c | 35 ++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-)arch/arm64/mm/mmu.c +32
-3@@ -24,6 +24,7 @@#include <linux/mm.h> #include <linux/vmalloc.h> #include <linux/set_memory.h> +#include <linux/suspend.h> #include <linux/kfence.h> #include <linux/pkeys.h> #include <linux/mm_inline.h> @@ -1024,13 +1025,13 @@ static void __init __map_memblock(pgd_t *pgdp, phys_addr_t start, prot, early_pgtable_alloc, flags); } -static void remap_linear_data_alias (void ) +static void remap_linear_data_alias (bool unmap) {extern const u8 __pgdir_start[];update_mapping_prot (__pa_symbol (__init_end), (unsigned long )lm_alias (__init_end), (unsigned long )__pgdir_start - (unsigned long )__init_end, -PAGE_KERNEL_RO ); + unmap ?__pgprot (0 ) :PAGE_KERNEL_RO ); }void __init remap_linear_kernel_alias (void )@@ -1041,7 +1042,7 @@ void __init remap_linear_kernel_alias(void)update_mapping_prot (__pa_symbol (_text), (unsigned long )lm_alias (_text), (unsigned long )__init_begin - (unsigned long )_text,PAGE_KERNEL_RO ); -remap_linear_data_alias (); +remap_linear_data_alias (true); }#ifdef CONFIG_KFENCE @@ -2257,3 +2258,31 @@ int arch_set_user_pkey_access(struct task_struct *tsk, int pkey, unsigned long i return 0; }#endif + +#ifdef CONFIG_HIBERNATION +static int arm64_hibernate_pm_notify (struct notifier_block *nb, +unsigned long mode,void *unused) +{ +switch (mode) { +case PM_HIBERNATION_PREPARE : +case PM_RESTORE_PREPARE : +remap_linear_data_alias (false); +break ; +case PM_POST_HIBERNATION : +case PM_POST_RESTORE : +remap_linear_data_alias (true); +break ; + } +return 0 ; +} + +static struct notifier_block arm64_hibernate_pm_notifier = { + .notifier_call = arm64_hibernate_pm_notify, +}; + +static int arm64_hibernate_register_pm_notifier (void ) +{ +return register_pm_notifier (&arm64_hibernate_pm_notifier); +} +late_initcall (arm64_hibernate_register_pm_notifier); +#endif
Re: [PATCH 4/4] arm64: Unmap kernel data/bss entirely from the linear map
Quoted 16 lines · Anshuman Khandual
Quoted 12 lines · Ard Biesheuvel
From: Ard Biesheuvel <[email protected]>
The linear aliases of the kernel text and rodata are mapped read-only as well. Given that the contents of these regions are mostly identical to the version in the loadable image, mapping them read-only is a reasonable hardening measure.
Data and bss, however, are now also mapped read-only but the contents of these regions are more likely to contain data that we'd rather not leak. So let's unmap these entirely in the linear map when the kernel is running normally.
Quoted 6 lines
Quoted 2 lines
Only when going into hibernation or waking up from it do these regions need to be mapped, so take care of this using a PM notifier.
Just curious - why do we need them mapped while going into or coming back from the hibernation ?
Because the kernel image is preserved/restored via the linear map. For some reason, it appears to be sufficient for this mapping to be read-only but unmapping it entirely results in failures to resume from hibernation.