linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@kernel.org>
To: x86@kernel.org, linux-kernel@vger.kernel.org
Cc: "Frédéric Weisbecker" <fweisbec@gmail.com>,
	"Rik van Riel" <riel@redhat.com>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Denys Vlasenko" <vda.linux@googlemail.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"Kees Cook" <keescook@chromium.org>,
	"Brian Gerst" <brgerst@gmail.com>,
	"Linus Torvalds" <torvalds@linux-foundation.org>,
	"Andy Lutomirski" <luto@kernel.org>
Subject: [RFC/PATCH 5/7] x86/vm86: Teach handle_vm86_trap to return to 32bit mode directly
Date: Wed,  8 Jul 2015 12:24:02 -0700	[thread overview]
Message-ID: <c3bfa8ab98867fe07521a55765b85b3d4b582579.1436383168.git.luto@kernel.org> (raw)
In-Reply-To: <cover.1436383168.git.luto@kernel.org>
In-Reply-To: <cover.1436383168.git.luto@kernel.org>

The TIF_NOTIFY_RESUME hack it was using was buggy and unsupportable.
vm86 mode was completely broken under ptrace, for example, because
we'd never make it to v8086 mode.

This code is still a huge, scary mess, but at least it's no longer
tangled with the exit-to-userspace loop.

Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
 arch/x86/entry/entry_32.S | 17 -----------------
 arch/x86/kernel/traps.c   | 12 ++++++++++++
 arch/x86/kernel/vm86_32.c |  8 ++------
 3 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S
index 66ff9c4055d7..3afd201bce55 100644
--- a/arch/x86/entry/entry_32.S
+++ b/arch/x86/entry/entry_32.S
@@ -481,29 +481,12 @@ work_resched:
 
 work_notifysig:					# deal with pending signals and
 						# notify-resume requests
-#ifdef CONFIG_VM86
-	testl	$X86_EFLAGS_VM, PT_EFLAGS(%esp)
-	movl	%esp, %eax
-	jnz	work_notifysig_v86		# special case for v86
-1:
-#else
 	movl	%esp, %eax
-#endif
 	TRACE_IRQS_ON
 	ENABLE_INTERRUPTS(CLBR_NONE)
 	xorl	%edx, %edx
 	call	do_notify_resume
 	jmp	resume_userspace
-
-#ifdef CONFIG_VM86
-	ALIGN
-work_notifysig_v86:
-	pushl	%ecx				# save ti_flags for do_notify_resume
-	call	save_v86_state			# %eax contains pt_regs pointer
-	popl	%ecx
-	movl	%eax, %esp
-	jmp	1b
-#endif
 END(work_pending)
 
 	# perform syscall exit tracing
diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
index 8e65d8a9b8db..f86172d4f5db 100644
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -190,6 +190,13 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
 		 * On nmi (interrupt 2), do_trap should not be called.
 		 */
 		if (trapnr < X86_TRAP_UD) {
+			/*
+			 * handle_vm86_trap may not return.  If that
+			 * happens, then there is no debug stack counter
+			 * (it's a 32-bit kernel) and handle_vm86_trap
+			 * will clear the preempt counter.
+			 */
+
 			if (!handle_vm86_trap((struct kernel_vm86_regs *) regs,
 						error_code, trapnr))
 				return 0;
@@ -650,6 +657,11 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
 	preempt_conditional_sti(regs);
 
 	if (v8086_mode(regs)) {
+		/*
+		 * handle_vm86_trap may not return.  If that happens, then
+		 * there is no debug stack counter (it's a 32-bit kernel)
+		 * and handle_vm86_trap will clear the preempt counter.
+		 */
 		handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
 					X86_TRAP_DB);
 		preempt_conditional_cli(regs);
diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
index fc9db6ef2a95..c526ee34c22d 100644
--- a/arch/x86/kernel/vm86_32.c
+++ b/arch/x86/kernel/vm86_32.c
@@ -351,6 +351,7 @@ static inline void return_to_32bit(struct kernel_vm86_regs *regs16, int retval)
 {
 	struct pt_regs *regs32;
 
+	preempt_count_set(0);
 	regs32 = save_v86_state(regs16);
 	regs32->ax = retval;
 	__asm__ __volatile__("movl %0,%%esp\n\t"
@@ -549,12 +550,7 @@ int handle_vm86_trap(struct kernel_vm86_regs *regs, long error_code, int trapno)
 {
 	if (VMPI.is_vm86pus) {
 		if ((trapno == 3) || (trapno == 1)) {
-			KVM86->regs32->ax = VM86_TRAP + (trapno << 8);
-			/* setting this flag forces the code in entry_32.S to
-			   the path where we call save_v86_state() and change
-			   the stack pointer to KVM86->regs32 */
-			set_thread_flag(TIF_NOTIFY_RESUME);
-			return 0;
+			return_to_32bit(regs, VM86_TRAP + (trapno << 8));
 		}
 		do_int(regs, trapno, (unsigned char __user *) (regs->pt.ss << 4), SP(regs));
 		return 0;
-- 
2.4.3


  parent reply	other threads:[~2015-07-08 19:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 19:23 [RFC/PATCH 0/7] x86_32: Migrate to new entry/exit paths Andy Lutomirski
2015-07-08 19:23 ` [RFC/PATCH 1/7] x86/entry/32: Remove 32-bit syscall audit optimizations Andy Lutomirski
2015-07-08 19:23 ` [RFC/PATCH 2/7] x86/entry/32: Fix an incorrect comment for work_notifysig_v86 Andy Lutomirski
2015-07-08 19:24 ` [RFC/PATCH 3/7] [TEMPORARY] x86/entry/32: Sanity check for work_notifysig Andy Lutomirski
2015-07-08 19:25   ` Andy Lutomirski
2015-07-08 19:24 ` [RFC/PATCH 4/7] x86/entry/32: Finish removing bogus kernel-mode check Andy Lutomirski
2015-07-08 19:25   ` Andy Lutomirski
2015-07-08 19:24 ` Andy Lutomirski [this message]
2015-07-09 22:41   ` [RFC/PATCH 5/7] x86/vm86: Teach handle_vm86_trap to return to 32bit mode directly Andy Lutomirski
2015-07-10  1:33     ` Andy Lutomirski
2015-07-10 15:27       ` Brian Gerst
2015-07-08 19:24 ` [RFC/PATCH 6/7] x86/entry/32: Use prepare_exit_to_usermode and syscall_return_slowpath Andy Lutomirski
2015-07-08 19:24 ` [RFC/PATCH 7/7] x86/entry: Remove do_notify_resume, syscall_trace_leave, and their TIF masks Andy Lutomirski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c3bfa8ab98867fe07521a55765b85b3d4b582579.1436383168.git.luto@kernel.org \
    --to=luto@kernel.org \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=fweisbec@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=riel@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=vda.linux@googlemail.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).