diff options
author | Arjan van de Ven <arjan@infradead.org> | 2008-01-30 07:34:08 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-01-30 07:34:08 -0500 |
commit | edeed30589f5defe63ce6aaae56f2b7c855e4520 (patch) | |
tree | a49736ff74dcbd3feba3c8318b204fb2165f892d /arch/x86/kernel/test_rodata.c | |
parent | adafdf6a4e45f2d1051e10aebe13025e89dbdf6d (diff) |
x86: add testcases for RODATA and NX protections/attributes
Latest update; I now have 4 NX tests, but 2 fail so they're #if 0'd.
I also cleaned up the NX test code quite a bit, and got rid of the ugly
exception table sorting stuff.
From: Arjan van de Ven <arjan@linux.intel.com>
This patch adds testcases for the CONFIG_DEBUG_RODATA configuration option
as well as the NX CPU feature/mappings. Both testcases can move to tests/
once that patch gets merged into mainline.
(I'm half considering moving the rodata test into mm/init.c but I'll
wait with that until init.c is unified)
As part of this I had to fix a not-quite-right alignment in the vmlinux.lds.h
for the RODATA sections, which lead to 1 page less being marked read only.
Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86/kernel/test_rodata.c')
-rw-r--r-- | arch/x86/kernel/test_rodata.c | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/arch/x86/kernel/test_rodata.c b/arch/x86/kernel/test_rodata.c new file mode 100644 index 00000000000..4c163772000 --- /dev/null +++ b/arch/x86/kernel/test_rodata.c | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * test_rodata.c: functional test for mark_rodata_ro function | ||
3 | * | ||
4 | * (C) Copyright 2008 Intel Corporation | ||
5 | * Author: Arjan van de Ven <arjan@linux.intel.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * as published by the Free Software Foundation; version 2 | ||
10 | * of the License. | ||
11 | */ | ||
12 | #include <linux/module.h> | ||
13 | #include <asm/sections.h> | ||
14 | extern int rodata_test_data; | ||
15 | |||
16 | int rodata_test(void) | ||
17 | { | ||
18 | unsigned long result; | ||
19 | unsigned long start, end; | ||
20 | |||
21 | /* test 1: read the value */ | ||
22 | /* If this test fails, some previous testrun has clobbered the state */ | ||
23 | if (!rodata_test_data) { | ||
24 | printk(KERN_ERR "rodata_test: test 1 fails (start data)\n"); | ||
25 | return -ENODEV; | ||
26 | } | ||
27 | |||
28 | /* test 2: write to the variable; this should fault */ | ||
29 | /* | ||
30 | * If this test fails, we managed to overwrite the data | ||
31 | * | ||
32 | * This is written in assembly to be able to catch the | ||
33 | * exception that is supposed to happen in the correct | ||
34 | * case | ||
35 | */ | ||
36 | |||
37 | result = 1; | ||
38 | asm volatile( | ||
39 | "0: mov %[zero],(%[rodata_test])\n" | ||
40 | " mov %[zero], %[rslt]\n" | ||
41 | "1:\n" | ||
42 | ".section .fixup,\"ax\"\n" | ||
43 | "2: jmp 1b\n" | ||
44 | ".previous\n" | ||
45 | ".section __ex_table,\"a\"\n" | ||
46 | " .align 16\n" | ||
47 | #ifdef CONFIG_X86_32 | ||
48 | " .long 0b,2b\n" | ||
49 | #else | ||
50 | " .quad 0b,2b\n" | ||
51 | #endif | ||
52 | ".previous" | ||
53 | : [rslt] "=r" (result) | ||
54 | : [rodata_test] "r" (&rodata_test_data), [zero] "r" (0UL) | ||
55 | ); | ||
56 | |||
57 | |||
58 | if (!result) { | ||
59 | printk(KERN_ERR "rodata_test: test data was not read only\n"); | ||
60 | return -ENODEV; | ||
61 | } | ||
62 | |||
63 | /* test 3: check the value hasn't changed */ | ||
64 | /* If this test fails, we managed to overwrite the data */ | ||
65 | if (!rodata_test_data) { | ||
66 | printk(KERN_ERR "rodata_test: Test 3 failes (end data)\n"); | ||
67 | return -ENODEV; | ||
68 | } | ||
69 | /* test 4: check if the rodata section is 4Kb aligned */ | ||
70 | start = (unsigned long)__start_rodata; | ||
71 | end = (unsigned long)__end_rodata; | ||
72 | if (start & (PAGE_SIZE - 1)) { | ||
73 | printk(KERN_ERR "rodata_test: .rodata is not 4k aligned\n"); | ||
74 | return -ENODEV; | ||
75 | } | ||
76 | if (end & (PAGE_SIZE - 1)) { | ||
77 | printk(KERN_ERR "rodata_test: .rodata end is not 4k aligned\n"); | ||
78 | return -ENODEV; | ||
79 | } | ||
80 | |||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | MODULE_LICENSE("GPL"); | ||
85 | MODULE_DESCRIPTION("Testcase for the DEBUG_RODATA infrastructure"); | ||
86 | MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>"); | ||