Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1662296

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

Path csiph.com!aioe.org!bofh.it!news.nic.it!robomod
From Borislav Petkov <bp@suse.de>
Newsgroups linux.kernel
Subject Re: [PATCH v7 22/26] x86/umip: Force a page fault when unable to copy emulated result to user
Date Fri, 09 Jun 2017 13:10:01 +0200
Message-ID <tQpXH-LP-1@gated-at.bofh.it> (permalink)
References <tDPZD-5j6-3@gated-at.bofh.it> <tDQ9l-5mF-23@gated-at.bofh.it>
X-Original-To Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Disposition inline
Content-Transfer-Encoding 8bit
User-Agent NeoMutt/20170113 (1.7.2)
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 132
Organization linux.* mail to news gateway
X-Original-Cc Ingo Molnar <mingo@redhat.com>, Thomas Gleixner <tglx@linutronix.de>, "H. Peter Anvin" <hpa@zytor.com>, Andy Lutomirski <luto@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Andrew Morton <akpm@linux-foundation.org>, Brian Gerst <brgerst@gmail.com>, Chris Metcalf <cmetcalf@mellanox.com>, Dave Hansen <dave.hansen@linux.intel.com>, Paolo Bonzini <pbonzini@redhat.com>, Masami Hiramatsu <mhiramat@kernel.org>, Huang Rui <ray.huang@amd.com>, Jiri Slaby <jslaby@suse.cz>, Jonathan Corbet <corbet@lwn.net>, "Michael S. Tsirkin" <mst@redhat.com>, Paul Gortmaker <paul.gortmaker@windriver.com>, Vlastimil Babka <vbabka@suse.cz>, Chen Yucong <slaoub@gmail.com>, Alexandre Julliard <julliard@winehq.org>, Stas Sergeev <stsp@list.ru>, Fenghua Yu <fenghua.yu@intel.com>, "Ravi V. Shankar" <ravi.v.shankar@intel.com>, Shuah Khan <shuah@kernel.org>, linux-kernel@vger.kernel.org, x86@kernel.org, linux-msdos@vger.kernel.org, wine-devel@winehq.org, Tony Luck <tony.luck@intel.com>
X-Original-Date Fri, 9 Jun 2017 13:02:30 +0200
X-Original-Message-ID <20170609110230.rjmce4ifqr5vddac@pd.tnic>
X-Original-References <20170505181724.55000-1-ricardo.neri-calderon@linux.intel.com> <20170505181724.55000-23-ricardo.neri-calderon@linux.intel.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1662296

Show key headers only | View raw


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.

> force_sig_info_fault is introduced to model the page fault.
> 
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: H. Peter Anvin <hpa@zytor.com>
> Cc: Borislav Petkov <bp@suse.de>
> Cc: Brian Gerst <brgerst@gmail.com>
> Cc: Chen Yucong <slaoub@gmail.com>
> Cc: Chris Metcalf <cmetcalf@mellanox.com>
> Cc: Dave Hansen <dave.hansen@linux.intel.com>
> Cc: Fenghua Yu <fenghua.yu@intel.com>
> Cc: Huang Rui <ray.huang@amd.com>
> Cc: Jiri Slaby <jslaby@suse.cz>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ravi V. Shankar <ravi.v.shankar@intel.com>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Tony Luck <tony.luck@intel.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Liang Z. Li <liang.z.li@intel.com>
> Cc: Alexandre Julliard <julliard@winehq.org>
> Cc: Stas Sergeev <stsp@list.ru>
> Cc: x86@kernel.org
> Cc: linux-msdos@vger.kernel.org
> Signed-off-by: Ricardo Neri <ricardo.neri-calderon@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...



> +		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.

> +			 */
> +			__force_sig_info_umip_fault(uaddr, regs);
> +			return true;
> +		}
>  	}
>  
>  	/* increase IP to let the program keep going */
> -- 
> 2.9.3
> 

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

Re: [PATCH v7 22/26] x86/umip: Force a page fault when unable to  copy emulated result to user Borislav Petkov <bp@suse.de> - 2017-06-09 13:10 +0200

csiph-web