[PATCH v7 22/26] x86/umip: Force a page fault when unable to copy emulated result to user

Ricardo Neri ricardo.neri-calderon at linux.intel.com
Tue Jul 25 18:50:03 CDT 2017


On Fri, 2017-06-09 at 13:02 +0200, Borislav Petkov wrote:
> On Fri, May 05, 2017 at 11:17:20AM -0700, Ricardo Neri wrote:
> > fixup_umip_exception() will be called from do_general_protection. If the
> 								  ^
> 								  |
> Please end function names with parentheses.		       ---+
> 
> > 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
> 
> That reads funny.

I will correct this.
> 
> > force_sig_info_fault is introduced to model the page fault.
> > 
> > Cc: Andy Lutomirski <luto at kernel.org>
> > Cc: Andrew Morton <akpm at linux-foundation.org>
> > Cc: H. Peter Anvin <hpa at zytor.com>
> > Cc: Borislav Petkov <bp at suse.de>
> > Cc: Brian Gerst <brgerst at gmail.com>
> > Cc: Chen Yucong <slaoub at gmail.com>
> > Cc: Chris Metcalf <cmetcalf at mellanox.com>
> > Cc: Dave Hansen <dave.hansen at linux.intel.com>
> > Cc: Fenghua Yu <fenghua.yu at intel.com>
> > Cc: Huang Rui <ray.huang at amd.com>
> > Cc: Jiri Slaby <jslaby at suse.cz>
> > Cc: Jonathan Corbet <corbet at lwn.net>
> > Cc: Michael S. Tsirkin <mst at redhat.com>
> > Cc: Paul Gortmaker <paul.gortmaker at windriver.com>
> > Cc: Peter Zijlstra <peterz at infradead.org>
> > Cc: Ravi V. Shankar <ravi.v.shankar at intel.com>
> > Cc: Shuah Khan <shuah at kernel.org>
> > Cc: Vlastimil Babka <vbabka at suse.cz>
> > Cc: Tony Luck <tony.luck at intel.com>
> > Cc: Paolo Bonzini <pbonzini at redhat.com>
> > Cc: Liang Z. Li <liang.z.li at intel.com>
> > Cc: Alexandre Julliard <julliard at winehq.org>
> > Cc: Stas Sergeev <stsp at list.ru>
> > Cc: x86 at kernel.org
> > Cc: linux-msdos at vger.kernel.org
> > Signed-off-by: Ricardo Neri <ricardo.neri-calderon at linux.intel.com>
> > ---
> >  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 c7c5795..ff7366a 100644
> > --- a/arch/x86/kernel/umip.c
> > +++ b/arch/x86/kernel/umip.c
> > @@ -148,6 +148,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)) {
> 
> Save an indentation level:
> 
> 	if (!(show_unhandled_signals && unhandled_signal(tsk, SIGSEGV)))
> 		return;
> 
> 	printk...
> 
I will implement like this.
> 
> 
> > +		printk_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);
> > +	}
> > +
> > +	tsk->thread.cr2		= (unsigned long)address;
> > +	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	= address;
> > +	force_sig_info(SIGSEGV, &info, tsk);
> > +}
> > +
> > +/**
> >   * fixup_umip_exception() - Fixup #GP faults caused by UMIP
> >   * @regs:	Registers as saved when entering the #GP trap
> >   *
> > @@ -235,8 +270,14 @@ bool fixup_umip_exception(struct pt_regs *regs)
> >  		if ((unsigned long)uaddr == -1L)
> >  			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
> 
> Pls end sentences in the comments with a fullstop.

I will correct this.

Thanks and BR,
Ricardo




More information about the wine-devel mailing list