Skip to content

Commit e7d23dd

Browse files
Suresh SiddhaIngo Molnar
authored andcommitted
x86_64, cpa: Use only text section in set_kernel_text_rw/ro
set_kernel_text_rw()/set_kernel_text_ro() are marking pages starting from _text to __start_rodata as RW or RO. With CONFIG_DEBUG_RODATA, there might be free pages (associated with padding the sections to 2MB large page boundary) between text and rodata sections that are given back to page allocator. So we should use only use the start (__text) and end (__stop___ex_table) of the text section in set_kernel_text_rw()/set_kernel_text_ro(). Signed-off-by: Suresh Siddha <[email protected]> Acked-by: Steven Rostedt <[email protected]> Tested-by: Steven Rostedt <[email protected]> LKML-Reference: <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 55ca3cc commit e7d23dd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

arch/x86/mm/init_64.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,28 +700,36 @@ int kernel_set_to_readonly;
700700
void set_kernel_text_rw(void)
701701
{
702702
unsigned long start = PFN_ALIGN(_text);
703-
unsigned long end = PFN_ALIGN(__start_rodata);
703+
unsigned long end = PFN_ALIGN(__stop___ex_table);
704704

705705
if (!kernel_set_to_readonly)
706706
return;
707707

708708
pr_debug("Set kernel text: %lx - %lx for read write\n",
709709
start, end);
710710

711+
/*
712+
* Make the kernel identity mapping for text RW. Kernel text
713+
* mapping will always be RO. Refer to the comment in
714+
* static_protections() in pageattr.c
715+
*/
711716
set_memory_rw(start, (end - start) >> PAGE_SHIFT);
712717
}
713718

714719
void set_kernel_text_ro(void)
715720
{
716721
unsigned long start = PFN_ALIGN(_text);
717-
unsigned long end = PFN_ALIGN(__start_rodata);
722+
unsigned long end = PFN_ALIGN(__stop___ex_table);
718723

719724
if (!kernel_set_to_readonly)
720725
return;
721726

722727
pr_debug("Set kernel text: %lx - %lx for read only\n",
723728
start, end);
724729

730+
/*
731+
* Set the kernel identity mapping for text RO.
732+
*/
725733
set_memory_ro(start, (end - start) >> PAGE_SHIFT);
726734
}
727735

0 commit comments

Comments
 (0)