linux-um.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Eli Cooper <elicooper@gmx.com>
To: user-mode-linux-devel@lists.sourceforge.net
Cc: Richard Weinberger <richard@nod.at>, Jeff Dike <jdike@addtoit.com>
Subject: [uml-devel] [PATCH] um: fix FPU register double-restore after sigreturn
Date: Wed, 16 Mar 2016 09:25:05 +0800	[thread overview]
Message-ID: <1458091505-967-1-git-send-email-elicooper@gmx.com> (raw)

This patch prevents userspace() from incorrectly restoring FPU registers
after a sigreturn or rt_sigreturn system call, which has already restored
FPU registers to the state prior to the signal handler was invoked.

Fixes FPU state corruption after invoking the signal handler.

Signed-off-by: Eli Cooper <elicooper@gmx.com>
---
 arch/um/os-Linux/skas/process.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/um/os-Linux/skas/process.c b/arch/um/os-Linux/skas/process.c
index 23025d6..664f184 100644
--- a/arch/um/os-Linux/skas/process.c
+++ b/arch/um/os-Linux/skas/process.c
@@ -310,6 +310,8 @@ void userspace(struct uml_pt_regs *regs)
 	int err, status, op, pid = userspace_pid[0];
 	/* To prevent races if using_sysemu changes under us.*/
 	int local_using_sysemu;
+	/* To prevent FPU register restore after sigreturn syscalls. */
+	int skip_fp_restore = 0;
 	siginfo_t si;
 
 	/* Handle any immediate reschedules or signals */
@@ -328,8 +330,9 @@ void userspace(struct uml_pt_regs *regs)
 		if (ptrace(PTRACE_SETREGS, pid, 0, regs->gp))
 			fatal_sigsegv();
 
-		if (put_fp_registers(pid, regs->fp))
-			fatal_sigsegv();
+		if (!skip_fp_restore)
+			if (put_fp_registers(pid, regs->fp))
+				fatal_sigsegv();
 
 		/* Now we set local_using_sysemu to be used for one loop */
 		local_using_sysemu = get_using_sysemu();
@@ -351,6 +354,7 @@ void userspace(struct uml_pt_regs *regs)
 		}
 
 		regs->is_user = 1;
+		skip_fp_restore = 0;
 		if (ptrace(PTRACE_GETREGS, pid, 0, regs->gp)) {
 			printk(UM_KERN_ERR "userspace - PTRACE_GETREGS failed, "
 			       "errno = %d\n", errno);
@@ -381,6 +385,12 @@ void userspace(struct uml_pt_regs *regs)
 				else handle_segv(pid, regs);
 				break;
 			case SIGTRAP + 0x80:
+#ifdef __i386__
+				if (PT_SYSCALL_NR(regs->gp) == __NR_sigreturn)
+					skip_fp_restore = 1;
+#endif
+				if (PT_SYSCALL_NR(regs->gp) == __NR_rt_sigreturn)
+					skip_fp_restore = 1;
 			        handle_trap(pid, regs, local_using_sysemu);
 				break;
 			case SIGTRAP:
-- 
2.7.2


------------------------------------------------------------------------------
Transform Data into Opportunity.
Accelerate data analysis in your applications with
Intel Data Analytics Acceleration Library.
Click to learn more.
http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel


             reply	other threads:[~2016-03-16  1:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-16  1:25 Eli Cooper [this message]
2016-03-17 22:21 ` [uml-devel] [PATCH] um: fix FPU register double-restore after sigreturn Richard Weinberger
2016-03-18  1:41   ` Eli Cooper
2016-03-18  8:20     ` Richard Weinberger
2016-03-18 16:13       ` Eli Cooper
2016-03-18 16:42         ` Jeff Dike
2016-03-18 20:12           ` Richard Weinberger

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=1458091505-967-1-git-send-email-elicooper@gmx.com \
    --to=elicooper@gmx.com \
    --cc=jdike@addtoit.com \
    --cc=richard@nod.at \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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).