vdso: randomize the i386 vDSO by moving it into a vma
Subsystems (5)
PATCH 3/3 vdso: randomize the i386 vDSO by moving it into a vma
From: Ingo Molnar <[email protected]>
move the i386 VDSO down into a vma and thus randomize it.
besides the security implications, this feature also helps debuggers, which can COW a vma-backed VDSO just like a normal DSO and can thus do single-stepping and other debugging features.
It's good for hypervisors (Xen, VMWare) too, which typically live in the same high-mapped address space as the VDSO, hence whenever the VDSO is used, they get lots of guest pagefaults and have to fix such guest accesses up - which slows things down instead of speeding things up (the primary purpose of the VDSO).
there's a new CONFIG_COMPAT_VDSO (default=y) option, which provides support for older glibcs that still rely on a prelinked high-mapped VDSO. Newer distributions (using glibc 2.3.3 or later) can turn this option off. Turning it off is also recommended for security reasons: attackers cannot use the predictable high-mapped VDSO page as syscall trampoline anymore.
there is a new vdso=[0|1] boot option as well, and a runtime /proc/sys/vm/vdso_enabled sysctl switch, that allows the VDSO to be turned on/off.
(this version of the VDSO-randomization patch also has working ELF coredumping, the previous patch crashed in the coredumping code.)
This code is a combined work of the exec-shield VDSO randomization code and Gerd Hoffmann's hypervisor-centric VDSO patch. Rusty Russell started this patch and i completed it.
--- Documentation/kernel-parameters.txt | 4 + arch/i386/Kconfig | 11 ++ arch/i386/kernel/asm-offsets.c | 4 - arch/i386/kernel/entry.S | 8 +- arch/i386/kernel/signal.c | 4 - arch/i386/kernel/sysenter.c | 131 +++++++++++++++++++++++++++++++++-- arch/i386/kernel/vsyscall-sysenter.S | 4 - arch/i386/kernel/vsyscall.lds.S | 4 - fs/proc/task_mmu.c | 30 ++++---- include/asm-i386/elf.h | 53 ++++++++++---- include/asm-i386/fixmap.h | 10 -- include/asm-i386/mmu.h | 1 include/asm-i386/page.h | 6 + include/asm-i386/thread_info.h | 1 include/linux/sched.h | 1 include/linux/sysctl.h | 1 kernel/sysctl.c | 13 +++ 17 files changed, 237 insertions(+), 49 deletions(-)
Documentation/kernel-parameters.txt +4 -0
@@ -1652,6 +1652,10 @@ running once the system is up. usbhid.mousepoll= [USBHID] The interval which mice are to be polled at. + vdso= [IA-32] + vdso=1: enable VDSO (default) + vdso=0: disable VDSO mapping + video= [FB] Frame buffer configuration See Documentation/fb/modedb.txt.
arch/i386/Kconfig +11 -0
@@ -762,6 +762,17 @@ config HOTPLUG_CPU enable suspend on SMP systems. CPUs can be controlled through /sys/devices/system/cpu. +config COMPAT_VDSO + bool "Compat VDSO support" + default y + help + Map the VDSO to the predictable old-style address too. + ---help--- + Say N here if you are running a sufficiently recent glibc + version (2.3.3 or later), to remove the high-mapped + VDSO mapping and to exclusively use the randomized VDSO. + + If unsure, say Y. endmenu
arch/i386/kernel/asm-offsets.c +3 -1
@@ -13,6 +13,7 @@#include <asm/fixmap.h> #include <asm/processor.h> #include <asm/thread_info.h> +#include <asm/elf.h> #define DEFINE (sym, val) \ asm volatile("\n->" #sym " %0 " #val : : "i" (val))
@@ -53,6 +54,7 @@ void foo(void)OFFSET (TI_preempt_count, thread_info, preempt_count);OFFSET (TI_addr_limit, thread_info, addr_limit);OFFSET (TI_restart_block, thread_info, restart_block); +OFFSET (TI_sysenter_return, thread_info, sysenter_return);BLANK ();OFFSET (EXEC_DOMAIN_handler, exec_domain, handler);
@@ -68,5 +70,5 @@ void foo(void) sizeof(struct tss_struct));DEFINE (PAGE_SIZE_asm,PAGE_SIZE ); -DEFINE (VSYSCALL_BASE ,__fix_to_virt (FIX_VSYSCALL )); +DEFINE (VDSO_PRELINK ,VDSO_PRELINK ); }
arch/i386/kernel/entry.S +6 -2
@@ -184,8 +184,12 @@ sysenter_past_esp: pushl %ebp pushfl pushl $(__USER_CS) - pushl $SYSENTER_RETURN - + /* + * Push current_thread_info()->sysenter_return to the stack. + * A tiny bit of offset fixup is necessary - 4*4 means the 4 words + * pushed above; +8 corresponds to copy_thread's esp0 setting. + */ + pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp) /* * Load the potential sixth argument from user stack. * Careful about security.
arch/i386/kernel/signal.c +2 -2
@@ -351,7 +351,7 @@ static int setup_frame(int sig, struct k goto give_sigsegv; } - restorer = &__kernel_sigreturn; + restorer = (void *)VDSO_SYM (&__kernel_sigreturn);if (ka->sa.sa_flags &SA_RESTORER ) restorer = ka->sa.sa_restorer;
@@ -447,7 +447,7 @@ static int setup_rt_frame(int sig, struc goto give_sigsegv;/* Set up to return from userspace. */ - restorer = &__kernel_rt_sigreturn; + restorer = (void *)VDSO_SYM (&__kernel_rt_sigreturn);if (ka->sa.sa_flags &SA_RESTORER ) restorer = ka->sa.sa_restorer; err |=__put_user (restorer, &frame->pretcode);
arch/i386/kernel/sysenter.c +127 -4
168 lines not on this page · raw message
arch/i386/kernel/vsyscall-sysenter.S +2 -2
@@ -42,10 +42,10 @@ __kernel_vsyscall: /* 7: align return point with nop's to make disassembly easier */ .space 7,0x90 - /* 14: System call restart point is here! (SYSENTER_RETURN - 2) */ + /* 14: System call restart point is here! (SYSENTER_RETURN-2) */ jmp .Lenter_kernel /* 16: System call normal return point is here! */ - .globl SYSENTER_RETURN /* Symbol used by entry.S. */ + .globl SYSENTER_RETURN /* Symbol used by sysenter.c */ SYSENTER_RETURN: pop %ebp .Lpop_ebp:
arch/i386/kernel/vsyscall.lds.S +2 -2
@@ -7,7 +7,7 @@ SECTIONS { - . = VSYSCALL_BASE + SIZEOF_HEADERS; + . = VDSO_PRELINK + SIZEOF_HEADERS; .hash : { *(.hash) } :text .dynsym : { *(.dynsym) }
@@ -20,7 +20,7 @@ SECTIONS For the layouts to match, we need to skip more than enough space for the dynamic symbol table et al. If this amount is insufficient, ld -shared will barf. Just increase it here. */ - . = VSYSCALL_BASE + 0x400; + . = VDSO_PRELINK + 0x400; .text : { *(.text) } :text =0x90909090 .note : { *(.note.*) } :text :note
fs/proc/task_mmu.c +18 -12
@@ -118,6 +118,11 @@ struct mem_size_statsunsigned long private_dirty; }; +__attribute__((weak))const char *arch_vma_name (struct vm_area_struct *vma) +{ +return NULL ; +} +static int show_map_internal (struct seq_file *m,void *v,struct mem_size_stats *mss) {struct task_struct *task = m->private;
@@ -153,22 +158,23 @@ static int show_map_internal(struct seq_pad_len_spaces (m, len);seq_path (m, file->f_vfsmnt, file->f_dentry,"\n" ); }else { -if (mm) { -if (vma->vm_start <= mm->start_brk && +const char *name =arch_vma_name (vma); +if (!name) { +if (mm) { +if (vma->vm_start <= mm->start_brk && vma->vm_end >= mm->brk) { -pad_len_spaces (m, len); -seq_puts (m,"[heap]" ); - }else { -if (vma->vm_start <= mm->start_stack && - vma->vm_end >= mm->start_stack) { - -pad_len_spaces (m, len); -seq_puts (m,"[stack]" ); + name ="[heap]" ; + }else if (vma->vm_start <= mm->start_stack && + vma->vm_end >= mm->start_stack) { + name ="[stack]" ; } + }else { + name ="[vdso]" ; } - }else { + } +if (name) {pad_len_spaces (m, len); -seq_puts (m,"[vdso]" ); +seq_puts (m, name); } }seq_putc (m,'\n' );
include/asm-i386/elf.h +40 -13
86 lines not on this page · raw message
include/asm-i386/fixmap.h +1 -9
@@ -52,7 +52,7 @@*/ enum fixed_addresses {FIX_HOLE , -FIX_VSYSCALL , +FIX_VDSO ,#ifdef CONFIG_X86_LOCAL_APIC FIX_APIC_BASE ,/* local (CPU) APIC) -- required for SMP or not */ #endif
@@ -116,14 +116,6 @@ extern void __set_fixmap (enum fixed_add#define __fix_to_virt (x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))#define __virt_to_fix (x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT) -/* -* This is the range that is readable by user mode, and things -* acting like user mode such as get_user_pages. -*/ -#define FIXADDR_USER_START (__fix_to_virt(FIX_VSYSCALL)) -#define FIXADDR_USER_END (FIXADDR_USER_START + PAGE_SIZE) - -extern void __this_fixmap_does_not_exist (void );/*
include/asm-i386/mmu.h +1 -0
@@ -12,6 +12,7 @@ typedef struct {int size;struct semaphore sem;void *ldt; + void *vdso; } mm_context_t;#endif
include/asm-i386/page.h +5 -1
@@ -97,6 +97,8 @@ typedef struct { unsigned long pgprot; }#ifndef __ASSEMBLY__ +struct vm_area_struct ; +/* * This much address space is reserved for vmalloc() and iomap() * as well as fixmap mappings.
@@ -107,6 +109,7 @@ extern int sysctl_legacy_va_layout;extern int page_is_ram (unsigned long pagenr); +const char *arch_vma_name (struct vm_area_struct *vma);#endif /* __ASSEMBLY__ */ #ifdef __ASSEMBLY__
@@ -121,7 +124,7 @@ extern int page_is_ram(unsigned long pag#define PAGE_OFFSET ((unsigned long)__PAGE_OFFSET)#define VMALLOC_RESERVE ((unsigned long)__VMALLOC_RESERVE) -#define MAXMEM (-__PAGE_OFFSET-__VMALLOC_RESERVE) +#define MAXMEM (__FIXADDR_TOP-__PAGE_OFFSET-__VMALLOC_RESERVE)#define __pa (x) ((unsigned long)(x)-PAGE_OFFSET)#define __va (x) ((void *)((unsigned long)(x)+PAGE_OFFSET))#define pfn_to_kaddr (pfn) __va((pfn) << PAGE_SHIFT)
@@ -137,6 +140,7 @@ extern int page_is_ram(unsigned long pag ((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \ VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) +#define __HAVE_ARCH_GATE_AREA 1#endif /* __KERNEL__ */ #include <asm-generic/memory_model.h>
include/asm-i386/thread_info.h +1 -0
@@ -38,6 +38,7 @@ struct thread_info {0-0xBFFFFFFF for user-thead 0-0xFFFFFFFF for kernel-thread */ +void *sysenter_return;struct restart_block restart_block;unsigned long previous_esp;/* ESP of the previous stack in case
include/linux/sched.h +1 -0
@@ -40,6 +40,7 @@#include <linux/auxvec.h> /* For AT_VECTOR_SIZE */ struct exec_domain ; +extern int print_fatal_signals;/* * cloning flags:
include/linux/sysctl.h +1 -0
@@ -187,6 +187,7 @@ enumVM_PERCPU_PAGELIST_FRACTION =30 ,/* int: fraction of pages in each percpu_pagelist */ VM_ZONE_RECLAIM_MODE =31 ,/* reclaim local zone memory before going off node */ VM_ZONE_RECLAIM_INTERVAL =32 ,/* time period to wait after reclaim failure */ + VM_VDSO_ENABLED=33, /* map VDSO into new processes? */ };
kernel/sysctl.c +12 -1
@@ -72,7 +72,6 @@ extern int printk_ratelimit_burst;extern int pid_max_min, pid_max_max;extern int sysctl_drop_caches;extern int percpu_pagelist_fraction; -extern int print_fatal_signals;#if defined(CONFIG_X86_LOCAL_APIC ) && defined(CONFIG_X86 )int unknown_nmi_panic;
@@ -924,6 +923,18 @@ static ctl_table vm_table[] = { .strategy = &sysctl_jiffies, },#endif +#ifdef CONFIG_X86_32 + { + .ctl_name = VM_VDSO_ENABLED, + .procname = "vdso_enabled", + .data = &vdso_enabled, + .maxlen = sizeof(vdso_enabled), + .mode = 0644, + .proc_handler = &proc_dointvec, + .strategy = &sysctl_intvec, + .extra1 = &zero, + }, +#endif { .ctl_name = 0 } };