From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752429AbdKHLIH (ORCPT ); Wed, 8 Nov 2017 06:08:07 -0500 Received: from terminus.zytor.com ([65.50.211.136]:42549 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752401AbdKHLIE (ORCPT ); Wed, 8 Nov 2017 06:08:04 -0500 Date: Wed, 8 Nov 2017 03:00:50 -0800 From: tip-bot for Ricardo Neri Message-ID: Cc: akpm@linux-foundation.org, ravi.v.shankar@intel.com, torvalds@linux-foundation.org, mhiramat@kernel.org, dave.hansen@linux.intel.com, tony.luck@intel.com, pbonzini@redhat.com, hpa@zytor.com, bp@alien8.de, jslaby@suse.cz, shuah@kernel.org, tglx@linutronix.de, paul.gortmaker@windriver.com, slaoub@gmail.com, ricardo.neri-calderon@linux.intel.com, luto@kernel.org, peterz@infradead.org, linux-kernel@vger.kernel.org, fenghua.yu@intel.com, corbet@lwn.net, brgerst@gmail.com, mingo@kernel.org, mst@redhat.com, dvlasenk@redhat.com, jpoimboe@redhat.com, bp@suse.de, cmetcalf@mellanox.com, vbabka@suse.cz, ray.huang@amd.com Reply-To: ray.huang@amd.com, vbabka@suse.cz, cmetcalf@mellanox.com, bp@suse.de, jpoimboe@redhat.com, dvlasenk@redhat.com, mst@redhat.com, mingo@kernel.org, brgerst@gmail.com, corbet@lwn.net, linux-kernel@vger.kernel.org, fenghua.yu@intel.com, luto@kernel.org, peterz@infradead.org, ricardo.neri-calderon@linux.intel.com, slaoub@gmail.com, paul.gortmaker@windriver.com, tglx@linutronix.de, shuah@kernel.org, jslaby@suse.cz, bp@alien8.de, pbonzini@redhat.com, hpa@zytor.com, tony.luck@intel.com, dave.hansen@linux.intel.com, torvalds@linux-foundation.org, mhiramat@kernel.org, ravi.v.shankar@intel.com, akpm@linux-foundation.org In-Reply-To: <1509935277-22138-9-git-send-email-ricardo.neri-calderon@linux.intel.com> References: <1509935277-22138-9-git-send-email-ricardo.neri-calderon@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/asm] x86/umip: Force a page fault when unable to copy emulated result to user Git-Commit-ID: c6a960bbf6a36572a06bde866d94a7338c7f256a X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: c6a960bbf6a36572a06bde866d94a7338c7f256a Gitweb: https://git.kernel.org/tip/c6a960bbf6a36572a06bde866d94a7338c7f256a Author: Ricardo Neri AuthorDate: Sun, 5 Nov 2017 18:27:53 -0800 Committer: Ingo Molnar CommitDate: Wed, 8 Nov 2017 11:16:22 +0100 x86/umip: Force a page fault when unable to copy emulated result to user fixup_umip_exception() will be called from do_general_protection(). If the former returns false, the latter will issue a SIGSEGV with SEND_SIG_PRIV. However, when emulation is successful but the emulated result cannot be copied to user space memory, it is more accurate to issue a SIGSEGV with SEGV_MAPERR with the offending address. A new function, inspired in force_sig_info_fault(), is introduced to model the page fault. Signed-off-by: Ricardo Neri Reviewed-by: Thomas Gleixner Cc: Andrew Morton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Borislav Petkov Cc: Brian Gerst Cc: Chen Yucong Cc: Chris Metcalf Cc: Dave Hansen Cc: Denys Vlasenko Cc: Fenghua Yu Cc: H. Peter Anvin Cc: Huang Rui Cc: Jiri Slaby Cc: Jonathan Corbet Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: Paul Gortmaker Cc: Peter Zijlstra Cc: Ravi V. Shankar Cc: Shuah Khan Cc: Tony Luck Cc: Vlastimil Babka Cc: ricardo.neri@intel.com Link: http://lkml.kernel.org/r/1509935277-22138-9-git-send-email-ricardo.neri-calderon@linux.intel.com Signed-off-by: Ingo Molnar --- arch/x86/kernel/umip.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/umip.c b/arch/x86/kernel/umip.c index d80b816..6ba82be 100644 --- a/arch/x86/kernel/umip.c +++ b/arch/x86/kernel/umip.c @@ -11,6 +11,10 @@ #include #include #include +#include + +#undef pr_fmt +#define pr_fmt(fmt) "umip: " fmt /** DOC: Emulation for User-Mode Instruction Prevention (UMIP) * @@ -196,6 +200,41 @@ static int emulate_umip_insn(struct insn *insn, int umip_inst, } /** + * force_sig_info_umip_fault() - Force a SIGSEGV with SEGV_MAPERR + * @addr: Address that caused the signal + * @regs: Register set containing the instruction pointer + * + * Force a SIGSEGV signal with SEGV_MAPERR as the error code. This function is + * intended to be used to provide a segmentation fault when the result of the + * UMIP emulation could not be copied to the user space memory. + * + * Returns: none + */ +static void force_sig_info_umip_fault(void __user *addr, struct pt_regs *regs) +{ + siginfo_t info; + struct task_struct *tsk = current; + + tsk->thread.cr2 = (unsigned long)addr; + tsk->thread.error_code = X86_PF_USER | X86_PF_WRITE; + tsk->thread.trap_nr = X86_TRAP_PF; + + info.si_signo = SIGSEGV; + info.si_errno = 0; + info.si_code = SEGV_MAPERR; + info.si_addr = addr; + force_sig_info(SIGSEGV, &info, tsk); + + if (!(show_unhandled_signals && unhandled_signal(tsk, SIGSEGV))) + return; + + pr_err_ratelimited("%s[%d] umip emulation segfault ip:%lx sp:%lx error:%x in %lx\n", + tsk->comm, task_pid_nr(tsk), regs->ip, + regs->sp, X86_PF_USER | X86_PF_WRITE, + regs->ip); +} + +/** * fixup_umip_exception() - Fixup a general protection fault caused by UMIP * @regs: Registers as saved when entering the #GP handler * @@ -311,8 +350,14 @@ bool fixup_umip_exception(struct pt_regs *regs) return false; nr_copied = copy_to_user(uaddr, dummy_data, dummy_data_size); - if (nr_copied > 0) - return false; + if (nr_copied > 0) { + /* + * If copy fails, send a signal and tell caller that + * fault was fixed up. + */ + force_sig_info_umip_fault(uaddr, regs); + return true; + } } /* increase IP to let the program keep going */