Revision 1e2e99f0e4aa6363e8515ed17011c210c8f1b52a authored by Jason Wessel on 06 July 2007, 09:39:50 UTC, committed by Linus Torvalds on 06 July 2007, 17:23:43 UTC
The commit 635cf99a80f4ebee59d70eb64bb85ce829e4591f introduced a
regression.  Executing a ptrace single step after certain int80
accesses will infinitely loop and never advance the PC.

The TIF_SINGLESTEP check should be done on the return from the syscall
and not before it.

I loops on each single step on the pop right after the int80 which writes out
to the console.  At that point you can issue as many single steps as you want
and it will not advance any further.

The test case is below:

/* Test whether singlestep through an int80 syscall works.
 */
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <asm/user.h>
#include <string.h>

static int child, status;
static struct user_regs_struct regs;

static void do_child()
{
	char str[80] = "child: int80 test\n";

	ptrace(PTRACE_TRACEME, 0, 0, 0);
	kill(getpid(), SIGUSR1);
	write(fileno(stdout),str,strlen(str));
	asm ("int $0x80" : : "a" (20)); /* getpid */
}

static void do_parent()
{
	unsigned long eip, expected = 0;
again:
	waitpid(child, &status, 0);
	if (WIFEXITED(status) || WIFSIGNALED(status))
		return;

	if (WIFSTOPPED(status)) {
		ptrace(PTRACE_GETREGS, child, 0, &regs);
		eip = regs.eip;
		if (expected)
			fprintf(stderr, "child stop @ %08lx, expected %08lx %s\n",
					eip, expected,
					eip == expected ? "" : " <== ERROR");

		if (*(unsigned short *)eip == 0x80cd) {
			fprintf(stderr, "int 0x80 at %08x\n", (unsigned int)eip);
			expected = eip + 2;
		} else
			expected = 0;

		ptrace(PTRACE_SINGLESTEP, child, NULL, NULL);
	}
	goto again;
}

int main(int argc, char * const argv[])
{
	child = fork();
	if (child)
		do_parent();
	else
		do_child();
	return 0;
}

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: <stable@kernel.org>
Cc: Chuck Ebbert <76306.1226@compuserve.com>
Acked-by: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent ef7320e
History
File Mode Size
Kconfig -rw-r--r-- 2.6 KB
Makefile -rw-r--r-- 494 bytes
associola.c -rw-r--r-- 39.1 KB
bind_addr.c -rw-r--r-- 10.9 KB
chunk.c -rw-r--r-- 8.0 KB
command.c -rw-r--r-- 2.4 KB
crc32c.c -rw-r--r-- 8.2 KB
debug.c -rw-r--r-- 4.7 KB
endpointola.c -rw-r--r-- 10.0 KB
input.c -rw-r--r-- 25.2 KB
inqueue.c -rw-r--r-- 6.3 KB
ipv6.c -rw-r--r-- 27.8 KB
objcnt.c -rw-r--r-- 4.0 KB
output.c -rw-r--r-- 19.3 KB
outqueue.c -rw-r--r-- 50.3 KB
primitive.c -rw-r--r-- 7.6 KB
proc.c -rw-r--r-- 10.9 KB
protocol.c -rw-r--r-- 34.1 KB
sm_make_chunk.c -rw-r--r-- 82.8 KB
sm_sideeffect.c -rw-r--r-- 43.3 KB
sm_statefuns.c -rw-r--r-- 169.1 KB
sm_statetable.c -rw-r--r-- 32.5 KB
socket.c -rw-r--r-- 174.4 KB
ssnmap.c -rw-r--r-- 3.5 KB
sysctl.c -rw-r--r-- 6.8 KB
transport.c -rw-r--r-- 18.1 KB
tsnmap.c -rw-r--r-- 10.4 KB
ulpevent.c -rw-r--r-- 28.2 KB
ulpqueue.c -rw-r--r-- 25.3 KB

back to top