aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/mm/init_64.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/mm/init_64.c')
-rw-r--r--arch/x86/mm/init_64.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index e6d36b490250..63fdc531601d 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -986,21 +986,48 @@ void free_initmem(void)
986const int rodata_test_data = 0xC3; 986const int rodata_test_data = 0xC3;
987EXPORT_SYMBOL_GPL(rodata_test_data); 987EXPORT_SYMBOL_GPL(rodata_test_data);
988 988
989static int kernel_set_to_readonly;
990
991void set_kernel_text_rw(void)
992{
993 unsigned long start = PFN_ALIGN(_stext);
994 unsigned long end = PFN_ALIGN(__start_rodata);
995
996 if (!kernel_set_to_readonly)
997 return;
998
999 pr_debug("Set kernel text: %lx - %lx for read write\n",
1000 start, end);
1001
1002 set_memory_rw(start, (end - start) >> PAGE_SHIFT);
1003}
1004
1005void set_kernel_text_ro(void)
1006{
1007 unsigned long start = PFN_ALIGN(_stext);
1008 unsigned long end = PFN_ALIGN(__start_rodata);
1009
1010 if (!kernel_set_to_readonly)
1011 return;
1012
1013 pr_debug("Set kernel text: %lx - %lx for read only\n",
1014 start, end);
1015
1016 set_memory_ro(start, (end - start) >> PAGE_SHIFT);
1017}
1018
989void mark_rodata_ro(void) 1019void mark_rodata_ro(void)
990{ 1020{
991 unsigned long start = PFN_ALIGN(_stext), end = PFN_ALIGN(__end_rodata); 1021 unsigned long start = PFN_ALIGN(_stext), end = PFN_ALIGN(__end_rodata);
992 unsigned long rodata_start = 1022 unsigned long rodata_start =
993 ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK; 1023 ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;
994 1024
995#ifdef CONFIG_DYNAMIC_FTRACE
996 /* Dynamic tracing modifies the kernel text section */
997 start = rodata_start;
998#endif
999
1000 printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n", 1025 printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n",
1001 (end - start) >> 10); 1026 (end - start) >> 10);
1002 set_memory_ro(start, (end - start) >> PAGE_SHIFT); 1027 set_memory_ro(start, (end - start) >> PAGE_SHIFT);
1003 1028
1029 kernel_set_to_readonly = 1;
1030
1004 /* 1031 /*
1005 * The rodata section (but not the kernel text!) should also be 1032 * The rodata section (but not the kernel text!) should also be
1006 * not-executable. 1033 * not-executable.