diff options
author | Florian Fainelli <f.fainelli@gmail.com> | 2017-09-08 19:15:31 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-08 21:26:49 -0400 |
commit | e4dace3615526fd66c86dd535ee4bc9e8c706e37 (patch) | |
tree | 48e3720ba8cebfba4d4c3ed753025a1854b9a758 | |
parent | 9888a588ea96ba2804f955bbc2667346719da887 (diff) |
lib: add test module for CONFIG_DEBUG_VIRTUAL
Add a test module that allows testing that CONFIG_DEBUG_VIRTUAL works
correctly, at least that it can catch invalid calls to virt_to_phys()
against the non-linear kernel virtual address map.
Link: http://lkml.kernel.org/r/20170808164035.26725-1-f.fainelli@gmail.com
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Cc: "Luis R. Rodriguez" <mcgrof@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | lib/Kconfig.debug | 11 | ||||
-rw-r--r-- | lib/Makefile | 1 | ||||
-rw-r--r-- | lib/test_debug_virtual.c | 49 |
3 files changed, 61 insertions, 0 deletions
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 7396f5044397..b19c491cbc4e 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug | |||
@@ -1930,6 +1930,17 @@ config TEST_KMOD | |||
1930 | 1930 | ||
1931 | If unsure, say N. | 1931 | If unsure, say N. |
1932 | 1932 | ||
1933 | config TEST_DEBUG_VIRTUAL | ||
1934 | tristate "Test CONFIG_DEBUG_VIRTUAL feature" | ||
1935 | depends on DEBUG_VIRTUAL | ||
1936 | help | ||
1937 | Test the kernel's ability to detect incorrect calls to | ||
1938 | virt_to_phys() done against the non-linear part of the | ||
1939 | kernel's virtual address map. | ||
1940 | |||
1941 | If unsure, say N. | ||
1942 | |||
1943 | |||
1933 | source "samples/Kconfig" | 1944 | source "samples/Kconfig" |
1934 | 1945 | ||
1935 | source "lib/Kconfig.kgdb" | 1946 | source "lib/Kconfig.kgdb" |
diff --git a/lib/Makefile b/lib/Makefile index 40c18372b301..469ce5e24e4f 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -62,6 +62,7 @@ obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o | |||
62 | obj-$(CONFIG_TEST_UUID) += test_uuid.o | 62 | obj-$(CONFIG_TEST_UUID) += test_uuid.o |
63 | obj-$(CONFIG_TEST_PARMAN) += test_parman.o | 63 | obj-$(CONFIG_TEST_PARMAN) += test_parman.o |
64 | obj-$(CONFIG_TEST_KMOD) += test_kmod.o | 64 | obj-$(CONFIG_TEST_KMOD) += test_kmod.o |
65 | obj-$(CONFIG_TEST_DEBUG_VIRTUAL) += test_debug_virtual.o | ||
65 | 66 | ||
66 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) | 67 | ifeq ($(CONFIG_DEBUG_KOBJECT),y) |
67 | CFLAGS_kobject.o += -DDEBUG | 68 | CFLAGS_kobject.o += -DDEBUG |
diff --git a/lib/test_debug_virtual.c b/lib/test_debug_virtual.c new file mode 100644 index 000000000000..b9cdeecc19dc --- /dev/null +++ b/lib/test_debug_virtual.c | |||
@@ -0,0 +1,49 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/module.h> | ||
3 | #include <linux/export.h> | ||
4 | #include <linux/mm.h> | ||
5 | #include <linux/vmalloc.h> | ||
6 | #include <linux/slab.h> | ||
7 | #include <linux/sizes.h> | ||
8 | |||
9 | #include <asm/page.h> | ||
10 | #ifdef CONFIG_MIPS | ||
11 | #include <asm/bootinfo.h> | ||
12 | #endif | ||
13 | |||
14 | struct foo { | ||
15 | unsigned int bar; | ||
16 | }; | ||
17 | |||
18 | struct foo *foo; | ||
19 | |||
20 | static int __init test_debug_virtual_init(void) | ||
21 | { | ||
22 | phys_addr_t pa; | ||
23 | void *va; | ||
24 | |||
25 | va = (void *)VMALLOC_START; | ||
26 | pa = virt_to_phys(va); | ||
27 | |||
28 | pr_info("PA: %pa for VA: 0x%lx\n", &pa, (unsigned long)va); | ||
29 | |||
30 | foo = kzalloc(sizeof(*foo), GFP_KERNEL); | ||
31 | if (!foo) | ||
32 | return -ENOMEM; | ||
33 | |||
34 | pa = virt_to_phys(foo); | ||
35 | va = foo; | ||
36 | pr_info("PA: %pa for VA: 0x%lx\n", &pa, (unsigned long)va); | ||
37 | |||
38 | return 0; | ||
39 | } | ||
40 | module_init(test_debug_virtual_init); | ||
41 | |||
42 | static void __exit test_debug_virtual_exit(void) | ||
43 | { | ||
44 | kfree(foo); | ||
45 | } | ||
46 | module_exit(test_debug_virtual_exit); | ||
47 | |||
48 | MODULE_LICENSE("GPL"); | ||
49 | MODULE_DESCRIPTION("Test module for CONFIG_DEBUG_VIRTUAL"); | ||