Merge branch 'siginfo-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ebieder...
[linux-2.6-block.git] / arch / x86 / entry / vsyscall / vsyscall_64.c
index d9d81ad7a4009aac0bfb37cd0345366a5d206164..e7c596dea947e3e09f4c74aeac426cf3687cfe39 100644 (file)
 #define CREATE_TRACE_POINTS
 #include "vsyscall_trace.h"
 
-static enum { EMULATE, NONE } vsyscall_mode =
+static enum { EMULATE, XONLY, NONE } vsyscall_mode __ro_after_init =
 #ifdef CONFIG_LEGACY_VSYSCALL_NONE
        NONE;
+#elif defined(CONFIG_LEGACY_VSYSCALL_XONLY)
+       XONLY;
 #else
        EMULATE;
 #endif
@@ -54,6 +56,8 @@ static int __init vsyscall_setup(char *str)
        if (str) {
                if (!strcmp("emulate", str))
                        vsyscall_mode = EMULATE;
+               else if (!strcmp("xonly", str))
+                       vsyscall_mode = XONLY;
                else if (!strcmp("none", str))
                        vsyscall_mode = NONE;
                else
@@ -106,14 +110,15 @@ static bool write_ok_or_segv(unsigned long ptr, size_t size)
                thread->cr2             = ptr;
                thread->trap_nr         = X86_TRAP_PF;
 
-               force_sig_fault(SIGSEGV, SEGV_MAPERR, (void __user *)ptr, current);
+               force_sig_fault(SIGSEGV, SEGV_MAPERR, (void __user *)ptr);
                return false;
        } else {
                return true;
        }
 }
 
-bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
+bool emulate_vsyscall(unsigned long error_code,
+                     struct pt_regs *regs, unsigned long address)
 {
        struct task_struct *tsk;
        unsigned long caller;
@@ -122,6 +127,22 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
        long ret;
        unsigned long orig_dx;
 
+       /* Write faults or kernel-privilege faults never get fixed up. */
+       if ((error_code & (X86_PF_WRITE | X86_PF_USER)) != X86_PF_USER)
+               return false;
+
+       if (!(error_code & X86_PF_INSTR)) {
+               /* Failed vsyscall read */
+               if (vsyscall_mode == EMULATE)
+                       return false;
+
+               /*
+                * User code tried and failed to read the vsyscall page.
+                */
+               warn_bad_vsyscall(KERN_INFO, regs, "vsyscall read attempt denied -- look up the vsyscall kernel parameter if you need a workaround");
+               return false;
+       }
+
        /*
         * No point in checking CS -- the only way to get here is a user mode
         * trap to a high address, which means that we're in 64-bit user code.
@@ -268,7 +289,7 @@ do_ret:
        return true;
 
 sigsegv:
-       force_sig(SIGSEGV, current);
+       force_sig(SIGSEGV);
        return true;
 }
 
@@ -284,7 +305,7 @@ static const char *gate_vma_name(struct vm_area_struct *vma)
 static const struct vm_operations_struct gate_vma_ops = {
        .name = gate_vma_name,
 };
-static struct vm_area_struct gate_vma = {
+static struct vm_area_struct gate_vma __ro_after_init = {
        .vm_start       = VSYSCALL_ADDR,
        .vm_end         = VSYSCALL_ADDR + PAGE_SIZE,
        .vm_page_prot   = PAGE_READONLY_EXEC,
@@ -357,12 +378,20 @@ void __init map_vsyscall(void)
        extern char __vsyscall_page;
        unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
 
-       if (vsyscall_mode != NONE) {
+       /*
+        * For full emulation, the page needs to exist for real.  In
+        * execute-only mode, there is no PTE at all backing the vsyscall
+        * page.
+        */
+       if (vsyscall_mode == EMULATE) {
                __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
                             PAGE_KERNEL_VVAR);
                set_vsyscall_pgtable_user_bits(swapper_pg_dir);
        }
 
+       if (vsyscall_mode == XONLY)
+               gate_vma.vm_flags = VM_EXEC;
+
        BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
                     (unsigned long)VSYSCALL_ADDR);
 }