Skip to contentSkip to conversation

x86_64: fix is_at_popf() for compat tasks

PATCH Chuck Ebbert 2 participants 2 messages Jul 31, 2006 ptrace support

lore
Share & tools
lore
#0 lore raw

In-Reply-To: <[email protected]>

Quoted 11 lines · Andi Kleen
Quoted 4 lines

When testing for the REX instruction prefix, first check for a 32-bit task because in compat mode the REX prefix is an increment instruction.

is_compat_task doesn't actually say that a task is in compat mode (it refers to the Linux compat layer, not x86-64 compat mode)

A better test would be regs->cs == __USER32_CS, but in theory there could be other code segments in LDT. I guess that can be ignored though.

How about checking for regs->cs != __USER_CS instead? In 64-bit mode a program shouldn't have any other value there while in 32-bit mode it could be using LDT segments.

From: Chuck Ebbert <[email protected]>

When testing for the REX instruction prefix, first check for 32-bit mode because in compat mode the REX prefix is an increment instruction.

arch/x86_64/kernel/ptrace.c +4 -1
@@ -141,8 +141,11 @@ static int is_at_popf(struct task_struct
 		case 0xf0: case 0xf2: case 0xf3:
 			continue;
 
-		/* REX prefixes */
 		case 0x40 ... 0x4f:
+			if (regs->cs != __USER_CS)
+				/* 32-bit mode: register increment */
+				return 0;
+			/* 64-bit mode: REX prefix */
 			continue;
 
 			/* CHECKME: f0, f2, f3 */
Signature · 1 line
Chuck
#1 lore raw
Quoted 4 lines

How about checking for regs->cs != __USER_CS instead? In 64-bit mode a program shouldn't have any other value there while in 32-bit mode it could be using LDT segments.

It could in theory, but it shouldn't agreed. Added thanks. -Andi