Commit 918ce325 authored by Andy Lutomirski's avatar Andy Lutomirski Committed by Thomas Gleixner

x86/vsyscall: Show something useful on a read fault

Just segfaulting the application when it tries to read the vsyscall page in
xonly mode is not helpful for those who need to debug it.

Emit a hint.
Signed-off-by: default avatarAndy Lutomirski <luto@kernel.org>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Cc: Florian Weimer <fweimer@redhat.com>
Cc: Jann Horn <jannh@google.com>
Link: https://lkml.kernel.org/r/8016afffe0eab497be32017ad7f6f7030dc3ba66.1561610354.git.luto@kernel.org
parent bd49e16e
...@@ -117,7 +117,8 @@ static bool write_ok_or_segv(unsigned long ptr, size_t size) ...@@ -117,7 +117,8 @@ static bool write_ok_or_segv(unsigned long ptr, size_t size)
} }
} }
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; struct task_struct *tsk;
unsigned long caller; unsigned long caller;
...@@ -126,6 +127,22 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address) ...@@ -126,6 +127,22 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
long ret; long ret;
unsigned long orig_dx; 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 * 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. * trap to a high address, which means that we're in 64-bit user code.
......
...@@ -13,10 +13,12 @@ extern void set_vsyscall_pgtable_user_bits(pgd_t *root); ...@@ -13,10 +13,12 @@ extern void set_vsyscall_pgtable_user_bits(pgd_t *root);
* Called on instruction fetch fault in vsyscall page. * Called on instruction fetch fault in vsyscall page.
* Returns true if handled. * Returns true if handled.
*/ */
extern bool emulate_vsyscall(struct pt_regs *regs, unsigned long address); extern bool emulate_vsyscall(unsigned long error_code,
struct pt_regs *regs, unsigned long address);
#else #else
static inline void map_vsyscall(void) {} static inline void map_vsyscall(void) {}
static inline bool emulate_vsyscall(struct pt_regs *regs, unsigned long address) static inline bool emulate_vsyscall(unsigned long error_code,
struct pt_regs *regs, unsigned long address)
{ {
return false; return false;
} }
......
...@@ -1369,16 +1369,15 @@ void do_user_addr_fault(struct pt_regs *regs, ...@@ -1369,16 +1369,15 @@ void do_user_addr_fault(struct pt_regs *regs,
#ifdef CONFIG_X86_64 #ifdef CONFIG_X86_64
/* /*
* Instruction fetch faults in the vsyscall page might need * Faults in the vsyscall page might need emulation. The
* emulation. The vsyscall page is at a high address * vsyscall page is at a high address (>PAGE_OFFSET), but is
* (>PAGE_OFFSET), but is considered to be part of the user * considered to be part of the user address space.
* address space.
* *
* The vsyscall page does not have a "real" VMA, so do this * The vsyscall page does not have a "real" VMA, so do this
* emulation before we go searching for VMAs. * emulation before we go searching for VMAs.
*/ */
if ((hw_error_code & X86_PF_INSTR) && is_vsyscall_vaddr(address)) { if (is_vsyscall_vaddr(address)) {
if (emulate_vsyscall(regs, address)) if (emulate_vsyscall(hw_error_code, regs, address))
return; return;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment