12
12
#include <linux/sizes.h>
13
13
#include <linux/of_fdt.h>
14
14
#include <linux/libfdt.h>
15
+ #include <linux/set_memory.h>
15
16
16
17
#include <asm/fixmap.h>
17
18
#include <asm/tlbflush.h>
@@ -477,6 +478,17 @@ static void __init setup_vm_final(void)
477
478
csr_write (CSR_SATP , PFN_DOWN (__pa_symbol (swapper_pg_dir )) | SATP_MODE );
478
479
local_flush_tlb_all ();
479
480
}
481
+
482
+ void free_initmem (void )
483
+ {
484
+ unsigned long init_begin = (unsigned long )__init_begin ;
485
+ unsigned long init_end = (unsigned long )__init_end ;
486
+
487
+ /* Make the region as non-execuatble. */
488
+ set_memory_nx (init_begin , (init_end - init_begin ) >> PAGE_SHIFT );
489
+ free_initmem_default (POISON_FREE_INITMEM );
490
+ }
491
+
480
492
#else
481
493
asmlinkage void __init setup_vm (uintptr_t dtb_pa )
482
494
{
@@ -488,6 +500,38 @@ static inline void setup_vm_final(void)
488
500
}
489
501
#endif /* CONFIG_MMU */
490
502
503
+ #ifdef CONFIG_STRICT_KERNEL_RWX
504
+ void set_kernel_text_rw (void )
505
+ {
506
+ unsigned long text_start = (unsigned long )_text ;
507
+ unsigned long text_end = (unsigned long )_etext ;
508
+
509
+ set_memory_rw (text_start , (text_end - text_start ) >> PAGE_SHIFT );
510
+ }
511
+
512
+ void set_kernel_text_ro (void )
513
+ {
514
+ unsigned long text_start = (unsigned long )_text ;
515
+ unsigned long text_end = (unsigned long )_etext ;
516
+
517
+ set_memory_ro (text_start , (text_end - text_start ) >> PAGE_SHIFT );
518
+ }
519
+
520
+ void mark_rodata_ro (void )
521
+ {
522
+ unsigned long text_start = (unsigned long )_text ;
523
+ unsigned long text_end = (unsigned long )_etext ;
524
+ unsigned long rodata_start = (unsigned long )__start_rodata ;
525
+ unsigned long data_start = (unsigned long )_data ;
526
+ unsigned long max_low = (unsigned long )(__va (PFN_PHYS (max_low_pfn )));
527
+
528
+ set_memory_ro (text_start , (text_end - text_start ) >> PAGE_SHIFT );
529
+ set_memory_ro (rodata_start , (data_start - rodata_start ) >> PAGE_SHIFT );
530
+ set_memory_nx (rodata_start , (data_start - rodata_start ) >> PAGE_SHIFT );
531
+ set_memory_nx (data_start , (max_low - data_start ) >> PAGE_SHIFT );
532
+ }
533
+ #endif
534
+
491
535
void __init paging_init (void )
492
536
{
493
537
setup_vm_final ();
0 commit comments