diff options
author | Andy Lutomirski <luto@MIT.EDU> | 2011-06-05 13:50:19 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2011-06-05 15:30:32 -0400 |
commit | 9fd67b4ed0714ab718f1f9bd14c344af336a6df7 (patch) | |
tree | 7dae7e978b68479b6ee316d92b81d703cee3a894 /arch | |
parent | 8b4777a4b50cb0c84c1152eac85d24415fb6ff7d (diff) |
x86-64: Give vvars their own page
Move vvars out of the vsyscall page into their own page and mark
it NX.
Without this patch, an attacker who can force a daemon to call
some fixed address could wait until the time contains, say,
0xCD80, and then execute the current time.
Signed-off-by: Andy Lutomirski <luto@mit.edu>
Cc: Jesper Juhl <jj@chaosbits.net>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Arjan van de Ven <arjan@infradead.org>
Cc: Jan Beulich <JBeulich@novell.com>
Cc: richard -rw- weinberger <richard.weinberger@gmail.com>
Cc: Mikael Pettersson <mikpe@it.uu.se>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Louis Rilling <Louis.Rilling@kerlabs.com>
Cc: Valdis.Kletnieks@vt.edu
Cc: pageexec@freemail.hu
Link: http://lkml.kernel.org/r/b1460f81dc4463d66ea3f2b5ce240f58d48effec.1307292171.git.luto@mit.edu
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/include/asm/fixmap.h | 1 | ||||
-rw-r--r-- | arch/x86/include/asm/pgtable_types.h | 2 | ||||
-rw-r--r-- | arch/x86/include/asm/vvar.h | 22 | ||||
-rw-r--r-- | arch/x86/kernel/vmlinux.lds.S | 28 | ||||
-rw-r--r-- | arch/x86/kernel/vsyscall_64.c | 5 |
5 files changed, 35 insertions, 23 deletions
diff --git a/arch/x86/include/asm/fixmap.h b/arch/x86/include/asm/fixmap.h index 4729b2b63117..460c74e4852c 100644 --- a/arch/x86/include/asm/fixmap.h +++ b/arch/x86/include/asm/fixmap.h | |||
@@ -78,6 +78,7 @@ enum fixed_addresses { | |||
78 | VSYSCALL_LAST_PAGE, | 78 | VSYSCALL_LAST_PAGE, |
79 | VSYSCALL_FIRST_PAGE = VSYSCALL_LAST_PAGE | 79 | VSYSCALL_FIRST_PAGE = VSYSCALL_LAST_PAGE |
80 | + ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1, | 80 | + ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1, |
81 | VVAR_PAGE, | ||
81 | VSYSCALL_HPET, | 82 | VSYSCALL_HPET, |
82 | #endif | 83 | #endif |
83 | FIX_DBGP_BASE, | 84 | FIX_DBGP_BASE, |
diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index d56187c6b838..6a29aed65902 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h | |||
@@ -108,6 +108,7 @@ | |||
108 | #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD) | 108 | #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD) |
109 | #define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER) | 109 | #define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER) |
110 | #define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT) | 110 | #define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT) |
111 | #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER) | ||
111 | #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE) | 112 | #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE) |
112 | #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE) | 113 | #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE) |
113 | #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE) | 114 | #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE) |
@@ -130,6 +131,7 @@ | |||
130 | #define PAGE_KERNEL_LARGE_EXEC __pgprot(__PAGE_KERNEL_LARGE_EXEC) | 131 | #define PAGE_KERNEL_LARGE_EXEC __pgprot(__PAGE_KERNEL_LARGE_EXEC) |
131 | #define PAGE_KERNEL_VSYSCALL __pgprot(__PAGE_KERNEL_VSYSCALL) | 132 | #define PAGE_KERNEL_VSYSCALL __pgprot(__PAGE_KERNEL_VSYSCALL) |
132 | #define PAGE_KERNEL_VSYSCALL_NOCACHE __pgprot(__PAGE_KERNEL_VSYSCALL_NOCACHE) | 133 | #define PAGE_KERNEL_VSYSCALL_NOCACHE __pgprot(__PAGE_KERNEL_VSYSCALL_NOCACHE) |
134 | #define PAGE_KERNEL_VVAR __pgprot(__PAGE_KERNEL_VVAR) | ||
133 | 135 | ||
134 | #define PAGE_KERNEL_IO __pgprot(__PAGE_KERNEL_IO) | 136 | #define PAGE_KERNEL_IO __pgprot(__PAGE_KERNEL_IO) |
135 | #define PAGE_KERNEL_IO_NOCACHE __pgprot(__PAGE_KERNEL_IO_NOCACHE) | 137 | #define PAGE_KERNEL_IO_NOCACHE __pgprot(__PAGE_KERNEL_IO_NOCACHE) |
diff --git a/arch/x86/include/asm/vvar.h b/arch/x86/include/asm/vvar.h index a4eaca4a6133..de656ac2af41 100644 --- a/arch/x86/include/asm/vvar.h +++ b/arch/x86/include/asm/vvar.h | |||
@@ -10,15 +10,14 @@ | |||
10 | * In normal kernel code, they are used like any other variable. | 10 | * In normal kernel code, they are used like any other variable. |
11 | * In user code, they are accessed through the VVAR macro. | 11 | * In user code, they are accessed through the VVAR macro. |
12 | * | 12 | * |
13 | * Each of these variables lives in the vsyscall page, and each | 13 | * These variables live in a page of kernel data that has an extra RO |
14 | * one needs a unique offset within the little piece of the page | 14 | * mapping for userspace. Each variable needs a unique offset within |
15 | * reserved for vvars. Specify that offset in DECLARE_VVAR. | 15 | * that page; specify that offset with the DECLARE_VVAR macro. (If |
16 | * (There are 896 bytes available. If you mess up, the linker will | 16 | * you mess up, the linker will catch it.) |
17 | * catch it.) | ||
18 | */ | 17 | */ |
19 | 18 | ||
20 | /* Offset of vars within vsyscall page */ | 19 | /* Base address of vvars. This is not ABI. */ |
21 | #define VSYSCALL_VARS_OFFSET (3072 + 128) | 20 | #define VVAR_ADDRESS (-10*1024*1024 - 4096) |
22 | 21 | ||
23 | #if defined(__VVAR_KERNEL_LDS) | 22 | #if defined(__VVAR_KERNEL_LDS) |
24 | 23 | ||
@@ -26,17 +25,17 @@ | |||
26 | * right place. | 25 | * right place. |
27 | */ | 26 | */ |
28 | #define DECLARE_VVAR(offset, type, name) \ | 27 | #define DECLARE_VVAR(offset, type, name) \ |
29 | EMIT_VVAR(name, VSYSCALL_VARS_OFFSET + offset) | 28 | EMIT_VVAR(name, offset) |
30 | 29 | ||
31 | #else | 30 | #else |
32 | 31 | ||
33 | #define DECLARE_VVAR(offset, type, name) \ | 32 | #define DECLARE_VVAR(offset, type, name) \ |
34 | static type const * const vvaraddr_ ## name = \ | 33 | static type const * const vvaraddr_ ## name = \ |
35 | (void *)(VSYSCALL_START + VSYSCALL_VARS_OFFSET + (offset)); | 34 | (void *)(VVAR_ADDRESS + (offset)); |
36 | 35 | ||
37 | #define DEFINE_VVAR(type, name) \ | 36 | #define DEFINE_VVAR(type, name) \ |
38 | type __vvar_ ## name \ | 37 | type name \ |
39 | __attribute__((section(".vsyscall_var_" #name), aligned(16))) | 38 | __attribute__((section(".vvar_" #name), aligned(16))) |
40 | 39 | ||
41 | #define VVAR(name) (*vvaraddr_ ## name) | 40 | #define VVAR(name) (*vvaraddr_ ## name) |
42 | 41 | ||
@@ -49,4 +48,3 @@ DECLARE_VVAR(16, int, vgetcpu_mode) | |||
49 | DECLARE_VVAR(128, struct vsyscall_gtod_data, vsyscall_gtod_data) | 48 | DECLARE_VVAR(128, struct vsyscall_gtod_data, vsyscall_gtod_data) |
50 | 49 | ||
51 | #undef DECLARE_VVAR | 50 | #undef DECLARE_VVAR |
52 | #undef VSYSCALL_VARS_OFFSET | ||
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S index 89aed99aafce..98b378dc7f86 100644 --- a/arch/x86/kernel/vmlinux.lds.S +++ b/arch/x86/kernel/vmlinux.lds.S | |||
@@ -161,12 +161,6 @@ SECTIONS | |||
161 | 161 | ||
162 | #define VVIRT_OFFSET (VSYSCALL_ADDR - __vsyscall_0) | 162 | #define VVIRT_OFFSET (VSYSCALL_ADDR - __vsyscall_0) |
163 | #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET) | 163 | #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET) |
164 | #define EMIT_VVAR(x, offset) .vsyscall_var_ ## x \ | ||
165 | ADDR(.vsyscall_0) + offset \ | ||
166 | : AT(VLOAD(.vsyscall_var_ ## x)) { \ | ||
167 | *(.vsyscall_var_ ## x) \ | ||
168 | } \ | ||
169 | x = VVIRT(.vsyscall_var_ ## x); | ||
170 | 164 | ||
171 | . = ALIGN(4096); | 165 | . = ALIGN(4096); |
172 | __vsyscall_0 = .; | 166 | __vsyscall_0 = .; |
@@ -192,19 +186,31 @@ SECTIONS | |||
192 | *(.vsyscall_3) | 186 | *(.vsyscall_3) |
193 | } | 187 | } |
194 | 188 | ||
195 | #define __VVAR_KERNEL_LDS | 189 | . = ALIGN(__vsyscall_0 + PAGE_SIZE, PAGE_SIZE); |
196 | #include <asm/vvar.h> | ||
197 | #undef __VVAR_KERNEL_LDS | ||
198 | |||
199 | . = __vsyscall_0 + PAGE_SIZE; | ||
200 | 190 | ||
201 | #undef VSYSCALL_ADDR | 191 | #undef VSYSCALL_ADDR |
202 | #undef VLOAD_OFFSET | 192 | #undef VLOAD_OFFSET |
203 | #undef VLOAD | 193 | #undef VLOAD |
204 | #undef VVIRT_OFFSET | 194 | #undef VVIRT_OFFSET |
205 | #undef VVIRT | 195 | #undef VVIRT |
196 | |||
197 | __vvar_page = .; | ||
198 | |||
199 | .vvar : AT(ADDR(.vvar) - LOAD_OFFSET) { | ||
200 | |||
201 | /* Place all vvars at the offsets in asm/vvar.h. */ | ||
202 | #define EMIT_VVAR(name, offset) \ | ||
203 | . = offset; \ | ||
204 | *(.vvar_ ## name) | ||
205 | #define __VVAR_KERNEL_LDS | ||
206 | #include <asm/vvar.h> | ||
207 | #undef __VVAR_KERNEL_LDS | ||
206 | #undef EMIT_VVAR | 208 | #undef EMIT_VVAR |
207 | 209 | ||
210 | } :data | ||
211 | |||
212 | . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE); | ||
213 | |||
208 | #endif /* CONFIG_X86_64 */ | 214 | #endif /* CONFIG_X86_64 */ |
209 | 215 | ||
210 | /* Init code and data - will be freed after init */ | 216 | /* Init code and data - will be freed after init */ |
diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c index 3e682184d76c..3cf1cef75a6a 100644 --- a/arch/x86/kernel/vsyscall_64.c +++ b/arch/x86/kernel/vsyscall_64.c | |||
@@ -284,9 +284,14 @@ void __init map_vsyscall(void) | |||
284 | { | 284 | { |
285 | extern char __vsyscall_0; | 285 | extern char __vsyscall_0; |
286 | unsigned long physaddr_page0 = __pa_symbol(&__vsyscall_0); | 286 | unsigned long physaddr_page0 = __pa_symbol(&__vsyscall_0); |
287 | extern char __vvar_page; | ||
288 | unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page); | ||
287 | 289 | ||
288 | /* Note that VSYSCALL_MAPPED_PAGES must agree with the code below. */ | 290 | /* Note that VSYSCALL_MAPPED_PAGES must agree with the code below. */ |
289 | __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_page0, PAGE_KERNEL_VSYSCALL); | 291 | __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_page0, PAGE_KERNEL_VSYSCALL); |
292 | __set_fixmap(VVAR_PAGE, physaddr_vvar_page, PAGE_KERNEL_VVAR); | ||
293 | BUILD_BUG_ON((unsigned long)__fix_to_virt(VVAR_PAGE) != | ||
294 | (unsigned long)VVAR_ADDRESS); | ||
290 | } | 295 | } |
291 | 296 | ||
292 | static int __init vsyscall_init(void) | 297 | static int __init vsyscall_init(void) |