diff options
author | Arjan van de Ven <arjan@linux.intel.com> | 2008-02-06 16:39:45 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-02-06 16:39:45 -0500 |
commit | 984bb80d94d891592ab16d4d129b988792752c7b (patch) | |
tree | efc22a5eb3e3cf05b056bedcbe48bbdb48b99ad8 | |
parent | a57dae3aa4d00a000b5bac4238025438204c78b2 (diff) |
x86: mark the .rodata section also NX
The .rodata section shouldn't just be read-only,
but also non-executable. This is free since we've broken
up the 2MB page already anyway.
also update test_nx to check for this.
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r-- | arch/x86/kernel/test_nx.c | 2 | ||||
-rw-r--r-- | arch/x86/mm/init_64.c | 9 |
2 files changed, 9 insertions, 2 deletions
diff --git a/arch/x86/kernel/test_nx.c b/arch/x86/kernel/test_nx.c index 36c100c323aa..10b8a6f69f84 100644 --- a/arch/x86/kernel/test_nx.c +++ b/arch/x86/kernel/test_nx.c | |||
@@ -139,7 +139,6 @@ static int test_NX(void) | |||
139 | * Until then, don't run them to avoid too many people getting scared | 139 | * Until then, don't run them to avoid too many people getting scared |
140 | * by the error message | 140 | * by the error message |
141 | */ | 141 | */ |
142 | #if 0 | ||
143 | 142 | ||
144 | #ifdef CONFIG_DEBUG_RODATA | 143 | #ifdef CONFIG_DEBUG_RODATA |
145 | /* Test 3: Check if the .rodata section is executable */ | 144 | /* Test 3: Check if the .rodata section is executable */ |
@@ -152,6 +151,7 @@ static int test_NX(void) | |||
152 | } | 151 | } |
153 | #endif | 152 | #endif |
154 | 153 | ||
154 | #if 0 | ||
155 | /* Test 4: Check if the .data section of a module is executable */ | 155 | /* Test 4: Check if the .data section of a module is executable */ |
156 | if (test_address(&test_data)) { | 156 | if (test_address(&test_data)) { |
157 | printk(KERN_ERR "test_nx: .data section is executable\n"); | 157 | printk(KERN_ERR "test_nx: .data section is executable\n"); |
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index 3a98d6f724ab..9b61c75a2355 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c | |||
@@ -591,10 +591,17 @@ void mark_rodata_ro(void) | |||
591 | if (end <= start) | 591 | if (end <= start) |
592 | return; | 592 | return; |
593 | 593 | ||
594 | set_memory_ro(start, (end - start) >> PAGE_SHIFT); | ||
595 | 594 | ||
596 | printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n", | 595 | printk(KERN_INFO "Write protecting the kernel read-only data: %luk\n", |
597 | (end - start) >> 10); | 596 | (end - start) >> 10); |
597 | set_memory_ro(start, (end - start) >> PAGE_SHIFT); | ||
598 | |||
599 | /* | ||
600 | * The rodata section (but not the kernel text!) should also be | ||
601 | * not-executable. | ||
602 | */ | ||
603 | start = ((unsigned long)__start_rodata + PAGE_SIZE - 1) & PAGE_MASK; | ||
604 | set_memory_nx(start, (end - start) >> PAGE_SHIFT); | ||
598 | 605 | ||
599 | rodata_test(); | 606 | rodata_test(); |
600 | 607 | ||