public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] x86: rename is_at_popf(), add iret to tests and fix insn length
@ 2006-08-02 12:37 Chuck Ebbert
  2006-08-02 12:54 ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: Chuck Ebbert @ 2006-08-02 12:37 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andi Kleen, Linus Torvalds

is_at_popf() needs to test for the iret instruction as well as
popf.  So add that test and rename it to is_setting_trap_flag().

Also change max insn length from 16 to 15 to match reality.

LAHF / SAHF can't affect TF, so the comment in x86_64 is removed.

Signed-off-by: Chuck Ebbert <76306.1226@compuserve.com>

---

Tested on x86_64.

--- 2.6.18-rc3-64.orig/arch/i386/kernel/ptrace.c
+++ 2.6.18-rc3-64/arch/i386/kernel/ptrace.c
@@ -185,17 +185,17 @@ static unsigned long convert_eip_to_line
 	return addr;
 }
 
-static inline int is_at_popf(struct task_struct *child, struct pt_regs *regs)
+static inline int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
 {
 	int i, copied;
-	unsigned char opcode[16];
+	unsigned char opcode[15];
 	unsigned long addr = convert_eip_to_linear(child, regs);
 
 	copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
 	for (i = 0; i < copied; i++) {
 		switch (opcode[i]) {
-		/* popf */
-		case 0x9d:
+		/* popf and iret */
+		case 0x9d: case 0xcf:
 			return 1;
 		/* opcode and address size prefixes */
 		case 0x66: case 0x67:
@@ -247,7 +247,7 @@ static void set_singlestep(struct task_s
 	 * don't mark it as being "us" that set it, so that we
 	 * won't clear it by hand later.
 	 */
-	if (is_at_popf(child, regs))
+	if (is_setting_trap_flag(child, regs))
 		return;
 	
 	child->ptrace |= PT_DTRACE;
--- 2.6.18-rc3-64.orig/arch/x86_64/kernel/ptrace.c
+++ 2.6.18-rc3-64/arch/x86_64/kernel/ptrace.c
@@ -116,17 +116,17 @@ unsigned long convert_rip_to_linear(stru
 	return addr;
 }
 
-static int is_at_popf(struct task_struct *child, struct pt_regs *regs)
+static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
 {
 	int i, copied;
-	unsigned char opcode[16];
+	unsigned char opcode[15];
 	unsigned long addr = convert_rip_to_linear(child, regs);
 
 	copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
 	for (i = 0; i < copied; i++) {
 		switch (opcode[i]) {
-		/* popf */
-		case 0x9d:
+		/* popf and iret */
+		case 0x9d: case 0xcf:
 			return 1;
 
 			/* CHECKME: 64 65 */
@@ -189,10 +189,8 @@ static void set_singlestep(struct task_s
 	 * ..but if TF is changed by the instruction we will trace,
 	 * don't mark it as being "us" that set it, so that we
 	 * won't clear it by hand later.
-	 *
-	 * AK: this is not enough, LAHF and IRET can change TF in user space too.
 	 */
-	if (is_at_popf(child, regs))
+	if (is_setting_trap_flag(child, regs))
 		return;
 
 	child->ptrace |= PT_DTRACE;
-- 
Chuck

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [patch] x86: rename is_at_popf(), add iret to tests and fix insn length
@ 2006-08-02 13:35 Chuck Ebbert
  2006-08-02 22:12 ` Andi Kleen
  0 siblings, 1 reply; 5+ messages in thread
From: Chuck Ebbert @ 2006-08-02 13:35 UTC (permalink / raw)
  To: Andi Kleen; +Cc: Linus Torvalds, linux-kernel, Albert Cahalan

In-Reply-To: <200608021454.33685.ak@suse.de>

On Wed, 2 Aug 2006 14:54:33 +0200. Andi Kleen wrote:

> > is_at_popf() needs to test for the iret instruction as well as
> > popf.  So add that test and rename it to is_setting_trap_flag().
> 
> Do you have a single real example where anybody is actually using IRET
> in user space? 

No, but Albert Cahalan complained so I figured it should be fixed.

-- 
Chuck


^ permalink raw reply	[flat|nested] 5+ messages in thread
[parent not found: <6FokL-6q5-7@gated-at.bofh.it>]

end of thread, other threads:[~2006-08-02 22:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-02 12:37 [patch] x86: rename is_at_popf(), add iret to tests and fix insn length Chuck Ebbert
2006-08-02 12:54 ` Andi Kleen
  -- strict thread matches above, loose matches on Subject: below --
2006-08-02 13:35 Chuck Ebbert
2006-08-02 22:12 ` Andi Kleen
     [not found] <6FokL-6q5-7@gated-at.bofh.it>
     [not found] ` <6Fouu-6Ch-17@gated-at.bofh.it>
2006-08-02 21:29   ` Bodo Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox