android_kernel_xiaomi_sm8350/arch/i386
Jason Wessel 1e2e99f0e4 i386: fix regression, endless loop in ptrace singlestep over an int80
The commit 635cf99a80 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>
2007-07-06 10:23:43 -07:00
..
boot i386: Fix wrong CPU error message in early boot path 2007-05-21 09:56:57 -07:00
crypto
kernel i386: fix regression, endless loop in ptrace singlestep over an int80 2007-07-06 10:23:43 -07:00
lib i386: Add safe variants of rdmsr_on_cpu and wrmsr_on_cpu 2007-05-08 17:22:01 +02:00
mach-default Add IRQF_IRQPOLL flag on i386 2007-05-08 11:15:22 -07:00
mach-es7000 ACPICA: Remove duplicate table manager 2007-02-02 21:14:28 -05:00
mach-generic i386 bigsmp: section mismatch fixes 2007-05-23 20:14:15 -07:00
mach-visws Add IRQF_IRQPOLL flag on i386 2007-05-08 11:15:22 -07:00
mach-voyager i386: fix voyager build 2007-05-15 08:54:01 -07:00
math-emu potential parse error in ifdef part 3 2007-06-08 17:23:33 -07:00
mm Allow DEBUG_RODATA and KPROBES to co-exist 2007-06-21 16:02:50 -07:00
oprofile x86: fix oprofile double free 2007-06-01 08:18:28 -07:00
pci PCI: i386: fixup for Siemens Nixdorf AG FSC Multiprocessor Interrupt Controllers 2007-05-31 16:56:37 -07:00
power [PATCH] x86: Save and restore the fixed-range MTRRs of the BSP when suspending 2007-05-02 19:27:17 +02:00
defconfig i386: Update defconfig 2007-05-21 09:56:56 -07:00
Kconfig i386: Make CMPXCHG64 only dependent on PAE 2007-06-22 18:41:18 -07:00
Kconfig.cpu i386: Make CMPXCHG64 only dependent on PAE 2007-06-22 18:41:18 -07:00
Kconfig.debug Allow DEBUG_RODATA and KPROBES to co-exist 2007-06-21 16:02:50 -07:00
Makefile Revert "[PATCH] x86: Drop cc-options call for all options supported in gcc 3.2+" 2007-05-17 20:18:11 -07:00
Makefile.cpu [PATCH] i386: Fix usage of -mtune when X86_GENERIC=y or CONFIG_MCORE2=y 2007-05-02 19:27:06 +02:00