Skip to content

Commit

Permalink
mark kernel_set_to_readonly as __ro_after_init
Browse files Browse the repository at this point in the history
This change was extracted from PaX where it's part of KERNEXEC.

Signed-off-by: Daniel Micay <danielmicay@gmail.com>
  • Loading branch information
thestinger authored and anthraxx committed Dec 30, 2018
1 parent b502273 commit 296db04
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions arch/x86/mm/init_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ int arch_remove_memory(u64 start, u64 size, struct vmem_altmap *altmap)
#endif
#endif

int kernel_set_to_readonly __read_mostly;
int kernel_set_to_readonly __ro_after_init;

void set_kernel_text_rw(void)
{
Expand Down Expand Up @@ -924,12 +924,11 @@ void mark_rodata_ro(void)
unsigned long start = PFN_ALIGN(_text);
unsigned long size = (unsigned long)__end_rodata - start;

kernel_set_to_readonly = 1;
set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
pr_info("Write protecting kernel text and read-only data: %luk\n",
size >> 10);

kernel_set_to_readonly = 1;

#ifdef CONFIG_CPA_DEBUG
pr_info("Testing CPA: Reverting %lx-%lx\n", start, start + size);
set_pages_rw(virt_to_page(start), size >> PAGE_SHIFT);
Expand Down
5 changes: 2 additions & 3 deletions arch/x86/mm/init_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ void __init mem_init(void)
mem_init_print_info(NULL);
}

int kernel_set_to_readonly;
int kernel_set_to_readonly __ro_after_init;

void set_kernel_text_rw(void)
{
Expand Down Expand Up @@ -1255,9 +1255,8 @@ void mark_rodata_ro(void)

printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
(end - start) >> 10);
set_memory_ro(start, (end - start) >> PAGE_SHIFT);

kernel_set_to_readonly = 1;
set_memory_ro(start, (end - start) >> PAGE_SHIFT);

/*
* The rodata/data/bss/brk section (but not the kernel text!)
Expand Down

0 comments on commit 296db04

Please sign in to comment.