Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752663AbdCEQS5 (ORCPT ); Sun, 5 Mar 2017 11:18:57 -0500 Received: from mail-ua0-f172.google.com ([209.85.217.172]:33074 "EHLO mail-ua0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752290AbdCEQSz (ORCPT ); Sun, 5 Mar 2017 11:18:55 -0500 MIME-Version: 1.0 In-Reply-To: <20170303214132.77244-18-ricardo.neri-calderon@linux.intel.com> References: <20170303214132.77244-1-ricardo.neri-calderon@linux.intel.com> <20170303214132.77244-18-ricardo.neri-calderon@linux.intel.com> From: Andy Lutomirski Date: Sun, 5 Mar 2017 08:18:32 -0800 Message-ID: Subject: Re: [v5 17/20] x86/umip: Force a page fault when unable to copy emulated result to user To: Ricardo Neri Cc: Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , Andy Lutomirski , Borislav Petkov , Peter Zijlstra , Andrew Morton , Brian Gerst , Chris Metcalf , Dave Hansen , Paolo Bonzini , Liang Z Li , Masami Hiramatsu , Huang Rui , Jiri Slaby , Jonathan Corbet , "Michael S. Tsirkin" , Paul Gortmaker , Vlastimil Babka , Chen Yucong , Alexandre Julliard , Stas Sergeev , Fenghua Yu , "Ravi V. Shankar" , Shuah Khan , "linux-kernel@vger.kernel.org" , X86 ML , linux-msdos@vger.kernel.org, wine-devel@winehq.org Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2315 Lines: 52 On Fri, Mar 3, 2017 at 1:41 PM, Ricardo Neri wrote: > 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 is inspired in > force_sig_info_fault is introduced to model the page fault. > > Signed-off-by: Ricardo Neri > --- > arch/x86/kernel/umip.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 43 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kernel/umip.c b/arch/x86/kernel/umip.c > index e932f40..5b6a7cf 100644 > --- a/arch/x86/kernel/umip.c > +++ b/arch/x86/kernel/umip.c > @@ -170,6 +170,41 @@ static int __emulate_umip_insn(struct insn *insn, enum umip_insn umip_inst, > } > > /** > + * __force_sig_info_umip_fault - Force a SIGSEGV with SEGV_MAPERR > + * @address: 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. > + * > + * Return: none > + */ > +static void __force_sig_info_umip_fault(void __user *address, > + struct pt_regs *regs) > +{ > + siginfo_t info; > + struct task_struct *tsk = current; > + > + if (show_unhandled_signals && unhandled_signal(tsk, SIGSEGV)) { > + printk_ratelimited("%s[%d] umip emulation segfault ip:%lx sp:%lx error:%lx in %lx\n", > + tsk->comm, task_pid_nr(tsk), regs->ip, > + regs->sp, UMIP_PF_USER | UMIP_PF_WRITE, > + regs->ip); > + } > + > + tsk->thread.cr2 = (unsigned long)address; > + tsk->thread.error_code = UMIP_PF_USER | UMIP_PF_WRITE; Please just move enum x86_pf_error_code into a header and rename the fields X86_PF_USER, etc rather than duplicating it. --Andy