Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 140784
b: refs/heads/master
c: 1623963
h: refs/heads/master
v: v3
  • Loading branch information
Steven Rostedt committed Feb 20, 2009
1 parent 50d36bd commit e5bff15
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 9 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 000ab691172db3921efa3cb7f17fc79235a1de7f
refs/heads/master: 16239630974516a8879a3695ee9b4dc661f79f96
5 changes: 5 additions & 0 deletions trunk/arch/x86/include/asm/cacheflush.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ void clflush_cache_range(void *addr, unsigned int size);
#ifdef CONFIG_DEBUG_RODATA
void mark_rodata_ro(void);
extern const int rodata_test_data;
void set_kernel_text_rw(void);
void set_kernel_text_ro(void);
#else
static inline void set_kernel_text_rw(void) { }
static inline void set_kernel_text_ro(void) { }
#endif

#ifdef CONFIG_DEBUG_RODATA_TEST
Expand Down
13 changes: 13 additions & 0 deletions trunk/arch/x86/kernel/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <linux/init.h>
#include <linux/list.h>

#include <asm/cacheflush.h>
#include <asm/ftrace.h>
#include <linux/ftrace.h>
#include <asm/nops.h>
Expand All @@ -26,6 +27,18 @@

#ifdef CONFIG_DYNAMIC_FTRACE

int ftrace_arch_code_modify_prepare(void)
{
set_kernel_text_rw();
return 0;
}

int ftrace_arch_code_modify_post_process(void)
{
set_kernel_text_ro();
return 0;
}

union ftrace_code_union {
char code[MCOUNT_INSN_SIZE];
struct {
Expand Down
35 changes: 32 additions & 3 deletions trunk/arch/x86/mm/init_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1155,17 +1155,47 @@ static noinline int do_test_wp_bit(void)
const int rodata_test_data = 0xC3;
EXPORT_SYMBOL_GPL(rodata_test_data);

static int kernel_set_to_readonly;

void set_kernel_text_rw(void)
{
unsigned long start = PFN_ALIGN(_text);
unsigned long size = PFN_ALIGN(_etext) - start;

if (!kernel_set_to_readonly)
return;

pr_debug("Set kernel text: %lx - %lx for read write\n",
start, start+size);

set_pages_rw(virt_to_page(start), size >> PAGE_SHIFT);
}

void set_kernel_text_ro(void)
{
unsigned long start = PFN_ALIGN(_text);
unsigned long size = PFN_ALIGN(_etext) - start;

if (!kernel_set_to_readonly)
return;

pr_debug("Set kernel text: %lx - %lx for read only\n",
start, start+size);

set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
}

void mark_rodata_ro(void)
{
unsigned long start = PFN_ALIGN(_text);
unsigned long size = PFN_ALIGN(_etext) - start;

#ifndef CONFIG_DYNAMIC_FTRACE
/* Dynamic tracing modifies the kernel text section */
set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
printk(KERN_INFO "Write protecting the kernel text: %luk\n",
size >> 10);

kernel_set_to_readonly = 1;

#ifdef CONFIG_CPA_DEBUG
printk(KERN_INFO "Testing CPA: Reverting %lx-%lx\n",
start, start+size);
Expand All @@ -1174,7 +1204,6 @@ void mark_rodata_ro(void)
printk(KERN_INFO "Testing CPA: write protecting again\n");
set_pages_ro(virt_to_page(start), size>>PAGE_SHIFT);
#endif
#endif /* CONFIG_DYNAMIC_FTRACE */

start += size;
size = (unsigned long)__end_rodata - start;
Expand Down
37 changes: 32 additions & 5 deletions trunk/arch/x86/mm/init_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -986,21 +986,48 @@ void free_initmem(void)
const int rodata_test_data = 0xC3;
EXPORT_SYMBOL_GPL(rodata_test_data);

static int kernel_set_to_readonly;

void set_kernel_text_rw(void)
{
unsigned long start = PFN_ALIGN(_stext);
unsigned long end = PFN_ALIGN(__start_rodata);

if (!kernel_set_to_readonly)
return;

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

set_memory_rw(start, (end - start) >> PAGE_SHIFT);
}

void set_kernel_text_ro(void)
{
unsigned long start = PFN_ALIGN(_stext);
unsigned long end = PFN_ALIGN(__start_rodata);

if (!kernel_set_to_readonly)
return;

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

set_memory_ro(start, (end - start) >> PAGE_SHIFT);
}

void mark_rodata_ro(void)
{
unsigned long start = PFN_ALIGN(_stext), end = PFN_ALIGN(__end_rodata);
unsigned long rodata_start =
((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK;

#ifdef CONFIG_DYNAMIC_FTRACE
/* Dynamic tracing modifies the kernel text section */
start = rodata_start;
#endif

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;

/*
* The rodata section (but not the kernel text!) should also be
* not-executable.
Expand Down

0 comments on commit e5bff15

Please sign in to comment.