All of lore.kernel.org
 help / color / mirror / Atom feed
* [uml-devel] [patch 1/1] SYSEMU: avoid intercepting syscall on return when using SYSCALL again.
@ 2004-10-21 23:18 blaisorblade_spam
  2004-10-22  0:37 ` BlaisorBlade
  2004-10-22  9:22 ` [uml-devel] " Bodo Stroesser
  0 siblings, 2 replies; 11+ messages in thread
From: blaisorblade_spam @ 2004-10-21 23:18 UTC (permalink / raw)
  To: bstroesser; +Cc: user-mode-linux-devel, jdike, blaisorblade_spam


From: Bodo Stroesser <bstroesser@fujitsu-siemens.com>

A guest process switching from using PTRACE_SYSEMU to PTRACE_SYSCALL crashes.

The problem is in arch/i386/kernel/entry.S. The current SYSEMU patch inhibits
the syscall-handler to be called, but does not prevent do_syscall_trace to be
called after this for syscall completion interception.

The appended patch fixes this. It reuses the flag TIF_SYSCALL_EMU to remember
"we come from PTRACE_SYSEMU and now are in PTRACE_SYSCALL", since the flag is
unused in the depicted situation.

The patch is tested, AFAICS, it works fine, i.e. sysemu can be switched on and
off dynamically without crash.

Bodo

Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade_spam@yahoo.it>
---

 vanilla-linux-2.6.7-SKAS-paolo/arch/i386/kernel/ptrace.c |   28 +++++++++++----
 1 files changed, 21 insertions(+), 7 deletions(-)

diff -puN arch/i386/kernel/ptrace.c~avoid-intercepting-syscall-on-return-when-changing-state arch/i386/kernel/ptrace.c
--- vanilla-linux-2.6.7-SKAS/arch/i386/kernel/ptrace.c~avoid-intercepting-syscall-on-return-when-changing-state	2004-10-22 00:55:06.632837000 +0200
+++ vanilla-linux-2.6.7-SKAS-paolo/arch/i386/kernel/ptrace.c	2004-10-22 01:12:48.391425160 +0200
@@ -366,16 +366,20 @@ asmlinkage int sys_ptrace(long request, 
 		ret = -EIO;
 		if ((unsigned long) data > _NSIG)
 			break;
+		/* If we came here with PTRACE_SYSEMU and now continue with
+		 * PTRACE_SYSCALL, entry.S used to intercept the syscall return. But it
+		 * shouldn't!
+		 * So we don't clear TIF_SYSCALL_EMU, which is always unused in this
+		 * special case, to remember, we came from SYSEMU. That flag
+		 * will be cleared by do_syscall_trace().
+		 */
 		if (request == PTRACE_SYSEMU) {
 			set_tsk_thread_flag(child, TIF_SYSCALL_EMU);
 		}
-		else {
-			clear_tsk_thread_flag(child, TIF_SYSCALL_EMU);
-		}
+
 		if (request == PTRACE_SYSCALL) {
 			set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
-		}
-		else {
+		} else {
 			clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
 		}
 		child->exit_code = data;
@@ -585,7 +589,7 @@ out:
 __attribute__((regparm(3)))
 int do_syscall_trace(struct pt_regs *regs, int entryexit)
 {
-	int is_sysemu;
+	int is_sysemu, is_systrace;
 	if (unlikely(current->audit_context)) {
 		if (!entryexit)
 			audit_syscall_entry(current, regs->orig_eax,
@@ -595,9 +599,19 @@ int do_syscall_trace(struct pt_regs *reg
 			audit_syscall_exit(current, regs->eax);
 	}
 	is_sysemu = test_thread_flag(TIF_SYSCALL_EMU);
+	is_systrace = test_thread_flag(TIF_SYSCALL_TRACE);
 
-	if (!test_thread_flag(TIF_SYSCALL_TRACE) && !is_sysemu)
+	if (!is_systrace && !is_sysemu)
 		return 0;
+	/* We can detect the case of coming from PTRACE_SYSEMU and now
+	 * running with PTRACE_SYSCALL, by TIF_SYSCALL_EMU being set
+	 * additionally.
+	 * If so let's reset the flag and return without action.
+	 */
+	if (is_sysemu && is_systrace) {
+		clear_thread_flag(TIF_SYSCALL_EMU);
+		return 0;
+	}
 	if (!(current->ptrace & PT_PTRACED))
 		return 0;
 	/* the 0x80 provides a way for the tracing parent to distinguish
_


-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2004-10-29 13:08 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-21 23:18 [uml-devel] [patch 1/1] SYSEMU: avoid intercepting syscall on return when using SYSCALL again blaisorblade_spam
2004-10-22  0:37 ` BlaisorBlade
2004-10-22  9:22 ` [uml-devel] " Bodo Stroesser
2004-10-22 16:14   ` BlaisorBlade
2004-10-22 16:23     ` Bodo Stroesser
2004-10-27 14:21       ` Bodo Stroesser
2004-10-28 23:04         ` Blaisorblade
2004-10-28 23:36           ` Bodo Stroesser
     [not found]             ` <200410290200.46907.blaisorblade_spam@yahoo.it>
2004-10-29  1:19               ` Bodo Stroesser
2004-10-29  7:51                 ` Gerd Knorr
2004-10-29 13:09                   ` Blaisorblade

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.